How to transform single echo data to same space (MNI152NLin2009cAsym) as combined-echo data

Dear all,

my question is similar to Fmriprep on multi-echo data: Exporting individual echos in MNI space, but the answer (“You can use antsApplyTransforms to transform the echos to MNI.”) was not detailed enough for me.

I would like to analyze single echo and combined-echo data from fmripreped multi-echo data. Since fmriprep writes the single echo data in native space and the combined data in a standard space I plan to transform the single-echo data, but I am not sure I) which transformation files to use, and II) about antsApplyTransformation’s syntax for two intended transformations: a) transform 3D single-echo time course data, b) transform a 3D-statistical map derived from that single-echo time course data from native to MNI space. At this point I’d like to follow up option a) because of specifics of my planned analysis.
I understand that in my scenario I need to apply the scanner-to-T1w and the T1w-to-standard transforms to the single-echo data.

DETAILED INFO:
I used fmriprep-24.0.0 to process 5 sessions (1 anatomical, 10 functional runs) of multi-echo data (4 echos) using the –me-output-echos option. My task is called “odl”.
For the sake of brevity, I’ll only talk about sub-02, ses-0, run-01, echo-1 (and the combined echo)

<>/derivatives/sub-02/ses-0/func:
Contains preprocessed single echo files in native space:
sub-02_ses-0_task-odl_run-01_echo-1_desc-preproc_bold.nii.gz

and combined-echos files in MNI space:
sub-02_ses-0_task-odl_run-01_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz

and a bunch of transformation files:

sub-02_ses-0_task-odl_run-01_from-boldref_to-auto00006_mode-image_xfm.txt
sub-02_ses-0_task-odl_run-01_from-boldref_to-T1w_mode-image_desc-coreg_xfm.txt
sub-02_ses-0_task-odl_run-01_from-orig_to-boldref_mode-image_desc-hmc_xfm.txt

<>/derivatives/sub-02/ses-0/anat:
sub-02_ses-0_from-orig_to-T1w_mode-image_xfm.txt

CONCRETE QUESTIONS:
How can I transform a) the time course file for the first echo (sub-02_ses-0_task-odl_run-01_echo-1_desc-preproc_bold.nii.gz) into the same space as the combined echo (sub-02_ses-0_task-odl_run-01_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz)?

To my knowledge transforming a volume-timecourse (4D), the syntax is

data_in=sub-02_ses-0_task-odl_run-01_echo-1_desc-preproc_bold.nii.gz
data_out=sub-02_ses-0_task-odl_run-01_echo-1_space-MNI152NLin6Asym_desc-preproc_bold.nii.gz
name_ref=???1 (do I need to extract <first_volume_of_combined_echo_BOLD>?)
scanner_to_T1w_transformation=???2
T1w_to_standard_transforms=???3
antsApplyTransforms –d 3 -e 3\
	–input-image-type 3 \
	–input $data_in \
	–default-value 0 \
	–float 1 \
	–interpolation LanczosWindowedSinc \
	–output $data_out \
	–reference-image $name_ref \
	–transform $scanner_to_T1w_transformation \
	–transform $T1w_to_standard_transforms

Is this syntax correct, and which respective files are ???1, ???2, and ???3
in the list below?

.
├── anat
│   ├── sub-02_desc-brain_mask.json
│   ├── sub-02_desc-brain_mask.nii.gz
│   ├── sub-02_desc-preproc_T1w.json
│   ├── sub-02_desc-preproc_T1w.nii.gz
│   ├── sub-02_from-MNI152NLin2009cAsym_to-T1w_mode-image_xfm.h5
│   ├── sub-02_from-MNI152NLin6Asym_to-T1w_mode-image_xfm.h5
│   ├── sub-02_from-T1w_to-MNI152NLin2009cAsym_mode-image_xfm.h5
│   ├── sub-02_from-T1w_to-MNI152NLin6Asym_mode-image_xfm.h5
│   ├── sub-02_from-T1w_to-fsnative_mode-image_xfm.txt
│   ├── sub-02_from-fsnative_to-T1w_mode-image_xfm.txt
│   …
├── ses-0
│   ├── anat
│   │   └── sub-02_ses-0_from-orig_to-T1w_mode-image_xfm.txt
│   ├── fmap
│   │   ├── sub-02_ses-0_run-01_fmapid-auto00006_desc-coeff0_fieldmap.nii.gz
│   │   ├── sub-02_ses-0_run-01_fmapid-auto00006_desc-coeff1_fieldmap.nii.gz
│   │   ├── sub-02_ses-0_run-01_fmapid-auto00006_desc-magnitude_fieldmap.nii.gz
│   │   ├── sub-02_ses-0_run-01_fmapid-auto00006_desc-preproc_fieldmap.json
│   │   ├── sub-02_ses-0_run-01_fmapid-auto00006_desc-preproc_fieldmap.nii.gz
│   │   ├── …
│   └── func
│       ├── sub-02_ses-0_task-odl_run-01_desc-brain_mask.json
│       ├── sub-02_ses-0_task-odl_run-01_desc-brain_mask.nii.gz
│       ├── sub-02_ses-0_task-odl_run-01_desc-confounds_timeseries.json
│       ├── sub-02_ses-0_task-odl_run-01_desc-confounds_timeseries.tsv
│       ├── sub-02_ses-0_task-odl_run-01_desc-coreg_boldref.json
│       ├── sub-02_ses-0_task-odl_run-01_desc-coreg_boldref.nii.gz
│       ├── sub-02_ses-0_task-odl_run-01_desc-hmc_boldref.json
│       ├── sub-02_ses-0_task-odl_run-01_desc-hmc_boldref.nii.gz
│       ├── sub-02_ses-0_task-odl_run-01_echo-1_desc-preproc_bold.json
│       ├── sub-02_ses-0_task-odl_run-01_echo-1_desc-preproc_bold.nii.gz
│       ├── …
│       ├── sub-02_ses-0_task-odl_run-01_from-boldref_to-T1w_mode-image_desc-coreg_xfm.json
│       ├── sub-02_ses-0_task-odl_run-01_from-boldref_to-T1w_mode-image_desc-coreg_xfm.txt
│       ├── sub-02_ses-0_task-odl_run-01_from-boldref_to-auto00006_mode-image_xfm.json
│       ├── sub-02_ses-0_task-odl_run-01_from-boldref_to-auto00006_mode-image_xfm.txt
│       ├── sub-02_ses-0_task-odl_run-01_from-orig_to-boldref_mode-image_desc-hmc_xfm.json
│       ├── sub-02_ses-0_task-odl_run-01_from-orig_to-boldref_mode-image_desc-hmc_xfm.txt
│       ├──…
│       ├── sub-02_ses-0_task-odl_run-01_space-MNI152NLin2009cAsym_boldref.json
│       ├── sub-02_ses-0_task-odl_run-01_space-MNI152NLin2009cAsym_boldref.nii.gz
│       ├── sub-02_ses-0_task-odl_run-01_space-MNI152NLin2009cAsym_desc-brain_mask.json
│       ├── sub-02_ses-0_task-odl_run-01_space-MNI152NLin2009cAsym_desc-brain_mask.nii.gz
│       ├── sub-02_ses-0_task-odl_run-01_space-MNI152NLin2009cAsym_desc-preproc_bold.json
│       ├── sub-02_ses-0_task-odl_run-01_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz
│       ├── …
├── ses-1
│   ├── …

28 directories, 3001 files

Thanks a lot,
Jens

For posterity, I (hope that I) figured out the answers to my own questions

  1. The syntax was not correct, the bash script below uses the correct syntax.
  2. The files denoted with ???1, ???2, and ???3 are
    ???1: name_ref=sub-02_ses-0_task-odl_run-01_space-MNI152NLin2009cAsym_boldref.nii.gz
    ???2: scanner_to_T1w_transformation=sub-02_ses-0_task-odl_run-01_from-boldref_to-T1w_mode-image_desc-coreg_xfm.txt
    ???3: T1w_to_standard_transforms=…/…/anat/sub-02_from-T1w_to-MNI152NLin2009cAsym_mode-image_xfm.h5

Shell script that transforms all four single echo files for all 10 runs in a given subject and session to MNI space matching the combined-echos file produced by tedana/fmriprep:

#transform_echo.sh
#using the fmriprep flag –me-output-echos exports the echo timeseries in the native space, whereas the combined echo time series is computed in MNI space
#this script transforms the single echo time series to MNI space
#jens.schwarzbach@ukr.de
#
#Example call (for transforming subject sub-02, session ses-0):
#./transform_echo.sh 02 0
sub_no=$1
ses_no=$2

for run_no in $(seq -f "%02g" 1 10)
do
	for echo_no in  {1..4}
	do
		project_dir=<YOUR_PATH_TO_PROJECT>
		subject_dir=${project_dir}/Nifti/derivatives/sub-${sub_no}
		anat_dir=$subject_dir/anat 
		func_dir=${subject_dir}/ses-${ses_no}/func
		data_in=${func_dir}/sub-${sub_no}_ses-${ses_no}_task-odl_run-${run_no}_echo-${echo_no}_desc-preproc_bold.nii.gz
		data_out=${func_dir}/sub-${sub_no}_ses-${ses_no}_task-odl_run-${run_no}_echo-${echo_no}_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz
		name_ref=${func_dir}/sub-${sub_no}_ses-${ses_no}_task-odl_run-${run_no}_space-MNI152NLin2009cAsym_boldref.nii.gz
		scanner_to_T1w_transformation=${func_dir}/sub-${sub_no}_ses-${ses_no}_task-odl_run-${run_no}_from-boldref_to-T1w_mode-image_desc-coreg_xfm.txt
		T1w_to_standard_transforms=${anat_dir}/sub-${sub_no}_from-T1w_to-MNI152NLin2009cAsym_mode-image_xfm.h5

		echo "$project_dir"
		echo "$subject_dir"
		echo "$anat_dir"

		if test -f ${data_out}; then
    			echo "${data_out} already exists."
		else 
			antsApplyTransforms -v \
      				-d 3 \
				--input-image-type 3 \
				--input $data_in \
				--default-value 0 \
				--float 1 \
				--interpolation LanczosWindowedSinc \
				--output $data_out \
				--reference-image $name_ref \
				--transform $scanner_to_T1w_transformation \
				--transform $T1w_to_standard_transforms
		fi
	done
done
1 Like