Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put this code in a seperate function so we can easily plot individual subtractio... #4

Open
github-actions bot opened this issue May 3, 2024 · 0 comments
Labels

Comments

@github-actions
Copy link

github-actions bot commented May 3, 2024

# TODO Put this code in a seperate function so we can easily plot individual subtractions

                            plot_dir=plot_dir,
                            n_sweeps=before_trace.NofSweeps)

            times = before_trace.get_times()
            voltage = before_trace.get_voltage()
            voltage_protocol = before_trace.get_voltage_protocol()

            voltage_steps = [tstart \
                             for tstart, tend, vstart, vend in
                             voltage_protocol.get_all_sections() if vend == vstart]

            current = hergqc.filter_capacitive_spikes(before_corrected - after_corrected,
                                                      times, voltage_steps)

            row_dict['QC6'] = hergqc.qc6(current,
                                         win=hergqc.qc6_win,
                                         label='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)))

            row_dict['QC4'] = all(hergqc.qc4([rseal_before, rseal_after],
                                             [cm_before, cm_after],
                                             [rseries_before, rseries_after]))

            np.savetxt(out_fname, subtracted_trace.flatten())
            rows.append(row_dict)

            param, leak = fit_linear_leak(current, voltage, times,
                                          *ramp_bounds)

            subtracted_trace = current - leak

            t_step = times[1] - times[0]
            row_dict['total before-drug flux'] = np.sum(current) * (1.0 / t_step)
            res = \
                get_time_constant_of_first_decay(subtracted_trace,
                                                 times, desc, args=args,
                                                 output_path=os.path.join(args.output_dir,
                                                                          'debug', '40mV time constant',
                                                                          f"{savename}-{well}-sweep{sweep}-time-constant-fit.png"))

            row_dict['40mV decay time constant'] = res[0]
            row_dict['40mV peak current'] = res[1]

        before_leak_current_dict[well] = np.vstack(before_leak_currents)
        after_leak_current_dict[well] = np.vstack(after_leak_currents)

    extract_df = pd.DataFrame.from_dict(rows)
    logging.debug(extract_df)

    times = before_trace.get_times()
    voltages = before_trace.get_voltage()

    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()}

    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()}

    # TODO Put this code in a seperate function so we can easily plot individual subtractions

    nsweeps = before_trace.NofSweeps
    for well in selected_wells:
        before_current = before_current_all[well]
        after_current = after_current_all[well]

        before_leak_currents = before_leak_current_dict[well]
        after_leak_currents = after_leak_current_dict[well]

        nsweeps = before_current_all[well].shape[0]

        sub_df = extract_df[extract_df.well == well]

        if len(sub_df.index):
            continue

        sweeps = sorted(list(sub_df.sweep.unique()))
        sub_df = sub_df.set_index('sweep')
        logging.debug(sub_df)

        do_subtraction_plot(fig, times, sweeps, before_current, after_current,
                            extract_df, voltages, well=well)

        fig.savefig(os.path.join(subtraction_plots_dir,
                                 f"{saveID}-{savename}-{well}-sweep{sweep}-subtraction"))
@github-actions github-actions bot added the todo label May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

0 participants