Automatic and manual spike sorting for tetrode recordings based on SpikeInterface.
Same as SpikeInterface
⚠️ Important: This pipeline uses the SpikeInterface version from 2020. Compatibility has not been tested with newer versions.
Please install each sorter as described here:
👉 SpikeInterface Sorter Installation Guide
If the method above causes issues, try these detailed installation instructions (PDF).
When using Matlab-based sorters, save them in:
~/Documents/SpikeSorting/
To be used on Linux 🐧. Add this folder to your path temporarily:
export PYTHONPATH=$PYTHONPATH:/path/to/this/folderTo make it permanent, paste it into your bashrc:
gedit ~/.bashrcconda activate <Name of environment>python -m check_length ‘/full/path/to/folder_with_Study_day_subfolders’
⚠️ Ensure trial folders don’t have duplicate channel files like100_CH1.continuousand100_CH1_2.continuous.
Use merge_channels_revised_T1_PT1.m or merge_channels_revised.m in MATLAB.
Ensure correct sampling rate (fs):
- Rats 1–9 used 20kHz, not 30kHz.
Check folders variable in the MATLAB script and make sure it lists the correct trial folders in the right order.
📌 Refer to the file:
RAT_OS_EPHYS_Channel_Normalization_Across_Animals.xlsx (Dropbox)
💡 Run merging twice:
- Trial1 + PostTrial1
- Presleep + T1 + PT1 + … + T5 + PT5 (+ Novelty trial if applicable)
📋 Refer to this Google Planning Sheet
Generate hpc.xlsx and cortex.xlsx with tetrode IDs and channel info.
Skip tetrodes with only 1 channel or reference tetrodes.
python -m fix_channel_name ‘/path/to/continuous_files’Copy the following files from the same study day (any trial or post-trial folder):
all_channels.eventsContinuous_Data.openephysmessages.eventssettings.xmltetrode.prb(same for all rats)hpc.xlsxandcortex.xlsx(omithpc.xlsxif not sorting HPC)
💻 Work locally! Copy the merged folder to your computer's data hard drive.
python -m rearrange_folders ‘/path/to/merged_data’📌 If only sorting cortical tetrodes, ensure rearrange_folders.py uses:
folders = ['cortex']Instead of:
folders = ['hpc', 'cortex']python -m run_tetrodes ‘/path/to/brain_region_folder_with_tetrodes’💡 Prefer using Spyder (prevents crashes):
conda activate spiketutorial
spyderIn Spyder:
- Load
run_tetrodes.py - Set the correct path in the
foldervariable - Press
Ctrl+AthenF9to run the script
python -m create_json ‘/path/to/brain_region_folder’Copy JSON files to the respective brain area folders of the full-day merged folder.
To run manual curation:
python -m run_tetrodes_manual ‘/path/to/brain_region_folder_with_tetrodes’During manual curation:
Alt+N= NoiseAlt+M= MUAAlt+G= Pyramidal unit- Leave unlabeled = Interneuron
⚠️ Always save first, then close. If you close first and then save, your curation won't be saved.
Both scripts (run_tetrodes.py or run_tetrodes_manual.py) create a phy folder with:
spike_times.npyspike_clusters.npy
You can generate activation matrices (25 ms bins) as actmat_auto_tetrode#.
To concatenate and detect assemblies:
python -m phy2assemblyTo view previous detections:
os.system('phy template-gui phy_AGR/params.py')Post-curation consensus:
python -m consensus_post_curation ‘/path/to/tetrode_folder’python -m quality_metricsRequires:
conda env create -f environment_qm.yml
conda activate spiketutorial_qm- Open
run_tetrodes.py - Press
Ctrl+A, thenF9
./loopThis calls run_tetrodes_brain_areas.py in a loop.
Download loop.sh → rename to loop.
Add loop to your PATH in ~/.bashrc.
Modify sorter.py: add exit() to the end of ms4() and auto() functions.
Navigate to:
/home/Username/anaconda3/envs/spiketutorial/lib/python3.6/site-packages/pyopenephys
Modify:
run_tetrodes_brain_areas.pyrun_tetrodes_json.pyrun_tetrodes_loop.pytruncate2.py