New preprocessing script based on Example 11b of afni_proc.py

Hello dear AFNI gurus,

Following along this question and it’s answers: Create ventricle mask in MNI space

I intend to do a resting state analysis without Freesurfer (that takes waaaay tooooo muuuuch time) and want to use MNI152 template. So I’m going through example 11b method (that ventricle extraction method seems okay to me, who am I to judge).

First, I will be running @SSwarper:


@SSwarper -input Session_1_t2_tse_tra_192_0_2.nii.gz \
-subid duodenumreyiz \
-odir  anat_warped \
-base  MNI152_2009_template_SSW.nii.gz \
-giant_move

Then, I’m resampling the ventricle mask in the suma_MNI152_2009 folder that I downloaded a while back. Now the question is: what should be the master dataset as above thread shows that using -dxyz method might give unintended results. I used preprocessed resting state of another subject, who was preprocessed using a different afni_proc.py script but aligned to MNI152 via @SSwarper and sampled to 3x3x3 mm^3. So the bulk of this question is this: does that make sense?


3dresample -master sub-10159.rest.nii -prefix ventricle_mask.nii -inset aparc+aseg_REN_vent.nii.gz

Then, do the preprocessing (slightly modified version of 11b):


afni_proc.py \
-blocks despike tshift align tlrc volreg blur mask scale regress \
-script proc.duodenumreyiz \
-subj_id duodenumreyiz \
-out_dir duodenumreyiz.preprocessed \
-scr_overwrite \
-copy_anat $subjpath/anat/anat_warped/anatSS.duodenumreyiz.nii \
-dsets $subjpath/func/Session_2_RSTpre_V01_R01_0_12.nii \
-tcat_remove_first_trs 2 \
-align_opts_aea -cost lpc+ZZ \
-tlrc_base $tpath/$btemplate \
-tlrc_NL_warp \
-tlrc_NL_warped_dsets \
$subjpath/anat/anat_warped/anatQQ.duodenumreyiz.nii \
$subjpath/anat/anat_warped/anatQQ.duodenumreyiz.aff12.1D \
$subjpath/anat/anat_warped/anatQQ.duodenumreyiz_WARP.nii \
-volreg_align_to MIN_OUTLIER \
-volreg_align_e2a \
-volreg_tlrc_warp \
-volreg_warp_dxyz 3 \
-mask_segment_anat yes \
-mask_segment_erode yes \
-mask_import Tvent ventricle_mask.nii \
-mask_intersect Svent CSFe Tvent \
-mask_epi_anat yes \
-regress_motion_per_run \
-regress_ROI_PC Svent 3 \
-regress_ROI_PC_per_run Svent \
-regress_make_corr_vols WMe Svent \
-regress_anaticor_fast \
-regress_censor_motion 0.2 \
-regress_censor_outliers 0.05 \
-regress_apply_mot_types demean deriv \
-regress_est_blur_epits \
-regress_est_blur_errts \
-regress_run_clustsim yes
-html_review_style pythonic

Is this a legitimate method as preprocessing?

Thanks and best regards,
Yasir

Just finished running the script and it failed drastically. The problems begin with the volreg block, so probably the mask is problematic. Any ideas why?

Yasir

Hi, Yasir-

One quick thought—WMe is never defined there, which I guess would typically be a follower dset of some kind.

Note, re. the speed of FreeSurfer—if you check this tutorial page about it, the “-parallel” option does speed things up a lot, if you have, say, 4 CPUs it can use on your computer:
https://afni.nimh.nih.gov/pub/dist/doc/htmldoc/tutorials/fs/fs_fsprep.html#run-recon-all-faster-parallel
The “B” case there is:


# example B: using default parallelization
recon-all                                  \
    -all                                   \
    -3T                                    \
    -sd      .                             \
    -subjid  FT                            \
    -i       FT_anat_cp.nii.gz             \
    -parallel

… and it took just over 2 hours to run. That might be worth considering. Then you could use the follower dsets from 11b, too, which will likely be better tissue maps for each subject. And you really don’t want the WM map, say, to overlap with your dataset’s GM (hence the erosion of those dsets).

–pt

Hi Paul,

Thanks for pointing the -parallel option, I’ll try that out today and return back.

On WMe follower datasets, I checked example 11b again but couldn’t find anything suggesting a follower dataset. Are you suggesting that I should find something in suma_MNI152_2009 folder?

Thanks,
Yasir

Hi, Yasir-

Ah, I see now-- these 2 options lead to the anat being segmented with 3dSeg, which creates known tissue-class names (WM, CSF, etc.), and then those masks are eroded (again with known labels applied: WMe, CSFe, etc.):


-mask_segment_anat yes                                    \
        -mask_segment_erode yes                                   \

What is the actual error that you are getting?

And what specifically did you do to get your ventricle mask? Does its grid match the resampled volreg dataset?

–pt

Hi,

There isn’t an error message, but the end result is problematic. When I inspect the blocks, problems start from volreg.

I extracted the ventricle mask from this link: https://afni.nimh.nih.gov/pub/dist/tgz/suma_MNI152_2009.tgz. I don’t know if it’s a reasonable way to do this but kinda followed this thread:
Create ventricle mask in MNI space

For resampling, I picked a previously preprocessed subject’s dataset. It was aligned to MNI152 via @SSwarper and sampled to 3x3x3 mm^3 with a different, more basic afni_proc script. Then I used this code:


3dresample -master sub-10159.rest.nii -prefix ventricle_mask.nii -inset aparc+aseg_REN_vent.nii.gz

-master is the old previously preprocessed dataset. -inset is from that link above (suma_MNI152_2009). So, this was the method.
Right now, I’m trying recon-all again. Will write the results of that too.

Thanks and best regards,
Yasir

Just to give an update on this one: the script with recon-all worked perfectly and took only 3-4 hours with 16 threads, which I guess, a reasonable time for a script with recon-all + @SSwarper + afni_proc.py.

Hi, Yasir-

Thanks for that feedback (seeing this now, after vacation time away…).

–pt

Thanks. 11 is working fine but just out of curiosity, is there a way I can operationalize example 11b the way I want?