Transforming fmriprep outputs into subject space

Hello Neurostars,

I found several old threads about this topic, but am still a bit unsure what would be the best procedure for this task.

I want to do some functional analysis in subject space instead of template space. Starting from the outputs of fmriprep (in MNI space), what would be the best (and simplest) way to get there?

Thanks already!

1 Like

It’s not starting from the outputs of fmriprep per se, but you can just rerun the fmriprep code but include --output-spaces anat in the call, which puts the fmri in T1w space. It should use cached information so the run won’t take as long. That’s probably the simplest way I can think of.

Best,
Steven

1 Like

Thanks for your reply! What exactly do you mean by cached information? The data from e.g. the freesurfer directory of the results? Other cached data from the initial run will probbly not be available. Would I then also need to add --fs-subjects-dir?

You do not have to update the fs-subjects-dir, unless it is in a non-default location $bids_dir/derivatives/freesurfer, so no need to run freesurfer again. Also, If you ran fmriprep with -w $scratch_directory, and that directory has not been cleared, a lot of steps will not have to be recomputed. Even if that directory is not available, I believe fmriprep can also use outputs from already completed runs (that is $bids_dir/derivatives/fmriprep. Does that make sense?

edit: even if cached info is not available, this is still probably the simplest and safest option, as your alternative would probably be to write a script to use FSL flirt to compute the MNI-T1w transform and apply that to all relevant files. And you would want to manually check all the outputs since spatial normalization can sometimes go wonky (that goes doubly for two normalizations BOLD–>MNI–>T1w), so there probably isn’t that much of a time benefit to doing this either.

Best,
Steven

Thank you so much for your help (and sorry for my many questions)!

I believe the original command was using a custom output directory
fmriprep-docker input_dir output_dir participant --participant-label sub-X --use-aroma --fs-license-file file_dir

So I don’t think there will be any cached information left?

If I rerun this now using
fmriprep-docker input_dir output_dir participant --output-spaces anat --participant-label sub-X --use-aroma --fs-license-file file_dir

(adding the output-space option), this should then rerun everything with outputs in T1w space while considering the previously calculated outputs?

It should, and also it will not delete your previous MNI runs, and the HTML files will reflect all completed runs/output-spaces.

1 Like

Thanks a lot! I will try my luck with this tomorrow and hope I’ll then be able to mark the thread as solved :slight_smile:

1 Like

If you have the space, pass the -w /path/to/scratch option so that you can reuse as much previously done work as possible.

There is some experimental support for reusing anatomical derivatives (--anat-derivatives), but not functional derivatives.

1 Like

I think the -w argument wasn’t used in the first run. Does fmriprep still keep some files in this case, or are they deleted?

If -w isn’t passed, then the working directory is created in the container, which generally does not persist. You can see if there’s an old copy of the container with docker ps -a. If the container from your previous run exists, you can use it with the -i flag in fmriprep-docker. Note that I haven’t tried this, so I can’t be sure how well it would work.

1 Like