Skip to content

Commit

Permalink
#21 Update calls to hergQC methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kwabenantim committed Aug 12, 2024
1 parent 2f56479 commit fa8644d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
6 changes: 4 additions & 2 deletions pcpostprocess/hergQC.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import logging
import os

from collections import OrderedDict

import matplotlib.pyplot as plt
import numpy as np
import scipy.stats
Expand Down Expand Up @@ -123,7 +125,7 @@ def run_qc(self, voltage_steps, times,
before = self.filter_capacitive_spikes(before, times, voltage_steps)
after = self.filter_capacitive_spikes(after, times, voltage_steps)

QC = {label: [(False, None)] for label in self.qc_labels}
QC = OrderedDict([(label, [(False, None)]) for label in self.qc_labels])

if len(before) == 0 or len(after) == 0:
return QC
Expand Down Expand Up @@ -213,7 +215,7 @@ def run_qc(self, voltage_steps, times,
plt.ylabel('Current [pA]')

# https://stackoverflow.com/a/13589144
from collections import OrderedDict # fix legend labels
# fix legend labels
handles, labels = plt.gca().get_legend_handles_labels()
by_label = OrderedDict(zip(labels, handles))
fig.legend(by_label.values(), by_label.keys())
Expand Down
20 changes: 12 additions & 8 deletions pcpostprocess/scripts/run_herg_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,18 +701,22 @@ def extract_protocol(readname, savename, time_strs, selected_wells, args):

row_dict['QC6'] = hergqc.qc6(current,
win=hergqc.qc6_win,
label='0')
label='0')[0]

#  Assume there is only one sweep for all non-QC protocols
rseal_before, cm_before, rseries_before = qc_before[well][0]
rseal_after, cm_after, rseries_after = qc_after[well][0]

row_dict['QC1'] = all(list(hergqc.qc1(rseal_before, cm_before, rseries_before)) +
list(hergqc.qc1(rseal_after, cm_after, rseries_after)))
qc1_1 = hergqc.qc1(rseal_before, cm_before, rseries_before)
qc1_2 = hergqc.qc1(rseal_after, cm_after, rseries_after)

row_dict['QC4'] = all(hergqc.qc4([rseal_before, rseal_after],
[cm_before, cm_after],
[rseries_before, rseries_after]))
row_dict['QC1'] = all([x for x, _ in qc1_1 + qc1_2])

qc4 = hergqc.qc4([rseal_before, rseal_after],
[cm_before, cm_after],
[rseries_before, rseries_after])

row_dict['QC4'] = all([x for x, _ in qc4])

if args.output_traces:
out_fname = os.path.join(traces_dir,
Expand Down Expand Up @@ -935,7 +939,7 @@ def run_qc_for_protocol(readname, savename, time_strs, args):
np.array(qc_before[well])[0, :],
np.array(qc_after[well])[0, :], nsweeps)

df_rows.append([well] + list(QC))
df_rows.append([well] + [all([x for x, _ in qc]) for qc in QC.values()])

if selected:
selected_wells.append(well)
Expand Down Expand Up @@ -1086,7 +1090,7 @@ def qc3_bookend(readname, savename, time_strs, args):
last_processed[well], times, voltage_steps
).flatten()

passed = hergqc.qc3(trace1, trace2)
passed = hergqc.qc3(trace1, trace2)[0]

res_dict[well] = passed

Expand Down
4 changes: 2 additions & 2 deletions tests/test_herg_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ def test_run_qc(self):

test_wells = ['A01', 'A02', 'A03', 'A04', 'A05', 'D01']

voltage_protocol = tr_before.get_voltage_protocol()

for well in test_wells:
with self.subTest(well):
voltage_protocol = tr_before.get_voltage_protocol()

# Take values from the first sweep only
qc_vals_before_well = np.array(qc_vals_before[well])[0, :]
qc_vals_after_well = np.array(qc_vals_after[well])[0, :]
Expand Down

0 comments on commit fa8644d

Please sign in to comment.