Skip to content

Accompanying analysis code for "Stability of motor representations after paralysis"

License

Notifications You must be signed in to change notification settings

AndersenLab-Caltech/fingers_rsa

Repository files navigation

Stability of motor representations after paralysis

This repository contains the scripts to generate figures for Stability of motor representations after paralysis.

Dataset

The dataset is available in NWB:N format from https://dandiarchive.org/dandiset/000147.

Analysis scripts

Python prerequisites

I recommend installing Python package dependencies using conda + poetry.

Package dependencies

Create a minimal virtual environment:

conda create -n fingers_rsa python=3.8
conda activate fingers_rsa

We use poetry to specify package dependencies in pyproject.toml and poetry.lock. To install the dependencies, from the repository directory, run:

poetry install

Downloading the dataset

To download the dataset, change to the data directory and run the download-script:

cd data/
./download_data.sh

For non-Unix environments, you can download the dataset using the equivalent DANDI command:

dandi download DANDI:000147/0.220913.2243

Running the scripts

We use Hydra to specify configuration files and command-line arguments. For some scripts, the default configuration is already specified in the script, so you can run the script without any command-line arguments.

python scripts/peth.py
python scripts/crossval_classify.py

These scripts will output figures to an outputs/date/time/ directory (e.g. outputs/2022-10-13/11-18-05/). The scripts will also log their working/output directory to the console.

To calculate the representational dissimilarity matrices (RDMs), you need to specify the sessions to use for the RSA analysis.

python scripts/calc_rdm.py --multirun session=2018-09-10,2018-09-17a,2018-09-17b,2018-09-24,2018-09-26,2018-10-01,2018-10-12,2018-10-15,2018-10-17,2018-10-22

The following command is equivalent:

python scripts/calc_rdm.py -m +sweep=all_sessions

With the --multirun (-m) option, Hydra effectively runs calc_rdm.py 10 times, once for each session. Aligning and binning spikes takes some time, so you can parallelize multiruns using joblib with the additional command-line argument: hydra/launcher=joblib.

The calc_rdm.py multirun will generate outputs in multirun/date/time/run/ directories (e.g., outputs/2022-10-13/09-51-04/0). The output RDM absolute paths are also logged by calc_rdm.py, e.g.:

[2022-10-13 09:51:27,590][__main__][INFO] - Saving RDMs to: /home/user/Development/fingers_rsa/multirun/2022-10-13/09-51-04/session=2018-09-24/sub-P1_ses-2018-09-24_rdm.hdf5

The RDM files (absolute-path) are used as inputs to representational similarity analysis. For the example above, you would run:

python scripts/representational_similarity_analysis.py rdm_files="/home/user/Development/fingers_rsa/multirun/2022-10-13/09-51-04/*/*_rdm.hdf5"

For representational dynamics analysis (RDA), RDMs need to be calculated for multiple sessions and times. You can run:

python scripts/calc_rdm.py -m +sweep=all_sessions_and_times

This will take ~10 minutes even with parallelization.

Then, similar to RSA, you would pass in the resulting output RDM files to the RDA script:

python scripts/representational_dynamics_analysis.py rdm_files="/home/user/Development/fingers_rsa/multirun/date/time/*/*_rdm.hdf5"

Development environment

I developed and tested these Python scripts on Ubuntu 20.04 LTS. While they should work on other operating systems, I have not tested them. If you run into any issues, please open an issue and list your operating system and Python version.

Citation

Charles Guan, Tyson Aflalo, Carey Y Zhang, Elena Amoruso, Emily R Rosario, Nader Pouratian, Richard A Andersen (2022) Stability of motor representations after paralysis eLife 11:e74478. https://doi.org/10.7554/eLife.74478

About

Accompanying analysis code for "Stability of motor representations after paralysis"

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published