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:
/home/roey/nipype_data/output/work_preproc/mcflirt/asub-07_ses-test_task-fingerfootlips_bold_roi_mcf_mean_reg.nii.gz
Could you please advise at what level this should be resolved?
Any help would be greatly appreciated,
Many thanks!
Roey
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
#MatlabCommand.set_default_paths(’/opt/spm12-r7219/spm12_mcr/spm12’)
matlab_cmd = ‘/home/roey/spm12/run_spm12.sh /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):
os.makedirs(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”: https://miykael.github.io/nipype_tutorial/notebooks/basic_workflow.html
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))
print(slice_order)
Initiate SliceTiming node here
slicetime = Node(SliceTiming(num_slices=30,
ref_slice=15,
slice_order=slice_order,
time_repetition=2.5,
time_acquisition=2.5-(2.5/30)),
name=‘slicetime’)
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,
save_plots=True),
name=‘mcflirt’)
preproc.connect([(slicetime, mcflirt, [(‘timecorrected_files’, ‘in_file’)])]) #timecorrected_files is the name of the output argument of slicetime: slicetime.outputs
preproc.run()