Skip to main content

No project description provided

Project description

pyKilomatch

View pyKilomatch on GitHub

This project is a Python implementation of Kilomatch, converted from the original MATLAB code.

Installation

  • It is recommended to install the pyKilomatch package using Anaconda:
conda create -n pyKilomatch python=3.11
conda activate pyKilomatch
pip install pyKilomatch

How to use it

Prepare the data

  • Your data should be organized in a folder with the following structure:
data_folder
├── channel_locations.npy
├── waveform_all.npy
├── session_index.npy
├── peth.npy (optional)
└── spike_times/
    ├── Unit0.npy
    ├── Unit1.npy
    ├── Unit2.npy
    └── ...
    └── UnitN.npy
  • The data files should adhere to the following formats:

    • session_index.npy: An array of length n_unit indicating the session for each unit. Session indices should start from 1 and be continuous without gaps.
    • waveform_all.npy: An n_unit x n_channel x n_sample tensor containing the mean waveform of each unit in μV. All units must share the same set of channels.
    • channel_locations.npy: An n_channel x 2 double array specifying the (x, y) coordinates (in μm) of each channel. The y-coordinate typically represents the depth.
    • peth.npy: (Optional but recommended) An n_unit x n_point double array containing the peri-event time histogram for each unit.
    • spike_times/UnitX.npy: An array of spike times (in milliseconds) for unit X. The filenames should follow the pattern UnitX.npy, where X is the unit index starting from 0 and incrementing continuously without gaps.
  • Specify the path to your data in the settings.json file.

  • Edit the settings.json file to set the path_to_data and output_folder.

  • Adjust other parameters within settings.json to match your specific data characteristics.

Running the Code

  • After configuring the settings.json file and ensuring the path to it is correctly specified in mainKilomatch.py, execute the following commands in your terminal:
conda activate pyKilomatch
python mainKilomatch.py

About the output

  • All temporary files, results, and generated figures will be saved in the output_folder defined in your settings.json file.
  • The output_folder will contain the following result files:
    • auto_corr.npy: An n_unit x n_point double array containing the auto-correlation of each unit.
    • isi.npy: An n_unit x n_point double array containing the inter-spike interval (ISI) of each unit.
    • peth.npy: An n_unit x n_point double array containing the peri-event time histogram (PETH) of each unit.
    • waveforms.npy: An n_unit x n_nearest_channel x n_sample tensor of the mean waveform for each unit (in μV) before motion correction.
    • waveforms_corrected.npy: An n_unit x n_nearest_channel x n_sample tensor of the mean waveform for each unit (in μV) after motion correction.
    • waveform_channels.npy: An n_unit x n_nearest_channel integer array indicating the channel index for each unit's waveform.
    • locations.npy: An n_unit x 3 double array containing the estimated x, y, and z coordinates of each unit.
    • IdxCluster.npy: An n_unit x 1 integer array assigning a cluster index to each unit. Units not assigned to any cluster are marked with -1.
    • ClusterMatrix.npy: An n_unit x n_unit logical matrix representing cluster assignments. ClusterMatrix(i, j) = 1 indicates that unit i and unit j belong to the same cluster.
    • MatchedPairs.npy: An n_pairs x 2 integer matrix listing the unit indices for each pair of units within the same cluster.
    • SimilarityWeights.npy: An n_features x 1 double array containing the weights of the similarity metrics computed by the IHDBSCAN algorithm.
    • SimilarityThreshold.npy: A 1 x 1 double value representing the threshold used to identify good matches in the GoodMatchesMatrix during the auto-curation process.
    • SimilarityMatrix.npy: An n_unit x n_unit double matrix representing the weighted sum of similarities between each pair of units.
    • motion.npy: A n_session x 1 double array indicating the estimated electrode positions for each session.
    • ClusteringResults.npz: A compressed file containing the clustering results after motion correction.
    • CurationResults.npz: A compressed file containing the curation results after motion correction.
    • Output.npz: A compressed file containing the final results of the Kilomatch analysis.

Notes

  • pyKilomatch is a conversion from MATLAB and is currently undergoing testing. Please report any bugs or issues you encounter.
  • For recordings using multi-shank probes, it is recommended to analyze each shank independently. The current Python version of Kilomatch is not yet designed to handle multi-shank data simultaneously.
  • Be careful that the waveforms included in this analysis should not be whitened as Kilosort does. Do not use the waveforms extracted from temp_wh.dat directly. Do not use whitening_mat_inv.npy or whitening_mat.npy in Kilosort2.5 / Kilosort3 because they are not what Kilosort used to whiten the data (https://github.com/cortex-lab/phy/issues/1040)!
  • Please analyze data from different brain regions like cortex and striatum individually since they might have different drifts and neuronal properties.
  • Please raise an issue if you meet any bugs or have any questions. We are looking forward to your feedback!

References

HDBSCAN
HDBSCAN - Hierarchical Density-Based Spatial Clustering of Applications with Noise. Performs DBSCAN over varying epsilon values and integrates the result to find a clustering that gives the best stability over epsilon. This allows HDBSCAN to find clusters of varying densities (unlike DBSCAN), and be more robust to parameter selection.

Campello, R.J.G.B., Moulavi, D., Sander, J. (2013). Density-Based Clustering Based on Hierarchical Density Estimates. In: Pei, J., Tseng, V.S., Cao, L., Motoda, H., Xu, G. (eds) Advances in Knowledge Discovery and Data Mining. PAKDD 2013. Lecture Notes in Computer Science(), vol 7819. Springer, Berlin, Heidelberg. Density-Based Clustering Based on Hierarchical Density Estimates

L. McInnes and J. Healy, (2017). Accelerated Hierarchical Density Based Clustering. In: IEEE International Conference on Data Mining Workshops (ICDMW), 2017, pp. 33-42. Accelerated Hierarchical Density Based Clustering

Kilosort
Fast spike sorting with drift correction

Pachitariu, Marius, Shashwat Sridhar, Jacob Pennington, and Carsen Stringer. “Spike Sorting with Kilosort4.” Nature Methods 21, no. 5 (May 2024): 914–21. https://doi.org/10.1038/s41592-024-02232-7.

DREDge
Robust online multiband drift estimation in electrophysiology data

DREDge: robust motion correction for high-density extracellular recordings across species. https://www.biorxiv.org/content/10.1101/2023.10.24.563768v1

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

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

pykilomatch-0.0.3.tar.gz (31.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pykilomatch-0.0.3-py3-none-any.whl (32.2 kB view details)

Uploaded Python 3

File details

Details for the file pykilomatch-0.0.3.tar.gz.

File metadata

  • Download URL: pykilomatch-0.0.3.tar.gz
  • Upload date:
  • Size: 31.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pykilomatch-0.0.3.tar.gz
Algorithm Hash digest
SHA256 55e5873e7a366d22bc28a469bb8d4da64da3f8f402bdefa48b5f9f0555abbbb9
MD5 057b05361a6e01ae0512f33a5f7563fd
BLAKE2b-256 18665e90db8dd55e9f41cb7e82bdebac93fb6b3469ff7183969d6acd73471d18

See more details on using hashes here.

Provenance

The following attestation bundles were made for pykilomatch-0.0.3.tar.gz:

Publisher: python-publish.yml on jiumao2/pyKilomatch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pykilomatch-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: pykilomatch-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 32.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pykilomatch-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e9e5c30b7d66a64cb089514487a2fa1f4b0292d81b2e63e7b5a446f51205089a
MD5 216caaf24d7be3a8901e952716760483
BLAKE2b-256 c30be1951e93bda0cb599bb34f77961ccde942b4333410fee1b5ebc2f25f8204

See more details on using hashes here.

Provenance

The following attestation bundles were made for pykilomatch-0.0.3-py3-none-any.whl:

Publisher: python-publish.yml on jiumao2/pyKilomatch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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