I am trying to implement a NiPype workflow for FSL's run_first_all command via nipype.interfaces.fsl.FIRST(). My worfklow class is as follows:
def create_subcort_seg(wf_name = 'subcort_seg'):
"""
Create FIRST segmentation/registration tool workflow
"""
# Create the workflow
subcort_wf = pe.Workflow(name=wf_name)
# Input node - load in the reoriented brain (original space, non-registered)
inputNode = pe.Node(interface=util.IdentityInterface(fields=['reor_brain']),
name='inputspec')
# FIRST Interface node
funcNode = pe.Node(interface=fsl.FIRST(),
name='first_seg')
# Set '-d' flag to keep intermediate files
funcNode.inputs.no_cleanup = True
# Output node - four outputs in FIRST we must define in the node
outputNode = pe.Node(interface=util.IdentityInterface(fields=['vtk_out',
'bvars_out',
'orig_out',
'seg_out']),
name='outputspec')
# Connect the nodes together to form the workflow
subcort_wf.connect(inputNode,'reor_brain',funcNode,'in_file')
subcort_wf.connect(funcNode,'vtk_surfaces',outputNode,'vtk_out')
subcort_wf.connect(funcNode,'bvars',outputNode,'bvars_out')
subcort_wf.connect(funcNode,'original_segmentations',outputNode,'orig_out')
subcort_wf.connect(funcNode,'segmentation_file',outputNode,'seg_out')
# Return the workflow
return subcort_wf
The problem with this is that only the first segment (BrStem)'s .bvars and .vtk files are being saved at the end of the workflow run (all 15 segments' files are being generated but all but the BrStem outputs are deleted after the run). I think the main reason for this is that when I connect the funcNode's 'bvars' and 'vtk_surfaces' fields to my outputNode's 'bvars_out' and 'vtk_out' fields, the outputNode is only grabbing the first item in the list of mesh structures (as 'vtk_surfaces' and 'bvars' from NiPype's fsl interface are lists, I believe). How do I route the entire list of structures to my outputNode to preserve the output mesh structures for all 15 segments?
I've also been told I should do this through Datasinks. In this case, there'd be like 15 Segments * (2 mesh files + 1 nifti file) = 45 outputs to sink for all of the segments. Is there an elegant way of doing this in code?
Thanks