This repository contains the Python and MATLAB scripts that have been used to produce and analyze the data presented in Markov et al, 2021 (preprint here).
The repo is organized in the following subfolders:
- experiment_control: scripts to run all the behavioral and imaging experiments, based on the Stytra library, and they provide a self-contained description of the behavioral paradigms described in the paper. To test them, you can refer to the Stytra documentation for software installation and a description of the hardware. These protocols were run using the 0.8.5 Stytra version.
- preprocessing: python notebooks and scripts to run all the preprocessing of the imaging data, using either the fimpy library or the suite2p library.
- analysis: MATLAB code for the analyses in the paper. Divided in three subsections:
- MATLAB_functions (utility functions)
- behavioral_analysis
- feedback_control_model
- imaging_analysis
- MATLAB code: all MATLAB code was developed using MATLAB 2018b
- Python code: all Python scripts has been tested and run on Python 3.7. Stytra scripts were run using Stytra 0.8.5. Suite2p calcium imaging data preprocessing was run using suite2p 0.7.1. Custom calcium imaging data preprocessing was done using code then moved to this fimpy repository.
For replication of experiments using Stytra, you can refer to the Stytra installation guide and the rest of Stytra documentation.
For reproducing MATLAB-based analyis, you will need the data uploaded with the manuscript.
Note that many functions use custom-written utility functions that can be found here, so please use addpath(genpath(path/to/utility functions))
in order to reproduce the analysis.
All behavioral data was acquired with Stytra and analyzed using custom-written MATLAB code here. This code uses raw compressed data uploaded with the manuscript and returns a master structure containing the processed information for every fish. This information includes time points of swimming bouts, parameters of each bout (such as bout duration, peak tail beat amplitude, power profiles, duration of subsequent interbout, etc.), parameters for each trial (such as average bout/interbout duration, number of bouts, etc.) and metadata for each fish.
All imaging data was acquired and pre-processed using custom-written Python software or the published package suite2p. The pre-processing included alignment and detection of ROIs. We provide the code used for image preprocessing, but not the raw imaging data for size constraints.
All subsequent analysis was performed in MATLAB using custom-written code in here. It is organized in three subfolders:
- whole_brain_imaging_inetgrators (experiment from Fig. 3)
- PC_imaging_long_term_adaptation (experiment from Fig. 6)
- whole_brain_imaging_long_term_adaptation (experiment from Fig. 7)
In each subfolder, there is a main filed called
[experiment_name]_analysis.mat
, and other files which are called by the main file. Each of the files performs a certain analysis step, such as anatomical registration of the ROIs to a common reference brain, computing triggered averages, sensory and motor scores, bar codes, time constants, etc., and saves the outcome of this step in a separate file. Note that we have only uploaded registered coordinates of ROIs, so reproduction of the registration step is not possible.
MATLAB code used for the feedback control model can be found at here and has a separate readme.txt file.
Finally, Markov_et_al_2021_Make_Figures.m takes analyzed data and produces all panels used in the Maniscript.
For any question about the code, you can write at ruben.portugues@tum.de.