Skip to content

Commit 8df64cd

Browse files
committed
Merge pull request #1151 from chrisfilo/fix/joinnode
Fixes JoinNode issues with File() traits
2 parents 050be47 + cfc36a4 commit 8df64cd

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

nipype/pipeline/engine.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from datetime import datetime
1616
from nipype.utils.misc import flatten, unflatten
17+
from nipype.interfaces.traits_extension import File
1718
try:
1819
from collections import OrderedDict
1920
except ImportError:
@@ -1947,6 +1948,7 @@ def _override_join_traits(self, basetraits, fields):
19471948
if name in fields and len(trait.inner_traits) == 1:
19481949
item_trait = trait.inner_traits[0]
19491950
dyntraits.add_trait(name, item_trait)
1951+
setattr(dyntraits, name, Undefined)
19501952
logger.debug("Converted the join node %s field %s"
19511953
" trait type from %s to %s"
19521954
% (self, name, trait.trait_type.info(),

nipype/pipeline/tests/test_join.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,27 @@
1313
import nipype.interfaces.base as nib
1414
import nipype.pipeline.engine as pe
1515
from nipype.interfaces.utility import IdentityInterface
16+
from nipype.interfaces.base import traits, File
17+
18+
class PickFirstSpec(nib.TraitedSpec):
19+
in_files = traits.List(File(exists=True), argstr="%s", position=2,
20+
mandatory=True)
21+
22+
class PickFirstOutSpec(nib.TraitedSpec):
23+
output1 = File(exists=True)
24+
25+
class PickFirst(nib.BaseInterface):
26+
input_spec = PickFirstSpec
27+
output_spec = PickFirstOutSpec
28+
29+
def _run_interface(self, runtime):
30+
runtime.returncode = 0
31+
return runtime
32+
33+
def _list_outputs(self):
34+
outputs = self._outputs().get()
35+
outputs['output1'] = self.inputs.in_files[0]
36+
return outputs
1637

1738

1839
class IncrementInputSpec(nib.TraitedSpec):
@@ -528,6 +549,32 @@ def test_itersource_two_join_nodes():
528549

529550
os.chdir(cwd)
530551
rmtree(wd)
552+
553+
def test_set_join_node_file_input():
554+
"""Test collecting join inputs to a set."""
555+
cwd = os.getcwd()
556+
wd = mkdtemp()
557+
os.chdir(wd)
558+
open('test.nii', 'w+').close()
559+
open('test2.nii', 'w+').close()
560+
561+
# Make the workflow.
562+
wf = pe.Workflow(name='test')
563+
# the iterated input node
564+
inputspec = pe.Node(IdentityInterface(fields=['n']), name='inputspec')
565+
inputspec.iterables = [('n', [os.path.join(wd, 'test.nii'), os.path.join(wd, 'test2.nii')])]
566+
# a pre-join node in the iterated path
567+
pre_join1 = pe.Node(IdentityInterface(fields=['n']), name='pre_join1')
568+
wf.connect(inputspec, 'n', pre_join1, 'n')
569+
# the set join node
570+
join = pe.JoinNode(PickFirst(), joinsource='inputspec',
571+
joinfield='in_files', name='join')
572+
wf.connect(pre_join1, 'n', join, 'in_files')
573+
574+
wf.run()
575+
576+
os.chdir(cwd)
577+
rmtree(wd)
531578

532579

533580
if __name__ == "__main__":

0 commit comments

Comments
 (0)