in vivo ephys analysis - KravitzLab/KreedLabWiki GitHub Wiki

Using Plexon OffLine Sorter for spike sorting

Background: Chronic extracellular recording is a powerful tool for correlating changes in neuronal firing with changes in the behavior or environment of an animal. With this technique, it is possible to isolate spikes from a single unit or to record “multiunit” activity from several units together on one electrode. Depending on the experimental goals, multiunit activity may be as useful as single unit activity, and is easier to acquire. Identifying multiunit activity in the recording is also useful for statistical quantification of the quality of single unit recordings (ie: are the “single unit” waveforms statistically different from the “multiunit” waveforms?). This spike sorting protocol covers the theory underlying spike sorting, how to process data in Plexon Sort Client and Offline Sorter, and how to quantify the quality of single unit recordings.

Highlights of the document are covered below:


1. Spike sorting.

The Plexon ephys system records raw waveforms during acquisition. We will use Plexon "OffLine Sorter" to sort these waveforms into unique shapes. image


2. Limiting data to improve spike sorting

In practice, we often record much more data than we use in our final analysis. This can include extended baseline periods before or after the recording, or manipulations that end up not being useful and are excluded from the analysis of each unit. Because of waveform variability and drift, these “unused” time periods will add variability to the cluster sorting, and removing them will clean things up. Often the actual analysis periods may not be known up front, but once these are known it is worth the effort to redo the spike sorting on just the time periods you care about in the recording.

To select which periods you want to retain before cluster sorting click Tools>Interval Selection:
image


3. Artifact rejection

Despite using differential recording (the signal from each electrode is subtracted from a reference electrode) artifacts can still occur on all channels. These can be movement related or generated by nearby equipment. While it is best to mitigate these issues before recording, this is not always possible. Instead, these must be “invalidated” afterwards. Offline Sorter retains “invalidated” waveforms, but will not visually display or include them in any future analyses. This is important because they can interfere with your ability to see the clustering of more relevant waveforms, as well as statistical analyses of these waveforms if left in. I find that these values (40 ticks, 30%) work well and would recommend not changing them to keep the processing consistent with other data. After clicking OK it will ask you again if it’s OK to invalidate the artifacts. Depending on the file size, this step can take a while (up to 30 minutes), and you might not get any feedback from Offline Sorter that it’s doing anything. It may look frozen up but it’s not - just let it run until it’s done.

image


4. Generate and sort clusters

To sort units, click ‘Add Unit’, and circle the cluster of points for each unit. Finer adjustments can be made with the ‘Add Wfs’ and ‘Remove Wfs’ buttons.
image

Once you have the putative clusters identified, use the ‘Template Sort’ feature to let Offline Sorter assign spikes to each unit. This method uses a simple nearest neighbor matching algorithm in PCA space. image

The stringency of each cluster can be adjusted by setting thresholds on the unit templates below the waveform view. Continue adding and removing waveforms, and adjusting the template stringency until you’re happy with the cluster sorting.
image

For consistency, sort the multiunit activity as unit A, and putative single units as units B, C, D, etc. Even if you’re not interested in multiunit activity, it is important to define the multiunit activity as a unit so that the software can make statistical comparisons of unit quality. For channels that only have “multiunit” activity (as in the example below), depending on your final analyses it still may be useful to select it and export timestamps.
image


5. Evaluate clusters to determine if they contain single or multiunit activity

To start with, two simple parameters should minimally be satisfied for all putative single units. In general, the electrodes we use record ~30uV peak-peak noise band. I look for units that are at least 3x this noise band, or ~90uV at a minimum. The amplitude of sorted clusters can be estimated from the grid on the 2D waveform view. Plexon also allows you to set a reference inter-spike-interval period, and calculates the % of spikes that violate this period. I set this to 1msec, and look for no more than 0.1% of all spikes to violate this. This number appears in the top left of the waveform template. The exact number of violations can also be found in the View>Info Grid Views>Stats page.

image

If a putative unit cluster does not satisfy these two conditions, I add it into the multiunit “unit a” at this point. On any recording channel, there may be single unit activity, multiunit activity, and “noise”. For this purpose, the statistical comparison that is most meaningful is whether the single unit is significantly separated from the multiunit activity, which we are defining as unit a. To get Offline Sorter to calculate clustering statistics, first go to Tools>Options>Stats and click on the options to calculate stats after each change, and calculate advanced stats.

image

To visualize the stats in real time as you sort you have to turn on two options in the “right click” menu. To access this menu, hold the ‘Alt’ key as you right click over the 2D cluster view. Click on ‘Show Statistics’, and ‘Show Cluster Quality’. Finally, it is useful to keep the View>Info Grid Views>Stats page open at all times to view the pairwise stats between all clusters. image

This will place 5 sorting statistics in a bar directly below the cluster scatter plots. These statistics are a MANOVA, J3, PseudoF, Davies-Bouldin, and Dunn statistics. A great overview of these statistics, and how to evaluate them can be found here (especially see supplemental text): [3]. Information on how these statistics are calculated is also in section 5-27 of the Offline Sorter manual. Here are some rules of thumb for using these stats to evaluate clusters.

In brief, the goal here is to compare each putative single unit cluster to the multiunit cluster, and decide if it is significantly different enough to call a single unit. The MANOVA performs a parametric statistical test of whether the multivariate data in each cluster is significantly different from the other clusters. At a minimum, the pairwise stats between the multiunit ‘unit a’ and any putative clusters should always be significant. This is really the only “necessary” statistic that I use for determining if a cluster is a single unit. However, it is useful to look at the other statistics.

The J3 statistic describes a ratio of within cluster to between cluster variance. In general, values over 1 are good, and values under 1 are bad. However, when the multiunit cluster is very large (if it contains a few “almost” single units in it) and the single unit is compact, the J3 value will be low. Therefore, I won’t exclude a unit for a low J3 value. The PseudoF stat is a normalized version of the J3, while the Davies-Bouldin and Dunn stats are alternative ratios of within-cluster to between cluster variance. In general, D-B values below 0.5 reflect good clustering, and values above 0.5 represent poor clustering. However, the J3 appears to be a better indicator of this [3].

In summary, a “single unit” should satisfy the following requirements:

  • Amplitude greater than 90uV
  • Less than 0.1% of spikes violating a 0.1sec ISI
  • Significant pairwise MANOVAs between all clusters
  • While not necessary, a J3 >1 is also an indicator of good clustering.

Despite these stats not being “necessary” for single unit identification, a good recommendation from [3] is to report the average and distribution of J3 and D-B values for all sorted “single units”.


6. Export finished files

When you are done, you can export 3 things:

  1. Export the file to a new .PL2 file. In this step I like to unclick the ‘Export Invalidated Waveforms’ option to discard all of the waveforms you invalidated that were artifacts, and those that are outside your analysis windows. For the purposes of data sharing this is a much nicer file to give someone, instead of explaining why certain data was invalidated and how they can replicate your invalidation steps.

image

  1. Export a Nex file that can be easily opened in Neuroexplorer. In Neuroexplorer, remember that all ‘a’ units are multiunit activity. These can be deleted in Neuroexplorer if you know you won’t use them.

  2. Finally, export summary sorting statistics to the same excel sheet by clicking File>Export Per Channel Data. If you don’t change the name this will append these stats to your waveform sheet, where you can set up some simple calculation columns to generate waveform amplitudes, durations, and average sorting stats for each experiment.