README copied from Exploration repo.
Analyzing fMRI data of humans playing video games.
Scripts are in /ncf/gershman/Lab/scripts/matlab/VGDL_fMRI/
.
Data are in /ncf/gershman/Lab/VGDL_fMRI/
.
Useful links:
- CBS cluster FAQ -- how to use the cluster, send jobs, ArcGet.py, slurm, sacct, etc
- CBS central login -- where the fMRI data live
- ccnl_fmri wiki -- how to use Sam's fMRI pipeline
-
Copy everything to the cluster and login
- See
scp_to_ncf.sh
, maybe edit it accordingly and run it./scp_to_ncf.sh
- See
-
Open
downloadConvertSBatch.sh
and editsubjects
to include the new subject only. -
Open
downloadConvert.sh
and editfileNames
if necessary. Read comments for details -
Run
./downloadConvertSBatch.sh
- Takes ~30 mins to complete.
- Make sure there are no scary errors in the .err file or the .out file.
- Make sure all files (struct.nii, run001.nii, etc) are written normally in the .out file
- Go to
/ncf/gershman/Lab/Exploration/subjects/
and make sure all subject files are there
-
Open
vgdl_getSubjectsDirsAndRuns.m
and append new subject info tosubjects
,subjdirs
, andnRuns
accordingly (so they include info for all subjects). Read comments for details. -
Open
ccnl_fmri_preproc.sh
and editsubjects
to include the index of the new subject only. This index is the ordinal of the subject info invgdl_getSubjectsDirsAndRuns.m
-
Run
./ccnl_fmri_preproc.sh
- Takes ~10 hours (!) to complete.
- Make sure there are no scary errors in the .err file or the .out file.
- Make sure all files are in the data directory (compare with previous subjects).
-
Open MATLAB with a GUI and cd into scripts directory
- Log into one of the cluster terminals in Northwest (e.g. by the fMRI scanner),
- or download XQuartz on your Mac,
ssh -X
into the cluster on one of the nvdi nodes, e.g.ssh -X mtomov13@ncfvdi.rc.fas.harvard.edu
, and runmatlab
on the command line. You should see the MATLAB splash screen, - or create an interactive VDI session through the NCFood website
-
Run
ccnl_plot_movement(vgdl_expt(), XX)
, where XX is the subject index (e.g. 1)- Make sure subject didn't move too much during runs
-
Run
ccnl_check_registration(vgdl_expt(), XX)
, where XX is the subject index- Click around (e.g. around ventricles), make sure average functional (top) is aligned with the structural (bottom)
-
Append the subject's behavioral data to
data.csv
and upload it to the cluster -
Check the raw BOLD traces with, e.g.
ccnl_view_mask('/ncf/gershman/Lab/VGDL_fMRI/subjects/200311_VGDL_001/preproc/swurun001.nii')
Tips
- Always check that the job is running with
sacct
- Wait until some output is printed to the .out file, to be sure that it didn't fail at the very beginning
- particularly important for long-running jobs
Common errors and mistakes
- ArcGet.py doesn't exist -> happens sometimes, idk why
- ArcGet.py can't access CBS Central -> read the CBS FAQ on ArcGet.py; you need to set it up first
- ArcGet.py can't find subject on CBS central -> make sure that the subject ID (e.g.
180807_UEP_025
) is exactly as it is on CBS Central- check date
- check spaces and underscores
- make sure no commas in the
subjects
array in the scriptdownloadConvertSBatch.sh
- make sure subject was actually sent to CBS central
- make sure all scans were sent to CBS central
- ArcGet.py can't write to data directory
- make sure you have permissions or someone else didn't download that subject already
- make sure data directory exists
- make sure that the directories in the scripts are correct
- Runs (run###.nii) or structurals (struct.nii) missing or empty -> make sure the file order in
fileNames
in the scriptdownloadConvert.sh
is the same as the session order of the subject- e.g. if another structural was acquired after run 4, it should be
fileNames=(struct_1 run001 run002 run004 run004 struct_2 run005 run006 run007 run008)
- e.g. if run 6 was interrupted and restarted, it should be
fileNames=(struct run001 run002 run004 run004 run005 run006_bad run006 run007 run008)
- e.g. if another structural was acquired after run 4, it should be
- Add the GLM to
vgdl_create_multi.m
- Test the GLM locally
- Call
multi = vgdl_create_multi(...)
in MATLAB - Inspect
multi
and make sure all the names, onsets, and pmods make sense - Batch test for all subjects and runs using
ccnl_check_multi.m
(this also creates the cached .mat files, which are important since MATLAB on the cluster doesn't have mongo)
- Call
- Copy
vgdl_create_multi.m
to the cluster- See
scp_to_ncf.sh
- See
- Log into the cluster and run an interactive job, e.g. with
./srun.sh
- Run MATLAB in the interactive job, e.g. with
./matlab.sh
- Test the GLM on the cluster
- repeat same steps as testing locally
- Dry run the GLM in MATLAB by calling
ccnl_fmri_glm(...)
to make sure SPM actually likes it; then interrupt it with Ctrl+C once it looks like it's working- Optionally use the
fake_glm=true
argument
- Optionally use the
- Exit MATLAB and edit
ccnl_fmri_glm.sh
- Change
goodSubjects = (...)
to include all subjects - Change
for model in {...}
to use your GLM only
- Change
- Run
./ccnl_fmri_glm.sh
- Add your contrast to
run_ccnl_fmri_con.m
- Copy-paste one of the calls to
ccnl_fmri_con
and modify accordingly - Please keep all previous contrasts, just comment them out
- Copy-paste one of the calls to
- Copy
run_ccnl_fmri_con.m
to the cluster - Log into the cluster and run an interactive job, e.g. with
./srun.sh
- Run MATLAB in the interactive job, e.g. with
./matlab.sh
- Test the contrast on the cluster
- Call
run_ccnl_fmri_con
in MATLAB, make sure it starts doing stuff and Ctrl+C it
- Call
- Exit MATLAB and run
./run_ccnl_fmri_con.sh
- Run
ccnl_mean.m
on the cluster, scpglmOutput/mean.nii
from cluster - Run MATLAB with a GUI and cd into scripts directory
- look for X11 above
- Run
ccnl_view
with the corresponding GLM and contrast- e.g.
ccnl_view(vgdl_expt(), 1, 'RR - SS')
- e.g.
Preliminaries:
- Create
masks/
directory, copy overmask.nii
from any contrast (e.g.../glmOutput/model1/con1/mask.nii
; it's the group-level whole-brain mask) - Create some anatomical masks using
ccnl_create_mask.m
-- see e.g. `create_anatomical_masks_AAL2.m - Create a GLM that extracts beta series -- see e.g. GLM 1 and GLM 22 for a block and event-based ways to do it
- Run the GLM, with and without smoothing (see
vgdl_expt_nosmooth.m
andccnl_fmri_glm_nosmooth.sh
)
To add and run a new RSA searchlight:
- Add a new RSA to
vgdl_create_rsa.m
- make sure to run e.g.
for s = 1:8, vgdl_create_rsa(2,s); end
in MATLAB to generate the.mat
files, since MATLAB on the cluster doesn't have mongo
- make sure to run e.g.
- Edit
ccnl_rsa_searchlight.sh
, check and adjust accordingly:vgdl_expt
vs.vgdl_expt_nosmooth
,- subjects,
- batch sizes,
- for loop over rsa's
- for loop over batches,
- memory limits,
- time limits
scp_to_ncf.sh
to copy .m and .mat files to cluster (check it first)- Run interactive MATLAB on cluster, test new RSA with
ccnl_check_rsa.m
- Run
ccnl_rsa_searchlight.sh
(recommended with only 1-2 batches first, as a sanity check) scp_from_ncf.sh
to copyrsaOutput
files from cluster locallyccnl_rsa_view_searchlight.m
to view RSA
Note: If you re-run the beta series GLM, you will have to go inside all rsaOutput/rsa*/
directories and remove the beta*.mat
files; we extract and cache them to speed things up, so if the GLM changes, we have to remove them.
Note: you have to remove the .nii tmap file once it's generated by ccnl_rsa_view
if you want to re-generate it
- create data directory on cluster
- create scripts directory on cluster
- copy over
vgdl_*.m
files, rename toyourproject_*.m
- create git repo, add files, push to github
git grep -i 'vgdl' *.m
-- change all prefixes, directories, etc. accordingly to reflect your project
Careful scp'ing to cluster while jobs are running -- reading files (e.g. mat files) can break if they're being overwritten