# Kilosort2: automated spike sorting with drift tracking and template matching on GPUs #
![](https://github.com/MouseLand/Kilosort2/blob/master/Docs/img/templates.png)
Welcome to Kilosort2, a MATLAB package for spike sorting electrophysiological data up to 1024 channels. In many cases, and especially for Neuropixels probes, the automated output of Kilosort2 requires minimal manual curation.
There is currently no preprint or paper for Kilosort2, so please read the wiki to find out [how it works](https://github.com/MouseLand/Kilosort2/wiki), and especially the [drift correction](https://github.com/MouseLand/Kilosort2/wiki/3.-More-on-drift-correction) section. Kilosort2 improves on Kilosort primarily by employing drift correction, which changes the templates continuously as a function of drift. Drift correction does not depend on a particular probe geometry, but denser spacing of sites generally helps to better track neurons, especially if the probe movement is large. Kilosort2 has been primarily developed on awake, head-fixed recordings from Neuropixels 1.0 data, but has also been tested in a few other configurations. To get a sense of how probe drift affects spike sorting, check out our "eMouse" simulation [here](https://github.com/MouseLand/Kilosort2/tree/master/eMouse_drift) and [its wiki page](https://github.com/MouseLand/Kilosort2/wiki/4.-eMouse-simulator-with-drift).
To aid in setting up a Kilosort2 run on your own probe configuration, we have developed a [graphical user interface](https://github.com/MouseLand/Kilosort2/wiki/1.-The-GUI) where filepaths can be set and data loaded and visually inspected, to make sure Kilosort2 sees it correctly. The picture above is another GUI visualization: it shows the templates detected by Kilosort2 over a 60ms interval from a Neuropixels recording. The final output of Kilosort2 can be visualized and curated in the [Phy GUI](https://github.com/kwikteam/phy), which must be installed separately (we recommend the development version). Since Phy is in Python, you will also need the [npy-matlab ](https://github.com/kwikteam/npy-matlab) package.
### Installation ###
Required toolboxes: parallel computing toolbox, signal processing toolbox, Statistics and Machine Learning Toolbox, MATLAB >=R2016b
You must run and complete successfully `mexGPUall.m` in the `CUDA` folder. This requires mexcuda support, which comes with the parallel computing toolbox. To set up mexcuda compilation, install the exact version of the CUDA toolkit compatible with your MATLAB version (see [here](https://www.mathworks.com/help/distcomp/gpu-support-by-release.html)). On Windows, you must also install a CPU compiler, for example the freely available [Visual Studio Community 2013](https://www.visualstudio.com/vs/older-downloads/). Note that the most recent editions of Visual Studio are usually not compatible with CUDA. If you had previously used a different CPU compiler in MATLAB, you must switch to the CUDA-compatible compiler using `mex -setup C++`. For more about mexcuda installation, see these [instructions](http://uk.mathworks.com/help/distcomp/mexcuda.html).
### General instructions for running Kilosort2 ###
#### Option 1: Using the GUI
Navigate to the `Kilosort2` directory and run `kilosort`:
```
>> cd \my\kilosort2\directory\
>> kilosort
```
See the [GUI documentation](https://github.com/MouseLand/Kilosort2/wiki/1.-The-GUI) for more details.
#### Option 2: Using scripts (classic method)
1. Make a copy of `master_kilosort.m` and `\configFiles\StandardConfig_MOVEME.m` and put them in a different directory. These files will contain your own settings, and you don't want them to be overwritten when you update Kilosort2.
2. Generate a channel map file for your probe using `\configFiles\createChannelMap.m` as a starting point.
3. Edit the config file with desired parameters. You should at least set the file paths `ops.fbinary`, `ops.root` and `ops.fproc` (this file will not exist yet - `kilosort` will create it), the sampling frequency `ops.fs`, the number of channels in the file `ops.NchanTOT` and the location of your channel map file `ops.chanMap`.
4. Edit `master_kilosort.m` so that the paths at the top ([lines 3–4](https://github.com/MouseLand/Kilosort2/blob/master/master_kilosort.m#L3-L4)) point to your local copies of those GitHub repositories, and so that the configuration file is correctly specified ([lines 6–7](https://github.com/MouseLand/Kilosort2/blob/2fba667359dbddbb0e52e67fa848f197e44cf5ef/master_kilosort.m#L6-L7)).
### Parameters ###
If you are unhappy with the quality of the automated sorting, try changing one of the main parameters:
`ops.Th = [10 4]` (default). Thresholds on spike detection used during the optimization `Th(1)` or during the final pass `Th(2)`. These thresholds are applied to the template projections, not to the voltage. Typically, `Th(1)` is high enough that the algorithm only picks up sortable units, while `Th(2)` is low enough that it can pick all of the spikes of these units. It doesn't matter if the final pass also collects noise: an additional per neuron threshold is set afterwards, and a splitting step ensures clusters with multiple units get split.
`ops.AUCsplit = 0.9` (default). Threshold on the area under the curve (AUC) criterion for performing a split in the final step. If the AUC of the split is higher than this, that split is considered good. However, a good split only goes through if, additionally, the cross-correlogram of the split units does not contain a big dip at time 0.
`ops.lam = 10` (default). The individual spike amplitudes are biased towards the mean of the cluster by this factor; 50 is a lot, 0 is no bias.
A list of all the adjustable parameters is in the example configuration file.
### Integration with Phy GUI ###
Kilosort2 provides a results file called `rez`, where the first column of `rez.st`are the spike times and the second column are the cluster identities. It also provides a field `rez.good` which is 1 if the algorithm classified that cluster as a good single unit. To visualize the results of Kilosort2, you can use [Phy](https://github.com/kwikteam/phy), which also provides a manual clustering interface for refining the results of the algorithm. Kilosort2 automatically sets the "good" units in Phy based on a <20% estimated contamination rate with spikes from other neurons (computed from the refractory period violations relative to expected).
Because Phy is written in Python, you also need to install [npy-matlab](https://github.com/kwikteam/npy-matlab), to provide read/write functions from MATLAB to Python.
Detailed instructions for interpreting results are provided [here](https://github.com/kwikteam/phy-contrib/blob/master/docs/template-gui.md). That documentation was developed for Kilosort1, so things will look a little different with Kilosort2.
### Credits ###
Kilosort2 by Marius Pachitariu
GUI by Nick Steinmetz
eMouse simulation by Jennifer Colonell
### Questions ###
Please create an issue for bugs / installation problems.
### Licence ###
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
没有合适的资源?快使用搜索试试~ 我知道了~
用于对使用 TDT 和 Intan 硬件采集的多通道数据进行尖峰排序的管道matlab代码.zip
共269个文件
m:184个
mat:26个
png:19个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 119 浏览量
2024-05-18
14:30:18
上传
评论
收藏 48.56MB ZIP 举报
温馨提示
1.版本:matlab2014/2019a/2021a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。
资源推荐
资源详情
资源评论
收起资源包目录
用于对使用 TDT 和 Intan 硬件采集的多通道数据进行尖峰排序的管道matlab代码.zip (269个子文件)
allen-postprocessing-python 9KB
relativeHist.c 1KB
mexMPnu8.cu 43KB
mexClustering2.cu 14KB
mexGetSpikes2.cu 13KB
mexNvidia_quicksort.cu 12KB
mexSVDsmall2.cu 10KB
mexThSpkPC.cu 10KB
mexClusteringFull.cu 8KB
mexDistances2.cu 6KB
mexWtW2.cu 4KB
mexFilterPCs.cu 3KB
mexRECONSTRUCT.cu 3KB
pnet.dll 72KB
.gitignore 589B
ksGUI.m 72KB
caraslab_TDTbin2mat.m 68KB
TDTbin2mat.m 67KB
TDT2mat.m 35KB
make_eMouseData_drift.m 33KB
SynapseAPI.m 24KB
caraslab_createChannelMap.m 23KB
load_open_ephys_data.m 20KB
get_timestamps_and_wf_measurements.m 19KB
wf_pca_across_days.m 17KB
TDTfilter.m 17KB
pca_compare_waveforms.m 17KB
caraslab_reformat_OpenEphysGUI_data.m 16KB
load_open_ephys_data_chunked.m 16KB
learnAndSolve8b_old.m 16KB
caraslab_EPhysIntan_pipeline.m 15KB
SEV2mat.m 14KB
urlread2.m 13KB
fraser_unit_tracker_wrapper.m 13KB
caraslab_EPhysSynapse_pipeline.m 13KB
caraslab_preprocessdat.m 13KB
TDEV.m 13KB
cluster_quality_metrics.m 12KB
remove_double_counted_spikes.m 12KB
learnTemplates.m 11KB
caraslab_artifact_reject.m 11KB
plot_unit_shanks.m 10KB
make_noise_model.m 10KB
splitAllClusters.m 10KB
TDTthresh.m 9KB
rgb.m 9KB
trackAndSort.m 9KB
id_noise_templates_wrapper.m 8KB
caraslab_concatenate_sameDepth_recordings.m 8KB
caraslab_concatenate_sameDay_recordings.m 8KB
load_open_ephys_data_faster.m 8KB
clusterSingleBatches.m 8KB
caraslab_createconfig.m 8KB
TDTUDP.m 7KB
gaussianMix.m 7KB
get_session_info.m 7KB
rezToPhy.m 7KB
getWaveForms.m 6KB
plot_raw_traces.m 6KB
bufferFilter_debug.m 6KB
caraslab_gpufilter_matfile.m 6KB
compareClustering2_drift.m 6KB
caraslab_gpufilter.m 6KB
unitIdentification.m 6KB
SynapseLive.m 5KB
caraslab_kilosort.m 5KB
preprocessDataSub.m 5KB
caraslab_reformat_synapse_data.m 5KB
benchmark_drift_simulation.m 5KB
TDTfft.m 5KB
load_open_ephys_binary.m 5KB
TDTdigitalfilter.m 5KB
chunkwiseDeline.m 5KB
OpenExLive.m 5KB
benchmark_drift_simulation_jrc.m 4KB
plot_autocorrelograms.m 4KB
main_eMouse_drift.m 4KB
caraslab_mat2datChunked.m 4KB
get_waveforms_from_folder.m 4KB
runTemplates.m 4KB
computeWaveScore.m 4KB
computeSurvival.m 4KB
batch_concatenate_sameDay_recordings.m 4KB
ccg.m 4KB
compile_data_for_analyses.m 4KB
normalize_wfs.m 3KB
set_cutoff.m 3KB
find_merges.m 3KB
loadChanMap.m 3KB
caraslab_intan_mat2dat.m 3KB
masterBench.m 3KB
isi_violations.m 3KB
caraslab_mat2dat.m 3KB
computeWhitening.m 3KB
get_good_channels.m 2KB
caraslab_traceviewer.m 2KB
main_kilosort.m 2KB
triageTemplates2.m 2KB
configFile384.m 2KB
StandardConfig_MOVEME.m 2KB
共 269 条
- 1
- 2
- 3
资源评论
matlab科研助手
- 粉丝: 3w+
- 资源: 5962
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功