Repository: nipy/nipype

Issue:
EpiReg with 'wmseg' input throws TraitError: Output 'seg' does not exist
### Summary


### Actual behavior

Passing a white matter segmentation with the 'wmseg' input to a Node using the EpiReg interface raises the following Error:

`TraitError: The 'seg' trait of an EpiRegOutputSpec instance must be a pathlike object or string representing an existing file but a value of "/Users/olivercontier/bigfri/scratch/preproc_bbr_workdir/sub-01/sub_wf/ses_wf/_ses_i_0/bbr/epi2struct_fast_seg.nii.gz" <class 'str'> was specified.`

### Expected behavior

FSL's epi_reg script does not perform segmentation when a white matter segmented file is already provided. Hence, the interface should not check whether the 'seg' output exists in that case.

I think this should be fixable by changing the behavior of _list_outputs() method of the EpiReg class.

### How to replicate the behavior

I tried to provide more details in my post on [neurostars](https://neurostars.org/t/traiterror-seg-output-when-using-epi-reg-via-nipype/17273).

### Platform details:

<!-- Please run the following code from your shell and place the output between the triple ticks, below.
python -c "import nipype; from pprint import pprint; pprint(nipype.get_info())"
-->

```
{'commit_hash': '07af08f98',
 'commit_source': 'repository',
 'networkx_version': '2.4',
 'nibabel_version': '3.1.1',
 'nipype_version': '1.6.0-dev+g07af08f98',
 'numpy_version': '1.18.5',
 'pkg_path': '/Users/olivercontier/bigfri/scratch/bids/code/sandbox/nipype_epireg/nipype/nipype',
 'scipy_version': '1.5.2',
 'sys_executable': '/opt/anaconda3/envs/bigfri/bin/python',
 'sys_platform': 'darwin',
 'sys_version': '3.8.5 | packaged by conda-forge | (default, Aug 20 2020, '
                '20:51:28) \n'
                '[Clang 10.0.1 ]',
 'traits_version': '6.1.0'}
```

### Execution environment

My python environment outside container


Discussion:

Resolving patch:
diff --git a/nipype/interfaces/fsl/epi.py b/nipype/interfaces/fsl/epi.py
--- a/nipype/interfaces/fsl/epi.py
+++ b/nipype/interfaces/fsl/epi.py
@@ -1306,20 +1306,19 @@ def _list_outputs(self):
             outputs["epi2str_inv"] = os.path.join(
                 os.getcwd(), self.inputs.out_base + "_inv.mat"
             )
-
+        if not isdefined(self.inputs.wmseg):
+            outputs["wmedge"] = os.path.join(
+                os.getcwd(), self.inputs.out_base + "_fast_wmedge.nii.gz"
+            )
+            outputs["wmseg"] = os.path.join(
+                os.getcwd(), self.inputs.out_base + "_fast_wmseg.nii.gz"
+            )
+            outputs["seg"] = os.path.join(
+                os.getcwd(), self.inputs.out_base + "_fast_seg.nii.gz"
+            )
         outputs["epi2str_mat"] = os.path.join(
             os.getcwd(), self.inputs.out_base + ".mat"
         )
-        outputs["wmedge"] = os.path.join(
-            os.getcwd(), self.inputs.out_base + "_fast_wmedge.nii.gz"
-        )
-        outputs["wmseg"] = os.path.join(
-            os.getcwd(), self.inputs.out_base + "_fast_wmseg.nii.gz"
-        )
-        outputs["seg"] = os.path.join(
-            os.getcwd(), self.inputs.out_base + "_fast_seg.nii.gz"
-        )
-
         return outputs
 
 


Test patch: