Freesurfer in fmriprep vs freesurfer run independently

Summary of what happened:

Public dataset: OpenNeuro

freesurfer fails with a seg fault for a single subject (#6), but I can run freesurfer independently successfully. I was under the impression from other forum posts that the runs should be equivalent however I am getting different responses from the two runs. Note from the logs below that there are 190 defects in the fmriprep version vs 39 in the independent freesurfer

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

docker run --rm -e DOCKER_VERSION_8395080871=24.0.6 -it -v /home/ra/license.txt:/opt/freesurfer/license.txt:ro -v /mnt/h/FMRI_SAMPLE/ds004835-download:/data:ro -v /mnt/h/FMRI_SAMPLE/out:/out -v /home/ra:/scratch nipreps/fmriprep:23.1.4 /data /out participant --participant-label sub-06 -w /scratch2

Note that a NEW working directory was used to force it to redo the subject

vs freesurfer run independently:

recon-all -s subj6-fmri-sample -i /mnt/h/FMRI_SAMPLE/ds004835-download/sub-06/anat/sub-06_run-01_T1w.nii.gz -all

Version:

23.2.0a2

Environment (Docker, Singularity, custom installation):

docker in wsl

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

Yes, the bids-validator was happy with the data

Relevant log outputs (up to 20 lines):

This is the fmriprep freesurfer log:

    CORRECTING DEFECT 186 (vertices=27, convex hull=46, v0=597340)
    After retessellation of defect 186 (v0=597340), euler #=360 (239876,677443,437927) : difference with theory (-38) = -398
    CORRECTING DEFECT 187 (vertices=8, convex hull=23, v0=600259)
    After retessellation of defect 187 (v0=600259), euler #=361 (239878,677456,437939) : difference with theory (-37) = -398
    CORRECTING DEFECT 188 (vertices=9, convex hull=28, v0=605686)
    After retessellation of defect 188 (v0=605686), euler #=362 (239879,677470,437953) : difference with theory (-36) = -398
    CORRECTING DEFECT 189 (vertices=5, convex hull=26, v0=610360)
    After retessellation of defect 189 (v0=610360), euler #=363 (239879,677476,437960) : difference with theory (-35) = -398
    CORRECTING DEFECT 190 (vertices=573370, convex hull=68765, v0=611940)
    Segmentation fault
    Linux 15913ee0f650 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

    recon-all -s sub-06 exited with ERRORS at Thu Dec  7 13:15:31 UTC 2023

This is the output from the freesurfer run independently:

CORRECTING DEFECT 38 (vertices=38, convex hull=59, v0=126206)
After retessellation of defect 38 (v0=126206), euler #=1 (131841,395513,263673) : difference with theory (1) = 0
CORRECTING DEFECT 39 (vertices=5, convex hull=18, v0=132854)
After retessellation of defect 39 (v0=132854), euler #=2 (131841,395517,263678) : difference with theory (2) = 0
computing original vertex metric properties…
storing new metric properties…
computing tessellation statistics…
vertex spacing 0.89 ± 0.25 (0.05–>11.98) (max @ vno 87490 → 89274)
face area -nan ± -nan (1000.00–>-1.00)
performing soap bubble on retessellated vertices for 0 iterations…
vertex spacing 0.89 ± 0.25 (0.05–>11.98) (max @ vno 87490 → 89274)
face area -nan ± -nan (1000.00–>-1.00)
tessellation finished, orienting corrected surface…
135 mutations (36.7%), 233 crossovers (63.3%), 736 vertices were eliminated
building final representation…
6107 vertices and 0 faces have been removed from triangulation
after topology correction, eno=2 (nv=131841, nf=263678, ne=395517, g=0)
writing corrected surface to /usr/local/freesurfer/7.4.1/subjects/subj6-fmri-sample/surf/lh.orig.premesh…

Screenshots / relevant information:

Very much appreciate your help

Hi @rcha,

How do you launch freesurfer “independently”? Do you mean that you are launching it from a local environment and not via Docker as you do for fmriprep? It may be possible that the ressources allowed to the docker image of fmriprep has access to less ressources that what is available when you launch the fmriprep locally. Try to increase the ressources available to docker to see if it changes the situation.

Just looking at sub-06/anat/sub-06_run-02_T1w.nii.gz, it looks like a mislabeled file. That may be a T2-weighted image, but it is definitely not T1-weighted. fMRIPrep will merge the two “T1w” images and pass them to FreeSurfer, which will unsurprisingly have difficulty.

I would suggest just removing that file and trying again. It’s also okay to run FreeSurfer separately and pass it as an input. But in this case, I suspect the spurious T1w file will cause other problems.

1 Like

Well spotted @effigies !