Combining fmriprep with ME-ICA from tedana

Hi Gershon,

I don’t believe that fMRIPrep labels the output preprocessed file as “optimally combined,” but it shouldn’t have echo-1 in the filename. Is that the case?

Currently, fMRIPrep doesn’t output the echo-specific images, which is why we recommend collecting the relevant files from fMRIPrep’s working directory and moving them into the output directory. We have some provisional code available here, although it’s currently just a notebook tailored to our project. We plan to convert it into a more general function soon, but you can almost certainly adapt it yourself to work with your own data structure. We have tested the code (and it looks good), but haven’t checked too deeply against fMRIPrep’s code, so we’re not 100% sure we’re grabbing the right files.

Regarding the field maps, it looks like you’re using --force-syn. That would force fMRIPrep to use field map-less distortion correction. I’m not sure about the sbref files. Are you sure it’s not using them? Can you share the captured stdout?


Thanks for the reply Taylor,

In the html report, the figure all point to figure labels with ‘echo-1’. For example, sub-018/figures/sub-018_ses-001_task-faces_echo-1_rois.svg

Moreover in my working directory I only find the following files:

about func_preproc_ses_001_task_faces_echo_1_wf
anat_preproc_wf func_preproc_ses_001_task_rest_echo_1_wf
bids_info func_preproc_ses_002_task_faces_echo_1_wf
bidssrc func_preproc_ses_002_task_rest_echo_1_wf
ds_report_about summary

Does this indicate that only echo_1 is analysed?

However, when I go to the output directory the files are not labeled with ‘echo…’. For example, fmriprep/sub-018/ses-001/func/sub-018_ses-001_task-faces_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz

Does this mean that the html report and working file label is indicating the echo-1 is being used as some reference, but actually the correct, optimally combined, images can be found in the output folder?

ie., the following image is the optimally combined image: sub-018_ses-001_task-faces_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz

I will examine your code and try to omit --force-syn.

Kind regards,

I believe that the echo-1 is probably just an oversight in the naming. Even after the data are optimally combined across echoes, the working directory may store the files in folders with echo-1 in the name. The desc-preproc file in the output directory should definitely be the optimally combined, preprocessed data.

Hi @tsalo and @emdupre,

My apologies for tagging you two again, but you seem to be the resident experts regarding combining fmriprep and tedana.

I have processed my data with the latest version of fmriprep 1.4, chosing MNI152NLin6Asym as an output space using --output-spaces.

I have managed to use the script ( provided by @tsalo to obtain the minimally preprocessed images for use in tedana. However, I am having some difficulty extracting the required files for subsequent warp transformation from native BOLD space to MNI152NLin6Asym.

For example, the script points to the folder in the wf called ‘bold_to_mni_trans_wf’, which does not seem to exist. I wonder if this has changed in subsequent version of fmriprep. I think I may have found the correct files in ‘op.join(task_dir, ‘bold_mni_trans_wf’,‘bold_to_mni_transform/_inputs.pklz’)’, but not entirely sure.

Using these files, I create two files:

I then tried to use the following to files using ApplyTransform to warp my BOLD image in native space to MNI152NLin6Asym (as a sanity check prior to running tedana), but this did not work (ie, the command ran but not image was displayed).

at = ApplyTransforms()
at.inputs.dimension = 3
at.inputs.interpolation = ‘NearestNeighbor’
at.inputs.float = False
at.inputs.transforms = op.join(sub_func_dir,‘sub-002_ses-002_task-faces_from-native_to-reference_mode-image_xfm.txt’)
at.inputs.input_image = op.join(sub_func_dir,‘sub-002_ses-002_task-faces_echo-1_space-native_desc-partialPreproc_bold.nii’)
at.inputs.reference_image = op.join(sub_func_dir,‘sub-002_ses-002_task-faces_space-MNI152NLin6Asym_desc-preproc_bold.nii.gz’)
at.inputs.output_image = ‘/home/fs0/gspitz/scratch/gut_study/data/fmriprep_output/fmriprep_derivative/test.nii.gz’

I was hoping you might have an easy fix to this. I am sure the files are there, but having difficulty locating the correct ones.

Kind regards,

Hi @gspitz !

I haven’t had a chance to look into your question yet, but I just wanted to let you know it’s on our radar ! Hoping to have time next week to check-in. In the mean time, not sure if some fmriprep folks (maybe @effigies or @oesteban ?) would know about fmriprep updates in saving transforms as of v1.4.

Sorry for the delay,


Thank you for the reply @emdupre --much appreciated.

I’ll look forward to any helpful replies.

Kind regards.


It’s unclear what files exactly you found and are trying to use, but a .txt file is not going to perform the warps needed to get you to the template space. We save the transform from T1w to template in the anat/ subdirectory, which should look something like:


It looks like you’re also using a BOLD image that hasn’t been resampled in T1w space, so you’ll probably need to dig up the affine transform from BOLD to T1w, which should be in something like:


You need to pass your transforms as a list, with the T1w-template first, and your BOLD-T1w second. If you are also using SDC, that should go third.


Hi @effigies,

Thank you for the reply.
I have the first two transforms you mentioned. I’ll hunt dow the SDC transform and also apply this.

Kind regards.

Hi @effigies,

Good news–I am able to transform my tedana-processed denoised epi to standard space using the t1_2_standard and bold_2_t1 transforms.

However, because I apply pepolar sdc, I would also like to apply this to my tedana-processed image. I can see that fmriprep uses the _warpfieldQwap_PLUS_WARP_fixhdr.nii.gz

However, opening this image just provide an empty image–just a rectangle with all ‘0’. Is this correct? Including this to my transform has no effect on the image. ie., no SDC correction applied.

Is this the correct transform file?

Kind regards

I’m not positive of the filename used, but you should be able to find it in the ApplyTransform transforms list, so if that’s what you’re seeing, then that’s probably right.

Are you sure that it’s all zeros? e.g.,

import nibabel as nb
img = nb.load(fname)
print("Zeros: ", np.allclose(img.get_fdata(), 0))

If so, I would inspect your input fieldmaps to make sure that they look sensible. All zeros suggests to me that you have the exact same data in your reverse-PE fieldmap, but this is just an intuition. I’m not as versed in the fieldmap components of the workflow as most of the rest.

Thanks for the quick reply @effigies

I used the Apply Transform to hunt down the correct transforms:

For SDC it is: single_subject_002_wf/func_preproc_ses_001_task_fmritask_echo_1_wf/sdc_wf/pepolar_unwarp_wf/cphdr_warp/_warpfieldQwarp_PLUS_WARP_fixhdr.nii.gz’

Using this file I return ‘False’ using the command you provided above.

I am using the following command for apply transform:

[‘antsApplyTransforms’, ‘–default-value’, ‘0’, ‘–input-image-type’, ‘3’, ‘–dimensionality’, ‘3’, ‘–float’, ‘1’, ‘–input’, ‘/home/fs0/gspitz/scratch/study/data/tedana_output/sub-002-ses-001/dn_ts_OC.nii’, ‘–interpolation’, ‘LanczosWindowedSinc’, ‘–output’, ‘/home/fs0/gspitz/scratch/study/data/fmriprep_output/fmriprep/sub-002/ses-001/func/sub-002_ses-001_task-fmritask_space-MNI152NLin6Asym_desc-dn_ts_OC_bold_test2.nii.gz’, ‘–reference-image’, ‘/home/fs0/gspitz/scratch/study/data/template/tpl-MNI152NLin6Asym_res-02_T1w.nii.gz’, ‘–transform’, ‘/home/fs0/gspitz/scratch/study/data/fmriprep_output/fmriprep/sub-002/anat/sub-002_from-T1w_to-MNI152NLin6Asym_mode-image_xfm.h5’, ‘–transform’, ‘/home/fs0/gspitz/scratch/study/data/fmriprep_output/fmriprep/sub-002/ses-001/func/sub-002_ses-001_task-fmritask_from-reference_to-T1w_mode-image_xfm.txt’, ‘–transform’, ‘/vols/Scratch/gspitz/study/data/fmriprep_output/fmriprep_wf/single_subject_002_wf/func_preproc_ses_001_task_fmritask_echo_1_wf/sdc_wf/pepolar_unwarp_wf/cphdr_warp/_warpfieldQwarp_PLUS_WARP_fixhdr.nii.gz’]

I have also inspected the phase-reverse epi for this participant. It looks sensible to me.

Kind regards,

Sorry, to be clear, are you saying that this is working for you? It sounds like your reverse-PE EPI looks good, you have a non-zero fieldmap estimate, and are able to apply the transforms. If you need further assistance, please clarify.


Looking at the images again, I seem to be able to ‘recover’ to original preprocessed image from fmriprep. There are some differences, which I suspect are due to a different mask being applied in tedana. Ie., voxels are in same place in both images, but some voxels, o the outside of the brain are missing. Ie., looks like at some point tedana applies a tighter mask.

So it looks like things are working well.

Thank you for the help!

1 Like

Hi Taylor and @emdupre,
I was reading through this string as I have ME data and am currently preprocessing with fMRIPrep (thanks for all of your work on the pipeline!). I’m wondering - since this post was back in March '19 - how close is fMRIPrep with integrating multi-echo denoising? Just trying to figure out if it’s worth waiting until it’s integrated, or using fMRIPrep and tedana separately, but within the same pipeline as suggested here. Thanks so much for any thoughts and suggestions!


Hi @NRob,

I was asking myself the same question and then stumbled onto the post below From April 2019. It seems that we will have to use fMRIPrep and tedana separately as they are no longer working to integrate them together.

“The choice to not incorporate tedana denoising into fMRIPrep was a conscious one. Given that fMRIPrep is geared towards robustness – and our lingering concerns as to whether tedana denoising was (yet) able to produce robust results – we decided not to include it for now.”

1 Like

Thanks for this. It does appear that putting tenana into the current workflow of fMRIPrep has been put on the back burner.

I’m still a bit confused about what fMRIPrep is actually currently doing with ME data:

  1. the --t2s-coreg option says that if this option is not enabled, ‘standard EPI-T1 coregistration in performed using the middle echo.’ There was a post back in Aug. 2018 where @emdupre says that " --t2s-coreg would not combine the multiple echos. It’s another way to coregister the functional and anatomical data by first generating a T2* map and then coregistering the anatomical to that single image rather than to each of the echos separately."

There are posts in 2019 that talk about removing this option all together based on issues raised about this option, so I’m hesitant to use it.

So, if we don’t use this option, (2) the boiler plate says it “optimally combines” the ME data, and gives a reference to the Posse 1999 paper. Is this what fMRIPrep is doing with the ME data? What is outlined by Posse et al.?

Yes, I’d recommend against using --t2s-coreg at this time.

Optimal combination averages the data across echoes, with each voxel’s average weighted based on that voxel’s T2* value. The idea is to essentially predict what the data would be if you acquired each voxel its specific best echo time. In the tedana documentation, we have a walkthrough of optimal combination with figures that might be helpful.

1 Like

Thank you so much, @tsalo! I really appreciate the clarification about optimal combination, and the confirmation in not using --t2s-coreg. Thank you!

Hi Chris,

It seems that these paths have changed with new versions of fmriprep (I’m using 20.1.1) - could you point me toward where I can find the second transform in the fmriprep workdir?


Got my answer here: