Mean waveforms for mouse intracellular waveforms

Hi,

I’m trying to obtain some mean waveforms for the mouse intracellular recorded waveforms as part of the Cell Types database and essentially my strategy was to,

  1. Find a sweep just above a neuron’s rheobase
  2. Detect spikes and extract a window of activity around the peak
  3. Average the activity windows to get a mean waveform

but I’m running into problems finding the correct long square pulse sweep that occurs just above rheobase? It seems the ordering and number of sweeps are not easily parsable unless I am missing something? So far, my code follows exactly this page. Also, rheobase isn’t special: I just wanted to get a sweep that is guaranteed at least one spike in a principled manner.

Alternatively, if it is easy to access averaged waveforms through the SDK (as appears as a red trace on the page for every recorded neuron; see attached), that would also make things very easy.

Thanks!
Kenji

Hi Kenji,

The information you need to pull together to do this is in a couple of different places.

First you set up a CellTypesCache object to access the data

from allensdk.core.cell_types_cache import CellTypesCache

ctc = CellTypesCache(manifest_file='cell_types/manifest.json')

Next, you can get the ephys features for all the cells, the data for a single cell (from the NWB file), and the sweep-level information for that cell.

# pick a cell to analyze
specimen_id = 628700262

# download the ephys data and sweep metadata
features = ctc.get_ephys_features()

# get the features just for the cell we are interested in
cell_features = [f for f in features if f["specimen_id"] == specimen_id][0]

# get the ephys data and sweep-level info
data_set = ctc.get_ephys_data(specimen_id)
sweeps = ctc.get_ephys_sweeps(specimen_id)

The cell_features variable is a dictionary of features. To get sweeps just above rheobase, you can get the rheobase stimulus amplitude by either getting it from the rheobase sweep

rheobase_sweep_number = cell_features["rheobase_sweep_number"]
rheobase_sweep_info = [s for s in sweeps if s["sweep_number"] == rheobase_sweep_number][0]
rheobase_amplitude = rheobase_sweep_info["stimulus_absolute_amplitude"]

Or you could know that the cell-level property threshold_i_long_square is also the rheobase amplitude

also_the_rheobase_amplitude = cell_features["threshold_i_long_square"]

Now you can grab the sweeps that (1) are long squares, (2) have spikes, and (3) are above rheobase by some amount (say +10 pA), then sort them by their amplitudes.

my_sweeps = [s for s in sweeps
             if s["stimulus_name"] == "Long Square"
             and s["stimulus_absolute_amplitude"] > rheobase_amplitude + 10
             and s["num_spikes"] > 0]
sorted_sweeps = sorted(my_sweeps, key=lambda x: x["stimulus_absolute_amplitude"])

Get the spike times and sweep data for the first one in that list by

my_sweep_number = sorted_sweeps[0]["sweep_number"]
spike_times = data_set.get_spike_times(my_sweep_number)
sweep_data = data_set.get_sweep(my_sweep_number)

And then you can go through and find the right times and intervals by getting the t and v vectors as in the page you linked.

1 Like

Hi Nathan,

Thanks so much for your help! This worked perfectly!

Happy holidays,
Kenji

1 Like