Skip to main content

spike sorting pipeline

Project description

Kilosort4

Documentation Status tests PyPI version Downloads Downloads Python version Licence: GPL v3 Contributors repo size GitHub stars GitHub forks

You can run Kilosort4 without installing it locally using google colab. An example colab notebook is available here. It will download some test data, run kilosort4 on it, and show some plots. Talk describing Kilosort4 is here.

Example notebooks are provided in the docs/source/tutorials folder and in the docs. The notebooks include:

  1. basic_example: sets up run on example data and shows how to modify parameters
  2. load_data: example data format conversion through SpikeInterface
  3. make_probe: making a custom probe configuration.

If you use Kilosort1-4, please cite the paper:
Pachitariu, M., Sridhar, S., Pennington, J., & Stringer, C. (2024). Spike sorting with Kilosort4.

Note on multi-shank probes : We are aware of some issues with sorting data from probes with multiple shanks or 2D arrays. See documentation here for recommended workarounds until the code is updated to handle these probes.

Note on reusing parameters from previous versions: This probably will not work well. Kilosort4 is a new algorithm, and the main parameters (the thresholds) can affect the results in a different way for your data. Please start with the default parameters and adjust from there based on what you see in Phy.

Warning :bangbang:: There were two bugs in Kilosort 2, 2.5 and 3 (but not 4) which caused fewer spikes to be detected in ~7ms periods at batch boundaries (every 2.1866s, issue #594). The patch1 releases fix these bugs, please use the new default NT and ntbuff parameters.

Installation

System requirements

Linux and Windows 64-bit are supported for running the code. At least 8GB of GPU RAM is required to run the software (see docs for more recommendations). The software has been tested on Windows 10 and Ubuntu 20.04.

Instructions

If you have an older kilosort environment you can remove it with conda env remove -n kilosort before creating a new one.

  1. Install an Anaconda distribution of Python. Note you might need to use an anaconda prompt if you did not add anaconda to the path.
  2. Open an anaconda prompt / command prompt which has conda for python 3 in the path
  3. Create a new environment with conda create --name kilosort python=3.9. Python 3.10 should work as well.
  4. To activate this new environment, run conda activate kilosort
  5. To install kilosort and the GUI, run python -m pip install kilosort[gui]. If you're on a zsh server, you may need to use ' ' around the kilosort[gui] call: `python -m pip install 'kilosort[gui]'.
  6. Instead of 5, you can install the minimal version of kilosort with python -m pip install kilosort.
  7. Next, if the CPU version of pytorch was installed (will happen on Windows), remove it with pip uninstall torch
  8. Then install the GPU version of pytorch conda install pytorch pytorch-cuda=11.8 -c pytorch -c nvidia

Note you will always have to run conda activate kilosort before you run kilosort. If you want to run jupyter notebooks in this environment, then also conda install jupyter or pip install notebook, and python -m pip install matplotlib.

Debugging pytorch installation

If step 8 does not work, you need to make sure the NVIDIA driver for your GPU is installed (available here). You may also need to install the CUDA libraries for it, we recommend CUDA 11.8.

If pytorch installation still fails, follow the instructions here to determine what version of pytorch to install. The Anaconda install is strongly recommended on Windows, and then choose the CUDA version that is supported by your GPU (newer GPUs may need newer CUDA versions > 10.2). For instance this command will install the 11.8 version on Linux and Windows (note the torchvision and torchaudio commands are removed because kilosort doesn't require them):

conda install pytorch pytorch-cuda=11.8 -c pytorch -c nvidia

This video has step-by-step installation instructions for NVIDIA drivers and pytorch in Windows (ignore the environment creation step with the .yml file, we have an environment already, to activate it use conda activate kilosort).

Running kilosort

  1. Open the GUI with python -m kilosort
  2. Select the path to the binary file and optionally the results directory. We recommend putting the binary file on an SSD for faster processing.
  3. Select the probe configuration (mat files recommended, they actually exclude off channels unlike prb files)
  4. Hit LOAD. The data should now be visible.
  5. Hit Run. This will run the pipeline and output the results in a format compatible with Phy, the most popular spike sorting curating software.

Debugging qt.qpa.plugin error

Some users have encountered the following error (or similar ones with slight variations) when attempting to launch the Kilosort4 GUI:

QObject::moveToThread: Current thread (0x2a7734988a0) is not the object's thread (0x2a77349d4e0).
Cannot move to target thread (0x2a7734988a0)

qt.qpa.plugin: Could not load the Qt platform plugin "windows" in "<FILEPATH>" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: minimal, offscreen, webgl, windows.

This is not specific to Kilosort4, it is a general problem with PyQt (the GUI library we chose to develop with) that doesn't appear to have a single cause or fix. If you encounter this error, please check issue 597 and issue 613 for some suggested solutions.

Integration with Phy GUI

Phy provides a manual clustering interface for refining the results of the algorithm. Kilosort4 automatically sets the "good" units in Phy based on a <10% estimated contamination rate with spikes from other neurons (computed from the refractory period violations relative to expected).

Check out the Phy repo for more install instructions. We recommend installing Phy in its own environment to avoid package conflicts.

After installation, activate your Phy environment and navigate to the results directory from Kilosort4 (by default, a folder named kilosort4 in the same directory as the binary data file) and run:

phy template-gui params.py

Developer instructions

To get the most up-to-date changes to the code, clone the repository and install in editable mode in your Kilosort environment, along with the other installation steps mentioned above.

git clone git@github.com:MouseLand/Kilosort.git
conda activate kilosort
pip install -e Kilosort[gui]
pip uninstall torch
conda install pytorch pytorch-cuda=11.8 -c pytorch -c nvidia

For unit testing, you will need to install pytest

pip install pytest

Then run all tests with:

pytest --runslow

To run on GPU:

pytest --gpu --runslow

Omitting the --runslow flag will only run the faster unit tests, not the slower regression tests.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kilosort-4.0.6.tar.gz (143.1 kB view details)

Uploaded Source

Built Distribution

kilosort-4.0.6-py3-none-any.whl (116.2 kB view details)

Uploaded Python 3

File details

Details for the file kilosort-4.0.6.tar.gz.

File metadata

  • Download URL: kilosort-4.0.6.tar.gz
  • Upload date:
  • Size: 143.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for kilosort-4.0.6.tar.gz
Algorithm Hash digest
SHA256 108e0601130a99c1ef0847bd338e593c59994a03c99e73584883adf6e9c4b278
MD5 71e4a03af086f9a02211d4079a76e9d8
BLAKE2b-256 1dc436d2cf72656e27877ed5bc0b3aaef896c67bdd72a7e63bc7556b967426e5

See more details on using hashes here.

File details

Details for the file kilosort-4.0.6-py3-none-any.whl.

File metadata

  • Download URL: kilosort-4.0.6-py3-none-any.whl
  • Upload date:
  • Size: 116.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for kilosort-4.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 fe56de09a3333e2990715ae69387a36d42ce2d6ca414657e62f92cb7cabc5201
MD5 ffc8aa0a923838717d3311a4755ca6b0
BLAKE2b-256 701822e7c9fdece045c5e8b588fb1fb2bddb5b4c78d063e58906b0c687671ee8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page