Error using FSL's mcflirt with mean_img in Nipype

Dear NeuroStarts community,

I’m new to Python and Nipype in particular, so I hope this question is not too basic. I use Spyder3 on Ubuntu 18.04 (inside an anaconda environment), and I’m going through the wonderful preprocessing tutorial by Miykael. I use FSL 6.0.

I encountered a problem running MCFLIRT. causing the workflow to terminate prematurely.
When viewing the crash file (nipypecli crash /home/roey/Documents/code/crash-20190308-145238-roey-mcflirt-db3c6b08-cdbf-407e-b382-0e2d23cb809a.pklz) I noticed that MCFLIRT was expecting to create one kind of output for the mean BOLD volume, but created another:

traits.trait_errors.TraitError: The trait ‘mean_img’ of a MCFLIRTOutputSpec instance is an existing file name, but the path ‘/home/roey/nipype_data/output/work_preproc/mcflirt/asub-07_ses-test_task-fingerfootlips_bold_roi_mcf.nii.gz_mean_reg.nii.gz’ does not exist.

As you can see, the file that wasn’t created has the “.nii.gz” extension twice in its name. Indeed, a different file was actually created, with the more reasonable name:


Could you please advise at what level this should be resolved?

Any help would be greatly appreciated,
Many thanks!


Below is the code I ran (sorry I wasn’t able to format it as a code block).
import os

Get the Node and Workflow object

from nipype import Node, Workflow

Specify which SPM to use

from nipype.interfaces import spm

#from nipype.interfaces.matlab import MatlabCommand $ Since I use a standalone SPM, I changed these two lines
matlab_cmd = ‘/home/roey/spm12/ /opt/MATLAB/MATLAB_Compiler_Runtime/v713/ script’
spm.SPMCommand.set_mlab_paths(matlab_cmd=matlab_cmd, use_mcr=True)

Create the workflow here

Hint: use ‘base_dir’ to specify where to store the working directory

data_dir = ‘/home/roey/nipype_data/’
out_dir = data_dir+‘output’
if not os.path.exists(out_dir):

preproc = Workflow(name=‘work_preproc’, base_dir=data_dir+’/output/’)

Import gunzip (unzip .gz files)

from nipype.algorithms.misc import Gunzip

Specify example input file

func_file = data_dir+’/ds000114/sub-07/ses-test/func/sub-07_ses-test_task-fingerfootlips_bold.nii.gz’

Initiate Gunzip node

gunzip_func = Node(Gunzip(in_file=func_file), name=‘gunzip_func’) # The name also determines the directory where this node will put its output. You can see it using gunzip_func.output_dir()

Remove the first 4 volumes (dummy volumes)

from nipype.interfaces.fsl import ExtractROI
extract = Node(ExtractROI(t_min=4, t_size=-1, output_type=‘NIFTI’),name=‘extract’)

Connect the gunzip_func with extractROI

See the source and dest definitions in a call to “connect”:

preproc.connect([(gunzip_func, extract, [(‘out_file’,‘in_file’)])])

Slice timing correction

from nipype.interfaces.spm import SliceTiming
slice_order = list(range(1, 31, 2)) + list(range(2, 31, 2))

Initiate SliceTiming node here

slicetime = Node(SliceTiming(num_slices=30,

Connect SliceTiming node to the other nodes here

preproc.connect([(extract, slicetime, [(‘roi_file’, ‘in_files’)])])

Motion correction

from nipype.interfaces.fsl import MCFLIRT
mcflirt = Node(MCFLIRT(mean_vol=True,

preproc.connect([(slicetime, mcflirt, [(‘timecorrected_files’, ‘in_file’)])]) #timecorrected_files is the name of the output argument of slicetime: slicetime.outputs


I think the problem is in using FSL 6.0, in which the output file of the -meanvol option is created without the redundant “.nii” or “.nii.gz” suffix inside the file name, and this is not what MCFLIRT expects (according to the “_gen_outfilename” method in the MCFLIRT class definition under the file).

I will therefore uninstall FSL 6.0 and work with FSL 5.0 instead.



Hi Roey,

I’ve been experiencing the same issue. I also tried downgrading FSL to 5.0 but the issue persisted. Did downgrading FSL to 5.0 end up fixing your issue?


I’m experiencing the exact same issue, and because I require FSL 6.0, downgrading ins’t an option for me. Will there be any plan to sort this out any time soon? Or is there a workaround that works with FSL 6.0?