Repository: nipy/nipype

Issue:
eddy node from `nipype.workflows.dmri.all_fsl_pipeline` workflow always gets executed
### Summary
Unnecessary execution of eddy correction node in `nipype.workflows.dmri.all_fsl_pipeline` due to the creation of the input file `index.txt` in each run.

### Actual behavior
The eddy correction node is always executed even if nothing changed in the pipeline from the previous run.

### Expected behavior
This node must only be run when changes in previous nodes modify its input.

### How to replicate the behavior
Create a workflow of type `nipype.workflows.dmri.all_fsl_pipeline` define the inputs and execute it twice in a row. 

### Script/Workflow details

The [connection of the eddy correction node](https://github.com/nipy/nipype/blob/master/nipype/workflows/dmri/fsl/artifacts.py#L276) calls the function [`_gen_index`](https://github.com/nipy/nipype/blob/master/nipype/workflows/dmri/fsl/artifacts.py#L235) that creates the file `index.txt` in every execution, forcing the node to run.

### Platform details:

{'pkg_path': '/Users/miguel/anaconda/lib/python3.5/site-packages/nipype', 'scipy_version': '0.19.1', 'numpy_version': '1.12.1', 'nipype_version': '1.0.0-dev', 'commit_hash': '<not found>', 'sys_platform': 'darwin', 'traits_version': '4.6.0', 'networkx_version': '1.11', 'sys_executable': '/Users/miguel/anaconda/bin/python', 'nibabel_version': '2.1.0', 'sys_version': '3.5.3 | packaged by conda-forge | (default, May 12 2017, 15:35:12) \n[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)]', 'commit_source': '(none found)'}
1.0.0-dev

IDE: Eclipse Oxigen + PyDev

### Execution environment

Choose one
- Container [Tag: ???]
- My python environment inside container [Base Tag: ???]
- My python environment outside container



Discussion:

Resolving patch:
diff --git a/nipype/workflows/dmri/fsl/artifacts.py b/nipype/workflows/dmri/fsl/artifacts.py
--- a/nipype/workflows/dmri/fsl/artifacts.py
+++ b/nipype/workflows/dmri/fsl/artifacts.py
@@ -232,7 +232,7 @@ def all_fsl_pipeline(name='fsl_all_correct',
     outputnode = pe.Node(niu.IdentityInterface(
         fields=['out_file', 'out_mask', 'out_bvec']), name='outputnode')
 
-    def _gen_index(in_file):
+    def gen_index(in_file):
         import numpy as np
         import nibabel as nb
         import os
@@ -242,6 +242,9 @@ def _gen_index(in_file):
         np.savetxt(out_file, np.ones((vols,)).T)
         return out_file
 
+    gen_idx = pe.Node(niu.Function(
+        input_names=['in_file'], output_names=['out_file'],
+        function=gen_index), name='gen_index')
     avg_b0_0 = pe.Node(niu.Function(
         input_names=['in_dwi', 'in_bval'], output_names=['out_file'],
         function=b0_average), name='b0_avg_pre')
@@ -272,10 +275,11 @@ def _gen_index(in_file):
                     ('topup.out_fieldcoef', 'in_topup_fieldcoef'),
                     ('topup.out_movpar', 'in_topup_movpar')]),
         (bet_dwi0, ecc, [('mask_file', 'in_mask')]),
+        (inputnode, gen_idx, [('in_file', 'in_file')]),
         (inputnode, ecc, [('in_file', 'in_file'),
-                          (('in_file', _gen_index), 'in_index'),
                           ('in_bval', 'in_bval'),
                           ('in_bvec', 'in_bvec')]),
+        (gen_idx, ecc, [('out_file', 'in_index')]),
         (inputnode, rot_bvec, [('in_bvec', 'in_bvec')]),
         (ecc, rot_bvec, [('out_parameter', 'eddy_params')]),
         (ecc, avg_b0_1, [('out_corrected', 'in_dwi')]),


Test patch: