Skip to content

Analysis protocol

Neal W Morton edited this page Mar 29, 2022 · 11 revisions

Analysis on local machine

Install scripts

conda create -n tesser python=3.7
conda activate tesser
git clone https://github.com/prestonlab/tesser.git
cd tesser
pip install -e .
pip install jupyterlab
python -m ipykernel install --user --name tesser

Launch Jupyter

. .profile  # this needs to be edited for your environment
jupyter lab &

Behavioral analysis

  • convert behavioral data to BIDS format
    • tesser_bids_events.py ~/Dropbox/tesser_successor ~/Dropbox/work/tesser/bids
  • analyze structure learning data
    • tesser/jupyter/plot_beh_struct.ipynb
  • analyze induction data
    • tesser/jupyter/plot_beh_induct.ipynb
  • analyze parsing data
    • tesser/jupyter/plot_beh_parse.ipynb
  • analyze grouping data
    • tesser/jupyter/plot_beh_group.ipynb
  • analyze relationships between behavioral measures
    • tesser/jupyter/plot_beh_regress.ipynb

Modeling

  • fit the community matrix model using group-level parameters
    • tesser/jupyter/fit_induct_comm_g.ipynb
  • fit the SR model with alpha fixed to 0.1 (for stability)
    • tesser/jupyter/fit_induct_sr_g_a10.ipynb
  • fit the hybrid community/SR model with alpha=0.1 and weights free to vary between question types
    • tesser/jupyter/fit_induct_sr_comm_gqw_a10.ipynb
  • use AIC weights to compare models of the inference task
    • tesser/jupyter/fit_induct_model_comp.ipynb
  • demonstrate model behavior under different parameter values
    • tesser/jupyter/demo_sr.ipynb

Analysis on a cluster

Installing on Frontera cluster

cd ~/analysis
git clone https://github.com/prestonlab/tesser.git
python3 -m venv $STOCKYARD/lonestar/venv/tesser3
. ~/analysis/tesser/.profile
pip install -U pip
pip install ezlaunch
pip install mindstorm
pip install -e ~/analysis/tesser

Prep for running scripts

. ~/analysis/tesser/.profile

Preprocessing

  • convert source data to BIDS-formatted raw data
    • slaunch -J heudiconv "tesser_heudiconv.sh {} $SCRATCH/tesser/sourcedata $HOME/analysis/tesser/bin/tesser_heuristic.py $SCRATCH/tesser/rawdata" $SUBJNOS -N 1 -n 37 -r 00:30:00 -p development
  • post-process raw data to add fieldmap information
    • tesser_bids_post.py $SCRATCH/tesser/rawdata
  • run minimal preprocessing using fMRIprep
    • slaunch -J fmriprep “tesser_fmriprep.sh $SCRATCH/tesser {}" $SUBJNOS -N 13 -n 39 -r 08:00:00 -p normal

Preparing ROI masks

  • create template space masks
    • slaunch -J template_rois "tesser_template_rois.sh /work2/03206/mortonne/frontera/.cache/templateflow/ MNI152NLin2009cAsym ~/scratch/tesser/derivatives/model/ {}" $SUBJNOS -N 2 -n 38 -p development -r 00:30:00
  • create IFG masks from FreeSurfer output (run through fMRIprep 20.2.1)
    • ezlaunch -J fs_prob "tesser_fs_prob.sh ~/scratch/tesser/derivatives/fmriprep-20.2.1/freesurfer MNI152NLin2009cAsym ~/scratch/tesser/derivatives/model/" -N 1 -n 1 -p development -r 00:30:00
  • create hippocampus masks from FreeSurfer hippocampus/amygdala segmentation (run separately using FreeSurfer 7.1.1)
    • ezlaunch -J fshs_prob "tesser_fshs_prob.sh ~/work/tesser MNI152NLin2009cAsym ~/scratch/tesser/derivatives/model/" -N 1 -n 1 -p development -r 00:30:00
  • create a gray matter mask with cortical and subcortical ROIs only
    • tesser_gray_prob.sh ~/scratch/tesser/derivatives/fmriprep-20.2.1/fmriprep/ MNI152NLin2009cAsym ~/scratch/tesser/derivatives/model/
  • transform the mPFC ROI
    • antsRegistrationSyN.sh -d 3 -f tpl-MNI152NLin2009cAsym_res-01_desc-brain_T1w.nii.gz -m MNI152_T1_1mm_brain.nii.gz -o transform -n 56
    • antsApplyTransforms -d 3 -e 0 -i -r tpl-MNI152NLin2009cAsym_res-01_desc-brain_T1w.nii.gz -o tpl-MNI152NLin2009cAsym_res-01_desc-mpfc_mask.nii.gz -n MultiLabel -t transform1Warp.nii.gz -t transform0GenericAffine.mat
    • tesser_mpfc_prob.sh ~/scratch/tesser/derivatives/model/ MNI152NLin2009cAsym

Preparing preprocessed data for modeling

  • smooth the functional data
    • slaunch -J smooth "tesser_smooth.sh ~/scratch/tesser/derivatives/fmriprep-20.2.1/fmriprep/ ~/scratch/tesser/derivatives/model/ {} MNI152NLin2009cAsym 4" $SUBJNOS -N 2 -n 38 -r 02:00:00 -p development

Preparing behavioral data for randomise

  • tesser_induct_bias.py ~/scratch/tesser/rawdata/ ~/scratch/tesser/derivatives/model/results/models/induct/induct_bias.tsv
  • tesser_group_within.py ~/scratch/tesser/rawdata/ ~/scratch/tesser/derivatives/model/results/models/group/group_within.tsv
  • tesser_parse_perf.py ~/scratch/tesser/rawdata/ ~/scratch/tesser/derivatives/model/results/models/parse/parse_perf.tsv
  • Glm &
    • run fsl’s glm gui program to generate a design. Copy and paste the z-scored induction bias scores using option+mouse click

Running a searchlight for a given ROI

  • estimate a betaseries based on the smoothed functional data
    • slaunch -J betaseries "tesser_roi_betaseries.py ~/scratch/tesser/rawdata/ ~/scratch/tesser/derivatives/model/ gray smooth4mm {} -s MNI152NLin2009cAsym -f image -m anat -t 0.1" $SUBJNOS -N 4 -n 40 -r 02:00:00 -p development
  • run a searchlight to detect within-community pattern similarity
    • slaunch -J sl_comm "ibrun -n 1 tesser_sl_comm.py ~/scratch/tesser/derivatives/model/ {} smooth4mm beta gray -p 1000 -n 10" $SUBJNOS -N 37 -n 37 -p development -r 02:00:00
    • ibrun throws warnings about not being able to access some queue, but everything runs as expected otherwise; there’s a separate node for each subject with the right number of processes per node
  • run randomise to determine voxel-level significance
    • ezlaunch -J randomise "tesser_randomise.sh ~/scratch/tesser/derivatives/model/results/beta/smooth4mm/gray/ withinMinusAcross community 5000" -N 1 -n 1 -p development -r 02:00:00
      • the version of randomise in fsl 6.0.4 was crashing in a really uninformative way, just saying that there was an unexpected error. fsl 5.0.11 works fine though. However, loading the other module for some reason didn’t update the path. So tesser_randomise.sh uses the FSLDIR variable to find the right programs
  • run randomise weighted by performance
    • create a community_bias directory
      • copy the model.* files there
      • copy the zstat_all.nii.gz image from the community directory
      • copy the mask.nii.gz image from the community directory
    • ezlaunch -J randomise "$FSLDIR/bin/randomise -i zstat_all.nii.gz -o zstat -D -m mask.nii.gz -d model.mat -t model.con -e model.grp -n 5000 -x --uncorrp" -N 1 -n 1 -p development -r 02:00:00

Small volume correction

  • estimate smoothness of betaseries residuals
    • slaunch -J acf "tesser_acf.sh ~/scratch/tesser/derivatives/model/results/beta/smooth4mm/gray/ {} 8" $SUBJNOS -N 2 -n 14 -r 01:00:00 -p development
  • calculate cluster threshold
    • ezlaunch -J clustsim "tesser_clustsim.py ~/scratch/tesser/derivatives/model/results/beta/smooth4mm/gray -n 56" -N 1 -n 1 -p development -r 00:20:00
  • run small-volume correction on randomise results
    • copy a native resolution template image into the betaseries directory as template.nii.gz
    • tesser_svc.sh ~/scratch/tesser/derivatives/model/results/beta/smooth4mm/GM/ community

Exporting clusters

  • tesser_cluster_pattern.py ~/scratch/tesser/rawdata/ ~/scratch/tesser/derivatives/model/results/beta/smooth4mm/hipr community 1 hipr
  • tesser_cluster_pattern.py ~/scratch/tesser/rawdata/ ~/scratch/tesser/derivatives/model/results/beta/smooth4mm/gray bias 52 precl
  • tesser_cluster_pattern.py ~/scratch/tesser/rawdata/ ~/scratch/tesser/derivatives/model/results/beta/smooth4mm/gray group 56 prcl

Follow-up analysis of clusters

  • tesser/jupyter/plot_sl_hipr.ipynb
  • tesser/jupyter/plot_sl_prcl.ipynb
  • tesser/jupyter/plot_sl_precl.ipynb