Using Precomputed anatomical segmentations outside fMRIPrep

Hi All,

I would like the following precomputed files to be used by fmriprep instead of it re-running the below steps

  1. Skull-stripped mask

  2. My own 3 tissue type mask for 7T anatomical processing instead of FSL FAST since it does not do a good job of separating GM-WM for 7T MP2RAGE. When I placed the *dseg.nii.gz and *probseg.nii.gz labels in the anat derivative folder it would replace the current files during the run.

  3. And I would also like to use the freesurfer 8.0 output instead of 7.3 and in order to use precomputed output for downstream processing, can I use this flag “–fs-no-resume”? after placing the freesurfer output in */sourcedata/freesurfer/$subj/? At this point fsaverage files are not created.

Command

apptainer run \
-B /home/naxos2-raid14/jayashre/.cache/templateflow:/templateflow:ro \
-B /home/udall-raid5/bids-data/Control_data/Nifti:/data \
-B /home/udall-raid5/bids-data/Control_data/fmriprep/output_ses02:/output \
-B /home/udall-raid5/bids-data/Control_data/fmriprep/work_ses02:/work \
-B /opt/local/dbs/bin/license.txt:/license.txt:ro /opt/local/dbs/bin/fmriprep-latest.simg \
/data /output participant \
--participant-label C126 \
--session-label 02 \
-w /work \
--fs-license-file /license.txt \
--ignore slicetiming \
--skull-strip-t1w skip \
--output-spaces MNI152NLin2009cAsym:res-native T1w fsnative \
--nthreads 8 --omp-nthreads 6 \
--skip-bids-validation

Version:

fmriprep 25.2.3

Environment (Docker, Singularity / Apptainer, custom installation):

Apptainer

OS: Linux Ubuntu 22.04.5


Hi @chand671 and welcome to neurostars!

You can look up documentation for using precomputed derivatives with the -d argument here: Usage Notes — fmriprep version documentation

You can run FreeSurfer outside of fmriprep and input your data with the --fs-subjects-dir flag.

That is primarily useful for alternative freesurfer runs (e.g., recon-all-clinical or fastsurfer), or if you get an error after trying FS8 normally.

Best,
Steven

Thank you @Steven.

I ran fmriprep with your recommended arguments, which is using a custom 3-tissue type mask and pointed the command to freesurfer directory (ran on native T1) and derivatives directory.

I ran with this space argument --output-spaces MNI152NLin2009cAsym:res-native fsnative. This created a transformed *aseg_dseg.nii.gz file to ACPC space due to fsnative argument, right? But since the native T1 was already present in the anat folder the BOLD images were no longer aligned with the native T1.

To avoid this misalignment issue should I re-run them using this argument instead --output-spaces MNI152NLin2009cAsym:res-native T1w?

Appreciate your help!

It is hard for me to properly answer without knowing how you named and organized your precomputed inputs.

@Steven, here is the full path I provided to the command,

-B /home/udall-raid5/bids-data/Control_data/fmriprep/output_ses01:/derivatives

And the files I copied to the /derivatives/anat/ folder includes,

sub-C126_ses-01_acq-axi_desc-preproc_T1w.nii.gz
sub-C126_ses-01_acq-axi_desc-brain_mask.nii.gz
sub-C126_ses-01_acq-axi_label-CSF_probseg.nii.gz
sub-C126_ses-01_acq-axi_label-GM_probseg.nii.gz
sub-C126_ses-01_acq-axi_label-WM_probseg.nii.gz
sub-C126_ses-01_acq-axi_dseg.nii.gz

And the provided this argument for the fs directory, --fs-subjects-dir /derivatives/sourcedata/freesurfer

These arguments worked because the files were not modified by fmriprep.

Please let me know if I can provide any other info.

Thank you,
Jayashree

How did you specify the -d flag in the command? I am not sure the files will be used if they are not organized in BIDS style folders, e.g., in derivatives/{whatever you named the -d argument}/sub-C126/ses-01/anat/. And if you are using session specific anatomicals instead of a subject average template, you should specify the --subject-anatomical-reference sessionwise.

Here is the full command. Since I have already included a session label --session-label 01 for this run, I think it was able to access /derivatives/sub-C126/ses-01/anat/

apptainer run \
-B /home/naxos2-raid14/jayashre/.cache/templateflow:/templateflow:ro \
-B /home/udall-raid5/bids-data/Control_data/Nifti:/data \
-B /home/udall-raid5/bids-data/Control_data/fmriprep/output_ses01:/output \
-B /home/udall-raid5/bids-data/Control_data/fmriprep/work_ses01:/work \
-B /home/udall-raid5/bids-data/Control_data/fmriprep/output_ses01:/derivatives \
-B /opt/local/dbs/bin/license.txt:/license.txt:ro \
/opt/local/dbs/bin/fmriprep-latest.simg \
/data /output participant \
--participant-label C126 --session-label 01 \
-w /work \
--fs-license-file /license.txt \
--derivatives /derivatives \
--fs-subjects-dir /derivatives/sourcedata/freesurfer \
--ignore slicetiming \
--skull-strip-t1w skip \
--output-spaces MNI152NLin2009cAsym:res-native fsnative \
--nthreads 8 --omp-nthreads 6 \
--skip-bids-validation

Hi @chand671,

In the future, please format your code for readability using tickmarks / the </> button in the text editor. You can see I have updated your above posts for you.

Not sure this is right. You have mounted the same folder twice to the container with different names. That could cause weirdness and is not recommended. Also, I believe the operation will work better if the precompted derivatives are in a place separated from the main fmriprep outputs.