Matlab and Python code for novelty exploration behavior analysis in mice. Used after DeepLabCut and MoSeq.
First, run DeepLabCut, please see Training a New Network for DeepLabCut and Running an existing network (Korleki)
After that,
- Edit configuration file
Config_NovAna.m
Especially, be sure to use correct networkname_format
, which is the network name after 'DeepLabCut' without the extension. For example DeepCut_resnet50_MoSeqNoveltySep12shuffle1_1030000
Be sure to use correct videoname_format
, an example file name of your videos, including the '.mp4' or '.avi' extensions. For example, C4_180907_rgb.mp4
- You will need to run the following code directly under the folder containing all the videos and
.csv
files, if the videos are placed under subfolders, use:MoveFromDir.m
- To mannually label the position of the arena and object, please use
MarkObjPos.m
- Calculate head position, speed, angle etc. Also plotting the trajectory, heatmap, etc.
Analysis.m
- Make labeled videos to check whether the labels are correct. This script generate labeled videos with a side bar showing the frame number, distance, orientation, speed, etc. for mannually labeling some interesting behaviors.
VideoLabeling.m
- Code for calculating and plotting the time spent around the object / orienting towards the object.
TimeStatistic.m
Plot_compare.m
- Code for calculating and plotting the time spent at different distances to the object per unit area.
DistHistPerUnitArea.m
- Code for event-based analyses, calculating and plotting several parameters, including number of interaction, time spent interacting with object, time per interaction, body length index, retreat speed, approach-retreat angle, etc.
EventBasedAnalysis.m
- Code for finding the approach-retreat behavior in stimulus novelty mice.
FindingPokeDTW.m
First, run all the Moseq analysis, see MoSeq Example Commands
After that,
- If necessary, split the RGB videos from the raw data generated by MoSeq.
MoSeqMoveRGB.m
- Transfer the data generated by MoSeq to MATLAB readable format.
ModelDataTransfer.py
Run this script in the moseq2
conda enviroment and under the directory where you saved this script (eg. Novelty_analysis/MoSeqAnalysis
), using the following command,
python3 ModelDataTransfer.py
Before running it, please remember to specify the path of the index file and model file, for example
index_file = '/media/richard/DataDrive1/MoSeqData/CvsS_180831/CvsS_20180831_MoSeq/moseq2-index.yaml'
model_file = '/media/richard/DataDrive1/MoSeqData/CvsS_180831/CvsS_20180831_MoSeq/my_model.p'
Also, specify where you would like to save the output file, for example,
save_directory='/home/richard/Desktop/MoSeqDataFrame.mat'
- if you are doing fiber phtotmetry with MoSeq, run the following code to transfer the fiber phtotmetry data to MATLAB readable format.
FPDataTransfer.py
Also, remember to specify the input and output directory.
save_directory='/home/richard/Desktop/MoSeqFP.mat'
filename = '/media/richard/DataDrive1/MoSeqData/MSFP_Test/180922/session_20180922154525/nidaq.dat'
nch=3
nch
is the number of channels plus 1 (timestamps) of your photometry recording. For example, if you are recording two channels, GCaMP and tdTomato, choose nch=3
- Edit mice index file for further analyses, you can find a template here
Mice_Index_Template.m
This script generates a data structure and assigns each mouse an unique integer index for grouping them together later. In the following scripts, mice indexes and date indexes are used by other scripts as specified in this file, please also spcify where to find this mice index file in the following scripts that you need to run.
- Make labeled videos which show the syllables numbers and a color bar in the bottom which shows the syllables being used.
MoSeqVideoLabeling.m
Make labeled videos which show the syllables numbers and a dynamic waveform graph showing the fiber photometry signals in the bottom.
MoSeqFP_Video.m
MoSeqFP_VideoLabeling.m
- Calculate and plot general syllable usage and conpare syllable expression of several different groups.
MoSeqGeneralSyllableAnalysis.m
Remember to spcify the mice and dates of each group. For example, G1 is contextual novelty mice, and G2 is stimulus novelty mice.
G1_Mice=[1 2 3 4];
G2_Mice=[5 6 7 8];
G1_Days=[3 4 5 6];
G2_Days=[3 4 5 6];
% G3 Base line
G3_Mice=1:8;
G3_Days=[1 2];
The results are sorted by (G2-G1)/(G2+G1)
, so on the left hand side are G2 enriched syllables and on the right hand side are G1 enriched syllables.
To do the statistical analysis by two sample t-test, please use
MoSeqSyllableUsageStatisticalAnalysis.m
MoSeqShuffling.m
To calculate syllable length, please use
MoSeqSyllableLength.m
- Structure clusting of syllables,
MoSeqSyllableClustering.m
- Plot the positions of interesting syllables.
MoSeqSyllablePos.m
Specify which syllable you would like to plot by setting IntSyllable
- Calculate and plot the syllable expression at different distance to the object.
MoSeqSyllableDisToObj.m
- Analyze general syllable transition,
MoSeqGeneralTransition.m
Remember to spcify the mice and dates of each group.
- Analyze transitions around an interesting syllable.
MoSeqInterestingNodeTransition.m
Remember to spcify the mice and dates of each group. Also specify which syllable you are interested in by setting, for example
IntNode='70';
- Calculate syllable usage around human labels of an interesting behavior.
MoSeqEventAlignedAnalysis.m
- Calculate syllable usage across trials, across days
MoSeqEventBasedAnalysis.m
- Fiber photometry analysis, Scripts for sychronizing photometry data,
MoSeqFP.m
MoSeqFP_Dis.m
MoSeqFP_raster.m
Running an existing network (Korleki)
Running an existing network (Mitsuko)
Running an existing network (Sara & Eva)
Training a New Network for DeepLabCut
- Train a network locally, and copy the network to the cluster
- Generate a singularity image based on docker image
- Log in the cluster, Copy video to the cluster (/n/regal/uchida_lab)
- Start an interactive session with GPUs
- Load modules and build singularity container
- Point GPUs to different videos and start extraction
- Log into the cluster
- Start an interactive session
- Install and activate moseq2 conda environment
- Install moseq packages
- Use moseq2-batch to generate a shell script
- Execute the shell script, start jobs inside an interactive session.