From af558a77efd22341f7af53c343e3e55c16ada84a Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 5 Aug 2024 12:04:20 +0100 Subject: [PATCH 01/27] Update leak-correction plots --- pcpostprocess/leak_correct.py | 4 ++-- pcpostprocess/scripts/run_herg_qc.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pcpostprocess/leak_correct.py b/pcpostprocess/leak_correct.py index 39dad18..ac542c3 100644 --- a/pcpostprocess/leak_correct.py +++ b/pcpostprocess/leak_correct.py @@ -168,9 +168,9 @@ def fit_linear_leak(current, voltage, times, ramp_start_index, ramp_end_index, I_leak[ramp_start_index:ramp_end_index+1], '--') ax4.plot(times, I_obs, label=r'$I_\mathrm{obs}$') - ax4.plot(times, I_leak, linestyle='--', label=r'$I_\mathrm{l}$') + ax4.plot(times, I_leak, linestyle='--', label=r'$I_\mathrm{L}$') ax4.plot(times, I_obs - I_leak, - linestyle='--', alpha=0.5, label=r'$I_\mathrm{obs} - I_\mathrm{l}$') + linestyle='--', alpha=0.5, label=r'$I_\mathrm{obs} - I_\mathrm{L}$') ax4.legend(frameon=False) if not os.path.exists(output_dir): diff --git a/pcpostprocess/scripts/run_herg_qc.py b/pcpostprocess/scripts/run_herg_qc.py index 237c08e..e67b0a5 100644 --- a/pcpostprocess/scripts/run_herg_qc.py +++ b/pcpostprocess/scripts/run_herg_qc.py @@ -735,7 +735,7 @@ def extract_protocol(readname, savename, time_strs, selected_wells, args): 'debug', '-120mV time constant', f"{savename}-{well}-sweep" - "{sweep}-time-constant-fit.png")) + "{sweep}-time-constant-fit.pdf")) row_dict['-120mV decay time constant 1'] = res[0][0] row_dict['-120mV decay time constant 2'] = res[0][1] @@ -1044,8 +1044,11 @@ def qc3_bookend(readname, savename, time_strs, args): last_before_current = last_before_current_dict[well][-1, :] last_after_current = last_after_current_dict[well][-1, :] + save_fname = os.path.join(output_dir, "leak_correction", f"{well}_{savename}_before0.pdf") + before_traces_first[well] = get_leak_corrected(first_before_current, voltage, times, + save_fname=save_fname, *ramp_bounds) before_traces_last[well] = get_leak_corrected(last_before_current, voltage, times, @@ -1197,11 +1200,12 @@ def fit_func(x, args=None): for ax in axs: ax.spines[['top', 'right']].set_visible(False) ax.set_ylabel(r'$I_\mathrm{obs}$ (pA)') - ax.set_xlabel(r'$t$ (ms)') + + axs[-1].set_xlabel(r'$t$ (ms)') protocol_ax, fit_ax = axs - protocol_ax.set_title('a', fontweight='bold') - fit_ax.set_title('b', fontweight='bold') + protocol_ax.set_title('a', fontweight='bold', loc='left') + fit_ax.set_title('b', fontweight='bold', loc='left') fit_ax.plot(peak_time, peak_current, marker='x', color='red') a, b, c, d = res1.x From fdbf12c73f36480bc127816967bc07f5a8f5b649 Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 5 Aug 2024 13:51:42 +0100 Subject: [PATCH 02/27] Fix output --- pcpostprocess/scripts/run_herg_qc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pcpostprocess/scripts/run_herg_qc.py b/pcpostprocess/scripts/run_herg_qc.py index e67b0a5..9eaff94 100644 --- a/pcpostprocess/scripts/run_herg_qc.py +++ b/pcpostprocess/scripts/run_herg_qc.py @@ -1044,7 +1044,8 @@ def qc3_bookend(readname, savename, time_strs, args): last_before_current = last_before_current_dict[well][-1, :] last_after_current = last_after_current_dict[well][-1, :] - save_fname = os.path.join(output_dir, "leak_correction", f"{well}_{savename}_before0.pdf") + save_fname = os.path.join(args.output_dir, "leak_correction", + f"{well}_{savename}_before0.pdf") before_traces_first[well] = get_leak_corrected(first_before_current, voltage, times, From 942e723bc1e05813794fdd0075691f7d66d130f8 Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 5 Aug 2024 15:27:22 +0100 Subject: [PATCH 03/27] Fix plots --- pcpostprocess/scripts/run_herg_qc.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pcpostprocess/scripts/run_herg_qc.py b/pcpostprocess/scripts/run_herg_qc.py index 9eaff94..70220d3 100644 --- a/pcpostprocess/scripts/run_herg_qc.py +++ b/pcpostprocess/scripts/run_herg_qc.py @@ -1044,12 +1044,13 @@ def qc3_bookend(readname, savename, time_strs, args): last_before_current = last_before_current_dict[well][-1, :] last_after_current = last_after_current_dict[well][-1, :] - save_fname = os.path.join(args.output_dir, "leak_correction", - f"{well}_{savename}_before0.pdf") + output_directory = os.path.join(args.output_dir, "leak_correction") + save_fname = f"{well}_{savename}_before0.pdf" before_traces_first[well] = get_leak_corrected(first_before_current, voltage, times, save_fname=save_fname, + output_directory=save_fname, *ramp_bounds) before_traces_last[well] = get_leak_corrected(last_before_current, voltage, times, From addc6c1c2a8abb01e25027a506a33073dbbb2024 Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 5 Aug 2024 16:24:15 +0100 Subject: [PATCH 04/27] Fix plots --- pcpostprocess/scripts/run_herg_qc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pcpostprocess/scripts/run_herg_qc.py b/pcpostprocess/scripts/run_herg_qc.py index 70220d3..76918a5 100644 --- a/pcpostprocess/scripts/run_herg_qc.py +++ b/pcpostprocess/scripts/run_herg_qc.py @@ -1050,7 +1050,7 @@ def qc3_bookend(readname, savename, time_strs, args): before_traces_first[well] = get_leak_corrected(first_before_current, voltage, times, save_fname=save_fname, - output_directory=save_fname, + output_dur=output_directory, *ramp_bounds) before_traces_last[well] = get_leak_corrected(last_before_current, voltage, times, From c6f601a2aaa9f6239d5f84591143cebbc2aff28a Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 5 Aug 2024 16:26:40 +0100 Subject: [PATCH 05/27] Fix typo --- pcpostprocess/scripts/run_herg_qc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pcpostprocess/scripts/run_herg_qc.py b/pcpostprocess/scripts/run_herg_qc.py index 76918a5..5d925fa 100644 --- a/pcpostprocess/scripts/run_herg_qc.py +++ b/pcpostprocess/scripts/run_herg_qc.py @@ -1050,7 +1050,7 @@ def qc3_bookend(readname, savename, time_strs, args): before_traces_first[well] = get_leak_corrected(first_before_current, voltage, times, save_fname=save_fname, - output_dur=output_directory, + output_dirr=output_directory, *ramp_bounds) before_traces_last[well] = get_leak_corrected(last_before_current, voltage, times, From 223fea0678974b32687ba5f72a4e5ec8ac812df0 Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 5 Aug 2024 16:28:20 +0100 Subject: [PATCH 06/27] Fix typo --- pcpostprocess/scripts/run_herg_qc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pcpostprocess/scripts/run_herg_qc.py b/pcpostprocess/scripts/run_herg_qc.py index 5d925fa..b3bc6a5 100644 --- a/pcpostprocess/scripts/run_herg_qc.py +++ b/pcpostprocess/scripts/run_herg_qc.py @@ -1050,7 +1050,7 @@ def qc3_bookend(readname, savename, time_strs, args): before_traces_first[well] = get_leak_corrected(first_before_current, voltage, times, save_fname=save_fname, - output_dirr=output_directory, + output_dir=output_directory, *ramp_bounds) before_traces_last[well] = get_leak_corrected(last_before_current, voltage, times, From 16a60168598ba4d9eb06d55350ee227634d96452 Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 5 Aug 2024 16:49:07 +0100 Subject: [PATCH 07/27] Tidy up subtraction plots --- pcpostprocess/scripts/run_herg_qc.py | 12 +++++------- pcpostprocess/subtraction_plots.py | 16 +++++++++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/pcpostprocess/scripts/run_herg_qc.py b/pcpostprocess/scripts/run_herg_qc.py index b3bc6a5..2d78ffe 100644 --- a/pcpostprocess/scripts/run_herg_qc.py +++ b/pcpostprocess/scripts/run_herg_qc.py @@ -755,11 +755,8 @@ def extract_protocol(readname, savename, time_strs, selected_wells, args): after_current_all = after_trace.get_trace_sweeps() # Convert everything to nA... - before_current_all = {key: value * 1e-3 for key, value in before_current_all.items()} - after_current_all = {key: value * 1e-3 for key, value in after_current_all.items()} - - before_leak_current_dict = {key: value * 1e-3 for key, value in before_leak_current_dict.items()} - after_leak_current_dict = {key: value * 1e-3 for key, value in after_leak_current_dict.items()} + # before_current_all = {key: value * 1e-3 for key, value in before_current_all.items()} + # after_current_all = {key: value * 1e-3 for key, value in after_current_all.items()} for well in selected_wells: before_current = before_current_all[well] @@ -1049,9 +1046,10 @@ def qc3_bookend(readname, savename, time_strs, args): before_traces_first[well] = get_leak_corrected(first_before_current, voltage, times, + *ramp_bounds save_fname=save_fname, - output_dir=output_directory, - *ramp_bounds) + output_dir=output_directory) + before_traces_last[well] = get_leak_corrected(last_before_current, voltage, times, *ramp_bounds) diff --git a/pcpostprocess/subtraction_plots.py b/pcpostprocess/subtraction_plots.py index 941c658..e0f6c88 100644 --- a/pcpostprocess/subtraction_plots.py +++ b/pcpostprocess/subtraction_plots.py @@ -26,6 +26,9 @@ def setup_subtraction_grid(fig, nsweeps): # Long axis for protocol on the bottom (full width) long_protocol_ax = fig.add_subplot(gs[5, :]) + for ax in list(protocol_axs) + list(before_axs) + list(after_axs) + list(corrected_axs) + [subtracted_ax]: + ax.spines[['top', 'right']].set_visible(False) + return protocol_axs, before_axs, after_axs, corrected_axs, subtracted_ax, long_protocol_ax @@ -39,10 +42,13 @@ def do_subtraction_plot(fig, times, sweeps, before_currents, after_currents, protocol_axs, before_axs, after_axs, corrected_axs, \ subtracted_ax, long_protocol_ax = axs + # Convert times from ms to s + times = times * 1e-3 + for ax in protocol_axs: ax.plot(times, voltages, color='black') ax.set_xlabel('time (s)') - ax.set_ylabel(r'$V_\mathrm{command}$ (mV)') + ax.set_ylabel(r'$V_\mathrm{cmd}$ (mV)') all_leak_params_before = [] all_leak_params_after = [] @@ -72,7 +78,7 @@ def do_subtraction_plot(fig, times, sweeps, before_currents, after_currents, gleak, Eleak = all_leak_params_before[i] ax.plot(times, before_currents[i, :], label=f"pre-drug raw, sweep {sweep}") ax.plot(times, before_leak_currents[i, :], - label=r'$I_\mathrm{leak}$.' f"g={gleak:1E}, E={Eleak:.1e}") + label=r'$I_\mathrm{L}$.' f"g={gleak:1E}, E={Eleak:.1e}") # ax.legend() if ax.get_legend(): @@ -86,7 +92,7 @@ def do_subtraction_plot(fig, times, sweeps, before_currents, after_currents, gleak, Eleak = all_leak_params_before[i] ax.plot(times, after_currents[i, :], label=f"post-drug raw, sweep {sweep}") ax.plot(times, after_leak_currents[i, :], - label=r"$I_\mathrm{leak}$." f"g={gleak:1E}, E={Eleak:.1e}") + label=r"$I_\mathrm{L}$." f"g={gleak:1E}, E={Eleak:.1e}") # ax.legend() if ax.get_legend(): ax.get_legend().remove() @@ -120,11 +126,11 @@ def do_subtraction_plot(fig, times, sweeps, before_currents, after_currents, (after_currents[i, :] - after_leak_currents[i, :]) ax.plot(times, subtracted_currents, label=f"sweep {sweep}") - ax.set_ylabel(r'$I_\mathrm{obs} - I_\mathrm{l}$ (mV)') + ax.set_ylabel(r'$I_\mathrm{obs} - I_\mathrm{L}$ (mV)') ax.set_xlabel('$t$ (s)') long_protocol_ax.plot(times, voltages, color='black') long_protocol_ax.set_xlabel('time (s)') - long_protocol_ax.set_ylabel(r'$V_\mathrm{command}$ (mV)') + long_protocol_ax.set_ylabel(r'$V_\mathrm{cmd}$ (mV)') long_protocol_ax.tick_params(axis='y', rotation=90) From fcfe79b20545d9f2fb408851a5a7d90284bb2ec4 Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 5 Aug 2024 16:49:48 +0100 Subject: [PATCH 08/27] Typo --- pcpostprocess/scripts/run_herg_qc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pcpostprocess/scripts/run_herg_qc.py b/pcpostprocess/scripts/run_herg_qc.py index 2d78ffe..14aeb9d 100644 --- a/pcpostprocess/scripts/run_herg_qc.py +++ b/pcpostprocess/scripts/run_herg_qc.py @@ -1046,7 +1046,7 @@ def qc3_bookend(readname, savename, time_strs, args): before_traces_first[well] = get_leak_corrected(first_before_current, voltage, times, - *ramp_bounds + *ramp_bounds, save_fname=save_fname, output_dir=output_directory) From 13d6ea1b1a404ccc1eee501295f059c4b68f7647 Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 5 Aug 2024 17:05:50 +0100 Subject: [PATCH 09/27] Fix subtraction plots --- pcpostprocess/scripts/run_herg_qc.py | 8 ++++++++ pcpostprocess/subtraction_plots.py | 13 ++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pcpostprocess/scripts/run_herg_qc.py b/pcpostprocess/scripts/run_herg_qc.py index 14aeb9d..9882e90 100644 --- a/pcpostprocess/scripts/run_herg_qc.py +++ b/pcpostprocess/scripts/run_herg_qc.py @@ -1044,12 +1044,20 @@ def qc3_bookend(readname, savename, time_strs, args): output_directory = os.path.join(args.output_dir, "leak_correction") save_fname = f"{well}_{savename}_before0.pdf" + # Plot subtraction + get_leak_corrected(first_before_current*1e3, + voltage, times, + *ramp_bounds, + save_fname=save_fname, + output_dir=output_directory) + before_traces_first[well] = get_leak_corrected(first_before_current, voltage, times, *ramp_bounds, save_fname=save_fname, output_dir=output_directory) + before_traces_last[well] = get_leak_corrected(last_before_current, voltage, times, *ramp_bounds) diff --git a/pcpostprocess/subtraction_plots.py b/pcpostprocess/subtraction_plots.py index e0f6c88..051c4e1 100644 --- a/pcpostprocess/subtraction_plots.py +++ b/pcpostprocess/subtraction_plots.py @@ -26,7 +26,7 @@ def setup_subtraction_grid(fig, nsweeps): # Long axis for protocol on the bottom (full width) long_protocol_ax = fig.add_subplot(gs[5, :]) - for ax in list(protocol_axs) + list(before_axs) + list(after_axs) + list(corrected_axs) + [subtracted_ax]: + for ax in list(protocol_axs) + list(before_axs) + list(after_axs) + list(corrected_axs) + [subtracted_ax] + [long_protocol_ax]: ax.spines[['top', 'right']].set_visible(False) return protocol_axs, before_axs, after_axs, corrected_axs, subtracted_ax, long_protocol_ax @@ -105,11 +105,11 @@ def do_subtraction_plot(fig, times, sweeps, before_currents, after_currents, corrected_before_currents = before_currents[i, :] - before_leak_currents[i, :] corrected_after_currents = after_currents[i, :] - after_leak_currents[i, :] ax.plot(times, corrected_before_currents, - label=f"leak corrected before drug trace, sweep {sweep}") + label=f"leak-corrected pre-drug trace, sweep {sweep}") ax.plot(times, corrected_after_currents, - label=f"leak corrected after drug trace, sweep {sweep}") + label=f"leak-corrected post-drug trace, sweep {sweep}") ax.set_xlabel(r'$t$ (s)') - ax.set_ylabel(r'leak corrected traces') + ax.set_ylabel(r'leak-corrected traces') # ax.tick_params(axis='y', rotation=90) # ax.yaxis.set_major_formatter(mtick.FormatStrFormatter('%.1e')) @@ -124,7 +124,10 @@ def do_subtraction_plot(fig, times, sweeps, before_currents, after_currents, subtracted_currents = before_currents[i, :] - before_leak_currents[i, :] - \ (after_currents[i, :] - after_leak_currents[i, :]) - ax.plot(times, subtracted_currents, label=f"sweep {sweep}") + ax.plot(times, subtracted_currents, label=f"sweep {sweep}", alpha=.5) + + # Cycle to next colour + ax.plot([np.nan], [np.nan], label=f"sweep {sweep}", alpha=.5) ax.set_ylabel(r'$I_\mathrm{obs} - I_\mathrm{L}$ (mV)') ax.set_xlabel('$t$ (s)') From c08f5e13ed916b5942b94f1b56a96e85edd186b0 Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 5 Aug 2024 17:22:51 +0100 Subject: [PATCH 10/27] Fix plots --- pcpostprocess/scripts/run_herg_qc.py | 8 ++++---- pcpostprocess/subtraction_plots.py | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pcpostprocess/scripts/run_herg_qc.py b/pcpostprocess/scripts/run_herg_qc.py index 9882e90..4a21703 100644 --- a/pcpostprocess/scripts/run_herg_qc.py +++ b/pcpostprocess/scripts/run_herg_qc.py @@ -772,7 +772,7 @@ def extract_protocol(readname, savename, time_strs, selected_wells, args): sweeps = sorted(list(sub_df.sweep.unique())) - do_subtraction_plot(fig, times, sweeps, before_current, after_current, + do_subtraction_plot(fig, times, sweeps, before_current*1e3, after_current, voltages, ramp_bounds, well=well, protocol=savename) @@ -1069,9 +1069,9 @@ def qc3_bookend(readname, savename, time_strs, args): voltage, times, *ramp_bounds) - # Store subtracted traces - first_processed[well] = before_traces_first[well] - after_traces_first[well] - last_processed[well] = before_traces_last[well] - after_traces_last[well] + # Store subtracted traces (converted to nA) + first_processed[well] = (before_traces_first[well] - after_traces_first[well]) * 1e-3 + last_processed[well] = (before_traces_last[well] - after_traces_last[well]) * 1e-3 voltage_protocol = VoltageProtocol.from_voltage_trace(voltage, times) diff --git a/pcpostprocess/subtraction_plots.py b/pcpostprocess/subtraction_plots.py index 051c4e1..b78efd4 100644 --- a/pcpostprocess/subtraction_plots.py +++ b/pcpostprocess/subtraction_plots.py @@ -26,8 +26,9 @@ def setup_subtraction_grid(fig, nsweeps): # Long axis for protocol on the bottom (full width) long_protocol_ax = fig.add_subplot(gs[5, :]) - for ax in list(protocol_axs) + list(before_axs) + list(after_axs) + list(corrected_axs) + [subtracted_ax] + [long_protocol_ax]: + for ax, cap in zip(list(protocol_axs) + list(before_axs) + list(after_axs) + list(corrected_axs) + [subtracted_ax] + [long_protocol_ax], 'abcdefghijklm'): ax.spines[['top', 'right']].set_visible(False) + ax.set_title(cap, loc='left', fontweight='bold') return protocol_axs, before_axs, after_axs, corrected_axs, subtracted_ax, long_protocol_ax From e072be395f65c324ee96dc0eff58725e6e7d187e Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 5 Aug 2024 17:31:08 +0100 Subject: [PATCH 11/27] Fix unit conversions --- pcpostprocess/scripts/run_herg_qc.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pcpostprocess/scripts/run_herg_qc.py b/pcpostprocess/scripts/run_herg_qc.py index 4a21703..bf58e6a 100644 --- a/pcpostprocess/scripts/run_herg_qc.py +++ b/pcpostprocess/scripts/run_herg_qc.py @@ -929,8 +929,8 @@ def run_qc_for_protocol(readname, savename, time_strs, args): selected, QC = hergqc.run_qc(voltage_steps, times, before_currents, after_currents, - np.array(qc_before[well])[0, :], - np.array(qc_after[well])[0, :], nsweeps) + np.array(qc_before[well])[0, :] * 1e-3, + np.array(qc_after[well])[0, :] * 1e-3, nsweeps) df_rows.append([well] + list(QC)) @@ -1069,9 +1069,9 @@ def qc3_bookend(readname, savename, time_strs, args): voltage, times, *ramp_bounds) - # Store subtracted traces (converted to nA) - first_processed[well] = (before_traces_first[well] - after_traces_first[well]) * 1e-3 - last_processed[well] = (before_traces_last[well] - after_traces_last[well]) * 1e-3 + # Store subtracted traces + first_processed[well] = (before_traces_first[well] - after_traces_first[well]) + last_processed[well] = (before_traces_last[well] - after_traces_last[well]) voltage_protocol = VoltageProtocol.from_voltage_trace(voltage, times) @@ -1097,7 +1097,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 *1e-3, trace2*1e-3) res_dict[well] = passed From 795566b1c12427dfd0b79ad993633b8ba4802aec Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 5 Aug 2024 18:10:44 +0100 Subject: [PATCH 12/27] Fix units --- pcpostprocess/scripts/run_herg_qc.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pcpostprocess/scripts/run_herg_qc.py b/pcpostprocess/scripts/run_herg_qc.py index bf58e6a..1da5fe7 100644 --- a/pcpostprocess/scripts/run_herg_qc.py +++ b/pcpostprocess/scripts/run_herg_qc.py @@ -772,7 +772,7 @@ def extract_protocol(readname, savename, time_strs, selected_wells, args): sweeps = sorted(list(sub_df.sweep.unique())) - do_subtraction_plot(fig, times, sweeps, before_current*1e3, after_current, + do_subtraction_plot(fig, times, sweeps, before_current, after_current, voltages, ramp_bounds, well=well, protocol=savename) @@ -929,8 +929,8 @@ def run_qc_for_protocol(readname, savename, time_strs, args): selected, QC = hergqc.run_qc(voltage_steps, times, before_currents, after_currents, - np.array(qc_before[well])[0, :] * 1e-3, - np.array(qc_after[well])[0, :] * 1e-3, nsweeps) + np.array(qc_before[well])[0, :], + np.array(qc_after[well])[0, :], nsweeps) df_rows.append([well] + list(QC)) @@ -1045,7 +1045,7 @@ def qc3_bookend(readname, savename, time_strs, args): save_fname = f"{well}_{savename}_before0.pdf" # Plot subtraction - get_leak_corrected(first_before_current*1e3, + get_leak_corrected(first_before_current, voltage, times, *ramp_bounds, save_fname=save_fname, From 116cbb5c0284007a708c98137a8105e49a402ffa Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 5 Aug 2024 18:35:50 +0100 Subject: [PATCH 13/27] Scale up current in plot --- pcpostprocess/scripts/run_herg_qc.py | 2 +- pcpostprocess/subtraction_plots.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pcpostprocess/scripts/run_herg_qc.py b/pcpostprocess/scripts/run_herg_qc.py index 1da5fe7..ec0f2d6 100644 --- a/pcpostprocess/scripts/run_herg_qc.py +++ b/pcpostprocess/scripts/run_herg_qc.py @@ -1097,7 +1097,7 @@ def qc3_bookend(readname, savename, time_strs, args): last_processed[well], times, voltage_steps ).flatten() - passed = hergqc.qc3(trace1 *1e-3, trace2*1e-3) + passed = hergqc.qc3(trace1, trace2) res_dict[well] = passed diff --git a/pcpostprocess/subtraction_plots.py b/pcpostprocess/subtraction_plots.py index b78efd4..b3065ba 100644 --- a/pcpostprocess/subtraction_plots.py +++ b/pcpostprocess/subtraction_plots.py @@ -39,6 +39,9 @@ def do_subtraction_plot(fig, times, sweeps, before_currents, after_currents, nsweeps = before_currents.shape[0] sweeps = list(range(nsweeps)) + before_currents = before_currents * 1e3 + after_currents = after_currents * 1e3 + axs = setup_subtraction_grid(fig, nsweeps) protocol_axs, before_axs, after_axs, corrected_axs, \ subtracted_ax, long_protocol_ax = axs From 04ca9420aa8a76e14b33c42d245e5b042d798b45 Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 5 Aug 2024 18:40:01 +0100 Subject: [PATCH 14/27] Fix plots --- pcpostprocess/subtraction_plots.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/pcpostprocess/subtraction_plots.py b/pcpostprocess/subtraction_plots.py index b3065ba..b5dfe9b 100644 --- a/pcpostprocess/subtraction_plots.py +++ b/pcpostprocess/subtraction_plots.py @@ -46,11 +46,8 @@ def do_subtraction_plot(fig, times, sweeps, before_currents, after_currents, protocol_axs, before_axs, after_axs, corrected_axs, \ subtracted_ax, long_protocol_ax = axs - # Convert times from ms to s - times = times * 1e-3 - for ax in protocol_axs: - ax.plot(times, voltages, color='black') + ax.plot(times*1e-3, voltages, color='black') ax.set_xlabel('time (s)') ax.set_ylabel(r'$V_\mathrm{cmd}$ (mV)') @@ -80,8 +77,8 @@ def do_subtraction_plot(fig, times, sweeps, before_currents, after_currents, for i, (sweep, ax) in enumerate(zip(sweeps, before_axs)): gleak, Eleak = all_leak_params_before[i] - ax.plot(times, before_currents[i, :], label=f"pre-drug raw, sweep {sweep}") - ax.plot(times, before_leak_currents[i, :], + ax.plot(times*1e-3, before_currents[i, :], label=f"pre-drug raw, sweep {sweep}") + ax.plot(times*1e-3, before_leak_currents[i, :], label=r'$I_\mathrm{L}$.' f"g={gleak:1E}, E={Eleak:.1e}") # ax.legend() @@ -94,8 +91,8 @@ def do_subtraction_plot(fig, times, sweeps, before_currents, after_currents, for i, (sweep, ax) in enumerate(zip(sweeps, after_axs)): gleak, Eleak = all_leak_params_before[i] - ax.plot(times, after_currents[i, :], label=f"post-drug raw, sweep {sweep}") - ax.plot(times, after_leak_currents[i, :], + ax.plot(times*1e-3, after_currents[i, :], label=f"post-drug raw, sweep {sweep}") + ax.plot(times*1e-3, after_leak_currents[i, :], label=r"$I_\mathrm{L}$." f"g={gleak:1E}, E={Eleak:.1e}") # ax.legend() if ax.get_legend(): @@ -108,9 +105,9 @@ def do_subtraction_plot(fig, times, sweeps, before_currents, after_currents, for i, (sweep, ax) in enumerate(zip(sweeps, corrected_axs)): corrected_before_currents = before_currents[i, :] - before_leak_currents[i, :] corrected_after_currents = after_currents[i, :] - after_leak_currents[i, :] - ax.plot(times, corrected_before_currents, + ax.plot(times*1e-3, corrected_before_currents, label=f"leak-corrected pre-drug trace, sweep {sweep}") - ax.plot(times, corrected_after_currents, + ax.plot(times*1e-3, corrected_after_currents, label=f"leak-corrected post-drug trace, sweep {sweep}") ax.set_xlabel(r'$t$ (s)') ax.set_ylabel(r'leak-corrected traces') @@ -128,7 +125,7 @@ def do_subtraction_plot(fig, times, sweeps, before_currents, after_currents, subtracted_currents = before_currents[i, :] - before_leak_currents[i, :] - \ (after_currents[i, :] - after_leak_currents[i, :]) - ax.plot(times, subtracted_currents, label=f"sweep {sweep}", alpha=.5) + ax.plot(times*1e-3, subtracted_currents, label=f"sweep {sweep}", alpha=.5) # Cycle to next colour ax.plot([np.nan], [np.nan], label=f"sweep {sweep}", alpha=.5) @@ -136,7 +133,7 @@ def do_subtraction_plot(fig, times, sweeps, before_currents, after_currents, ax.set_ylabel(r'$I_\mathrm{obs} - I_\mathrm{L}$ (mV)') ax.set_xlabel('$t$ (s)') - long_protocol_ax.plot(times, voltages, color='black') + long_protocol_ax.plot(times*1e-3, voltages, color='black') long_protocol_ax.set_xlabel('time (s)') long_protocol_ax.set_ylabel(r'$V_\mathrm{cmd}$ (mV)') long_protocol_ax.tick_params(axis='y', rotation=90) From 8106788c390f6404b8234e14c8945d6d38cf675b Mon Sep 17 00:00:00 2001 From: Joseph Date: Tue, 6 Aug 2024 10:24:44 +0100 Subject: [PATCH 15/27] Fix subtraction plots --- pcpostprocess/subtraction_plots.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pcpostprocess/subtraction_plots.py b/pcpostprocess/subtraction_plots.py index b5dfe9b..097679e 100644 --- a/pcpostprocess/subtraction_plots.py +++ b/pcpostprocess/subtraction_plots.py @@ -39,8 +39,8 @@ def do_subtraction_plot(fig, times, sweeps, before_currents, after_currents, nsweeps = before_currents.shape[0] sweeps = list(range(nsweeps)) - before_currents = before_currents * 1e3 - after_currents = after_currents * 1e3 + before_currents = before_currents + after_currents = after_currents axs = setup_subtraction_grid(fig, nsweeps) protocol_axs, before_axs, after_axs, corrected_axs, \ @@ -69,10 +69,15 @@ def do_subtraction_plot(fig, times, sweeps, before_currents, after_currents, np.nan) for i, sweep in enumerate(sweeps): - gleak, Eleak = all_leak_params_before[i] + b0, b1 = all_leak_params_before[i] + gleak = b1 + Eleak = -b2/b1 before_leak_currents[i, :] = gleak * (voltages - Eleak) - gleak, Eleak = all_leak_params_after[i] + b0, b1 = all_leak_params_after[i] + gleak = b1 + Eleak = -b2/b1 + after_leak_currents[i, :] = gleak * (voltages - Eleak) for i, (sweep, ax) in enumerate(zip(sweeps, before_axs)): From a075618246877d1bf513744f8ed2039612eeb3ba Mon Sep 17 00:00:00 2001 From: Joseph Date: Tue, 6 Aug 2024 11:40:42 +0100 Subject: [PATCH 16/27] Fix subtraction plot --- pcpostprocess/subtraction_plots.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pcpostprocess/subtraction_plots.py b/pcpostprocess/subtraction_plots.py index 097679e..a323a8a 100644 --- a/pcpostprocess/subtraction_plots.py +++ b/pcpostprocess/subtraction_plots.py @@ -71,12 +71,12 @@ def do_subtraction_plot(fig, times, sweeps, before_currents, after_currents, b0, b1 = all_leak_params_before[i] gleak = b1 - Eleak = -b2/b1 + Eleak = -b1/b0 before_leak_currents[i, :] = gleak * (voltages - Eleak) b0, b1 = all_leak_params_after[i] gleak = b1 - Eleak = -b2/b1 + Eleak = -b1/b0 after_leak_currents[i, :] = gleak * (voltages - Eleak) From 5490049d443b09165a232c011f75f03f7afc2711 Mon Sep 17 00:00:00 2001 From: Joseph Date: Thu, 8 Aug 2024 10:16:52 +0100 Subject: [PATCH 17/27] Remove pointless file output --- pcpostprocess/scripts/run_herg_qc.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pcpostprocess/scripts/run_herg_qc.py b/pcpostprocess/scripts/run_herg_qc.py index ec0f2d6..ac9faea 100644 --- a/pcpostprocess/scripts/run_herg_qc.py +++ b/pcpostprocess/scripts/run_herg_qc.py @@ -229,10 +229,6 @@ def main(): fout.write(well) fout.write('\n') - logfile = os.path.join(savedir, 'table-%s.txt' % saveID) - with open(logfile, 'a') as f: - f.write('\\end{table}\n') - # Export all protocols savenames, readnames, times_list = [], [], [] for protocol in res_dict: From e5478b53f8c42951a612603adc9bc9074fd3391c Mon Sep 17 00:00:00 2001 From: Joseph Date: Thu, 8 Aug 2024 10:36:24 +0100 Subject: [PATCH 18/27] Modify R leftover handling --- pcpostprocess/scripts/run_herg_qc.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/pcpostprocess/scripts/run_herg_qc.py b/pcpostprocess/scripts/run_herg_qc.py index ac9faea..27e99d2 100644 --- a/pcpostprocess/scripts/run_herg_qc.py +++ b/pcpostprocess/scripts/run_herg_qc.py @@ -197,7 +197,7 @@ def main(): qc_df.to_json(os.path.join(savedir, 'QC-%s.json' % saveID), orient='records') - # Overwrite old files + # Overwrite old file for protocol in list(export_config.D2S_QC.values()): fname = os.path.join(savedir, 'selected-%s-%s.txt' % (saveID, protocol)) with open(fname, 'w') as fout: @@ -666,8 +666,6 @@ def extract_protocol(readname, savename, time_strs, selected_wells, args): row_dict['R_leftover'] =\ np.sqrt(np.sum((after_corrected)**2)/(np.sum(before_corrected**2))) - row_dict['QC.R_leftover'] = row_dict['R_leftover'] < 0.5 - row_dict['E_rev'] = E_rev row_dict['E_rev_before'] = E_rev_before row_dict['E_rev_after'] = E_rev_after @@ -858,11 +856,11 @@ def run_qc_for_protocol(readname, savename, time_strs, args): # Check if any cell first! if (None in qc_before[well][0]) or (None in qc_after[well][0]): - # no_cell = True + no_cell = True continue else: - # no_cell = False + no_cell = False pass nsweeps = before_trace.NofSweeps @@ -914,6 +912,14 @@ def run_qc_for_protocol(readname, savename, time_strs, args): before_currents[sweep, :] = before_raw after_currents[sweep, :] = after_raw + R_leftover = np.full(before_currents.shape[0], np.nan) + + for sweep in range(before_currents.shape[0]): + R_leftover[sweep] = np.sqrt(np.sum((after_currents_corrected[sweep, :])**2)/\ + (np.sum(before_currents_corrected[sweep, :]**2))) + + QC_R_leftover = np.all(R_leftover < 0.5) + logging.info(f"{well} {savename}\n----------") logging.info(f"sampling_rate is {sampling_rate}") @@ -922,14 +928,16 @@ def run_qc_for_protocol(readname, savename, time_strs, args): voltage_protocol.get_all_sections() if vend == vstart] # Run QC with raw currents - selected, QC = hergqc.run_qc(voltage_steps, times, + _, QC = hergqc.run_qc(voltage_steps, times, before_currents, after_currents, np.array(qc_before[well])[0, :], np.array(qc_after[well])[0, :], nsweeps) + QC = list(QC) + [QC_R_leftover] df_rows.append([well] + list(QC)) + selected = QC_R_leftover and np.all(QC) and not no_cell if selected: selected_wells.append(well) @@ -953,7 +961,7 @@ def run_qc_for_protocol(readname, savename, time_strs, args): 'qc2.subtracted', 'qc3.raw', 'qc3.E4031', 'qc3.subtracted', 'qc4.rseal', 'qc4.cm', 'qc4.rseries', 'qc5.staircase', 'qc5.1.staircase', 'qc6.subtracted', 'qc6.1.subtracted', - 'qc6.2.subtracted'] + 'qc6.2.subtracted', 'qc_r_leftover'] df = pd.DataFrame(np.array(df_rows), columns=column_labels) From 235f1a01f8e724518e591622f12ffc4637af861d Mon Sep 17 00:00:00 2001 From: Joseph Date: Thu, 8 Aug 2024 10:51:27 +0100 Subject: [PATCH 19/27] Modify removal duration --- pcpostprocess/hergQC.py | 2 +- pcpostprocess/scripts/run_herg_qc.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pcpostprocess/hergQC.py b/pcpostprocess/hergQC.py index 049e010..06d8c17 100644 --- a/pcpostprocess/hergQC.py +++ b/pcpostprocess/hergQC.py @@ -18,7 +18,7 @@ class hERGQC(object): no_QC = len(QCnames) def __init__(self, sampling_rate=5, plot_dir=None, voltage=np.array([]), - n_sweeps=None, removal_time=2): + n_sweeps=None, removal_time=5): # TODO docstring if plot_dir is not None: diff --git a/pcpostprocess/scripts/run_herg_qc.py b/pcpostprocess/scripts/run_herg_qc.py index 27e99d2..8fc1e59 100644 --- a/pcpostprocess/scripts/run_herg_qc.py +++ b/pcpostprocess/scripts/run_herg_qc.py @@ -861,7 +861,6 @@ def run_qc_for_protocol(readname, savename, time_strs, args): else: no_cell = False - pass nsweeps = before_trace.NofSweeps assert after_trace.NofSweeps == nsweeps @@ -923,7 +922,7 @@ def run_qc_for_protocol(readname, savename, time_strs, args): logging.info(f"{well} {savename}\n----------") logging.info(f"sampling_rate is {sampling_rate}") - voltage_steps = [tstart + voltage_steps = [tend for tstart, tend, vstart, vend in voltage_protocol.get_all_sections() if vend == vstart] From 9ba2d04ddd44ea70df3e0b4f1ba5edfa5a6a2ed7 Mon Sep 17 00:00:00 2001 From: Joseph Date: Thu, 8 Aug 2024 11:00:52 +0100 Subject: [PATCH 20/27] Run QC on leak-corrected traces --- pcpostprocess/scripts/run_herg_qc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pcpostprocess/scripts/run_herg_qc.py b/pcpostprocess/scripts/run_herg_qc.py index 8fc1e59..9e229c7 100644 --- a/pcpostprocess/scripts/run_herg_qc.py +++ b/pcpostprocess/scripts/run_herg_qc.py @@ -928,8 +928,8 @@ def run_qc_for_protocol(readname, savename, time_strs, args): # Run QC with raw currents _, QC = hergqc.run_qc(voltage_steps, times, - before_currents, - after_currents, + before_currents_corrected, + after_currents_corrected, np.array(qc_before[well])[0, :], np.array(qc_after[well])[0, :], nsweeps) From 750f4e67f1b02baf63688ef0acbf5a1aca975161 Mon Sep 17 00:00:00 2001 From: Joseph Date: Thu, 8 Aug 2024 14:07:24 +0100 Subject: [PATCH 21/27] (Revert changes) Apply R_leftover to every trace --- pcpostprocess/scripts/run_herg_qc.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pcpostprocess/scripts/run_herg_qc.py b/pcpostprocess/scripts/run_herg_qc.py index 9e229c7..8620042 100644 --- a/pcpostprocess/scripts/run_herg_qc.py +++ b/pcpostprocess/scripts/run_herg_qc.py @@ -666,6 +666,9 @@ def extract_protocol(readname, savename, time_strs, selected_wells, args): row_dict['R_leftover'] =\ np.sqrt(np.sum((after_corrected)**2)/(np.sum(before_corrected**2))) + QC_R_leftover = np.all(R_leftover < 0.5) + row_dict['QC.R_leftover'] = QC_R_leftover + row_dict['E_rev'] = E_rev row_dict['E_rev_before'] = E_rev_before row_dict['E_rev_after'] = E_rev_after @@ -917,7 +920,6 @@ def run_qc_for_protocol(readname, savename, time_strs, args): R_leftover[sweep] = np.sqrt(np.sum((after_currents_corrected[sweep, :])**2)/\ (np.sum(before_currents_corrected[sweep, :]**2))) - QC_R_leftover = np.all(R_leftover < 0.5) logging.info(f"{well} {savename}\n----------") logging.info(f"sampling_rate is {sampling_rate}") @@ -933,7 +935,7 @@ def run_qc_for_protocol(readname, savename, time_strs, args): np.array(qc_before[well])[0, :], np.array(qc_after[well])[0, :], nsweeps) - QC = list(QC) + [QC_R_leftover] + QC = list(QC) df_rows.append([well] + list(QC)) selected = QC_R_leftover and np.all(QC) and not no_cell @@ -960,7 +962,7 @@ def run_qc_for_protocol(readname, savename, time_strs, args): 'qc2.subtracted', 'qc3.raw', 'qc3.E4031', 'qc3.subtracted', 'qc4.rseal', 'qc4.cm', 'qc4.rseries', 'qc5.staircase', 'qc5.1.staircase', 'qc6.subtracted', 'qc6.1.subtracted', - 'qc6.2.subtracted', 'qc_r_leftover'] + 'qc6.2.subtracted'] df = pd.DataFrame(np.array(df_rows), columns=column_labels) From 29c8f439e918d3089d79b03aaaa2c984609d3522 Mon Sep 17 00:00:00 2001 From: Joseph Date: Thu, 8 Aug 2024 14:15:27 +0100 Subject: [PATCH 22/27] Fix QC_R_leftover --- pcpostprocess/scripts/run_herg_qc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pcpostprocess/scripts/run_herg_qc.py b/pcpostprocess/scripts/run_herg_qc.py index 8620042..6d6009e 100644 --- a/pcpostprocess/scripts/run_herg_qc.py +++ b/pcpostprocess/scripts/run_herg_qc.py @@ -666,7 +666,7 @@ def extract_protocol(readname, savename, time_strs, selected_wells, args): row_dict['R_leftover'] =\ np.sqrt(np.sum((after_corrected)**2)/(np.sum(before_corrected**2))) - QC_R_leftover = np.all(R_leftover < 0.5) + QC_R_leftover = np.all(row_dict['R_leftover'] < 0.5) row_dict['QC.R_leftover'] = QC_R_leftover row_dict['E_rev'] = E_rev @@ -938,7 +938,7 @@ def run_qc_for_protocol(readname, savename, time_strs, args): QC = list(QC) df_rows.append([well] + list(QC)) - selected = QC_R_leftover and np.all(QC) and not no_cell + selected = np.all(QC) and not no_cell if selected: selected_wells.append(well) From 25af1da93ed21cd8bbfe25005695f134acaa4262 Mon Sep 17 00:00:00 2001 From: Joseph Date: Thu, 8 Aug 2024 14:51:27 +0100 Subject: [PATCH 23/27] Lint --- pcpostprocess/scripts/run_herg_qc.py | 14 ++++++-------- pcpostprocess/subtraction_plots.py | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/pcpostprocess/scripts/run_herg_qc.py b/pcpostprocess/scripts/run_herg_qc.py index 6d6009e..ddf4b9a 100644 --- a/pcpostprocess/scripts/run_herg_qc.py +++ b/pcpostprocess/scripts/run_herg_qc.py @@ -917,10 +917,9 @@ def run_qc_for_protocol(readname, savename, time_strs, args): R_leftover = np.full(before_currents.shape[0], np.nan) for sweep in range(before_currents.shape[0]): - R_leftover[sweep] = np.sqrt(np.sum((after_currents_corrected[sweep, :])**2)/\ + R_leftover[sweep] = np.sqrt(np.sum((after_currents_corrected[sweep, :])**2) / (np.sum(before_currents_corrected[sweep, :]**2))) - logging.info(f"{well} {savename}\n----------") logging.info(f"sampling_rate is {sampling_rate}") @@ -930,10 +929,10 @@ def run_qc_for_protocol(readname, savename, time_strs, args): # Run QC with raw currents _, QC = hergqc.run_qc(voltage_steps, times, - before_currents_corrected, - after_currents_corrected, - np.array(qc_before[well])[0, :], - np.array(qc_after[well])[0, :], nsweeps) + before_currents_corrected, + after_currents_corrected, + np.array(qc_before[well])[0, :], + np.array(qc_after[well])[0, :], nsweeps) QC = list(QC) df_rows.append([well] + list(QC)) @@ -1049,7 +1048,7 @@ def qc3_bookend(readname, savename, time_strs, args): output_directory = os.path.join(args.output_dir, "leak_correction") save_fname = f"{well}_{savename}_before0.pdf" - # Plot subtraction + #  Plot subtraction get_leak_corrected(first_before_current, voltage, times, *ramp_bounds, @@ -1062,7 +1061,6 @@ def qc3_bookend(readname, savename, time_strs, args): save_fname=save_fname, output_dir=output_directory) - before_traces_last[well] = get_leak_corrected(last_before_current, voltage, times, *ramp_bounds) diff --git a/pcpostprocess/subtraction_plots.py b/pcpostprocess/subtraction_plots.py index a323a8a..38e84db 100644 --- a/pcpostprocess/subtraction_plots.py +++ b/pcpostprocess/subtraction_plots.py @@ -132,7 +132,7 @@ def do_subtraction_plot(fig, times, sweeps, before_currents, after_currents, (after_currents[i, :] - after_leak_currents[i, :]) ax.plot(times*1e-3, subtracted_currents, label=f"sweep {sweep}", alpha=.5) - # Cycle to next colour + #  Cycle to next colour ax.plot([np.nan], [np.nan], label=f"sweep {sweep}", alpha=.5) ax.set_ylabel(r'$I_\mathrm{obs} - I_\mathrm{L}$ (mV)') From 4a63b6988c2a5c5e45e5fe5ba324b086b53a4448 Mon Sep 17 00:00:00 2001 From: Joseph Date: Thu, 8 Aug 2024 15:25:50 +0100 Subject: [PATCH 24/27] Breakup long line --- pcpostprocess/subtraction_plots.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pcpostprocess/subtraction_plots.py b/pcpostprocess/subtraction_plots.py index 38e84db..cc149fc 100644 --- a/pcpostprocess/subtraction_plots.py +++ b/pcpostprocess/subtraction_plots.py @@ -26,7 +26,10 @@ def setup_subtraction_grid(fig, nsweeps): # Long axis for protocol on the bottom (full width) long_protocol_ax = fig.add_subplot(gs[5, :]) - for ax, cap in zip(list(protocol_axs) + list(before_axs) + list(after_axs) + list(corrected_axs) + [subtracted_ax] + [long_protocol_ax], 'abcdefghijklm'): + for ax, cap in zip(list(protocol_axs) + list(before_axs)\ + + list(after_axs) + list(corrected_axs)\ + + [subtracted_ax] + [long_protocol_ax], + 'abcdefghijklm'): ax.spines[['top', 'right']].set_visible(False) ax.set_title(cap, loc='left', fontweight='bold') From 7106263d53b6d8fd3dd470ee9c15e8e57503e494 Mon Sep 17 00:00:00 2001 From: Joseph Date: Thu, 8 Aug 2024 15:51:14 +0100 Subject: [PATCH 25/27] Fix linting --- pcpostprocess/subtraction_plots.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pcpostprocess/subtraction_plots.py b/pcpostprocess/subtraction_plots.py index cc149fc..bef1216 100644 --- a/pcpostprocess/subtraction_plots.py +++ b/pcpostprocess/subtraction_plots.py @@ -26,8 +26,8 @@ def setup_subtraction_grid(fig, nsweeps): # Long axis for protocol on the bottom (full width) long_protocol_ax = fig.add_subplot(gs[5, :]) - for ax, cap in zip(list(protocol_axs) + list(before_axs)\ - + list(after_axs) + list(corrected_axs)\ + for ax, cap in zip(list(protocol_axs) + list(before_axs) + + list(after_axs) + list(corrected_axs) + [subtracted_ax] + [long_protocol_ax], 'abcdefghijklm'): ax.spines[['top', 'right']].set_visible(False) From 34b7ca7754e1cd93b1e085d5df9d7b0d39b3c4ec Mon Sep 17 00:00:00 2001 From: Joseph Date: Thu, 8 Aug 2024 15:56:10 +0100 Subject: [PATCH 26/27] Update workflow --- .github/workflows/pytest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 76f5fdd..5878ab6 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -27,7 +27,7 @@ jobs: eval `ssh-agent -s` ssh-add - <<< '${{ secrets.syncropatch_export_key }}' python -m pip install --upgrade pip - python -m pip install .[test] + python -m pip install -e .[test] - name: Extract test data run: | wget https://cardiac.nottingham.ac.uk/syncropatch_export/test_data.tar.xz -P tests/ From 5e6ba3ea9f6cb910cecefdf891d9201e3e8e9c80 Mon Sep 17 00:00:00 2001 From: Joseph Date: Thu, 8 Aug 2024 16:23:15 +0100 Subject: [PATCH 27/27] Tidy up commented lines and pointless changes --- pcpostprocess/scripts/run_herg_qc.py | 20 ++++---------------- pcpostprocess/subtraction_plots.py | 3 --- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/pcpostprocess/scripts/run_herg_qc.py b/pcpostprocess/scripts/run_herg_qc.py index ddf4b9a..496c9f2 100644 --- a/pcpostprocess/scripts/run_herg_qc.py +++ b/pcpostprocess/scripts/run_herg_qc.py @@ -197,7 +197,7 @@ def main(): qc_df.to_json(os.path.join(savedir, 'QC-%s.json' % saveID), orient='records') - # Overwrite old file + # Overwrite old files for protocol in list(export_config.D2S_QC.values()): fname = os.path.join(savedir, 'selected-%s-%s.txt' % (saveID, protocol)) with open(fname, 'w') as fout: @@ -751,10 +751,6 @@ def extract_protocol(readname, savename, time_strs, selected_wells, args): before_current_all = before_trace.get_trace_sweeps() after_current_all = after_trace.get_trace_sweeps() - # Convert everything to nA... - # before_current_all = {key: value * 1e-3 for key, value in before_current_all.items()} - # after_current_all = {key: value * 1e-3 for key, value in after_current_all.items()} - for well in selected_wells: before_current = before_current_all[well] after_current = after_current_all[well] @@ -914,12 +910,6 @@ def run_qc_for_protocol(readname, savename, time_strs, args): before_currents[sweep, :] = before_raw after_currents[sweep, :] = after_raw - R_leftover = np.full(before_currents.shape[0], np.nan) - - for sweep in range(before_currents.shape[0]): - R_leftover[sweep] = np.sqrt(np.sum((after_currents_corrected[sweep, :])**2) / - (np.sum(before_currents_corrected[sweep, :]**2))) - logging.info(f"{well} {savename}\n----------") logging.info(f"sampling_rate is {sampling_rate}") @@ -1057,9 +1047,7 @@ def qc3_bookend(readname, savename, time_strs, args): before_traces_first[well] = get_leak_corrected(first_before_current, voltage, times, - *ramp_bounds, - save_fname=save_fname, - output_dir=output_directory) + *ramp_bounds) before_traces_last[well] = get_leak_corrected(last_before_current, voltage, times, @@ -1073,8 +1061,8 @@ def qc3_bookend(readname, savename, time_strs, args): *ramp_bounds) # Store subtracted traces - first_processed[well] = (before_traces_first[well] - after_traces_first[well]) - last_processed[well] = (before_traces_last[well] - after_traces_last[well]) + first_processed[well] = before_traces_first[well] - after_traces_first[well] + last_processed[well] = before_traces_last[well] - after_traces_last[well] voltage_protocol = VoltageProtocol.from_voltage_trace(voltage, times) diff --git a/pcpostprocess/subtraction_plots.py b/pcpostprocess/subtraction_plots.py index bef1216..2f90141 100644 --- a/pcpostprocess/subtraction_plots.py +++ b/pcpostprocess/subtraction_plots.py @@ -42,9 +42,6 @@ def do_subtraction_plot(fig, times, sweeps, before_currents, after_currents, nsweeps = before_currents.shape[0] sweeps = list(range(nsweeps)) - before_currents = before_currents - after_currents = after_currents - axs = setup_subtraction_grid(fig, nsweeps) protocol_axs, before_axs, after_axs, corrected_axs, \ subtracted_ax, long_protocol_ax = axs