diff --git a/nipype/pipeline/engine/tests/test_join.py b/nipype/pipeline/engine/tests/test_join.py index 436d29d9e7..54ff15048f 100644 --- a/nipype/pipeline/engine/tests/test_join.py +++ b/nipype/pipeline/engine/tests/test_join.py @@ -7,11 +7,9 @@ absolute_import) from builtins import open -import os - from ... import engine as pe from ....interfaces import base as nib -from ....interfaces.utility import IdentityInterface +from ....interfaces.utility import IdentityInterface, Function, Merge from ....interfaces.base import traits, File @@ -612,3 +610,20 @@ def nested_wf(i, name='smallwf'): # there should be six nodes in total assert len(result.nodes()) == 6, \ "The number of expanded nodes is incorrect." + + +def test_name_prefix_join(tmpdir): + tmpdir.chdir() + + def sq(x): + return x ** 2 + + wf = pe.Workflow('wf', base_dir=tmpdir.strpath) + square = pe.Node(Function(function=sq), name='square') + square.iterables = [('x', [1, 2])] + square_join = pe.JoinNode(Merge(1, ravel_inputs=True), + name='square_join', + joinsource='square', + joinfield=['in1']) + wf.connect(square, 'out', square_join, "in1") + wf.run() diff --git a/nipype/pipeline/engine/utils.py b/nipype/pipeline/engine/utils.py index 2b6bb6ed39..301a35844e 100644 --- a/nipype/pipeline/engine/utils.py +++ b/nipype/pipeline/engine/utils.py @@ -1050,7 +1050,17 @@ def make_field_func(*pair): expansions = defaultdict(list) for node in graph_in.nodes(): for src_id in list(old_edge_dict.keys()): - if node.itername.startswith(src_id): + # Drop the original JoinNodes; only concerned with + # generated Nodes + if hasattr(node, 'joinfield'): + continue + # Patterns: + # - src_id : Non-iterable node + # - src_id.[a-z]\d+ : IdentityInterface w/ iterables + # - src_id.[a-z]I.[a-z]\d+ : Non-IdentityInterface w/ iterables + # - src_idJ\d+ : JoinNode(IdentityInterface) + if re.match(src_id + r'((\.[a-z](I\.[a-z])?|J)\d+)?$', + node.itername): expansions[src_id].append(node) for in_id, in_nodes in list(expansions.items()): logger.debug("The join node %s input %s was expanded"