Fmriprep fails to run Freesurfer auto-recon

Summary of what happened:

fmriprep fails on Freesurfer auto-recon step. I have used the same Singularity containers in the past without issue, and the error message (from FreeSurfer, that a subject number hasn’t been specified) doesn’t make sense because the output includes a subject number in the command that fmriprep passed to Freesurfer.

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

#SBATCH --partition=caslake
#SBATCH --time=36:00:00
#SBATCH -c 8
#SBATCH --mem-per-cpu=16000
#SBATCH -J fmriprep_BF_042
#SBATCH --account=pi-decety
#SBATCH --output=fmriprep_BF_042-srun++.out
#SBATCH --error=fmriprep_BF_042-srun++.err


echo "working directory = "$SLURM_SUBMIT_DIR

module load intel/13.1
module load intel-mpi/4.1.3
module load singularity
module unload fsl
module list
ulimit -s unlimited

export TEMPLATEFLOW_HOME=/project/decety/templateflow
export SINGULARITYENV_TEMPLATEFLOW_HOME=/project/decety/templateflow

NPROCS=`srun --nodes=${SLURM_NNODES} bash -c 'hostname' |wc -l`
echo "Launch fmriprep with srun"
#The PMI library is necessary for srun
export I_MPI_PMI_LIBRARY=/usr/lib64/
srun singularity run -B /project/decety -B /scratch/midway3/mscohen /project/decety/my_images/fmriprep-23.1.4.simg --participant_label=042 --fs-license-file="/project/decety/freesurfer_license.txt" -v -v --nthreads 4 --output-spaces MNI152NLin6Asym:res-2 --bold2t1w-dof 6 --use-aroma --fd-spike-threshold 0.9 --dvars-spike-threshold 3 --skull-strip-template OASIS30ANTs -w /scratch/midway3/mscohen /project/decety/BrainFog_BIDS /project/decety/BrainFog_BIDS/derivatives/fmriprep participant 


23.1.4 and 22.1.1

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

Singularity container

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

	1: [WARN] The recommended file /README is missing. See Section 03 (Modality agnostic files) of the BIDS specification. (code: 101 - README_FILE_MISSING)

	Please visit for existing conversations about this issue.

	2: [WARN] The Authors field of dataset_description.json should contain an array of fields - with one author per field. This was triggered because there are no authors, which will make DOI registration from dataset metadata impossible. (code: 113 - NO_AUTHORS)

	Please visit for existing conversations about this issue.

        Summary:                Available Tasks:        Available Modalities: 
        483 Files, 5.9GB        estroop                 MRI                   
        17 - Subjects           flanker                                       
        2 - Sessions            rest                                          

	If you have any questions, please post on

Relevant log outputs (up to 20 lines):

	recon-all -autorecon1 -i /scratch/midway3/mscohen/fmriprep_23_1_wf/single_subject_042_wf/anat_preproc_wf/anat_template_wf/anat_merge/sub-042_ses-01_T1w_noise_corrected_template.nii.gz -noskullstrip -noT2pial -noFLAIRpial -hires -openmp 3 -subjid sub-042 -sd /project/decety/BrainFog_BIDS/derivatives/fmriprep/sourcedata/freesurfer -expert /scratch/midway3/mscohen/fmriprep_23_1_wf/single_subject_042_wf/anat_preproc_wf/surface_recon_wf/autorecon1/expert.opts
	ERROR: must specify a subject id
	mktemp: failed to create file via template ‘/scratch/local/jobs/19320194/tmp.XXXXXXXXXX’: No such file or directory
	mktemp: failed to create file via template ‘/scratch/local/jobs/19320194/tmp.XXXXXXXXXX’: No such file or directory
	Traceback (most recent call last):
	  File "/opt/freesurfer/python/scripts/rca-config2csh", line 20, in <module>
	    configfile = sys.argv[1]
	IndexError: list index out of range
	RuntimeError: subprocess exited with code 1.

Screenshots / relevant information:

Hi @michaelcohen,

Does the error persist when adding -e to the singularity preamble which makes sure nothing from your computational environment is carried into the container?


Oh it looks like that was the problem! Good catch. It looks like it runs successfully when I include that flag. (I had used the --cleanenv flag in other scripts, which I assume does the same thing?, but had accidentally left it out here.)