Nipype MapNode help

Hi, kinda basic question here:

I have the situation as in this example:
graphviz-5ccfc22ea445e4176159a1a40eca28bcfd01d77b

Except that I have two outputs instead of four. Anyhow, my two outputs that comes from node A should go to fsl’s BET node and then to a DAtasink Node I wanna write it like this:

A = Node(A(), name=A)
BET= MapNode(BET(), iterfield = ['in_file'], name = B)
datasink = Node(DataSink(base_directory = output_dir,
                         container= "datasink"), name="datasink")

wf_test= Workflow(name=test, base_dir = output_dir)
wf_test.connect([(A, BET,[('out_file1','in_file'),
                         ('out_file2','in_file') ]),
                [(BET, datasink ,[('out_file', 'skullstripped') ])
 
              
                ])

But I cant connect both out_file1 and out_file2 to the BET node. How do I get it to work?

Sincerely, Jesper

Hi @jesperbrowall,

I’ve ran into this a few times as well, and it happens when I have similar inputs that I want to run through the same pipeline.

If Node A gives two distinct outputs, then I would probably want to keep them separate throughout the rest of the pipeline so I can keep track of those outputs separately.

I’m assuming out_file1 and out_file2 from node A are both lists of images.

The code would look something like:

A = Node(A(), name=A)
BET_1 = MapNode(BET(), iterfield=['in_file'], name="B")
BET_2 = BET_1.clone(name="C")

datasink = Node(DataSink(base_directory = output_dir,
                         container= "datasink"), name="datasink")

wf_test= Workflow(name=test, base_dir=output_dir)
wf_test.connect([(A, BET_1, [('out_file1', 'in_file')]),
                           (A, BET_2, [('out_file2', 'in_file')]),
                           (BET_1, datasink ,[('out_file', 'skullstripped_1')]),
                           (BET_2, datasink, [('out_file', 'skullstripped_2')]),
                ])

Let me know if you have further questions and/or need additional help.
James

Hi @jdkent! Thank you for taking your time and helping me.

Yes you’re right, out_file1 and out_file2 is a list of images and I do see the point of having tho distinct nodes to keep track of what’s going on.

Though, with your example code I don’t really see the point of using MapNode since it’s not iterated and you create a second node (BET_2). Isn’t this the same as using to BET-nodes with the same settings?

But let’s say that I wanna do like in this exqample: https://miykael.github.io/nipype_tutorial/notebooks/basic_mapnodes.html

but instead of having i file list:

files = ['/data/ds000114/sub-01/ses-test/func/sub-01_ses-test_task-fingerfootlips_bold.nii.gz',
         '/data/ds000114/sub-01/ses-test/func/sub-01_ses-test_task-fingerfootlips_bold.nii.gz']

I have my two outputs out_file1 and out_file2.

Any suggestions?

Sincerely, Jesper

Some great questions,

Assuming out_file1 is a list of images, MapNode will iterate over each of the files listed in out_file1 and treat each one as an input to the BET_1 node.

yes, you are correct that creating two BET nodes with the same settings is the same as cloning a BET node, but the benefit of cloning is that if you decided to change the settings of the BET nodes, you would only have to change the code in one place instead of two.

To directly answer your question, you should create a merge node that combines out_file1 and out_file2 of node A, and then passes the output list to the BET MapNode.

Hope that helps,
James

@jdkent, thank you so much for your help!