Iterables in Gunzip node

I have several files that I wish to gunzip (iteration) but I’m not sure how to connect the SelectFiles node with the Gunzip node, and whether there is a better way of doing this in a workflow. Here’s my code:

subject_list = [‘01’,‘02’]

infosource = Node(IdentityInterface(fields=[“subject_id”]), name=“infosource”)
infosource.iterables = [(“subject_id”, subject_list)]

template = {‘f1’: opj(“sub-{subject_id}”, ‘f1.nii.gz’),
	    ‘f2’: opj(“sub-{subject_id}”, ‘f2.nii.gz’),
	    ‘f3’: opj(“sub-{subject_id}”, ‘f3.nii.gz’),
	    ‘f4’: opj(“sub-{subject_id}”, ‘f4.nii.gz’)}
selectfiles = Node(SelectFiles(template, base_directory="/data"), name=‘selectfiles’)

gunzip = MapNode(Gunzip(), iterfield=['in_file'], base_dir=/data/gunzip, name='gunzip')

wf = Workflow(name=“wf”, base_dir="/data")

wf.connect(infosource, “subject_id”, select_files, “subject_id”)
wf.connect(select_files, f1, gunzip, ‘infile’)
wf.connect(select_files, f2, gunzip, ‘infile’)
wf.connect(select_files, f3, gunzip, ‘infile’)
wf.connect(select_files, f4, gunzip, ‘infile’)

wf.run()

Hi @mri, I’m not sure if you need MapNode in gunzip. If you want to gunzip all files for all subjects and for f1, f2, f3, and f4 you can try to use iterables with two fields (“subject_if” and “f…”), an example can be found here.

Thanks for your help @djarecka

1 Like