AllenInstitute / ipfx

computes intrinsic cell features from intracellular electrophysiology data
https://ipfx.readthedocs.io/en/latest/
Other
27 stars 37 forks source link

Pre- and Post-stimulus baselines should be compared to target voltage #533

Open ru57y34nn opened 3 years ago

ru57y34nn commented 3 years ago

Describe the bug IPFX is not currently considering the taget autobias command voltage when QCing the pre- and post-stimulus baselines, and this is occasionally causing IPFX to fail sweeps that passed in MIES. In certain cases, this has prevented the extraction of certain sets of features.

Currently, IPFX measures the mean pre- and post-stimulus baselines and then gets the absolute difference between them (vm_delta_mv). Any sweeps that have a vm_delta_mv greater than 1 mV are failed during QC. Whereas, MIES first gets the target autobias command voltage for the given sweep and then measures the mean pre- and post-stimulus baselines and gets the absolute difference between the target autobias command voltage and the pre- and post-stimulus baselines independently. This way, MIES is checking that the pre- and post-stimulus baselines are each within 1 mV of the target voltage. The problem with how IPFX is doing this is that the pre- and post-stimulus baselines can each be within 1 mV of the target voltage, while the difference between the pre-and post-stimulus baselines can be greater than 1mV.

Example experiment demonstrating the issue: Cell name: Htr3a-Cre_NO152;Ai14-589339.07.09.03 Path to NWB file: \allen\programs\celltypes\production\mousecelltypes\prod3258\Ephys_Roi_Result_1121464496\ (See attached image: Htr3-Cre_NO152;Ai14-589339.07.09.03_baseline_issue)

Htr3-Cre_NO152;Ai14-589339 07 09 03_baseline_issue

Sweep 49, the rheobase sweep (hero sweep) had a target autobias command voltage of -68 mV and the mean pre-stimulus baseline of -67.205 and a mean post-stimulus baseline of -68.752, so both baselines were within 1mV of the target voltage, but the delta between them was 1.548 mV, so this sweep was failed during QC and as a result, the shortsquare features were not extracted.

To Reproduce I have attached an image from a notebook (see attached image: vm_delta_mv_notebook) that I am using to demonstrate the current behavior for how vm_delta_mv is currently determined (circled in red), and how that should be replaced with pre_vm_delta_mv and post_vm_delta_mv (circled in green).

vm_delta_mv_notebook

Expected behavior Since we have a target voltage set, it is important that we ensure that the pre- and post-stimulus baselines are independently within +/- 1 mV of the target autobias voltage. The important metric here is not that they are within 1 mV of eachother, but that they are each within 1 mV of the target voltage.

Actual Behavior No errors are produced by this bug, it is just incorrectly doing a comparison between the pre- and post-stimulus baselines and returning a single vm_delta_mv value when it should be comparing each of those independently to the target autobias voltage and returning pre_vm_delta_mv and post_vm_delta_mv values.

Environment (please complete the following information):

Additional context I think that the target autobias command voltage should be added to the sweep_record dictionary of the get_sweep_metadata() function in the MIESNWBData class in mise_nwb_data.py with: “autobias_v” = self.notebook.get_value(“Autobias Vcom”, sweep_number, None)

so that the sweep() function in ephys_data_set.py can get it via: sweep_metadata = self._data.get_sweep_metadata(sweep_number)

and then set it as: autobias_v = sweep_metadata[“autobias_v”] (The Sweep class in sweep.py will also need to add autobias_v as an attribute)

The measure_vm_delta() function in qc_features will need to take in a baseline and the target voltage and return the difference between those, rather than taking the pre- and post-stimulus baselines and returning the difference between the two baselines, and the current_clamp_sweep_qc_features() function in qc_feature_extractor.py will need to return “pre_vm_delta_mv” and “post_vm_delta_mv” in the qc_features dictionary, rather than just “vm_delta_mv”.

Do you want to work on this issue? I am working on a pull request for this now which should at least give a good idea of what we are looking for.

tmchartrand commented 3 years ago

@ru57y34nn this may be a reasonable change to make, but I certainly wouldn't call it a bug. This use of delta between pre and post is consistent with our published QC steps in the ephys whitepaper and the first mouse IVSCC publication, so it's really MIES that has departed from the standard here. I'm certainly open to this as a reasonable slight relaxation of that criteria (we're already relaxing the delta mv cutoff for processing human data, and I believe Nathan has in some cases too). But we should probably be clear that this is a desired direction and have signoff from at least Tim and Nathan before putting effort in on this.

ru57y34nn commented 3 years ago

Thanks @tmchartrand for the additional information. I am wondering then if I should resubmit this but as a feature request rather than a bug, and if we should keep vm_delta_mv, and just add pre_vm_delta_mv and post_vm_delta_mv. It seem to me that there should at least be a check somewhere to make sure that the pre- and post-stimulus baselines are within range of the target voltage. Perhaps we could also just relax the qc criteria for vm_delta_mv to +/- 2 mV, since the pre- and post-stimulus baselines can each be up to 1 mV from the target and so no more than 2 mV from eachother?

timjarsky commented 3 years ago

@tmchartrand baseline potentials are compared to the target voltage to ensure the cell's RMP hasn't changed from the break-in potential (the potential that's closest to the cell's physiological RMP). So from this point of view, I think it makes sense for the pre-pulse baseline and post-pulse baseline to be evaluated against the same criteria.