I often face the same issue: i would like to define an iterable on a list only known after an interface is run.
The most recent example is the one when i run a preprocessing pipeline, the output for each subject being saved with the following format:
subject_id_mymask1.nii.gz, subject_id_mymask2.nii.gz, ..., subject_id_mymaskN.nii.gz
For the main pipeline i need an iterable on these masks, but i can't get the iterable list before running first a datagrabber or selectfiles node and so the following won't work:
subjectIDs = pe.Node(util.IdentityInterface(fields=["subject_id"]),"subjectIDs")
subjectIDs.iterables = ('subject_id', ['subject1','subject2', ..., 'subjectK'])
masks = dict(mask1 = '{subject_id}_mymask1.nii.gz',
mask2 = '{subject_id}_mymask2.nii.gz',
...
maskN = '{subject_id}_mymaskN.nii.gz')
allmymasks = pe.Node(SelectFiles(masks, base_directory='/path/to/my/masks'), "allmymasks")
MergeMasks= pe.Node(Merge(N), "MergeMasks")
MyOpOnAllMasks = pe.Node(Op(fields=["Mask"]), "MyOpOnAllMasks")
MyOpOnAllMasks.iterables = [("Mask", Can't put my mask list here because masks haven't been grabbed yet)]
MyWf.connect([
(subjectIDs, allmymasks,
[('subject_id', 'subject_id')]),
(allmymasks, MergeMasks,
[('mask1', 'in1'), etc.,('maskN', 'inN') ]),
(MergeMasks, MyOpOnAllMasks,
[('out', 'Mask')]),
...
]) Won't work
How to solve this issue elegantly?