AFNI Class 05: 09/06/2019 [11/17 & 12/1/2025]
afni_proc.py for Resting and Nonlinear
using 11b modern [restingstate without freesurfer]
3dcalc -a /software/AFNI_25.2.06/TT_desai_dd_mpm+tlrc -expr 'amongst(a,152,170)' -prefix template_ventricle
We are replacing this with ... kmeans_ants.R
3dresample -dxyz 4 4 4 -inset MNI152_2009_Vent.nii.gz -prefix template_ventricle_4mm.nii.gz
afni_proc.py \
-subj_id ${subj} \
-blocks despike tshift align tlrc volreg blur mask scale regress \
-copy_anat ${subj}.nii.gz \
-dsets ${subj}rsfMRI_Run?.nii.gz \
-tcat_remove_first_trs 2 \
-align_unifize_epi local \
-copy_anat anatSS.${subj}.nii.gz \
-anat_has_skull no -align_opts_aea -cost nmi -giant_move -check_flip \
-volreg_align_to MIN_OUTLIER -volreg_align_e2a \
-volreg_tlrc_warp -tlrc_base MNI152_2009_template_SSW.nii.gz \
-tlrc_NL_warp -tlrc_NL_warped_dsets anatQQ.${subj}.nii.gz \
anatQQ.${subj}.aff12.1D anatQQ.${subj}_WARP.nii.gz \
-volreg_warp_dxyz 4 \
-blur_size 4 \
-mask_segment_anat yes \
-mask_segment_erode yes \
-mask_import Tvent template_ventricle_4mm.nii.gz \
-mask_intersect Svent CSFe Tvent \
-mask_epi_anat yes \
-regress_apply_mot_types demean deriv \
-regress_motion_per_run -regress_anaticor_fast \
-regress_ROI_PC Svent 3 \
-regress_ROI_PC_per_run Svent \
-regress_censor_motion 0.2 \
-regress_censor_outliers 0.05 \
-regress_make_corr_vols WMe Svent \
-regress_est_blur_epits -regress_est_blur_errts \
-regress_bandpass 0.01 0.1 \
-regress_run_clustsim yes
Which creates: proc.Rest.BP
Ways resting differs from task:
- Censor level on frame displacement set to .2
1d_tool.py -infile dfile_rall.1D -set_nruns 2 \
-show_censor_count -censor_prev_TR \
-censor_motion 0.2 motion_${subj}
-show_censor_count -censor_prev_TR \
-censor_motion 0.2 motion_${subj}
- Removing Ventricular signal:
3dpc -mask mask_inter_Svent+tlrc -pcsave 3 \
-prefix rm.ROIPC.Svent.r${run} rm.det_pcin_r$run+tlrc
1d_tool.py -censor_fill_parent rm.censor.r$run.1D \
-infile rm.ROIPC.Svent.r${run}_vec.1D -write - \
| 1d_tool.py -set_run_lengths $tr_counts -pad_into_many_runs $run 2 \
-infile - -write ROIPC.Svent.r$run.1D
-prefix rm.ROIPC.Svent.r${run} rm.det_pcin_r$run+tlrc
1d_tool.py -censor_fill_parent rm.censor.r$run.1D \
-infile rm.ROIPC.Svent.r${run}_vec.1D -write - \
| 1d_tool.py -set_run_lengths $tr_counts -pad_into_many_runs $run 2 \
-infile - -write ROIPC.Svent.r$run.1D
...
3dDeconvolve -ortvec ROIPC.Svent.r01.1D ROIPC.Svent.r01 \
-ortvec ROIPC.Svent.r02.1D ROIPC.Svent.r02 \
- Bandpass filter set to .01 .1
1dBport -nodata $nt 2 -band 0.01 0.1 -invert -nozero >! rm.bpass.1D
1d_tool.py -infile rm.bpass.1D -pad_into_many_runs $run $#runs \
-set_run_lengths $tr_counts \
-write bpass.r$run.1D
...
1dcat bpass.r*1D > bandpass_rall.1D
...
3dDeconvolve -ortvec bandpass_rall.1D bandpass
- Using 3dTproject to handle final analysis as data cleaning [note ran with and without WM resid]
3dTproject -polort 0 -input pb05.$subj.r*.scale+tlrc.HEAD \
-censor censor_${subj}_combined_2.1D -cenmode ZERO \
-dsort Local_WMe_rall+tlrc \
-ort X.nocensor.xmat.1D -prefix errts.$subj.fanaticor
Other Thoughts:
- This path is primarily for graph theory work you can extract for working with graph metrics like igraph
- Can use 3dROIstats and 3dNetCorr
- if you are doing seed based then replace the 3dTproject with the REML
3dDeconvolve -num_stimts 1 -stim_file 1 seed.1D -stim_label 1 seed
tcsh stats.REML_cmd
- you can also consider doing ICA analysis for resting state consider using fsl melodic or Conn
- you can also use GIMME for SEM style graph analysis
NL with task and @SSwarper:
first strip data:
basename `pwd` | xargs -I % @SSwarper -input %.nii.gz -base MNI152_2009_template_SSW.nii.gz -subid %
then you can add to your afni_proc.py the following:
-tlrc_NL_warp -tlrc_NL_warped_dsetsanatQQ.${subj}.niianatQQ.aff12.1DanatQQ.${subj}_WARP.nii