├── doDecon.sh ├── fmriprep_Scripted.sh ├── fmriprep_singleSubj.sh └── script_fMRIPrep_Analysis.sh /doDecon.sh: -------------------------------------------------------------------------------- 1 | #!/bin/tcsh 2 | # For the fMRIPrep tutorial, copy and paste this into the "func" directory of ${subj} in the "derivatives/fmriprep" folder 3 | # and type: "tcsh doDecon.sh ${subj}" 4 | 5 | if ( $#argv > 0 ) then 6 | set subj = $argv[1] 7 | else 8 | set subj = s01 9 | endif 10 | 11 | 3dDeconvolve -input r*_scale.nii \ 12 | # -censor motion_${subj}_censor.1D \ 13 | -mask full_mask.nii \ 14 | -polort 2 \ 15 | -num_stimts 14 \ 16 | -stim_times 1 stimuli/congruent.1D 'BLOCK(2,1)' \ 17 | -stim_label 1 congruent \ 18 | -stim_times 2 stimuli/incongruent.1D 'BLOCK(2,1)' \ 19 | -stim_label 2 incongruent \ 20 | -stim_file 3 trans_x_run1.txt'[0]' -stim_base 3 -stim_label 3 trans_x_01 \ 21 | -stim_file 4 trans_y_run1.txt'[0]' -stim_base 4 -stim_label 4 trans_y_01 \ 22 | -stim_file 5 trans_z_run1.txt'[0]' -stim_base 5 -stim_label 5 trans_z_01 \ 23 | -stim_file 6 rot_x_run1.txt'[0]' -stim_base 6 -stim_label 6 rot_x_01 \ 24 | -stim_file 7 rot_y_run1.txt'[0]' -stim_base 7 -stim_label 7 rot_y_01 \ 25 | -stim_file 8 rot_z_run1.txt'[0]' -stim_base 8 -stim_label 8 rot_z_01 \ 26 | -stim_file 9 trans_x_run2.txt'[0]' -stim_base 9 -stim_label 9 trans_x_02 \ 27 | -stim_file 10 trans_y_run2.txt'[0]' -stim_base 10 -stim_label 10 trans_y_02 \ 28 | -stim_file 11 trans_z_run2.txt'[0]' -stim_base 11 -stim_label 11 trans_z_02 \ 29 | -stim_file 12 rot_x_run2.txt'[0]' -stim_base 12 -stim_label 12 rot_x_02 \ 30 | -stim_file 13 rot_y_run2.txt'[0]' -stim_base 13 -stim_label 13 rot_y_02 \ 31 | -stim_file 14 rot_z_run2.txt'[0]' -stim_base 14 -stim_label 14 rot_z_02 \ 32 | -jobs 8 \ 33 | -gltsym 'SYM: incongruent -congruent' \ 34 | -glt_label 1 incongruent-congruent \ 35 | -gltsym 'SYM: congruent -incongruent' \ 36 | -glt_label 2 congruent-incongruent \ 37 | -fout -tout -x1D X.xmat.1D -xjpeg X.jpg \ 38 | -x1D_uncensored X.nocensor.xmat.1D \ 39 | -fitts fitts.$subj \ 40 | -errts errts.${subj} \ 41 | -bucket stats.$subj 42 | -------------------------------------------------------------------------------- /fmriprep_Scripted.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | subject=$1 4 | 5 | #User inputs: 6 | bids_root_dir=$HOME/Desktop/Flanker 7 | subj=$subject 8 | nthreads=4 9 | mem=20 #gb 10 | container=docker #docker or singularity 11 | 12 | #Begin: 13 | 14 | #Convert virtual memory from gb to mb 15 | mem=`echo "${mem//[!0-9]/}"` #remove gb at end 16 | mem_mb=`echo $(((mem*1000)-5000))` #reduce some memory for buffer space during pre-processing 17 | 18 | #export TEMPLATEFLOW_HOME=$HOME/.cache/templateflow 19 | export FS_LICENSE=$HOME/Desktop/Flanker/derivatives/license.txt 20 | 21 | #Run fmriprep 22 | if [ $container == singularity ]; then 23 | unset PYTHONPATH; singularity run -B $HOME/.cache/templateflow:/opt/templateflow $HOME/fmriprep.simg \ 24 | $bids_root_dir $bids_root_dir/derivatives \ 25 | participant \ 26 | --participant-label $subj \ 27 | --skip-bids-validation \ 28 | --md-only-boilerplate \ 29 | --fs-license-file $HOME/Desktop/Flanker/derivatives/license.txt \ 30 | --fs-no-reconall \ 31 | --output-spaces MNI152NLin2009cAsym:res-2 \ 32 | --nthreads $nthreads \ 33 | --stop-on-first-crash \ 34 | --mem_mb $mem_mb \ 35 | -w $HOME 36 | else 37 | fmriprep-docker $bids_root_dir $bids_root_dir/derivatives \ 38 | participant \ 39 | --participant-label $subj \ 40 | --skip-bids-validation \ 41 | --md-only-boilerplate \ 42 | --fs-license-file $HOME/Desktop/Flanker/derivatives/license.txt \ 43 | --fs-no-reconall \ 44 | --output-spaces MNI152NLin2009cAsym:res-2 \ 45 | --nthreads $nthreads \ 46 | --stop-on-first-crash \ 47 | --mem_mb $mem_mb \ 48 | -w $HOME 49 | fi 50 | -------------------------------------------------------------------------------- /fmriprep_singleSubj.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Template provided by Daniel Levitas of Indiana University 3 | #Edits by Andrew Jahn, University of Michigan, 07.22.2020 4 | 5 | #User inputs: 6 | bids_root_dir=$HOME/Desktop/Flanker 7 | subj=08 8 | nthreads=4 9 | mem=20 #gb 10 | container=docker #docker or singularity 11 | 12 | #Begin: 13 | 14 | #Convert virtual memory from gb to mb 15 | mem=`echo "${mem//[!0-9]/}"` #remove gb at end 16 | mem_mb=`echo $(((mem*1000)-5000))` #reduce some memory for buffer space during pre-processing 17 | 18 | #export TEMPLATEFLOW_HOME=$HOME/.cache/templateflow 19 | export FS_LICENSE=$HOME/Desktop/Flanker/derivatives/license.txt 20 | 21 | #Run fmriprep 22 | if [ $container == singularity ]; then 23 | unset PYTHONPATH; singularity run -B $HOME/.cache/templateflow:/opt/templateflow $HOME/fmriprep.simg \ 24 | $bids_root_dir $bids_root_dir/derivatives \ 25 | participant \ 26 | --participant-label $subj \ 27 | --skip-bids-validation \ 28 | --md-only-boilerplate \ 29 | --fs-license-file $HOME/Desktop/Flanker/derivatives/license.txt \ 30 | --fs-no-reconall \ 31 | --output-spaces MNI152NLin2009cAsym:res-2 \ 32 | --nthreads $nthreads \ 33 | --stop-on-first-crash \ 34 | --mem_mb $mem_mb \ 35 | else 36 | fmriprep-docker $bids_root_dir $bids_root_dir/derivatives \ 37 | participant \ 38 | --participant-label $subj \ 39 | --skip-bids-validation \ 40 | --md-only-boilerplate \ 41 | --fs-license-file $HOME/Desktop/Flanker/derivatives/license.txt \ 42 | --fs-no-reconall \ 43 | --output-spaces MNI152NLin2009cAsym:res-2 \ 44 | --nthreads $nthreads \ 45 | --stop-on-first-crash \ 46 | --mem_mb $mem_mb 47 | fi 48 | -------------------------------------------------------------------------------- /script_fMRIPrep_Analysis.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #This script assumes you have already run the file make_Timings.sh, as explained in this chapter: https://andysbrainbook.readthedocs.io/en/latest/OpenScience/OS/fMRIPrep_Demo_5_1stLevelAnalysis.html 4 | #This is combined code from the OpenScience module of Andy's Brain Book: https://andysbrainbook.readthedocs.io/en/latest/OpenScience/OS/fMRIPrep_Demo.html 5 | 6 | 7 | for i in `cat subjList.txt`; do 8 | cd code; 9 | bash fmriprep_Scripted.sh $i; 10 | cd ../derivatives/fmriprep/${i}/func 11 | for run in 1 2; do 12 | 3dmerge -1blur_fwhm 4.0 -doall -prefix r${run}_blur.nii \ 13 | ${i}_task-flanker_run-${run}_space-MNI152NLin2009cAsym_res-2_desc-preproc_bold.nii.gz; 14 | done 15 | for run in 1 2; do 16 | 3dTstat -prefix rm.mean_r${run}.nii r${run}_blur.nii; 17 | 3dcalc -a r${run}_blur.nii -b rm.mean_r${run}.nii \ 18 | -c ${i}_task-flanker_run-${run}_space-MNI152NLin2009cAsym_res-2_desc-brain_mask.nii.gz \ 19 | -expr 'c * min(200, a/b*100)*step(a)*step(b)' \ 20 | -prefix r${run}_scale.nii; 21 | done 22 | rm rm*; 23 | 3dmask_tool -inputs *mask.nii.gz -union -prefix full_mask.nii 24 | mkdir stimuli; 25 | cp ../../../../${i}/func/*.1D stimuli; 26 | cp ../../../../doDecon.sh .; 27 | for reg in trans_x trans_y trans_z rot_x rot_y rot_z; do 28 | for run in 1 2; do 29 | awk -v col=$reg 'NR==1{for(i=1;i<=NF;i++){if($i==col){c=i;break}} print $c} NR>1{print $c}' ${i}_task-flanker_run-${run}_desc-confounds_regressors.tsv > ${reg}_run${run}_all_tmp.txt; 30 | sed '1d' ${reg}_run${run}_all_tmp.txt > ${reg}_run${run}_noHead_tmp.txt 31 | sed '1!d' ${reg}_run${run}_all_tmp.txt > ${reg}_run${run}_Head_tmp.txt 32 | done 33 | done 34 | NT=`3dinfo -nt r1_scale.nii` 35 | if [ -f zeros_tmp.txt ]; then rm zeros_tmp.txt; fi 36 | for ((j=0; j<$NT; j++)); do echo 0 >> zeros_tmp.txt; done 37 | for reg in trans_x trans_y trans_z rot_x rot_y rot_z; do 38 | for run in 1 2; do 39 | if [ $run -eq 1 ]; then 40 | cat ${reg}_run${run}_noHead_tmp.txt > ${reg}_run${run}.txt 41 | else 42 | cat zeros_tmp.txt ${reg}_run${run}_noHead_tmp.txt > ${reg}_run${run}.txt 43 | fi 44 | done 45 | done 46 | rm *tmp* 47 | tcsh doDecon.sh $i 48 | cd ../../../.. 49 | done 50 | --------------------------------------------------------------------------------