nipreps / fmriprep

fMRIPrep is a robust and easy-to-use pipeline for preprocessing of diverse fMRI data. The transparent workflow dispenses of manual intervention, thereby ensuring the reproducibility of the results.
https://fmriprep.org
Apache License 2.0
615 stars 288 forks source link

Prerun freesurfer with -hires and -expert flags are not able to be used with fmriprep #3306

Open adam-coates opened 1 month ago

adam-coates commented 1 month ago

What happened?

Running fMRIprep with pre-computed freesurfer output using -hires and -expert options flag in recon-all makes fMRIprep crash at autorecon1 stage

What command did you use?

docker run -u $(id -u):$(id -g) --rm -it -v /usr/local/freesurfer_7.3.2/license.txt:/opt/freesurfer/license.txt -v $niidir/../fmriprep_tmp:/scratch -v $niidir:/data:ro -v $niidir/derivatives/fmriprep:/out -v $niidir/derivatives/freesurfer:/sub-dir nipreps/fmriprep:23.2.3 /data /out participant --fs-subjects-dir /sub-dir --participant-label $subject --skip-bids-validation --md-only-boilerplate  --stop-on-first-crash --nthreads 4 -w /scratch --output-spaces T1w MNI152NLin2009cAsym fsaverage

What version of fMRIPrep are you running?

23.2.3

How are you running fMRIPrep?

Docker

Is your data BIDS valid?

Yes

Are you reusing any previously computed results?

FreeSurfer

Please copy and paste any relevant log output.

240614-20:19:00,374 nipype.workflow INFO:
     [Node] Finished "autorecon1", elapsed time 0.000461s.
240614-20:19:00,375 nipype.workflow WARNING:
     Storing result file without outputs
240614-20:19:00,376 nipype.workflow WARNING:
     [Node] Error on "fmriprep_23_2_wf.sub_1181001_wf.anat_fit_wf.surface_recon_wf.autorecon1" (/scratch/fmriprep_23_2_wf/sub_1181001_wf/anat_fit_wf/surface_recon_wf/autorecon1)
240614-20:19:01,928 nipype.workflow ERROR:
     Node autorecon1 failed to run on host c597201c5eb9.
240614-20:19:01,934 nipype.workflow ERROR:
     Saving crash info to /out/sub-1181001/log/20240614-195521_5685aeed-766c-48f5-b04d-aff41e5c82ca/crash-20240614-201901-UID1013-autorecon1-c7aa1b97-c397-4afb-be66-147b2b0bfb0e.txt
Traceback (most recent call last):
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/plugins/multiproc.py", line 67, in run_node
    result["result"] = node.run(updatehash=updatehash)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 527, in run
    result = self._run_interface(execute=True)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 645, in _run_interface
    return self._run_command(execute)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 771, in _run_command
    raise NodeExecutionError(msg)
nipype.pipeline.engine.nodes.NodeExecutionError: Exception raised while executing Node autorecon1.

Traceback:
    Traceback (most recent call last):
      File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 735, in _run_interface
        runtime.cmdline = self.cmdline
      File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/smriprep/interfaces/freesurfer.py", line 130, in cmdline
        cmd += self._prep_expert_file()
      File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/freesurfer/preprocess.py", line 1660, in _prep_expert_file
        if not isdefined(self.inputs.xopts) and self._get_expert_file() == contents:
      File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/freesurfer/preprocess.py", line 1681, in _get_expert_file
        return fobj.read()
      File "/opt/conda/envs/fmriprep/lib/python3.10/codecs.py", line 322, in decode
        (result, consumed) = self._buffer_decode(data, self.errors, final)
    UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 10: invalid continuation byte

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
      File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 397, in run
        runtime = self._run_interface(runtime)
      File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 737, in _run_interface
        raise RuntimeError(
    RuntimeError: Error raised when interpolating the command line

240614-20:19:01,957 nipype.workflow CRITICAL:
     fMRIPrep failed: Traceback (most recent call last):
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/plugins/multiproc.py", line 67, in run_node
    result["result"] = node.run(updatehash=updatehash)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 527, in run
    result = self._run_interface(execute=True)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 645, in _run_interface
    return self._run_command(execute)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 771, in _run_command
    raise NodeExecutionError(msg)
nipype.pipeline.engine.nodes.NodeExecutionError: Exception raised while executing Node autorecon1.

Traceback:
    Traceback (most recent call last):
      File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 735, in _run_interface
        runtime.cmdline = self.cmdline
      File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/smriprep/interfaces/freesurfer.py", line 130, in cmdline
        cmd += self._prep_expert_file()
      File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/freesurfer/preprocess.py", line 1660, in _prep_expert_file
        if not isdefined(self.inputs.xopts) and self._get_expert_file() == contents:
      File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/freesurfer/preprocess.py", line 1681, in _get_expert_file
        return fobj.read()
      File "/opt/conda/envs/fmriprep/lib/python3.10/codecs.py", line 322, in decode
        (result, consumed) = self._buffer_decode(data, self.errors, final)
    UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 10: invalid continuation byte

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
      File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 397, in run
        runtime = self._run_interface(runtime)
      File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 737, in _run_interface
        raise RuntimeError(
    RuntimeError: Error raised when interpolating the command line

240614-20:19:02,190 nipype.workflow INFO:
     [Node] Finished "res_target", elapsed time 1.939527s.
240614-20:19:07,855 cli ERROR:
     Preprocessing did not finish successfully. Errors occurred while processing data from participants: 1181001 (1). Check the HTML reports for details.

Additional information / screenshots

Node: fmriprep_23_2_wf.sub_1181001_wf.anat_fit_wf.surface_recon_wf.autorecon1 Working directory: /scratch/fmriprep_23_2_wf/sub_1181001_wf/anat_fit_wf/surface_recon_wf/autorecon1

Node inputs:

FLAIR_file = T1_files = ['/scratch/fmriprep_23_2_wf/sub_1181001_wf/anat_fit_wf/anat_template_wf/anat_merge/sub-1181001_ses-1_acq-highres_T1w_noise_corrected_template.nii.gz'] T2_file = args = big_ventricles = brainstem = directive = autorecon1 environ = {} expert = flags = ['-noskullstrip', '-noT2pial', '-noFLAIRpial'] hemi = hippocampal_subfields_T1 = hippocampal_subfields_T2 = hires = True mprage = mri_aparc2aseg = mri_ca_label = mri_ca_normalize = mri_ca_register = mri_edit_wm_with_aseg = mri_em_register = mri_fill = mri_mask = mri_normalize = mri_pretess = mri_remove_neck = mri_segment = mri_segstats = mri_tessellate = mri_watershed = mris_anatomical_stats = mris_ca_label = mris_fix_topology = mris_inflate = -n 50 mris_make_surfaces = mris_register = mris_smooth = mris_sphere = mris_surf2vol = mrisp_paint = openmp = 3 parallel = steps = subject_id = sub-1181001 subjects_dir = /sub-dir talairach = use_FLAIR = use_T2 = xopts =

Traceback (most recent call last): File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/plugins/multiproc.py", line 67, in run_node result["result"] = node.run(updatehash=updatehash) File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 527, in run result = self._run_interface(execute=True) File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 645, in _run_interface return self._run_command(execute) File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 771, in _run_command raise NodeExecutionError(msg) nipype.pipeline.engine.nodes.NodeExecutionError: Exception raised while executing Node autorecon1.

Traceback: Traceback (most recent call last): File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 735, in _run_interface runtime.cmdline = self.cmdline File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/smriprep/interfaces/freesurfer.py", line 130, in cmdline cmd += self._prep_expert_file() File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/freesurfer/preprocess.py", line 1660, in _prep_expert_file if not isdefined(self.inputs.xopts) and self._get_expert_file() == contents: File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/freesurfer/preprocess.py", line 1681, in _get_expert_file return fobj.read() File "/opt/conda/envs/fmriprep/lib/python3.10/codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 10: invalid continuation byte

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 397, in run
    runtime = self._run_interface(runtime)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 737, in _run_interface
    raise RuntimeError(
RuntimeError: Error raised when interpolating the command line
adam-coates commented 1 month ago

Leaving this here for anyone who's working with sub mm data. If using -hires flag in recon-all (pre-run) before fMRIprep then T1.mgz will not be downsampled to 1mm isotropic and instead T1.mgz will still be the same voxel sizes as the input. fMRIprep does not automatically assume that the MNI output space should be resampled (i.e. if T1.mgz is not 1mm then specifying the MNI outputspace will cause fMRIprep to fail at autorecon1) . Instead it seems possible to specify and define non-standard spaces e.g. an MNI space with 0.6mm isotropic voxel sizes.

For now the above command runs with only --output-spaces T1w