Use of Merge() after selectfiles in Nipype does not work

Hi,

I aim to create a workflow using Nipype and fsl interfaces. Due to the way the data has been given to me, the first step of my pipeline consists in merging two nii.gz files containing the b0 volumes to afterwards use topup on them. My problem is that the merge node I created expects a list with the two images to merge, but there is no way this list can be introduced. I tried with iterables, but with the case of 2 subjects the result is 4 files without merging. The code I used:

subjects=[‘hs01’,‘hs02’]
acquisitions=[‘1’,‘2’]

infosource=Node(IdentityInterface(fields=[‘subject_id’,‘acquisition_id’]), name=‘infosource’)
infosource.iterables=[(‘subject_id’, subjects), (‘acquisition_id’, acquisitions)]

templates={‘dti’:’/local/{subject_id}/dti{acquisition_id}.nii.gz’,
‘refdti’:’/local/{subject_id}/refdti{acquisition_id}.nii.gz’

selectfiles=Node(SelectFiles(templates, base_directory=experiment_dir, force_lists=[‘dti’,‘refdti’]), name=‘selectfiles’)

imagemerger_node=Node(Merge(dimension=‘t’), name='imagemerger)

datasink=Node(DataSink(base_directory=experiment_dir, container=output_folder),
name='datasink)

myworkflow=Workflow(name=‘pipeline’)

myworkflow.connect([(infosource,selectfiles,[(‘subject_id’,‘subject_id’), (‘acquisition_id’,‘acquisition_id’)]), (selectfiles, imagemerger_node,[(‘refdti’,‘in_files’)]), (imagemeger_node, datasink,[(‘merged_file’,‘mergedimages’)])])

I think the problem is in the way SelectFiles returns the output, since in the command line the fsl Merge line shows:

fslmerge -t ref_dti1_merged /local/hs01/refdti1

which means that is trying to merge an existent file (/local/hs01/refdti1) with ref_dti1_merged that does not exist

If someone has been able to use Merge after Selectfiles please show me how.

Thank you in advance!!

I modified my code in the following way and it works, but it does not iterate subjects, meaning that it only returns the merged image for the subject hs01 even though I am specifying to iterate subjects:

imagemerger_node=Node(Merge(dimension=‘t’),
name=‘imagemerger’)

topup_node=Node(TOPUP(), name=‘topup’)

meanunwarped_node=Node(MeanImage(dimension=‘T’), name=‘meanb0unwarpednode’)

betnode=Node(BET(outline=True, mask=True),name=‘bet_node’)

eddy_node=Node(Eddy(), name=‘eddynode’)

#-------------------------------------------------WORKFLOW-------------------------------------------------------------------------

#let’s create a workflow that first does the meanimage of the unwarpedb0 and then extracts the brain mask
workflowprova2=Workflow(name=‘prova’)

#We must first create the nodes for data input and output stream.
#first we create a function to iterate over a list of subject names, using IdentityInterface
infosource=Node(IdentityInterface(fields=[‘subject_id’, ‘acquisition_id’]),
name=‘infosource’)
infosource.iterables=[(‘subject_id’, subjects),
(‘acquisition_id’, acquisitions)]

#Files to use (input node):
templates={‘dti’:’/Users/Documents/segon_semestre/TFG/pipeline/{subject_id}/dti{acquisition_id}.nii.gz’,
‘refdti’:’/Users/Documents/segon_semestre/TFG/pipeline/{subject_id}/ref_dti{acquisition_id}_{subject_id}.nii.gz’,
}

selectfiles=JoinNode(SelectFiles(templates, base_directory=experiment_dir), joinsource=‘infosource’,joinfield=‘acquisition_id’,
name=‘selectfiles’)

#output node:
datasink=Node(DataSink(base_directory=experiment_dir, container=output_folder),
name=‘datasink’)

#We are saying that the out_file of meanunwarped_node will be the in_file for betnode
workflowprova2.connect([(infosource,selectfiles,[(‘subject_id’,‘subject_id’),
(‘acquisition_id’,‘acquisition_id’)]),
(selectfiles, imagemerger_node,[(‘refdti’, ‘in_files’)]),
(imagemerger_node,datasink,[(‘merged_file’, ‘mergedimages’)])
])

MANAGED BY INCF