Analysis code for: "Dynamic network features of functional and structural brain networks support visual working memory in aging adults"
This repository contains the code used for analyses in:
Neudorf, J., Shen, K., & McIntosh, A. R. (2024). Dynamic network features of functional and structural brain networks support visual working memory in aging adults. bioRxiv. https://doi.org/10.1101/2024.07.30.605891
git clone https://github.com/McIntosh-Lab/dFC_Cam-CAN.git
cd dFC_Cam-CAN
conda create -n neudorf_dFC -c conda-forge python=3.10 numpy scipy nibabel nilearn matplotlib pillow pandas seaborn tqdm statsmodels plotnine
conda activate neudorf_dFC
pip install nctpy
python -m pip install matlabengine=9.13.11 #matlab 2022b.2
cd python_packages/brainvistools
python -m pip install .
cd ../PLS_wrapper
python -m pip install .
cd ../PyNeudorf
python -m pip install .git clone https://github.com/McIntosh-Lab/dFC_Cam-CAN.git
cd dFC_Cam-CAN
module load StdEnv/2020 matlab/2022b.2 python/3.10
python3.10 -m venv neudorf_dFC
source neudorf_dFC/bin/activate
pip install numpy scipy nibabel nilearn matplotlib==3.6.2 pillow pandas seaborn==0.12.1 tqdm statsmodels plotnine==0.12.3 certifi
pip install nctpy
#edit line below by finding matlabroot using `which matlab`, and substitute `matlab` executable with `glnxa64`
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/cvmfs/restricted.computecanada.ca/easybuild/software/2020/x86-64-v3/Core/matlab/2022b.2/bin/glnxa64
#set matlabengine version number to match matlab version 2022b.2
python -m pip install matlabengine==9.13.11
cd python_packages/brainvistools
python -m pip install .
cd ../PLS_wrapper
python -m pip install .
cd ../PyNeudorf
python -m pip install . Rscript install_packages.rmodule load StdEnv/2020 r/4.3.1 gcc/9.3.0 gdal/3.5.1 udunits/2.2.28
mkdir -p ~/.local/R/$EBVERSIONR
export R_LIBS=~/.local/R/$EBVERSIONR/
Rscript install_packages.rFollow instructions here and add plscmd folder to startup.m: https://github.com/McIntosh-Lab/PLS
These commands should be run in the main dFC_Cam-CAN directory.
git clone https://github.com/McIntosh-Lab/PLS
cp -r PLS/plscmd ~/matlab
echo "addpath(genpath('~/matlab/plscmd'))" >> ~/matlab/startup.m
echo "addpath(genpath('${PWD}/python_packages/PLS_wrapper'))" >> ~/matlab/startup.mLEiDA results used in paper are in matlab_toolboxes/leida-matlab-1.0/res_Cam-CAN_TVB_SchaeferTian_218
PLS in outputs/leida-matlab/PLS, PLS_group_analyses, and outputs/nctpy/5/PLS
NCT outputs in outputs/nctpy
For code review:
Get data from ~/projects/def-rmcintos/jneudorf/Cam-CAN/code_review (behavioural data, SC matrices and rsfMRI timecourses)
Extract data/ folder from dFC_data.tar.gz into main folder.
To reproduce:
- Figure 4 PLS behavioural correlation (A;
outputs/leida-matlab/PLS/TP_dict_K5_age_1000_its_197_subs_0_to_150_age_range/TP_dict_K5_age_1000_its_197_subs_0_to_150_age_range_lv1_behav_corr.png) and BSR transition probability matrix (B;outputs/leida-matlab/PLS/TP_dict_K5_age_1000_its_197_subs_0_to_150_age_range/TP_dict_K5_age_1000_its_197_subs_0_to_150_age_range_lv1_bsr_matrix.png) - Figure 5 young adult behavioural correlation (B;
outputs/nctpy/5/PLS/state_transition_5_to_3_node_energy_dict_continous_age_Prcsn_PerceptionTest_1000_its_114_subs_0_to_50_age_range/state_transition_5_to_3_node_energy_dict_continous_age_Prcsn_PerceptionTest_1000_its_114_subs_0_to_50_age_range_lv1_behav_corr.png) and brain map BSR (C;outputs/nctpy/5/PLS/state_transition_5_to_3_node_energy_dict_continous_age_Prcsn_PerceptionTest_1000_its_114_subs_0_to_50_age_range/state_transition_5_to_3_node_energy_dict_continous_age_Prcsn_PerceptionTest_1000_its_114_subs_0_to_50_age_range_lv1_bsr_cortex.pngandoutputs/nctpy/5/PLS/state_transition_5_to_3_node_energy_dict_continous_age_Prcsn_PerceptionTest_1000_its_114_subs_0_to_50_age_range/state_transition_5_to_3_node_energy_dict_continous_age_Prcsn_PerceptionTest_1000_its_114_subs_0_to_50_age_range_lv1_bsr_subcortex.png) plus older adult behavioural correlation (D;outputs/nctpy/5/PLS/state_transition_5_to_3_node_energy_dict_continous_age_Prcsn_PerceptionTest_1000_its_83_subs_50_to_150_age_range/state_transition_5_to_3_node_energy_dict_continous_age_Prcsn_PerceptionTest_1000_its_83_subs_50_to_150_age_range_lv1_behav_corr.png) and brain map BSR (E;outputs/nctpy/5/PLS/state_transition_5_to_3_node_energy_dict_continous_age_Prcsn_PerceptionTest_1000_its_83_subs_50_to_150_age_range/state_transition_5_to_3_node_energy_dict_continous_age_Prcsn_PerceptionTest_1000_its_83_subs_50_to_150_age_range_lv1_bsr_cortex.pngandoutputs/nctpy/5/PLS/state_transition_5_to_3_node_energy_dict_continous_age_Prcsn_PerceptionTest_1000_its_83_subs_50_to_150_age_range/state_transition_5_to_3_node_energy_dict_continous_age_Prcsn_PerceptionTest_1000_its_83_subs_50_to_150_age_range_lv1_bsr_subcortex.png) Note that the exact BSRs will be different than in the paper because of resampling. PLS outputs saved inoutputs/leida-matlab/PLSandoutputs/nctpy/5/PLS
Order to run code:
consistency_thresholding.pyimport_Cam-CAN_data.pyprep_data.py- LEiDA toolbox in
matlab_toolboxes/leida-matlab-1.0/. Info is in README.md as well, but edit paths at the top ofLEiDA_Start.mandrun_all_after_start.m. Then runLEiDA_Start.mfollowed byrun_all_after_start.m. You can changen_permutationsandn_bootstrapsto a lower number for testing to make these run faster. leida-matlab_analyses.pywill perform PLS analyses on the LEiDA outputs and produce images used in figures 2, 3, and 4.nctpy_analyses.pywill perform the network control theory simulation and the PLS analysis of the state 5 to 3 transition (figure 5).PLS_group_analyses/PLS_group_analyses.mperforms secondary mean-centred PLS analyses for LEiDA and NCT analyses.
For HPC (Alliance Canada), use sbatch submission scripts provided. These scripts should be submitted as a job while in the main dFC_Cam-CAN directory, unless otherwise specified. In order to submit these scripts as jobs, please use the sbatch command (see first bullet for an example):
sbatch 1_2_3_submit_preprocessing.sh- change directories with
cd matlab_toolboxes/leida-matlab-1.0thensbatch 4_submit_leida.sh(refer to step 4. above and edit paths. This script should be submitted as a job while in thematlab_toolboxes/leida-matlab-1.0/directory.) When finished change directories back to project directory withcd ../... sbatch 5_submit_leida_analyses.shsbatch 6_submit_nctpy_analyses.sh(changeRSCRIPT='/usr/bin/Rscript'at top ofnctpy_analyses.pytoRSCRIPT='/cvmfs/soft.computecanada.ca/easybuild/software/2020/avx2/Core/r/4.3.1/bin/Rscript')- change directories with
cd PLS_group_analysesthensbatch 7_submit_group_analysis.sh(This script should be submitted as a job while in thePLS_group_analyses/directory.)