Skip to content

Commit

Permalink
update export plots
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Shuttleworth committed May 3, 2024
1 parent b137a97 commit cd60bd2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
30 changes: 24 additions & 6 deletions scripts/run_herg_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,7 @@ def get_time_constant_of_first_decay(trace, times, protocol_desc, args, output_p
peak_time = times[indices[peak_index]]

indices = np.argwhere((times >= peak_time) & (times <= tend - 50))
print(indices)

def fit_func(x):
a, b, c = x
Expand Down Expand Up @@ -1109,16 +1110,33 @@ def fit_func(x):

res = best_res

if not res:
logging.warning('finding 40mv decay timeconstant failed:' + str(res))

if output_path and res:
fig = plt.figure(figsize=args.figsize)
ax = fig.subplots()
fig = plt.figure(figsize=args.figsize, constrained_layout=True)
axs = fig.subplots(2)

for ax in axs:
ax.spines[['top', 'right']].set_visible(False)
ax.set_ylabel(r'$I_\text{obs}$ (pA)')
ax.set_xlabel(r'$t$ (ms)')

protocol_ax, fit_ax = axs
protocol_ax.set_title('a', fontweight='bold')
fit_ax.set_title('b', fontweight='bold')
fit_ax.plot(peak_time, tend-50, alpha=.5)

ax.plot(times[indices], trace[indices], color='grey', alpha=.5)
a, b, c = res.x
ax.plot(times[indices], c + a * np.exp(-(1.0/b) * (times[indices] - peak_time)),
color='red', linestyle='--')
fit_ax.plot(times[indices], c + a * np.exp(-(1.0/b) * (times[indices] - peak_time)),
color='red', linestyle='--')

res_string = r'$\tau_{40\text{mV}} = ' f"{b:.1f}" r'\text{ms}$'
fit_ax.annotate(res_string, xy=(0.5, 0.05), xycoords='axes fraction')

protocol_ax.plot(times, trace)
# protocol_ax.axvspan(peak_time, tend - 50, alpha=.5, color='grey')

ax.set_title(f"timescale {b}ms")
fig.savefig(output_path)
plt.close(fig)

Expand Down
21 changes: 13 additions & 8 deletions scripts/summarise_herg_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ def do_chronological_plots(df, normalise=False):
'E_leak_after', 'E_rev', 'pre-drug leak magnitude',
'post-drug leak magnitude',
'E_rev_before', 'Cm', 'Rseries',
'40mV decay time constant']
'40mV decay time constant',
'40mV peak current']

# df = df[leak_parameters_df['selected']]
df = df[df['passed QC']].copy()
Expand All @@ -202,20 +203,24 @@ def do_chronological_plots(df, normalise=False):
# 'E_leak_after':,
# 'E_leak_before':,
'pre-drug leak magnitude': 'pA',
'40mV_decay_time_constant': 'ms'
'40mV decay time constant': 'ms',
'40mV peak current': 'pA'
}

pretty_vars = {
'pre-drug leak magnitude': r'$\bar{I}_\text{l}$',
'pre-drug leak magnitude': r'$\tau_{40\textrm{mV}}$'
'40mV decay time constant': r'$\tau_{40\text{mV}}$',
'40mV peak current': r'$I_\text{peak}$'
}

def label_func(p, s):
p = p[1:-1]
return r'$' + str(p) + r'^{(' + str(s) + r')}$'

for var in vars:
df['x'] = df.protocol.astype(str) + '_' + df.sweep.astype(str)
sns.scatterplot(data=df, x='x', y=var, hue='passed QC', ax=ax,
hue_order=[False, True])
sns.lineplot(data=df, x='x', y=var, hue='passed QC', ax=ax, style='well', legend=True,
legend_kws={'fontsize': 12})
df['x'] = [label_func(p, s) for p, s in zip(df.protocol, df.sweep)]
sns.lineplot(data=df, x='x', y=var, hue='well', style='well', ax=ax,
legend=True)

if var == 'E_rev' and np.isfinite(args.reversal):
ax.axhline(args.reversal, linestyle='--', color='grey', label='Calculated Nernst potential')
Expand Down

0 comments on commit cd60bd2

Please sign in to comment.