Fmriprepv23 freesurfer recon-all autorecon1 Tailrach transform failing

Summary of what happened:

I am running fMRIprep over a BIDS dataset and have gotten errors for over half the subjects on errors related to FreeSurfer. Some of the subjects have multiple sessions so I’m not sure if that’s related to these errors. The successful runs typically only have 1 run in their /anat folder. I am using fMRIprep v23.2.0 and Freesurfer v7.3.2,.

Command used (and if a helper script was used, a link to the helper script or the command generated):

Here’s my run command:

singularity run \
  --cleanenv \
  --containall \
  -B ${TEMPLATEFLOW_DIR}:/opt/templateflow \
  -B ${bids_root_dir}:/bids  \
  -B ${target_dir}:/out \
  -B ${work_dir}:/work \
  -B ${FS_LICENSE}:/license.txt \
  $fmriprep_path \
        /bids \
        /out \
        participant \
        --participant-label $subj \
        --skip-bids-validation \
        --omp-nthreads 20 \
        --mem_mb 350000 \
        --fs-license-file $bids_root_dir/derivatives/freesurfer_license.txt \
        --bids-filter-file $bids_root_dir/code/bids_filter.json \
        --work-dir /scratch/groups/kpohl/data/work/ \
        --output-spaces MNI152NLin2009cAsym:res-2 func \
        --stop-on-first-crash \
        --verbose \

Version:

23.2.0

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

Singularity

Data formatted according to a validatable standard? Please provide the output of the validator:

PASTE VALIDATOR OUTPUT HERE

Relevant log outputs (up to 20 lines):

The first error occurs within the recon-all -autorecon1 command, specifically in the Talairach transformation:

--src: orig.mgz src image (geometry).
	--trg: /opt/freesurfer/average/mni305.cor.mgz trg image (geometry).
	--inmni: transforms/talairach.xfm input MNI/XFM transform.
	--outlta: transforms/talairach.xfm.lta output LTA.
	--s: fsaverage subject name
	--ltavox2vox: output LTA as VOX_TO_VOX transform.
	 LTA read, type : 1
	 0.92433  -0.11243   0.14324   11.01506;
	 0.16067  -1.09314   15.85526   788.03479;
	 0.07971   2.21911  -11.43803  -597.01575;
	 0.00000   0.00000   0.00000   1.00000;
	setting subject to fsaverage
	Writing  LTA to file transforms/talairach.xfm.lta...
	lta_convert successful.
	/out/sourcedata/freesurfer/sub-61/mri/transforms /out/sourcedata/freesurfer/sub-61/mri 
	/out/sourcedata/freesurfer/sub-61/mri 
	#--------------------------------------------
	#@# Talairach Failure Detection Fri Mar  1 08:07:31 PST 2024
	/out/sourcedata/freesurfer/sub-61/mri

	 talairach_afd -T 0.005 -xfm transforms/talairach.xfm 

	ERROR: talairach_afd: Talairach Transform: transforms/talairach.xfm ***FAILED*** (p=0.0000, pval=0.0000 < threshold=0.0050)

	Manual Talairach alignment may be necessary, or
	include the -notal-check flag to skip this test,
	making sure the -notal-check flag follows -all
	or -autorecon1 in the command string.
	See:

	http://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/Talairach

	INFO: Retrying Talairach align using 3T-based atlas...

	#--------------------------------------------
	#@# Talairach Fri Mar  1 08:07:31 PST 2024
	/out/sourcedata/freesurfer/sub-61/mri

	 mri_nu_correct.mni --no-rescale --i orig.mgz --o orig_nu.mgz --ants-n4 --n 1 --proto-iters 1000 --distance 50 

	/usr/bin/bc
	/out/sourcedata/freesurfer/sub-61/mri
	/opt/freesurfer/bin/mri_nu_correct.mni
	--no-rescale --i orig.mgz --o orig_nu.mgz --ants-n4 --n 1 --proto-iters 1000 --distance 50
	nIters 1
	mri_nu_correct.mni 7.3.2
	Linux sh03-13n05.int 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
	Fri Mar  1 08:07:31 PST 2024
	tmpdir is ./tmp.mri_nu_correct.mni.115008
	cd /out/sourcedata/freesurfer/sub-61/mri
	AntsN4BiasFieldCorrectionFs -i orig.mgz -o ./tmp.mri_nu_correct.mni.115008/nu0.mgz --dtype uchar
	AntsN4BiasFieldCorrectionFs done
	mri_convert ./tmp.mri_nu_correct.mni.115008/nu0.mgz orig_nu.mgz --like orig.mgz --conform
	mri_convert ./tmp.mri_nu_correct.mni.115008/nu0.mgz orig_nu.mgz --like orig.mgz --conform 
	reading from ./tmp.mri_nu_correct.mni.115008/nu0.mgz...
	TR=0.00, TE=0.00, TI=0.00, flip angle=0.00
	i_ras = (-1, -9.24047e-10, -1.16415e-10)
	j_ras = (-1.74623e-10, 1.49012e-08, -1)
	k_ras = (-2.77942e-09, 1, 1.49012e-08)
	INFO: transform src into the like-volume: orig.mgz
	writing to orig_nu.mgz...
 
 
	Fri Mar  1 08:10:23 PST 2024
	mri_nu_correct.mni done

	 talairach_avi --i orig_nu.mgz --xfm transforms/talairach.auto.xfm --atlas 3T18yoSchwartzReactN32_as_orig 

	talairach_avi log file is transforms/talairach_avi.log...
	mv -f /out/sourcedata/freesurfer/sub-61/mri/talsrcimg_to_3T18yoSchwartzReactN32_as_orig_t4_vox2vox.txt /out/sourcedata/freesurfer/sub-61/mri/transforms/talsrcimg_to_3T18yoSchwartzReactN32_as_orig_t4_vox2vox.txt
	Started at Fri Mar 1 08:10:23 PST 2024
	Ended   at Fri Mar  1 08:10:54 PST 2024
	talairach_avi done

	 cp transforms/talairach.auto.xfm transforms/talairach.xfm 

	lta_convert --src orig.mgz --trg /opt/freesurfer/average/mni305.cor.mgz --inxfm transforms/talairach.xfm --outlta transforms/talairach.xfm.lta --subject fsaverage --ltavox2vox
	7.3.2

	--src: orig.mgz src image (geometry).
	--trg: /opt/freesurfer/average/mni305.cor.mgz trg image (geometry).
	--inmni: transforms/talairach.xfm input MNI/XFM transform.
	--outlta: transforms/talairach.xfm.lta output LTA.
	--s: fsaverage subject name
	--ltavox2vox: output LTA as VOX_TO_VOX transform.
	 LTA read, type : 1
	 0.53527   0.65987  -3.08316  -133.94702;
	-0.78485   0.30994  -4.63404  -235.27417;
	-0.33244   0.75488   0.01389  -1.38382;
	 0.00000   0.00000   0.00000   1.00000;
	setting subject to fsaverage
	Writing  LTA to file transforms/talairach.xfm.lta...
	lta_convert successful.
	/out/sourcedata/freesurfer/sub-61/mri/transforms /out/sourcedata/freesurfer/sub-61/mri 
	/out/sourcedata/freesurfer/sub-61/mri 
	#--------------------------------------------
	#@# Talairach Failure Detection Fri Mar  1 08:10:56 PST 2024
	/out/sourcedata/freesurfer/sub-61/mri

	 talairach_afd -T 0.005 -xfm transforms/talairach.xfm 

	ERROR: talairach_afd: Talairach Transform: transforms/talairach.xfm ***FAILED*** (p=0.0000, pval=0.0000 < threshold=0.0050)

	Manual Talairach alignment may be necessary, or
	include the -notal-check flag to skip this test,
	making sure the -notal-check flag follows -all
	or -autorecon1 in the command string.
	See:

	http://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/Talairach

	INFO: Trying MINC mritotal to perform Talairach align...

	#--------------------------------------------
	#@# Talairach Fri Mar  1 08:10:56 PST 2024
	/out/sourcedata/freesurfer/sub-61/mri

	 mri_nu_correct.mni --no-rescale --i orig.mgz --o orig_nu.mgz --ants-n4 --n 1 --proto-iters 1000 --distance 50 

	/usr/bin/bc
	/out/sourcedata/freesurfer/sub-61/mri
	/opt/freesurfer/bin/mri_nu_correct.mni
	--no-rescale --i orig.mgz --o orig_nu.mgz --ants-n4 --n 1 --proto-iters 1000 --distance 50
	nIters 1
	mri_nu_correct.mni 7.3.2
	Linux sh03-13n05.int 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
	Fri Mar  1 08:10:56 PST 2024
	tmpdir is ./tmp.mri_nu_correct.mni.115470
	cd /out/sourcedata/freesurfer/sub-61/mri
	AntsN4BiasFieldCorrectionFs -i orig.mgz -o ./tmp.mri_nu_correct.mni.115470/nu0.mgz --dtype uchar
	AntsN4BiasFieldCorrectionFs done
	mri_convert ./tmp.mri_nu_correct.mni.115470/nu0.mgz orig_nu.mgz --like orig.mgz --conform
	mri_convert ./tmp.mri_nu_correct.mni.115470/nu0.mgz orig_nu.mgz --like orig.mgz --conform 
	reading from ./tmp.mri_nu_correct.mni.115470/nu0.mgz...
	TR=0.00, TE=0.00, TI=0.00, flip angle=0.00
	i_ras = (-1, -9.24047e-10, -1.16415e-10)
	j_ras = (-1.74623e-10, 1.49012e-08, -1)
	k_ras = (-2.77942e-09, 1, 1.49012e-08)
	INFO: transform src into the like-volume: orig.mgz
	writing to orig_nu.mgz...
 
 
	Fri Mar  1 08:13:49 PST 2024
	mri_nu_correct.mni done

	 talairach --i orig_nu.mgz --xfm transforms/talairach.auto.xfm 

	/out/sourcedata/freesurfer/sub-61/mri
	/opt/freesurfer/bin/talairach
	--i orig_nu.mgz --xfm transforms/talairach.auto.xfm
	talairach 7.3.2
	Linux sh03-13n05.int 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
	Fri Mar  1 08:13:49 PST 2024
	tmpdir is transforms/tmp.talairach.115702
	/out/sourcedata/freesurfer/sub-61/mri
	mri_convert orig_nu.mgz transforms/tmp.talairach.115702/src.mnc
	mri_convert orig_nu.mgz transforms/tmp.talairach.115702/src.mnc 
	reading from orig_nu.mgz...
	TR=0.00, TE=0.00, TI=0.00, flip angle=0.00
	i_ras = (-1, -9.24047e-10, -1.16415e-10)
	j_ras = (-1.74623e-10, 1.49012e-08, -1)
	k_ras = (-2.77942e-09, 1, 1.49012e-08)
	writing to transforms/tmp.talairach.115702/src.mnc...
	--------------------------------------------
	mritotal -verbose -debug -clobber -modeldir /opt/freesurfer/mni/bin/../share/mni_autoreg -protocol icbm transforms/tmp.talairach.115702/src.mnc transforms/talairach.auto.xfm
	spawn: exec of mincinfo failed: No such file or directory
	mritotal: crashed while running mincinfo (termination status=65280)
	ERROR: mritotal failed, see transforms/talairach.log

More information:

I have verified that the /anat raw files for each subject have the same parameters, e.g. 2D T1-weighted. Previously, I noticed some subjects had both 2D and 3D T1-weighted images so I filtered those out by manually renaming the 3D filenames to include an acquisition and excluded them using a bids_filter file (criteria below):

{
    "t1w": {
        "datatype": "anat",
        "acquisition": null,
        "suffix": "T1w"
    }
}

I have searched for existing solutions and they seem to all rely on running Freesurfer independently, but that would take a significant time to do for the number of subjects and data I have. Checking here to make sure I’m not missing anything critical before I pivot to another pipeline.


Hi @favour-nerrise, and welcome to neurostars!

I think you should be using 3D images and exclude 2D images (e.g., single slice images).

You could also put the FreeSurfer command in the same script you are using to run fMRIPrep, to simplify the output sharing / incorporation if this fix doesn’t work. I can help with that.

Best,
Steven

Looks like there’s another minc tool that we need to restore to the Docker image.

Note that the reason it’s getting to this point is because FreeSurfer is having difficulty processing with its default tools and is falling back to some alternatives. I would suggest having a look at this subject’s anatomical data and making sure that it’s of high enough quality to be worth processing.

Thanks for the welcome! I had pivoted to another dataset and am now back on this dataset and unfortunately still stuck on this issue.

This is complicated because some of the subjects only have 2D (multiple runs) so I’d have no T1w scans if I filtered out all 2D images. I had to stop filtering out acq-3d as well because some subjects only have 3D images (sometimes one run, sometimes multiple runs) => hence my dilemma. I can’t filter out either 2D or 3D T1w images exclusively. My goal is to define a criteria where if both are present, take acq-3d, but I’m not sure how to implement this with BIDS formatting for fMRIPrep.

Exploring this as a backup now with bids/freesurfer, but it takes much longer and am looking for a solution directly within the fMRIPrep pipeline that is repeatable for an eventual longitudinal processing of this same dataset.

Hi @favour-nerrise,

Those subjects would not be able to run through fMRIPrep. fMRIPrep needs a 3D whole brain T1w image. Although, I’ve heard of extreme cases where someone uses the scout image as a T1w if there’s truly no other alternative viable option (like in some infant/toddler datasets). The scout wouldn’t work in FreeSurfer I imagine though.

Best,
Steven

Thank you so much!! I’m not sure how/why I glazed over the 3D T1w requirement. The 2D scans I had were from a 2D GRE MT sequence, and my mistake was blindly following an open source config.json which assigned these to the default T1w space. I’ve now separated these by assigning an acq-2d custom entity in my config.json file so fMRIPrep doesn’t attempt to stack both 2D and 3D scans in the anat/ folders. I also re-downloaded 3D T1w images for subjects missing it, re-ran dcm2bids, and updated .bidsignore to select only acq-3d. I’m now able to process subjects within 6-8 hours each, as expected.

2 Likes