Repository: nipy/nipype

Issue:
TraitError with 'transform0DerivedInitialMovingTranslation.mat' not found
Hi guys,

I'm running antsRegistration on the latest Nipype (Master branch, commit 4d855cb786) using the parameter initial-moving-transform-com, set to 0:

antsRegistration --collapse-linear-transforms-to-fixed-image-header 0 --collapse-output-transforms 0 --dimensionality 3 --initial-moving-transform [ {reference}, {input}, 0 ] .... etc.

In the node's folder in the working directory, I'm getting every warp file I would get if I ran the same command from terminal:
transform0DerivedInitialMovingTranslation.mat
transform1Rigid.mat
transform2Affine.mat
transform3InverseWarp.nii.gz
transform3Warp.nii.gz

However, upon completion of the command, Nipype throws this error:

TraitError: Each element of the 'forward_transforms' trait of a RegistrationOutputSpec instance must be an existing file name, but a value of 'transform0DerivedInitialMovingTranslation.mat' <type 'str'> was specified.

Any thoughts? Thanks!



Discussion:
@oesteban could you have a look?

@sgiavasis could you handle over me the 'command.txt' output or the output of the cmdline of the interface?

```
from nipype.interfaces.ants import Registration
reg = Registration()
reg.inputs.fixed_image = ['fixed1.nii', 'fixed2.nii']
reg.inputs.moving_image = ['moving1.nii', 'moving2.nii']
reg.inputs.output_transform_prefix = "output_"
...
reg.cmdline
```

This is potentially related to #883 

Hi oesteban,

Thanks for getting back to me. Here's the command.txt:

antsRegistration --collapse-linear-transforms-to-fixed-image-header 0 --collapse-output-transforms 0 --dimensionality 3 --initial-moving-transform [ {reference}, {input}, 0 ] --interpolation Linear --output [ transform, transform_Warped.nii.gz ] --transform Rigid[ 0.1 ] --metric MI[ {reference}, {input}, 1, 32, Regular, 0.25 ] --convergence [ 1000x500x250x100, 1e-08, 10 ] --smoothing-sigmas 3.0x2.0x1.0x0.0 --shrink-factors 8x4x2x1 --use-histogram-matching 1 --transform Affine[ 0.1 ] --metric MI[ {reference}, {input}, 1, 32, Regular, 0.25 ] --convergence [ 1000x500x250x100, 1e-08, 10 ] --smoothing-sigmas 3.0x2.0x1.0x0.0 --shrink-factors 8x4x2x1 --use-histogram-matching 1 --transform SyN[ 0.1, 3.0, 0.0 ] --metric CC[ {reference}, {input}, 1, 4 ] --convergence [ 100x100x70x20, 1e-09, 15 ] --smoothing-sigmas 3.0x2.0x1.0x0.0 --shrink-factors 6x4x2x1 --use-histogram-matching 1 --winsorize-image-intensities [ 0.01, 0.99 ] 

Is that what you were asking for?

Thanks @sgiavasis, that's great.

I unfortunately don't have access to ANTS at the moment, but we need to get this fix before releasing. @sgiavasis is there anything you guys would like to merge before?

Let me check, but I think Nipype now encompasses any interfaces I hacked in months ago - I'm testing the newer dev of CPAC with the current Nipype commit and I haven't had any troubles yet. When are you releasing?

Last Thursday ;)

On Mon, Oct 13, 2014 at 2:39 PM, sgiavasis notifications@github.com wrote:

> Let me check, but I think Nipype now encompasses any interfaces I hacked
> in months ago - I'm testing the newer dev of CPAC with the current Nipype
> commit and I haven't had any troubles yet. When are you releasing?
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/nipy/nipype/issues/944#issuecomment-58958836.

That will be here in no time!

Not unless we use DHL...

On Mon, Oct 13, 2014 at 2:41 PM, sgiavasis notifications@github.com wrote:

> That will be here in no time!
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/nipy/nipype/issues/944#issuecomment-58959057.

@sgiavasis @chrisfilo I'm currently looking at this


Resolving patch:
diff --git a/nipype/interfaces/ants/registration.py b/nipype/interfaces/ants/registration.py
--- a/nipype/interfaces/ants/registration.py
+++ b/nipype/interfaces/ants/registration.py
@@ -688,7 +688,7 @@ def _list_outputs(self):
                     transformCount,
                     'Initial',
                     True)
-                outputs['forward_transforms'].append(forwardFileName)
+                outputs['forward_transforms'].append(os.path.abspath(forwardFileName))
                 outputs['forward_invert_flags'].append(False)
                 outputs['reverse_transforms'].insert(0,
                                                      os.path.abspath(reverseFileName))
diff --git a/nipype/interfaces/ants/segmentation.py b/nipype/interfaces/ants/segmentation.py
--- a/nipype/interfaces/ants/segmentation.py
+++ b/nipype/interfaces/ants/segmentation.py
@@ -486,8 +486,11 @@ def _format_arg(self, opt, spec, val):
             retval = '-t %s' %(val)
             return retval
         if opt == 'segmentation_priors':
-            _, _, ext = split_filename(self.inputs.segmentation_priors[0])
-            retval = "-p BrainSegmentationPrior%02d"
+            priors_directory, _, ext = split_filename(self.inputs.segmentation_priors[0])
+            if priors_directory is not '':
+                retval = "-p %s/BrainSegmentationPrior%%02d" %(priors_directory)
+            else:
+                retval = "-p BrainSegmentationPrior%02d" 
             retval += ext
             return retval
         return super(ANTSCommand, self)._format_arg(opt, spec, val)
@@ -521,16 +524,19 @@ def _list_outputs(self):
                                                      'BrainSegmentation0N4.' +
                                                      self.inputs.image_suffix)
         outputs['BrainSegmentationPosteriorsCSF'] = os.path.join(os.getcwd(),
-                                                 self.inputs.out_prefix +
-                                                 'BrainSegmentationPosteriors01.' +
-                                                 self.inputs.image_suffix)
+                                                  self.inputs.out_prefix +
+                                                  'BrainSegmentationPosteriors01.' +
+                                                  self.inputs.image_suffix)
         outputs['BrainSegmentationPosteriorsGM'] = os.path.join(os.getcwd(),
+                                                  self.inputs.out_prefix +
                                                   'BrainSegmentationPosteriors02.' +
                                                   self.inputs.image_suffix)
         outputs['BrainSegmentationPosteriorsWM'] = os.path.join(os.getcwd(),
+                                                  self.inputs.out_prefix +
                                                   'BrainSegmentationPosteriors03.' +
                                                    self.inputs.image_suffix)
         outputs['BrainSegmentationPosteriorsDGM'] = os.path.join(os.getcwd(),
+                                                  self.inputs.out_prefix +
                                                   'BrainSegmentationPosteriors04.' +
                                                    self.inputs.image_suffix)
         outputs['CorticalThickness'] = os.path.join(os.getcwd(),


Test patch: