Logan's neurophysiology pipeline - theunissenlab/lab-documentation GitHub Wiki
- Instructions for creating accounts for condor
- isolate suss code so its not imported in songephys
Note: The network is organized as 2 separate (but connected) subnetworks: The TLab network that you access from any desktop machine (ex aquilla, corvus..) and the data servers (ex condor). Any environment, software that you install under your account in one subnetwork will NOT "propagate" to the other and you will have to set them independently.
Refer to this page for instructions, make sure you select the appropriate instructions (linux): https://www.anaconda.com/docs/getting-started/miniconda/install#macos-linux-installation
Note: you will have to restart the ssh agent each time you login (eval "$(ssh-agent -s)"
) unless you do the following:
-
vi ~/.bashrc
open your bashrc file in edit mode - add the following lines at the end:
-
eval $(ssh-agent -s)
Starts ssh agent at each boot -
ssh-add ~/.ssh/id_<KEYNAME>
Add the key to the ssh agent at each boot. KEYNAME is how you decided to name it when you created it. if you don't remember, just check the name of the last ssh key you added by runningls -lt ~/.ssh/id_*
-
1.3 - Creating songephys environment on your lab accounts under both the TLab network and Condor network:
-
git clone -b songephys-module [[email protected]](mailto:[email protected]):theunissenlab/songephys
Clone the songephys github where you store your code (ex:auto/fhome/username/code
or/nfs/zdrive/username/code
): -
cd songephys
Go into the directory -
conda env create -f environment.yml
Build the environment -
conda activate song
Activate the environment -
pip install -e .
Install the source code in editable mode so that you can pull new versions without having to install again the code with pip
Copy probes to kilosort probe dir: Kilosort stores prb files for probes in ~/.kilosort/probes.
from songephys directory in your code folder, copy the probes to a kilosort directory you make at the root
mkdir -p ~/.kilosort/probes
cp probes/* ~/.kilosort/probes
Pull strfpy from github in your code directory (This step is probably only necessary on your Condor network account, strfpy is used when creating nwb files at the end of step 2.2):
git clone [email protected]:theunissenlab/strfPy.git
cd strfPy/module
-
pip install -e .
Install the source code in editable mode so that you can pull new versions without having to install again the code with pip
Open your bashrc file (~/.bashrc) with your preferred editor (vi, vim) and add the following lines:
-
export DATA_DIR="/mnt/condor/Data/"
This is the root path to the raw data folder where data are transferred to from the acquisition computer in 131. These data are never touched after transfer. The exact path to raw data for a given experiment (=bird) is/mnt/condor/Data/OperantEphys/<Birdname>
-
export SONGEPHYS_DIR="/mnt/condor/<username>/songephys_data/"
This is the path to your working directory under condor where you will append your analysis results in your own directory (ex spike sorting etc...) -
export PATH="/nfs/zdrive/<username>/<codeFolder>/songephys/bin":$PATH
This is the path to the code you cloned from github at step 1.3 on Condor network
NOTE: for these changes to take effect you must close and reopen your terminal connection (logout and ssh again)
Open your bashrc file (~/.bashrc) with your preferred editor (vi, vim) and add the following lines:
-
export DATA_DIR="/mnt/condor/Data/"
This is the root path to the raw data folder where data are transferred to from the acquisition computer in 131. These data are never touched after transfer. The exact path to raw data for a given experiment (=bird) is/mnt/condor/Data/OperantEphys/<Birdname>
-
export SONGEPHYS_DIR="/path/to/local/ssd/"
(ex: on corvus/mnt/Data/<username>/songephys-data/
) This is a path to your local working directory, a local SSD storage on which you want to refer to when running local code on your desktop machine and avoid data transfer over to Condor -
export PATH="/auto/fhome/<username>/<codefolder>/songephys/bin":$PATH
This is the path to the code you cloned from github at step 1.3 on TLab network
NOTE: for these changes to take effect you must close and reopen your terminal connection (logout and ssh again)
Follow the installation instruction in the readme of the official GitHub page for Phy: https://github.com/cortex-lab/phy What worked on Julie's TLab account:
-
conda create -n phy2 -y python=3.9 cython dask h5py joblib matplotlib numpy pillow pip pyopengl pyqt pyqtwebengine pytest python qtconsole requests responses scikit-learn scipy traitlets
Install phy with conda but using Python 3.9 -
pip install git+https://github.com/cortex-lab/phy.git
pip install the phy library -
conda remove krb5
removibg the krb5 library which was causing issues -
pip install matplotlib
reinstalling matplotlib that was removed when removing krb5 with conda -
pip install qtconsole
reinstalling qtconsole that was removed when removing krb5 with conda
Once your data is copied into the raw data folder /mnt/condor/Data
(DATA_DIR
)
ssh condor
-
conda activate song
Activate your environment -
cd $SONGEPHYS_DIR
Go to root of the path to your working folder under Condor -
mkdir -p OperantEphys/<BIRDNAME>
Make the folder for that experiment (=bird) -
song create-config OperantEphys/<BIRDNAME>
Create a project config file atOperantEphys/<BIRDNAME>/project_config.yaml
Edit that file to reflect accurate ML position of electrodes, and probe name. H10 is the standard Cambridge probe
If not already done during that terminal session:
-
ssh condor
-
conda activate song
Activate your environment -
cd $DATA_DIR/OperantEphys/<BIRDNAME>
Go to the raw data folder for that experiment e.g/mnt/condor/Data/OperantEphys/<BIRDNAME>
-
song gen-filelists
generate txt files in$DATA_DIR/OperantEphys/<BIRDNAME>/filelists
, 1 file per rhd folder in your raw directory (= 1 file per continuous recording with the Intan software = recording session = site). Each of these files lists the path to all files related to that recording session with respect to the experiment path$DATA_DIR/OperantEphys/<BIRDNAME>/
: name of the settings file, names of the rhd files recorded during that session, names of the pyoperant files recorded during that session.
The analysis code relies on these lists of files to map neural recordings with behavior and playback data. Because you copy these when you analyze each of the recording session, you can at this point modify them if you want for instance ignore certain pyoperant data.
2.2 - Setting up and obtaining binary versions of neural recordings for a site = recording session = continuous recording session under Intan
All the automatically detected sites are listed as txt files (generated above, see 2.1.2) in the raw data folder for that experiment: $DATA_DIR/OperantEphys/<BIRDNAME>/filelists
From now on you will not be writing to the raw data folder but to your working directory under Condor ($SONGEPHYS_DIR/OperantEphys/<BIRDNAME>
). You will obtain and save neural recordings for each site as binary files which are the input format to the spike sorting algorithm Kilosort.
NOTE: All song
commands have to be run from the experiment working directory $SONGEPHYS_DIR/OperantEphys/<BIRDNAME>
If not already done during that terminal session:
-
ssh condor
-
conda activate song
Activate your environment -
cd $SONGEPHYS_DIR/OperantEphys/<BIRDNAME>
orcd /mnt/condor/<USERNAME>/songephys_data/OperantEphys/<BIRDNAME>
Go to your working directory on Condor subnetwork -
mkdir sites
Create a directory to store your data for each site
For each site listed under $DATA_DIR/OperantEphys/<BIRDNAME>/filelists
, you want to create a directory for that site, copy the txt file listing all the files related to that sites in this directory (here is the option to modify that txt file if you want the analysis code to ignore some problematic rhd files, pyoperant files etc...) and create a site config. For example let's create a site for filelists/ColCol000000S__yymmdd_hhmmss.txt
where ColCol000000S is <BIRDNAME>
:
-
mkdir sites/ColCol000000S__yymmdd_hhmmss_site1_op_pb
Create a site directory (the name can be whatever you want, but make it descriptive) -
cp $DATA_DIR/OperantEphys/ColCol000000S/filelists/ColCol000000S__yymmdd_hhmmss.txt sites/ColCol000000S__yymmdd_hhmmss_site1_op_pb/filelist.txt
Copy the file list into the site directory -
song create-site sites/ColCol000000S__yymmdd_hhmmss_site1_op_pb --auto --depth 2.00
Create a site config file (site_config.yaml) inside this site directory and specify the recording depth at 2.00 mm (change that to be your own recording depth!)
At this point, you can add bad_channels
to the site config site_config.yaml (use your favorite Terminal editor, vi or vim or else)
Example:
bad_channels:` `- 8` `- 10` `- 14` `- 16` `- 20` `- 22` `- 25` `- 63
You can check the sites that you have set-up so far by running the following command from the experiment directory ($SONGEPHYS_DIR/OperantEphys/<BIRDNAME>
):
-
song list-sites
-
song gen-singlesite-files sites/ColCol000000S__yymmdd_hhmmss_site1_op_pb
Generates all binary files necessary to spike sort with Kilosort in a newraw
folder in this site folder for that experiment (sites/ColCol000000S__yymmdd_hhmmss_site1_op_pb
), in Condor working directory. -
song gen-nwb sites/ColCol000000S__yymmdd_hhmmss_site1_op_pb
Generates an nwb file that combine all the binary files of that site and create a unique structured dataset in the nwb format in this site folder for that experiment (sites/ColCol000000S__yymmdd_hhmmss_site1_op_pb
), in Condor working directory.
This is useful whenever you want to work on your data locally but want to avoid the slow data transfer between your local desktop machine and Condor, for instance to run Kilosort locally instead of over Condor and to run phy). Better do this step now because in the end you will want your data to be local for phy manual curation (see 2.4.2).
On the machine you want to do processing (e.g. spike sorting on a local machine) and in the folder you set as being your local working folder at step 1.4.2 ($SONGEPHYS_DIR):
If not already done during that terminal session:
-
conda activate song
Activate your environment -
mkdir -p OperantEphys/<BIRDNAME>
make a director for Ephys data and then a directory for the bird. BIRDNAME should be the same as the one you set in your raw data directory on Condor -
cd OperantEphys/<BIRDNAME>
-
song create-remote-config <path/to/condor/working/directory>/OperantEphys/<BIRDNAME>
Remember that your working directory under condor was set at step 1.4.1 as/mnt/condor/<USERNAME>/songephys_data/
. Here you CANNOT use the $SONGEPHYS_DIR variable because under the TLab network it points to the working directory you are currently in and not to your working directory under Condor. -
ls $SONGEPHYS_DIR/OperantEphys/<BIRDNAME>
Confirm thatremote_config.yaml
now exists in your local working directory for that experiment -
song list-sites
will list all the sites you processed on Condor at step 2.2 although you are on a different machine and nothing is in your working directory for now but your remote_config.yaml file -> The set up is working!
From the Experiment working directory (on Condor or on your local machine if you did step 2.3):
If not already done during that terminal session:
-
conda activate song
Activate your environment -
song sort-singlesite sites/<SITENAME> -d ks4_<intials>_<date>
SITENAME is for instance: ColCol000000S__yymmdd_hhmmss_site1_op_pb. This command will copy the binary files if you are on a local desktop machine from Condor to a newraw
folder in your site folder, and run spike sorting, saving the output of kilosort in the folderks4_<intials>_<date>
. In this folder, You will find one folder per shank. They each have been spike sorted independently.
Known issue with sort-singlesite
: it imports the module suss-sorter which is not set up in your song environment. If the command fails with the following error: ModuleNotFoundError: No module named 'suss'
pip install suss from your code directory:
cd $PATH
cd ..
cd ..
pip install git+ssh://[email protected]/theunissenlab/suss-sorter.git
At this point you want to work in a local machine working directory and not on Condor, so go to step 2.3 if you did not do that already. Copy the kilosort output folder ks4__ on your local machine. If you did the spike sorting on your Experiment folder on Condor then the params.py will point to that folder directly. Alternatively you can also copy your raw
folder that contains all the binary files from your Condor working directory to your local machine working directory and then modify the path to the data indicated in params.py.
From the Experiment working directory on your local machine:
-
cd /sites/<SITENAME>/ks4_<INITIALS>_<DATE>/shank_0
Go to the first shank directory -
phy template-gui params.py
launch manual curation with phy on first shank data -
cd /sites/<SITENAME>/ks4_<INITIALS>_<DATE>/shank_1
Go to the second shank directory -
phy template-gui params.py
launch manual curation with phy on second shank data
If you want to sort with Phy on a machine that is not on the Theunissen network then transfer data on your machine after installing Phy (step 1.5 above):
-
cd <PHY_WORKING_DIR>
go to the directory from which you will run Phy on your local machine -
scp -r corvus:/mnt/nfs_share/<USERNAME>/songephys_data/OperantEphys/<BIRDNAME>/sites/<SITENAME>/ks4_<INITIALS>_<DATE> .
Copy the result of Kilosort -
cd ks4_<INITIALS>_<DATE>
mkdir raw
cd raw
create the directory that will contain the raw data -
scp corvus:/mnt/nfs_share/<USERNAME>/songephys_data/OperantEphys/<BIRDNAME>/sites/<SITENAME>/raw/<SITENAME>.bin
transfer raw data locally -
cd ..
cd ks4_<INITIALS>_<DATE>
vi params.py
Update the path to raw data in Phy params file to point to your new raw directory (ks4_<INITIALS>_<DATE>/raw
)
Then follow the steps above from each shank directory to perform the manual curation. Once done, delete the raw directory that you created locally (rm -r <PHY_WORKING_DIR>/ks4_<INITIALS>_<DATE>/raw
) and transfer the data back on the Theunissen Lab network (scp -r <PHY_WORKING_DIR>/ks4_<INITIALS>_<DATE> corvus:/mnt/nfs_share/<USERNAME>/songephys_data/OperantEphys/<BIRDNAME>/sites/<SITENAME>/
).
2.4.3 - Transfer data back to Condor working directory and create an updated nwb file with spike sorting results
From your Experiment working directory on TLab ($SONGEPHYS_DIR/OperantEphys/)
-
rsync --progress -rv --exclude=".*/" sites/<SITENAME>/ks4_<INITIALS>_<DATE>/ /mnt/condor/<USERNAME>/songephys_data/OperantEphys/<BIRDNAME>/sites/<SITENAME>/ks4__phy_<INITIALS>_<DATE>
Transfers the data. ssh condor
conda activate song
cd /mnt/condor/<USERNAME>/songephys_data/OperantEphys/<BIRDNAME>
-
song add-sorted-units sites/<SITENAME> --dir ks4__phy_<INITIALS>_<DATE>
Updated the nwb of that site with results of spike sorting