Repository: nipy/nipype

Issue:
Issue with node name that starts with another node's name
I think the [line ~801 in util.py](https://github.com/nipy/nipype/edit/master/nipype/pipeline/engine/utils.py#L801) should be something like this:

            for node in graph_in.nodes():
                for src_id, edge_data in list(old_edge_dict.items()):
                    if node.itername.startswith(src_id + '.'):  # <-- add '.' to src_id
                        expansions[src_id].append(node)

For example, if the node "input" feeds into "input_files", the "input_files" can be included if you just test for node.itername.startswith(src_id). This change would prevent "input_files" from being included. 

Edit: removed last part of my comment.

Discussion:

Patch:
diff --git a/nipype/pipeline/engine/utils.py b/nipype/pipeline/engine/utils.py
index 2b6bb6ed3..301a35844 100644
--- a/nipype/pipeline/engine/utils.py
+++ b/nipype/pipeline/engine/utils.py
@@ -1050,7 +1050,17 @@ def generate_expanded_graph(graph_in):
             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"


Test patch:
diff --git a/nipype/pipeline/engine/tests/test_join.py b/nipype/pipeline/engine/tests/test_join.py
index 436d29d9e..54ff15048 100644
--- a/nipype/pipeline/engine/tests/test_join.py
+++ b/nipype/pipeline/engine/tests/test_join.py
@@ -7,11 +7,9 @@ from __future__ import (print_function, division, unicode_literals,
                         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 test_nested_workflow_join(tmpdir):
     # 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()