Fmriprep:how to match functional datasets with subject’s individual T1 space

I intend to analyze the data in AFNI at the individual level, after preprocessed by fmriprep:


fmriprep-docker /media/work21/BIDS/Nifti /media/work21/ BIDS_T1 participant --participant-label 1 --output-spaces T1w    --skull-strip-t1w force --fs-license-file /home/Downloads/freesurfer/license.txt --fs-no-reconall --n_cpus 32

However, after preprocessing, I got anat in original format (sub1_T1+orig.HEAD) while EPIs in tlrc format after transformed by 3dcopy in AFNI (sub-1_task-checker_acq-TR156_space-T1w_desc-preproc_bold+tlrc.HEAD). As a result, after GLM analysis, I cannot use T1 as underlay, when applying the stats in tlrc format as overlay. Is there a command that might work for me?
Thanks for the helping!

Hi-

I don’t see why the 3dcopy would change this parameter. I assume it has to be the qform_code and sform_code values from FMRIprep output that are defining the space. What is the output of the following from your FMRIprep output:

A:


nifti_tool -disp_hdr -field qform_code -field sform_code -infiles DSET_EPI

B:


nifti_tool -disp_hdr -field qform_code -field sform_code -infiles DSET_ANAT

You can change the header property of space with 3drefit, but before discussing that, I would like to understand what is happening (and likely what should be happening). I am not very familiar with FMRIprep, so please let me know what A and B outputs are.

And for the “should be happening” part, am I correct that your FMRIprep command above should be outputting the EPIs in alignment with the subject anatomical (so, basically in a “native” subject space)?

–pt

Hi PT,

Thank you so much for your reply. Yes,the FMRIprep command above should be outputting the EPIs in alignment with the subject anatomical , basically in a “native” subject space).

And the A and B outputs are:
A:


N-1 header file 'sub-1_task-checker_acq-TR156_space-T1w_desc-brain_mask.nii.gz', num_fields = 2
  name                offset  nvals  values
  ------------------- ------  -----  ------
  qform_code           252      1    2
  sform_code           254      1    2


B:


N-1 header file 'sub-1_desc-preproc_T1w.nii.gz', num_fields = 2
  name                offset  nvals  values
  ------------------- ------  -----  ------
  qform_code           252      1    1
  sform_code           254      1    1


Many thanks for your help!

—Aaron

Hi-

OK, so that shows why they have different ‘space’ properties: the sform_code = qform_code = 2 for your EPI, while sform_code = qform_code = 1 for the anatomical. I am not sure why that software outputs these final datasets with different values for these codes (presumably they should overlap at that point, even if they have different grids/voxelsizes?).

What do {s,q}form_code values do? They are supposed to tell whether the dataset is in native or standard space. Scrolling down in the NIFTI code here:
https://raw.githubusercontent.com/NIFTI-Imaging/nifti_clib/7934f742f435c3d6628a1099cd2dba14d6cd2216/niftilib/nifti1.h
… you will see that each of these can take one of the following integer values:


/* [qs]form_code value:  */      /* x,y,z coordinate system refers to:    */
   /*-----------------------*/      /*---------------------------------------*/

/*! \defgroup NIFTI1_XFORM_CODES
    \brief nifti1 xform codes to describe the "standard" coordinate system
    @{
 */
                                    /*! Arbitrary coordinates (Method 1). */

#define NIFTI_XFORM_UNKNOWN      0

                                    /*! Scanner-based anatomical coordinates */

#define NIFTI_XFORM_SCANNER_ANAT 1

                                    /*! Coordinates aligned to another file's,
                                        or to anatomical "truth".            */

#define NIFTI_XFORM_ALIGNED_ANAT 2

                                    /*! Coordinates aligned to Talairach-
                                        Tournoux Atlas; (0,0,0)=AC, etc. */

#define NIFTI_XFORM_TALAIRACH    3

                                    /*! MNI 152 normalized coordinates. */

#define NIFTI_XFORM_MNI_152      4

                                    /*!  Normalized coordinates (for
                                         any general standard template
                                         space). Added March 8, 2019. */

#define NIFTI_XFORM_TEMPLATE_OTHER  5

So, a value of 3, 4, or 5 will be recognized by AFNI as a standard space, by definition—those will get “+tlrc” in BRIK/HEAD names. A value of 1 will be recognized as non-standard, or subject, space—it will get “+orig” (as I think a value of 0 will. However, the case of a value of 2 is ambiguous—I think our preference would be that software never output that value, because it is ambiguous as to whether the dset is in standard or some subject space.

There is actually an environment variable to control this ambiguity how you wish. It is described here:
https://afni.nimh.nih.gov/pub/dist/doc/htmldoc/educational/readme_env_vars.html
… as:


AFNI_NIFTI_VIEW

    The default view extension used for output when creating AFNI format
    datasets from NIFTI datasets.This variable is only applicable for
    sform and qform codes that do not have clearly defined views
    (sform/qform code = 2). Set to "tlrc" or "orig". See also
    AFNI_DEFAULT_STD_SPACE and AFNI_NIFTI_PRIORITY. Note sform/qform code=5
    can be used for spaces other than MNI or TLRC including MNI_ANAT or D99
    spaces.

So, sorry about the long post, but to summarize:

  • your EPI and anatomical come out of FMRIprep with differing {s,q}form_codes. I am not sure why this is the case, since these dsets should overlay well, assuming they are both the final EPI and anatomical dataset. Maybe someone else can answer that.
  • The {s,q}form_code of the anatomical is 1, so AFNI recognizes that directly as “orig” data.
  • The {s,q}form_code of the EPI is 2, which is unfortunately both different and ambiguous. Right now, the default on your system is to interpret it as “+tlrc”.
  • You could choose to have an {s,q}form_code of 2 be interpreted as “orig” by setting the above environment variable in your ~/.afnirc or in your script for copying the NIFTI → BRIK/HEAD. To do this in your ~/.afnirc, that would be:

AFNI_NIFTI_VIEW = orig

–pt

Hi again!

Thank you soooo much for the detailed explanation! I set the above environment variable and the problem was solved successfully!:)-D

However, I found that epi image became slightly deviated from anat. Could you please tell me know how can I fix this?

Aaron

11.jpg

Hmmm, just to check, what is the output of:


3dinfo -obliquity -prefix DSET_ANAT DSET_EPI

?

–pt

Hi-
Thanks for your reply ! This is the output:


0.000	        sub-1_T1image
0.000	               stats.sub-1

–Aaron

OK, there is no obliquity in the dsets, so that is not responsible for any alignment issues.

I assume that this alignment is the result of FMRIprep processing, but I am not familiar with how FMRIprep allows you to check the alignment. (In the afni_proc.py output QC HTML, there are separate images showing EPI to anatomical alignment, and also anatomical to template alignment, for any of those alignments that are performed).

–pt

Hi pt,

Three is also a QC HTML in fmriprep,and below is the QC images for “aligment of functional and anatomical”

Aaron

OK, thanks for sharing that. I guess that is internal anatomical edges overlaid on the EPI?

A lot of the internal structures look well aligned. Has the EPI been skullstripped or something, though? It looks like some parts have been removed? Or is that just the presence of EPI distortions? Without seeing the set of anatomical lines that represents the pial surface (“outer” GM boundary), as well as the boundary of the anatomical, it is a little hard to see if that might be responsible for some alignment issues. (see the attach APQC HTML image for EPI-anatomical alignmnet for what I mean: the EPI is underlayed beneath edges of the anatomical volume; NB that here the EPI FOV did not include cerebellum—you can see distortion in the lowest slices from acquisition, but not how well the cortical structures align; you can also see how well the GM as a whole fits in, because there is both gray-white boundary and pial lines.)

EPI-anatomical alignment is also made trickier by the presence of EPI distortion. Do you have a sense of how much such distortion there is in this EPI? I can’t tell from this image (I’m not sure if it is a raw EPI). Various EPI distortions can really be strong in the subcortical volume, esp. around sinuses and inferior frontal cortex.

–pt