Skip to content

03. Automatic Spike Sort

Xin Niu edited this page Oct 15, 2024 · 1 revision

Spike sorting is composed of spike detection, spike code calculation, and spike clustering. Spike detection creates *_spikes.mat, spike code calculation creates '*_spikeCodes.mat', and spike clustering creates times_*.mat. This is only for microchannels, as macro ones do not detect spikes due to low sampling frequency (and perhaps the nature of electrodes).

As the input CSC files may have multiple segments (_), we will combine the raw CSC voltage signals and do spike sorting (spike detection and spike clustering). Spikes across the segments are combined in one file as the output of spike detection.

If not enough spikes are detected, spike clustering will be skipped, and no times_*.mat file will be created. In this case, linear interpolation in LFP extraction still removes the spikes from the raw signals.

Single-Exp Analysis

Input Data

Experiment<exp_id>
  - CSC_micro
    - G[A-D][1-8]-<channel_name>_<suffix1>.mat
    - G[A-D][1-8]-<channel_name>_<suffix2>.mat
    ...

Output Data

Experiment<exp_id>
  - CSC_micro_spikes
    - G[A-D][1-8]-<channel_name>_spikes.mat
      - spikes
      - spikesTimestamps
    - G[A-D][1-8]-<channel_name>_spikeCodes.mat
      - spikeCodes
      - spikeHist
      - spikeHistPrecise
    - times_G[A-D][1-8]-<channel_name>.mat
      - cluster_class
      - timestampsStart

Spikes are extracted from the filtered signals (instead of the raw signals), which are used in spike detection. spikeTimestamps is relative to the start of the experiment. The Unix timestamps can be recovered by adding timestampsStart.

Cluster_class: [class, spikeTimestamps]. Zero-based across all experiments

Multi-Exp Analysis

In multi-exp analysis, we use the CSC data from multiple experiments to calculate the spike detection threshold. The minimum threshold (no less than 18) across multiple experiments is used for spike detection. For details, check getDetectionThresh.

The minimum threshold does not apply to single-exp analysis The detected spikes are then combined before spike clustering. The number of experiments to combine varies across patients from 3 to 8. The procedure for multi-exp analysis is the same as for single-experiment analysis, with multiple segments and the same max gap duration.

Input Data

Experiment<exp_id1>
  - CSC_micro
    - G[A-D][1-8]-<channel_name>_<suffix1>.mat
    - G[A-D][1-8]-<channel_name>_<suffix2>.mat
    ...
Experiment<exp_id2>
  - CSC_micro
    - G[A-D][1-8]-<channel_name>_<suffix1>.mat
    - G[A-D][1-8]-<channel_name>_<suffix2>.mat
    ...
...

Output Data

Experiment-<exp_id1>-<exp_id2>-...
  - CSC_micro_spikes
    - G[A-D][1-8]-<channel_name>_spikes.mat
    - G[A-D][1-8]-<channel_name>_spikeCodes.mat
    - times_G[A-D][1-8]-<channel_name>.mat