@@ -1102,8 +1102,8 @@ def _get_dot(self, prefix=None, hierarchy=None, colored=True,
1102
1102
class InterfacedWorkflow (Workflow ):
1103
1103
"""
1104
1104
A workflow that automatically generates the input and output nodes to avoid
1105
- repetitive inputnode.* and outputnode.* connections and allow for fast pipeline
1106
- chaining.
1105
+ repetitive inputnode.* and outputnode.* connections and allow for agile
1106
+ pipeline chaining.
1107
1107
"""
1108
1108
1109
1109
@property
@@ -1129,22 +1129,26 @@ def __init__(self, name, base_dir=None, input_names=[], output_names=[]):
1129
1129
super (InterfacedWorkflow , self ).__init__ (name , base_dir )
1130
1130
1131
1131
if isinstance (input_names , str ):
1132
- input_names = [ input_names ]
1132
+ input_names = [input_names ]
1133
1133
1134
1134
if input_names is None or not input_names :
1135
- raise ValueError ('InterfacedWorkflow input_names must be a non-empty list' )
1135
+ raise ValueError (('InterfacedWorkflow input_names must be a '
1136
+ 'non-empty list' ))
1136
1137
1137
1138
if isinstance (output_names , str ):
1138
- output_names = [ output_names ]
1139
+ output_names = [output_names ]
1139
1140
1140
1141
if output_names is None or not output_names :
1141
- raise ValueError ('InterfacedWorkflow output_names must be a non-empty list' )
1142
+ raise ValueError (('InterfacedWorkflow output_names must be a '
1143
+ 'non-empty list' ))
1142
1144
1143
1145
self ._input_names = input_names
1144
1146
self ._output_names = output_names
1145
1147
1146
- self ._inputnode = Node (IdentityInterface (fields = input_names ), name = 'inputnode' )
1147
- self ._outputnode = Node (IdentityInterface (fields = output_names ), name = 'outputnode' )
1148
+ self ._inputnode = Node (IdentityInterface (fields = input_names ),
1149
+ name = 'inputnode' )
1150
+ self ._outputnode = Node (IdentityInterface (fields = output_names ),
1151
+ name = 'outputnode' )
1148
1152
1149
1153
def connect (self , * args , ** kwargs ):
1150
1154
"""
@@ -1189,7 +1193,8 @@ def connect(self, *args, **kwargs):
1189
1193
dstnames = dstnode .inputs .copyable_trait_names ()
1190
1194
for n in srcnames :
1191
1195
if n not in dstnames :
1192
- raise RuntimeError (('Interface missmatch between workflows, %s port is not '
1196
+ raise RuntimeError (('Interface missmatch between '
1197
+ 'workflows, %s port is not '
1193
1198
'present in destination node' ) % n )
1194
1199
ports = [(srcpref + k , dstpref + k ) for k in srcnames ]
1195
1200
else :
@@ -1255,6 +1260,26 @@ class GraftWorkflow(InterfacedWorkflow):
1255
1260
i/o interfaces, and are run on the same input data.
1256
1261
This workflow produces as many outputs as inserted subworkflows, and
1257
1262
an outputnode with all the outputs merged.
1263
+
1264
+ Example
1265
+ -------
1266
+ >>> import nipype.pipeline.engine as npe
1267
+ >>> import nipype.interfaces.utility as niu
1268
+ >>> from nipype.algorithms.metrics import ErrorMap
1269
+ >>> from nipype.interfaces.utility import IdentityInterface
1270
+ >>> wf1 = npe.InterfacedWorkflow(name='testname1', input_names=['in_ref',
1271
+ >>> 'in_tst', 'mask'],
1272
+ >>> output_names=['out_map'])
1273
+ >>> errormap = npe.Node(ErrorMap(), name='internalnode')
1274
+ >>> wf1.connect([ ('in', errormap), (errormap, 'out') ])
1275
+ >>> wf2 = wf1.clone(name='testname2')
1276
+ >>> wf = npe.GraftWorkflow(name='graft', fields_from=wf1)
1277
+ >>> wf.insert(wf1)
1278
+ >>> wf.insert(wf2)
1279
+ >>> wf.inputs.in_ref = 'reference.nii'
1280
+ >>> wf.inputs.in_tst = 'test.nii'
1281
+ >>> wf.write_graph(format='pdf') # doctest: +SKIP
1282
+ >>> wf.run() # doctest: +SKIP
1258
1283
"""
1259
1284
_children = dict ()
1260
1285
_outnodes = dict ()
@@ -1286,10 +1311,6 @@ def __init__(self, name, base_dir=None, fields_from=None,
1286
1311
input_names = input_names ,
1287
1312
output_names = output_names )
1288
1313
1289
- self ._outputnode = InputMultiNode (IdentityInterface (
1290
- fields = output_names ),
1291
- name = 'outputnode' )
1292
-
1293
1314
def insert (self , workflow ):
1294
1315
"""
1295
1316
Inserts an InterfacedWorkflow into the workflow
@@ -1320,11 +1341,14 @@ def insert(self, workflow):
1320
1341
self .connect ([('in' , workflow ), (workflow , self ._outnodes [ckey ]),
1321
1342
(self ._outnodes [ckey ], 'out' )])
1322
1343
1323
- def write_graph (self , * args , ** kwargs ):
1324
- return super (GraftWorkflow , self ).write_graph (* args , ** kwargs )
1344
+ # def write_graph(self, *args, **kwargs):
1345
+ # return super(GraftWorkflow, self).write_graph(*args, **kwargs)
1325
1346
1326
1347
def run (self , * args , ** kwargs ):
1327
- return super (GraftWorkflow , self ).run (* args , ** kwargs )
1348
+ logger .debug ('Starting GraftWorkflow %s' % self )
1349
+ runtime = super (GraftWorkflow , self ).run (* args , ** kwargs )
1350
+ logger .debug ('Ending GraftWorkflow %s' % self )
1351
+ return runtime
1328
1352
1329
1353
1330
1354
class Node (WorkflowBase ):
@@ -1694,6 +1718,7 @@ def _save_hashfile(self, hashfile, hashed_inputs):
1694
1718
else :
1695
1719
logger .critical ('Unable to open the file in write mode: %s' %
1696
1720
hashfile )
1721
+
1697
1722
def _get_inputs (self ):
1698
1723
return self ._get_all_inputs ()
1699
1724
@@ -1999,6 +2024,16 @@ def write_report(self, report_type=None, cwd=None):
1999
2024
class InputMultiNode (Node ):
2000
2025
"""
2001
2026
Wraps interface objects that join nodes into lists of inputs
2027
+
2028
+ Examples
2029
+ --------
2030
+
2031
+ >>> from nipype import InputMultiNode
2032
+ >>> from nipype.interfaces.fsl import Threshold
2033
+ >>> realign = InputMultiNode(spm.Realign(), 'realign')
2034
+ >>> realign.inputs.in_files = 'functional.nii'
2035
+ >>> realign.inputs.register_to_mean = True
2036
+ >>> realign.run() # doctest: +SKIP
2002
2037
"""
2003
2038
def __init__ (self , interface , name , ** kwargs ):
2004
2039
"""
@@ -2046,15 +2081,13 @@ def set_input(self, parameter, val):
2046
2081
2047
2082
Priority goes to interface.
2048
2083
"""
2049
- logger .debug ('InputMultiNode: setting nodelevel(%s) input %s = %s' % (str (self ),
2050
- parameter ,
2051
- str (val )))
2084
+ logger .debug (('InputMultiNode: setting nodelevel(%s) input '
2085
+ '%s = %s' ) % (str (self ), parameter , str (val )))
2052
2086
self ._set_multinode_input (self .inputs , parameter , deepcopy (val ))
2053
2087
2054
2088
def _set_multinode_input (self , object , name , newvalue ):
2055
- logger .debug ('setting multinode(%s) input: %s -> %s' % (str (self ),
2056
- name ,
2057
- str (newvalue )))
2089
+ logger .debug (('setting multinode(%s) input: %s ->'
2090
+ ' %s' ) % (str (self ), name , str (newvalue )))
2058
2091
if name in self .fields :
2059
2092
setattr (self ._inputs , name , newvalue )
2060
2093
else :
@@ -2504,6 +2537,7 @@ def _slot_value(self, field, index):
2504
2537
" to hold the %s value at index %d: %s"
2505
2538
% (self , slot_field , field , index , e ))
2506
2539
2540
+
2507
2541
class MapNode (Node ):
2508
2542
"""Wraps interface objects that need to be iterated on a list of inputs.
2509
2543
0 commit comments