ephys-analysis
scripts and utilities for processing electrophysiology data
Quick introduction
These scripts are designed to operate on the data after manually sorting the phy output and mergining stimuli information. As a result, everything that follows assumes that:
- you have sorted your data with phy
- you have manually sorted your data with the phy gui
- you have merged events into your kwik file with merge_stim_kwik
Data analysis functions are divided into logically separate components.
We have strived to maintain well documented code, so you won't find detailed escriptions of the functions here. Go to the code and read the docstrings for the functions to get more specifics.
- 'core' contains routines for loading the data and metadata, such as sampling rate.
- 'events' contains routines for loading trial information
- 'clust' constains routines for computing basic features of the clusters, such as waveform metrics and geometric location
- 'spiketrains' contains functions for dealing with segments of your data. You can pass parameters to describe which slice of data you wish to extract and it will return to you the spiketrain. For example, you can use the trials dataframe to find trial times, and then pass those times into 'get_spiketrain' to get the spikes during that trial
-'viz' contains routines to visualize clusters.
input file structure
these scripts assume that they are dealing with an experiment that has been sorted by phy. an example structure is as follows:
Pen01_Lft_AP2500_ML1350__Site10_Z2026__B997_cat_P01_S10_Epc10/
- directory containing the files. the naming convention comes from the way that ChronicScript.s2s and ExportMatlab.s2s name directories. This directory is from Penetration 1 (Left hemisphere, 2500um Anterior, 1350um Lateral), Site 10 (2026um depth), and consists of Epoch10. B997_cat_P01_S10_Epc10
is manually named in the prompt in MatlabExport.s2s so might vary and should not be considered reliable.
Inside this directory are the following files:
B997_cat_P01_S10_Epc10.kwik
- hdf5 file containing spike times, cluster assignments, and event times
B997_cat_P01_S10_Epc10.kwx
- hdf5 file containing the PCA-reduced features that phy used to cluster spikes
B997_cat_P01_S10_Epc10.raw.kwd
- hdf5 file containing the raw waveforms used by phy
B997_cat_P01_S10_Epc10.phy
- a working directory used by phy to cache compture features and masks
params.prm
- python file containing the parameters that phy used to detect and cluster spikes
A1x32-Poly3-6mm-50.prb
- python-formatted probe file defining the channels and adjacency matrix used by phy
More details on these files can be found at http://phy.readthedocs.org/en/latest/kwik-format/
The directory also contains the following files generated by make_kwd
:
B997_cat_P01_S10_Epc10_info.json
- record of parameters used to generate raw.kwd file
indx_port_site.txt
- csv file of raw.kwd channel mapping. columns indicate the phy index, Spike2 channel name, and neuronexus site number
analysis architercture
what we need to be able to do
- get spikes from a given trial
- get spikes from a given stimulus or event
- get spikes from a given neuron
- get spikes from a population of neurons
- make rasters
- make PSTH
- plot spike shapes
- get spike widths
- identify neuron location
- cluster quality metrics
- plot distribution of spike widths in a population
what Zeke also wants
- save needed metadata into one of the HDF5 files (params.prm, indx_port_site.txt, probe file, _info.json, other)
-
Core
- load spikes
- load clusters
- load events
- load spike shapes
- load LFP
- load metadata
-
Neuron metrics
- isolation quality measures
- waveform, features
- spike width
- neuron location
-
Event-responses
- rasters
- PSTHs
- gaussian smoothed
-
Behavior
Test Data
There is data to use for testing on the cube share under ephys-example-data
. It is probably safest to copy this somewhere else for testing analysis code.
Pen01_Lft_AP2500_ML1350__Site10_Z2026__B997_cat_P01_S10_Epc10
- awake behaving block (Justin)
Pen01_Lft_AP100_ML1300__Site03_Z2500__B1056_cat_P01_S03_1
- acute block (Krista & Brad)
approach
If you have code written already that works toward these ends, do the following...
- create a new branch of this repository
- add your files to
ephys
- open a pull request for your branch
We'll hack on and merge branches as needed during the hackathon.
approach (step-by-step)
if you are not already familiar with this process you might enjoy these hopefully interpretable steps
If you have code written already that works toward these ends, do the following...
- Clone the repository on your local computer.
- From the terminal command line on your local computer
- change to the directory you want this repository to live,
- RUN
git clone [https link for repository]
- Branch the repository before making any changes (add files, modify files, etc)
- from within the repository (so cd ../ephys-analysis)
- RUN
git checkout -b [whatever you want to name your branch]
- Add (file system language) files to "ephys" directory
- copy your script that you want to contribute (using cp command in terminal OR dragging and dropping using Finder)
- (or if you do not already have the code written, create a new file from withing ephys and write whatever script you want)
- "Add" (git language) - means something more specific than "copy"
- RUN
git add .
- Adds the files in the local repository and stages them for commit. To unstage a file, use
git reset HEAD YOUR-FILE
.
- commit these changes
- Commits the tracked changes and prepares them to be pushed to a remote repository. To remove this commit and modify the file, use
git reset --soft HEAD~1
and commit and add the file again.
- RUN
git commit -m "whatever message you want to provide about what you did"
- push the changes to the repository [on github?]
- RUN
git push origin [whatever you named your branch in step #2]
- Pushes the changes in your local repository up to the remote repository you specified as the origin
- go online to http://github.com/gentnerlab/ephys-analysis/ to create a pull request for your branch
- after you "pushed your branch" from your computer, your branch should show up in the list under the branches tab in this repository
- CLICK on the "Pull Requests" tab
- CLICK "New Pull Request"
- CHOOSE "base: master" and "compare: [whatever you named your branch in step#2]"
naming conventions
- Functions that put together a filename are prefixed with 'find_'
- Functions that open files on disk and read their contents into memory are prefixed 'load_'
- Functions that return an attribute of some (data, object, etc) are prefixed 'get_'
- Functions that perform a computation are prefixed 'calc_'