Clarification on Using Subject-Space and MNI-Space T1s/masks in afni_proc.py

AFNI version info (afni -ver): Precompiled binary macos_10.12_local: Oct 31 2024 (Version AFNI_24.3.06 'Elagabalus')

Hi all,

I’m working on my first complete afni_proc.py script to analyze resting-state data and have been following Example 11 from the AFNI afni_proc.py examples.

Here’s what I’ve done so far:

  1. I’ve processed my T1-weighted images using sswarper2, which generated skull-stripped and MNI-warped versions of the T1s.
  2. I’m running the original (subject-space) T1s through recon-all to generate the aaseg, aeseg, white matter, and ventricle masks.

Now, here’s where I’m confused:
In my afni_proc.py script, I am including both the original (subject-space) and MNI-warped (from sswarper2) T1s. Since recon-all was run on the subject-space T1, the resulting masks for white matter and ventricles will also be in subject space, right? How do I handle this mismatch when incorporating these masks into the MNI-warped space for my analysis?

Any advice or guidance on best practices for this situation would be greatly appreciated!

#!/bin/bash
 
# Template for Preprocessing Resting-State Data with afni_proc.py

# Each line is commented to explain its purpose. Replace placeholders with your specific data.
 
# Main afni_proc.py command to process resting-state data

afni_proc.py \

    -subj_id                  <SUBJECT_ID>                          # Unique subject identifier (e.g., sub-001)

    -blocks                   despike tshift align tlrc volreg blur  \ # Steps in the preprocessing pipeline

                              mask scale regress                     # These are common blocks for resting-state analysis

    -radial_correlate_blocks  tcat volreg regress                    # Run radial correlation checks at specific stages

    # Anatomical Dataset

    -copy_anat                <ANAT_SKULL_STRIPPED_FILE>             # Skull-stripped anatomical dataset (e.g., anatSS.sub-001.nii)

    -anat_has_skull           no                                     # Indicate that the anatomical image is skull-stripped

    -anat_follower            anat_w_skull anat <ANAT_WITH_SKULL_FILE> # Anatomical dataset with skull (e.g., anatU.sub-001.nii)
 
    # FreeSurfer Outputs (if available)

    -anat_follower_ROI        aaseg anat <AASEG_FILE>                # FreeSurfer aseg parcellation on anatomical grid

    -anat_follower_ROI        aeseg epi <AESEG_FILE>                 # FreeSurfer aseg parcellation on EPI grid

    -anat_follower_ROI        FSvent epi <FS_VENTRICLE_FILE>         # FreeSurfer ventricle mask

    -anat_follower_ROI        FSWe epi <FS_WHITE_MATTER_FILE>        # FreeSurfer white matter mask

    -anat_follower_erode      FSvent FSWe                            # Erode ventricle and white matter masks
 
    # Functional Dataset

    -dsets                    <FUNC_FILES>                           # Functional datasets (e.g., sub-001_task-rest_bold+orig.HEAD)

    -tcat_remove_first_trs    <NUM_TRS_TO_REMOVE>                    # Number of initial TRs to remove (e.g., 2)
 
    # Alignment Options

    -align_unifize_epi        local                                  # Unifize EPI for alignment

    -align_opts_aea           -cost lpc+ZZ                           # Alignment cost function

                              -giant_move                            # Allow large movements for alignment

                              -check_flip                            # Check for left-right flipping issues
 
    # Template Registration

    -tlrc_base                MNI152_2009_template_SSW.nii.gz        # Template for normalization

    -tlrc_NL_warp                                                    # Use non-linear warping for template alignment

    -tlrc_NL_warped_dsets     <ANAT_WARPED> <AFFINE_TRANSFORM>       # Non-linear warp outputs from SSwarper
<NONLINEAR_WARP>                       # Files: anatQQ.sub-001.nii, anatQQ.sub-001.aff12.1D, anatQQ.sub-001_WARP.nii
 
    # Motion Correction and Warping

    -volreg_align_to          MIN_OUTLIER                            # Align volumes to the one with the least outliers

    -volreg_align_e2a                                                # Align EPI to anatomy

    -volreg_tlrc_warp                                                # Apply warps to EPI data
 
    # Masks

    -mask_epi_anat            yes                                    # Create EPI mask aligned with anatomy
 
    # Smoothing

    -blur_size                4                                      # Apply spatial smoothing with 4mm FWHM kernel
 
    # Regressors

    -regress_apply_mot_types  demean deriv                           # Regress motion parameters (demeaned and derivatives)

    -regress_motion_per_run                                          # Regress motion separately for each run

    -regress_anaticor_fast                                           # Use fast ANATICOR for local white matter regression

    -regress_anaticor_label   FSWe                                   # Use FreeSurfer white matter mask for ANATICOR

    -regress_ROI_PC           FSvent 3                               # Regress first 3 principal components from ventricles

    -regress_ROI_PC_per_run   FSvent                                 # Compute PCs per run

    -regress_censor_motion    0.2                                    # Censor TRs with motion > 0.2 mm

    -regress_censor_outliers  0.05                                   # Censor TRs with > 5% outliers

    -regress_make_corr_vols   aeseg FSvent                           # Create correlation volumes for gray matter and ventricles
 
    # Estimation and Review

    -regress_est_blur_epits                                          # Estimate smoothness of preprocessed data

    -regress_est_blur_errts                                          # Estimate smoothness of residuals

    -html_review_style        pythonic                               # Generate Python-style HTML QC report
 
# Areas to Fill In:

# - <SUBJECT_ID>: Unique identifier for the subject (e.g., sub-001).

# - <ANAT_SKULL_STRIPPED_FILE>: Skull-stripped anatomical dataset (e.g., anatSS.sub-001.nii).

# - <ANAT_WITH_SKULL_FILE>: Anatomical dataset with the skull included (e.g., anatU.sub-001.nii).

# - <AASEG_FILE>, <AESEG_FILE>: FreeSurfer parcellation outputs.

# - <FS_VENTRICLE_FILE>, <FS_WHITE_MATTER_FILE>: FreeSurfer ventricle and white matter masks.

# - <FUNC_FILES>: Functional datasets for preprocessing.

# - <NUM_TRS_TO_REMOVE>: Number of initial TRs to remove from functional datasets.

# - <ANAT_WARPED>, <AFFINE_TRANSFORM>, <NONLINEAR_WARP>: Outputs from @SSwarper for non-linear warping.
 


The -anat_follower_ROIs are in the native subject space. The -ROI_import ROIs are in the final template space.

Thank you for the reply! Could you clarify, which are the -ROI_import ROIs? Would that be the FSvent and FSWe files?

Howdy-

I think you are looking pretty set with your command there, but just to note that this recent paper on using afni_proc.py might be a helpful guide for some option usage:

  • Reynolds RC, Glen DR, Chen G, Saad ZS, Cox RW, Taylor PA (2024). Processing, evaluating and understanding FMRI data with afni_proc.py. Imaging Neuroscience 2:1-52.
    https://doi.org/10.1162/imag_a_00347

Regarding anat_follower_ROIs, this is what it comments:

There are several situations where it can be useful to add precalculated masks or ROI atlas maps into the processing stream, each of which ends up in the final space (here, MNI) on either the EPI or anatomical grid, as specified. Here, the “-anat_follower_ROI ..” option is used to bring anatomical parcellation datasets FreeSurfer’s recon-all into the processing stream. For each imported dataset, the user assigns a brief label for working with the dataset within the code and also designates the final grid. Here, we are bringing in the gray matter (GM) map from FreeSurfer’s “2009” parcellation ([Destrieux et al., 2010](javascript:;)), which is used twice: one copy will have “epi” grid spacing (label = “aegm09”) and one will have “anat” grid spacing (label = “aagm09”). These could be imported as part of processing for an ROI-based analysis, for example (in which case we would remove the blur block in the afni_proc.py command), but in the present case, they will be used only for QC-related purposes.

There are also associated script examples. This one from Ex. 6 contains both anat_follower_ROIs (which come from FS: both WM and ventricles that are used for fast ANATICOR, and GM ones just to show how they could be done) and ROI_imports (which are bringing in ROIs from various atlases for TSNR checks). In both cases, the ROIs end up in the final space appropriately and in a desired grid: for anat_follower_ROIs, you specify whether the resulting ROIs should on the final EPI or anatomical grid; for ROI_imports, they will be in the final EPI grid. The main difference is where the input ROI maps live: anat_follower_ROIs live in the copy_anat space, and import_ROIs live in the final space space (like the template here).

It is appropriate to use anat_follower_ROIs for the FS ventricle and WM maps like you are doing.

You don't need ROI_import ROIs for running your analysis here. I think the mention of them was just that the option exists and has a different use.

--pt

Thank you for the thorough response, that makes sense. I will take a look at the paper. I knew that this was likely a non-issue but it is good to know that is the distinction.