Last active
August 29, 2015 14:19
-
-
Save whacked/28cfc76d876c3f705281 to your computer and use it in GitHub Desktop.
nipype JoinNode test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nipype.pipeline.engine as pe | |
from nipype.interfaces.utility import Function | |
def func_A(subject): | |
return '%s --> [A]'%subject | |
def func_B(subject, in_file): | |
return '%s --> B[%s]'%(subject,in_file) | |
def func_C(in_file): | |
return '%s --> [C]'%in_file | |
def func_D(in_files): | |
for n, file in enumerate(in_files,start=1): | |
print '(join) %s. %s --> [D]'%(n, file) | |
return '%s --> [D]'%in_files | |
a = pe.Node(interface=Function(input_names=["subject"], output_names=["subject"], function=func_A), name="A") | |
a.inputs.subject = 'subject 1' | |
b = pe.Node(interface=Function(input_names=["subject", "in_file"], output_names=["out_file"], function=func_B), name="B") | |
b.iterables = ("in_file", ["file%s"%n for n in (1,2,3,4)]) | |
c = pe.Node(interface=Function(input_names=["in_file"], output_names=["out_file"], function=func_C), name="C") | |
d = pe.JoinNode(interface=Function(input_names=["in_files"], output_names=["output"], function=func_D), joinsource="B", | |
joinfield="in_files", name="D") | |
my_workflow = pe.Workflow(name="my_workflow") | |
my_workflow.connect([(a,b,[("subject","subject")]), | |
(b,c,[("out_file","in_file")]), | |
(c,d,[("out_file","in_files")]), | |
]) | |
my_workflow.run() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment