MATLAB and Python workflows for exploring neuronal spike waveforms, calculating waveform attributes, comparing k-means with Ward hierarchical clustering, and visualizing clusters in PCA space.
The repository also includes a plot of all waveforms and a results slide deck.
- Inspect waveform traces and check for missing values
- Calculate maximum amplitude, minimum amplitude, and area under the curve
- Classify waveforms by the relative size of their positive and negative peaks
- Group waveforms using k-means and Ward hierarchical clustering
- Project waveforms onto the first two principal components to visualize cluster assignments
- Plot individual waveforms and mean traces for each cluster
PCA is used for visualization in these scripts; clustering is performed on waveform samples. Area under the curve is calculated as a waveform attribute, not used as a clustering input.
analyze_spike_waveforms.m— MATLAB waveform attributes, clustering, PCA plots, cluster traces, and attribute plotsspike_clustering.py— Python command-line workflow that saves waveform, PCA, and cluster-trace figuresneuroPixels_crossCorr_night.m— separate MATLAB cross-correlation analysisDS.txt— optional direction-selectivity values; the Python clustering script checks this file but does not use it to form clusters*.png— selected example outputsspike_clustering_results_verified.pptx— additional results
The clustering scripts require a text file containing one waveform per row and one sample per column. spike_waveforms.txt is not currently included in this repository. Supply an appropriately shareable waveform file before running the scripts.
The MATLAB script expects spike_waveforms.txt beside analyze_spike_waveforms.m. It reads DS.txt from the same location when available. It stops if the waveform matrix contains NaN values, so clean missing values before running it.
Place spike_waveforms.txt in the repository directory and run analyze_spike_waveforms.m in MATLAB. The script uses eight clusters by default; change numClusters near the top to use another value.
Install NumPy, Matplotlib, SciPy, and scikit-learn, then run:
python spike_clustering.py spike_waveforms.txt --output-dir figuresTo include the optional direction-selectivity file:
python spike_clustering.py spike_waveforms.txt --ds DS.txt --output-dir figuresThe Python script uses the first 2,000 waveforms for its clustering demonstration by default. Adjust this with --n-demo; adjust the cluster count with --clusters. Ward clustering can be skipped with --no-ward.
Data_Science_Tasks contains Jupyter notebooks for PCA, clustering-method comparison, and cluster characterization. neuropixels_analysis contains a separate waveform import and cleaning notebook.