Skip to content
/ SHJ Public

Axion Biosystem to CellExplorer Pipeline for the Shawn Hervey-Jumper Lab

License

Notifications You must be signed in to change notification settings

ajcheng1/SHJ

Repository files navigation

SHJ

Spike Sorting and identification of cortical neurons on Axion MEA using Python and MATLAB.

Author

Alvin Cheng, Department of Neurosurgery, UC San Francisco

Usage

This pipeline utilizes AxionFileLoader, Spikeinterface, Mountainsort5, Kilosort4, Phy and CellExplorer. Requires large amount of storage 8-10 gb/file and in special cases, access to Nvidia GPU (cuda). See below for recommendations image

  1. Create an account on UCSF Wynton. Transfer .raw files from box over to the Wynton server via UCSF Wynton HPC Box Connector. Name each folder appropriately and place the .raw file within there.
  2. Please download AxionFileLoader folder on their GitHub repository. The main utility is to load the data from all electrodes in a particular well
Data=AxisFile(‘Filename.raw’).DataSets.LoadData(‘B1’);
  1. Add relative path of AxionFileLoader to AxionDat2.m
  2. Select the wells you wish to process or all of them (A1, A2, A3, ..., D4, D5, D6)
addpath('/wynton/home/hervey-jumper/acheng1/scripts_singlecell') % change to actual path of script and .raw file 
AxionDat2('files_singlecell/D14 post CC-1-24-23-000/D14 post CC-1-24-23-000.raw')
  1. Navigate to run_kilosort.py or Kilosort.ipynb. Use run_kilosort.py or kilosort_analysis.py if the job requires CUDA/GPU and/or submitting many jobs or kilosort.ipynb for step-by-step tutorial. Interleaved dat file will be loaded, read and preprocessed as a binary file. A multicolumn probe resembling Axion 24-well MEA plate is created, and then finally the recording is spike sorted using kilosort4 using special parameters for the low density MEA probe. Depending on plating condition and spike sorter, parameters may have to be adjusted. See guide here on changing Kilosort4 parameters*
  2. Both files will create 3 folders: spike sorting result, a sorting analyzer to briefly visualize waveforms, and files in Phy format.

image image image

  1. Download folder containing Phy files either by transferring files through UCSF BOX or tar.gz download via JupyterNoteBook Downloader
  2. Manually curate via Phy. Remember to label units as good before proceeding or else the following steps will not work. Positive spikes tend to correspond to axons while negative spikes are good. Rarely on low density MEA plates will there be overlapping signals/multi-unit activity . See instructions here: Phy
Conda init
conda activate phy2
Cd [path to directory where phy output that also contains params.py]
phy template-gui params.py
  1. Finally, head to MATLAB and load CellExplorerAC.m. Ensure file path of Phy files is correct .
  2. Ensure you have downloaded CellExplorer and added it to the path
  3. Happy spike sorting and characterization! image image

* kilosort_analysis requires a virtual environment with necessary packages installed. Create a .sh file to submit multiple jobs

source spikesort/bin/activate
cd /wynton/home/hervey-jumper/acheng1/job_scripts/or/to/wherever/run_kilosort.py/is/located
qsub -m bea kilosort_job.sh

Hardware/Software Best Practices

Tool Compatibility Notes
Kilosort4 HPC Job (Python 3.9+) Sorting can take a substantial time
Mountainsort5 HPC Job (Python 3.9+) Isosplit6 not developed for M-series Mac. However, Mountainsort4 works on M-series Mac
Spikeinterface Python 3.9+ Jupyter Notebook preferred for visualization
CellExplorer Windows PC or Mac (Matlab) GUI
Phy Windows PC (Conda Env, Python) GUI (not developed for M-series Mac)
AxionFileLoader Any Matlab
Plexon Offline Sorter + Axion Tools Windows PC Great for manual curation
UCSF Wynton Any computer terminal HPC, must be on UCSF IVANTI VPN. Best to use for spike sorting and for dat conversion. Ease of data transfer to and from UCSF BOX

TLDR EXAMPLE GUIDE

This assumes all software is installed correctly and is on the UCSF wynton.

  1. In globus, in the “Collections” search field enter “UCSF Wynton HPC Box Connector”. Then locate UCSF Wynton HPC collection, and to the folder containing the .raw files. Transfer them over to the server
  2. Connect to matlab using one of the dev nodes and convert .raw files into interleaved dat files
ssh dev1.wynton.ucsf.edu
module load matlab 
matlab -nosplash -nodesktop
addpath('/wynton/home/hervey-jumper/acheng1/scripts_singlecell')
AxionDat2('files_singlecell/D14 post CC-1-24-23-000/D14 post CC-1-24-23-000.raw')
  1. To run kilosort and convert to phy, activate the virtual enviornment and submit multiple jobs via qsub. Ensure the full path is listed and no quotes! Alternatively, you can use python directly in the terminal or kilosort.ipynb to directly visualize waveforms and edit kilosort parameters.
source spikesort/bin/activate
cd /wynton/home/hervey-jumper/acheng1/job_scripts
qsub kilosort_job.sh /wynton/home/hervey-jumper/acheng1/files_singlecell/D14-post-CC-1-24-23-000/A4/Well-A4-interleaved.dat
python kilosort.py /wynton/home/hervey-jumper/acheng1/files_singlecell/D14-post-CC-1-24-23-000/A4/Well-A4-interleaved.dat
  1. Head over to SpikeVisualizer.ipynb and enter the path to the analyzer folder. Visualize waveforms.
  2. Transfer files over to Box using Globus.
  3. Download phy_output folder and activate Phy enviornment. Manual curate and label spikes.
Conda init
conda activate phy2
Cd [path to directory where phy-output location is AND FOLDER THAT CONTAINS params.py]
phy template-gui params.py
  1. Add phy_output folder to CellExplorer. Add path to phy_output. Edit the name of the session.extracellular.fileName and optionally session.spikeSorting{1}.relativePath if the phy_output is not in the same folder as the dat file. Run the program and a GUI should pop up.
path = '/Users/Alvin/MATLAB/Neuron Sorting/Data/D14 post CC-1-24-23-000 Well A5 Interleaved/phy_output D14 post CC-1-24-23-000A5Well A5 interleaved';
session.extracellular.fileName = 'Well A5 interleaved.dat'; % name of original dat file
session.spikeSorting{1}.relativePath = 'phy_output D14 post CC-1-24-23-000A5Well A5 interleaved';  % Path to your Phy output folder

Citations

Peter C. Petersen, Joshua H. Siegle, Nicholas A. Steinmetz, Sara Mahallati, György Buzsáki. CellExplorer: A framework for visualizing and characterizing single neurons. Neuron, September 29, 2021; doi: [https://doi.org/10.1016/j.neuron.2021.09.002](https://doi.org/10.1016/j.neuron.2021.09.002).
Chung, J. E., Magland, J. F., Barnett, A. H., Tolosa, V. M., Tooker, A. C., Lee, K. Y., Shah, K. G., Felix, S. H., Frank, L. M., & Greengard, L. F. (2017). A Fully Automated Approach to Spike Sorting. Neuron, 95(6), 1381–1394.e6. https://doi.org/10.1016/j.neuron.2017.08.030
Alessio Paolo Buccino, Cole Lincoln Hurwitz, Samuel Garcia, Jeremy Magland, Joshua H Siegle, Roger Hurwitz, Matthias H Hennig (2020) SpikeInterface, a unified framework for spike sorting eLife 9:e61834 https://doi.org/10.7554/eLife.61834
Pachitariu, M., Sridhar, S., Pennington, J., & Stringer, C. (2024). Spike sorting with Kilosort4. Nature Methods , 21, pages 914–921

About

Axion Biosystem to CellExplorer Pipeline for the Shawn Hervey-Jumper Lab

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published