scientific-skills/Data Analysis/neuropixels-analysis/SKILL.md
End-to-end Neuropixels extracellular electrophysiology analysis (SpikeGLX/Open Ephys/NWB) including preprocessing, motion correction, Kilosort4 spike sorting, QC metrics, and Allen/IBL-style curation; use when processing Neuropixels recordings or when users mention Neuropixels, SpikeGLX, Open Ephys, Kilosort, quality metrics, drift/motion correction, or unit curation.
npx skillsauth add aipoch/medical-research-skills neuropixels-analysisInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
4 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this skill in any of the following situations:
.ap.bin/.lf.bin/.meta), Open Ephys (.continuous/.oebin), or NWB (.nwb) into a consistent analysis pipeline.Reference guides (if present in the repository) can be used for deeper explanations:
reference/standard_workflow.mdreference/api_reference.mdreference/plotting_guide.mdreference/PREPROCESSING.md, reference/MOTION_CORRECTION.md, reference/SPIKE_SORTING.mdreference/QUALITY_METRICS.md, reference/AUTOMATED_CURATION.md, reference/AI_CURATION.mdPython dependencies (typical versions known to work; adjust to your environment):
python >= 3.9spikeinterface[full] >= 0.99probeinterface >= 0.2neo >= 0.13kilosort >= 4.0 (Kilosort4; GPU required)spykingcircus >= 1.1 (SpykingCircus2; CPU)mountainsort5 >= 0.5 (CPU)anthropic >= 0.20ibllib >= 2.0ibl-neuropixel >= 1.0The following example is designed to be a complete, runnable script (assuming dependencies and a valid dataset path). It loads SpikeGLX data, preprocesses, estimates/corrects motion, runs Kilosort4, computes metrics, curates units, generates a report, and exports to Phy and NWB.
import spikeinterface.full as si
import neuropixels_analysis as npa
def main():
# Parallelization / chunking settings used by SpikeInterface functions
job_kwargs = dict(n_jobs=-1, chunk_duration="1s", progress_bar=True)
# 1) Load data (SpikeGLX example)
# For Open Ephys: si.read_openephys("/path/to/Record_Node_101/")
# For NWB: si.read_nwb("/path/to/file.nwb")
recording = si.read_spikeglx("/path/to/spikeglx_folder", stream_id="imec0.ap")
# Optional: slice first 60 seconds for a quick test
fs = recording.get_sampling_frequency()
recording = recording.frame_slice(0, int(60 * fs))
# 2) Preprocess (recommended chain; wrapper may include the same steps)
# Note: phase_shift is mandatory for Neuropixels 1.0 and not needed for 2.0.
rec = npa.preprocess(recording)
# 3) Estimate drift/motion and correct if needed
motion_info = npa.estimate_motion(rec, preset="kilosort_like", **job_kwargs)
npa.plot_drift(rec, motion_info, output="drift_map.png")
# Example threshold: correct if max drift exceeds 10 µm
if float(motion_info["motion"].max()) > 10.0:
rec = npa.correct_motion(rec, preset="nonrigid_accurate", **job_kwargs)
# 4) Spike sorting (Kilosort4 recommended; requires GPU)
sorting = si.run_sorter("kilosort4", rec, folder="ks4_output", **job_kwargs)
# 5) Post-processing + metrics
analyzer = si.create_sorting_analyzer(sorting, rec, sparse=True)
analyzer.compute("random_spikes", max_spikes_per_unit=500, **job_kwargs)
analyzer.compute("waveforms", ms_before=1.0, ms_after=2.0, **job_kwargs)
analyzer.compute("templates", operators=["average", "std"], **job_kwargs)
analyzer.compute("spike_amplitudes", **job_kwargs)
analyzer.compute("correlograms", window_ms=50.0, bin_ms=1.0, **job_kwargs)
analyzer.compute("unit_locations", method="monopolar_triangulation", **job_kwargs)
analyzer.compute("quality_metrics", **job_kwargs)
metrics = analyzer.get_extension("quality_metrics").get_data()
metrics.to_csv("quality_metrics.csv")
# 6) Automated curation (Allen/IBL-style)
labels = npa.curate(metrics, method="allen") # e.g., "allen", "ibl", "strict"
# 7) Report
results = {"sorting": sorting, "metrics": metrics, "labels": labels, "analyzer": analyzer}
npa.generate_analysis_report(results, "output_report/")
npa.print_analysis_summary(results)
# 8) Export
si.export_to_phy(
analyzer,
output_folder="phy_export/",
compute_pc_features=True,
compute_amplitudes=True,
)
from spikeinterface.exporters import export_to_nwb
export_to_nwb(rec, sorting, "output.nwb")
if __name__ == "__main__":
main()
si.read_spikeglx(path, stream_id="imec0.ap")si.read_openephys(path)si.read_nwb(path)Neuropixels probe types commonly encountered:
A standard spike-band preprocessing sequence is:
si.phase_shift) for NP1.0.si.detect_bad_channels) and removal.Key parameters:
freq_min (high-pass cutoff): typical 300–400 Hzpreset="kilosort_like": faster estimation aligned with common sorter assumptionspreset="nonrigid_accurate": more robust correction for severe driftOperational threshold often used in practice:
Sorter parameters to tune (Kilosort4 examples):
batch_size: samples per batch (often ~30000 by default)nblocks: number of drift blocks (increase for long recordings)Th_learned: detection threshold (lower → more spikes, potentially more false positives)Using SortingAnalyzer, the pipeline typically computes:
ms_before, ms_after)window_ms=50, bin_ms=1)monopolar_triangulation)Common QC thresholds (dataset-dependent; document your choices):
snr_threshold: often 3–5isi_violations_ratio: often 0.01–0.5presence_ratio: often 0.5–0.95A conservative “good unit” selection often combines:
Example rule (illustrative):
presence_ratio > 0.9isi_violations_ratio < 0.5amplitude_cutoff < 0.1For borderline units (e.g., moderate SNR), AI-assisted review can be used to interpret:
If your repository provides npa.analyze_unit_visually(...), it can be integrated with an API client (e.g., anthropic) to generate structured curation suggestions.
tools
Generates complete conventional oncology bulk-transcriptome biomarker and hub-gene research designs from a user-provided cancer type and study direction. Always use this skill whenever a user wants to design, plan, or build a tumor bioinformatics study centered on differential expression, prognostic filtering or risk modeling, PPI-based hub-gene prioritization, diagnostic/prognostic evaluation, clinical association, immune infiltration context, methylation context, and optional tissue or cell validation. Covers five study patterns (signature-first prognostic workflow, hub-gene-first biomarker workflow, hybrid signature-to-hub workflow, immune-context biomarker workflow, translational validation workflow) and always outputs four workload configs (Lite / Standard / Advanced / Publication+) with recommended primary plan, step-by-step workflow, figure plan, validation strategy, minimal executable version, publication upgrade path...
development
Generates complete conventional non-oncology bioinformatics research designs from a user-provided disease context, process-related gene family or biological theme, and validation direction. Use when a study centers on multi-dataset bulk transcriptome integration, DEG analysis, process-gene intersection, enrichment analysis, GSEA, PPI hub-gene prioritization, TF/miRNA regulatory networks, ROC-based biomarker evaluation, and immune infiltration analysis. Covers five study patterns (process-DEG discovery, enrichment/GSEA interpretation, hub-gene prioritization, regulatory-network and immune interpretation, multi-layer public validation) and always outputs Lite / Standard / Advanced / Publication+ with a recommended primary plan, stepwise workflow, figure plan, validation hierarchy, minimal executable version, publication upgrade path, and strictly verified literature retrieval.
tools
Plans confounder control, variable adjustment logic, and bias mitigation strategies at the protocol stage for clinical, epidemiologic, translational, observational, and biomarker studies. Always use this skill when a user needs to identify major confounders, decide which variables should or should not be adjusted for, compare matching/stratification/weighting approaches, anticipate selection or measurement bias, or pressure-test a study design before execution. Focus on bias sensing, causal structure awareness, variable-role classification, and critical design review rather than generic statistical advice.
testing
Generates complete comparative network-toxicology research designs from a user-provided exposure pair, shared toxic phenotype, and validation direction. Use when a study centers on two related exposures under one outcome and needs target collection, shared-vs-specific target decomposition, enrichment, PPI hub prioritization, docking, optional transcriptomic cross-checks, and conservative mechanistic synthesis. Covers five study patterns and always outputs Lite / Standard / Advanced / Publication+ with a recommended primary plan, stepwise workflow, figure plan, validation hierarchy, minimal executable version, publication upgrade path, and strictly verified literature retrieval.