From 0c28b39172da5f91776964cf7270a5961055a80f Mon Sep 17 00:00:00 2001 From: Satrajit Ghosh Date: Fri, 23 Feb 2018 16:03:27 -0500 Subject: [PATCH] fix: dtitk interface specs --- nipype/interfaces/afni/preprocess.py | 2 +- nipype/interfaces/dtitk/registration.py | 330 +++++++++++------------- nipype/interfaces/dtitk/utils.py | 221 +++++----------- 3 files changed, 213 insertions(+), 340 deletions(-) diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index 666f4b7be1..0f68ed4b47 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -2516,7 +2516,7 @@ class TProjectInputSpec(AFNICommandInputSpec): rather than the value stored in the dataset header.""", argstr='-TR %g') mask = File( - exist=True, + exists=True, desc="""Only operate on voxels nonzero in the mset dataset. ++ Voxels outside the mask will be filled with zeros. ++ If no masking option is given, then all voxels diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 3dd1c068c8..4be863cce6 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -1,16 +1,28 @@ -from ..base import TraitedSpec, CommandLineInputSpec, traits, isdefined +# -*- coding: utf-8 -*- +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- +# vi: set ft=python sts=4 ts=4 sw=4 et: +"""DTITK registration interfaces + + Change directory to provide relative paths for doctests + >>> import os + >>> filepath = os.path.dirname( os.path.realpath( __file__ ) ) + >>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data')) + >>> os.chdir(datadir) +""" + +from ..base import TraitedSpec, CommandLineInputSpec, traits, isdefined, File from ...utils.filemanip import fname_presuffix import os from .base import CommandLineDtitk class RigidInputSpec(CommandLineInputSpec): - fixed_file = traits.Str(desc="fixed diffusion tensor image", - exists=True, mandatory=True, - position=0, argstr="%s") - moving_file = traits.Str(desc="diffusion tensor image path", exists=True, - mandatory=True, position=1, argstr="%s") - similarity_metric = traits.Enum('EDS', 'GDS', 'DDS', 'NMI', exists=True, + fixed_file = File(desc="fixed diffusion tensor image", + exists=True, mandatory=True, + position=0, argstr="%s") + moving_file = File(desc="diffusion tensor image path", exists=True, + mandatory=True, position=1, argstr="%s", copyfile=False) + similarity_metric = traits.Enum('EDS', 'GDS', 'DDS', 'NMI', mandatory=True, position=2, argstr="%s", desc="similarity metric") samplingX = traits.Float(mandatory=True, position=3, argstr="%s", @@ -24,35 +36,34 @@ class RigidInputSpec(CommandLineInputSpec): default_value=4) ftol = traits.Float(mandatory=True, position=6, argstr="%s", desc="cost function tolerance", default_value=0.01) - useInTrans = traits.Float(mandatory=False, position=7, argstr="%s", + useInTrans = traits.Float(position=7, argstr="%s", desc="to initialize with existing xfm set as 1", default_value=1) class RigidOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) - out_file_xfm = traits.File(exists=True) + out_file = File(exists=True) + out_file_xfm = File(exists=True) class RigidTask(CommandLineDtitk): + """Performs rigid registration between two tensor volumes + + Example + ------- + + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.RigidTask() + >>> node.inputs.fixed_file = 'diffusion.nii.gz' + >>> node.inputs.moving_file = 'diffusion2.nii.gz' + >>> node.inputs.similarity_metric = 'EDS' + >>> node.inputs.samplingX = 4 + >>> node.inputs.samplingY = 4 + >>> node.inputs.samplingZ = 4 + >>> node.inputs.ftol = 0.01 + >>> node.inputs.useInTrans = 1 + >>> node.run() # doctest: +SKIP """ - Performs rigid registration between two tensor volumes - - Example - ------- - - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.RigidTask() - >>> node.inputs.fixed_file = 'diffusion.nii.gz' - >>> node.inputs.moving_file = 'diffusion2.nii.gz' - >>> node.inputs.similarity_metric = 'EDS' - >>> node.inputs.samplingX = 4 - >>> node.inputs.samplingY = 4 - >>> node.inputs.samplingZ = 4 - >>> node.inputs.ftol = 0.01 - >>> node.inputs.useInTrans = 1 - >>> node.run() # doctest: +SKIP - """ input_spec = RigidInputSpec output_spec = RigidOutputSpec _cmd = 'dti_rigid_reg' @@ -67,12 +78,12 @@ def _list_outputs(self): class AffineInputSpec(CommandLineInputSpec): - fixed_file = traits.Str(desc="fixed diffusion tensor image", - exists=True, mandatory=True, - position=0, argstr="%s") - moving_file = traits.Str(desc="diffusion tensor image path", exists=True, - mandatory=True, position=1, argstr="%s") - similarity_metric = traits.Enum('EDS', 'GDS', 'DDS', 'NMI', exists=True, + fixed_file = File(desc="fixed diffusion tensor image", + exists=True, mandatory=True, + position=0, argstr="%s") + moving_file = File(desc="diffusion tensor image path", exists=True, + mandatory=True, position=1, argstr="%s", copyfile=False) + similarity_metric = traits.Enum('EDS', 'GDS', 'DDS', 'NMI', mandatory=True, position=2, argstr="%s", desc="similarity metric") samplingX = traits.Float(mandatory=True, position=3, argstr="%s", @@ -86,35 +97,34 @@ class AffineInputSpec(CommandLineInputSpec): default_value=4) ftol = traits.Float(mandatory=True, position=6, argstr="%s", desc="cost function tolerance", default_value=0.01) - useInTrans = traits.Float(mandatory=False, position=7, argstr="%s", + useInTrans = traits.Float(position=7, argstr="%s", desc="to initialize with existing xfm set as 1", default_value=1) class AffineOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) - out_file_xfm = traits.File(exists=True) + out_file = File(exists=True) + out_file_xfm = File(exists=True) class AffineTask(CommandLineDtitk): + """Performs affine registration between two tensor volumes + + Example + ------- + + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.AffineTask() + >>> node.inputs.fixed_file = 'diffusion.nii.gz' + >>> node.inputs.moving_file = 'diffusion2.nii.gz' + >>> node.inputs.similarity_metric = 'EDS' + >>> node.inputs.samplingX = 4 + >>> node.inputs.samplingY = 4 + >>> node.inputs.samplingZ = 4 + >>> node.inputs.ftol = 0.01 + >>> node.inputs.useInTrans = 1 + >>> node.run() # doctest: +SKIP """ - Performs affine registration between two tensor volumes - - Example - ------- - - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.AffineTask() - >>> node.inputs.fixed_file = 'diffusion.nii.gz' - >>> node.inputs.moving_file = 'diffusion2.nii.gz' - >>> node.inputs.similarity_metric = 'EDS' - >>> node.inputs.samplingX = 4 - >>> node.inputs.samplingY = 4 - >>> node.inputs.samplingZ = 4 - >>> node.inputs.ftol = 0.01 - >>> node.inputs.useInTrans = 1 - >>> node.run() # doctest: +SKIP - """ input_spec = AffineInputSpec output_spec = AffineOutputSpec _cmd = 'dti_affine_reg' @@ -129,14 +139,11 @@ def _list_outputs(self): class DiffeoInputSpec(CommandLineInputSpec): - fixed_file = traits.Str(desc="fixed diffusion tensor image", - exists=True, mandatory=False, position=0, - argstr="%s") - moving_file = traits.Str(desc="moving diffusion tensor image", - exists=True, mandatory=False, - position=1, argstr="%s") - mask = traits.Str(desc="mask", exists=True, mandatory=False, position=2, - argstr="%s") + fixed_file = File(desc="fixed diffusion tensor image", + exists=True, position=0, argstr="%s") + moving_file = File(desc="moving diffusion tensor image", + exists=True, position=1, argstr="%s", copyfile=False) + mask = File(desc="mask", exists=True, position=2, argstr="%s") legacy = traits.Float(desc="legacy parameter; always set to 1", exists=True, mandatory=True, position=3, default_value=1, argstr="%s") @@ -149,27 +156,26 @@ class DiffeoInputSpec(CommandLineInputSpec): class DiffeoOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) - out_file_xfm = traits.File(exists=True) + out_file = File(exists=True) + out_file_xfm = File(exists=True) class DiffeoTask(CommandLineDtitk): + """Performs diffeomorphic registration between two tensor volumes + + Example + ------- + + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.DiffeoTask() + >>> node.inputs.fixed_file = 'diffusion.nii.gz' + >>> node.inputs.moving_file = 'diffusion2.nii.gz' + >>> node.inputs.mask = 'mask.nii.gz' + >>> node.inputs.legacy = 1 + >>> node.inputs.n_iters = 6 + >>> node.inputs.ftol = 0.002 + >>> node.run() # doctest: +SKIP """ - Performs diffeomorphic registration between two tensor volumes - - Example - ------- - - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.DiffeoTask() - >>> node.inputs.fixed_file = 'diffusion.nii.gz' - >>> node.inputs.moving_file = 'diffusion2.nii.gz' - >>> node.inputs.mask = 'mask.nii.gz' - >>> node.inputs.legacy = 1 - >>> node.inputs.n_iters = 6 - >>> node.inputs.ftol = 0.002 - >>> node.run() # doctest: +SKIP - """ input_spec = DiffeoInputSpec output_spec = DiffeoOutputSpec _cmd = 'dti_diffeomorphic_reg' @@ -184,32 +190,32 @@ def _list_outputs(self): class ComposeXfmInputSpec(CommandLineInputSpec): - in_df = traits.Str(desc='diffeomorphic file.df.nii.gz', exists=True, - mandatory=False, position=1, argstr="-df %s") - in_aff = traits.Str(desc='affine file.aff', exists=True, mandatory=False, + in_df = File(desc='diffeomorphic file.df.nii.gz', exists=True, + position=1, argstr="-df %s", copyfile=False) + in_aff = File(desc='affine file.aff', exists=True, position=0, argstr="-aff %s") - out_file = traits.Str(desc='output_path', exists=True, mandatory=False, + out_file = traits.Str(desc='output_path', exists=True, position=2, argstr="-out %s", name_source="in_df", name_template="%s_comboaff.nii.gz") class ComposeXfmOutputSpec(TraitedSpec): - out_file = traits.File(desc='cheese', exists=True) + out_file = File(desc='cheese', exists=True) class ComposeXfmTask(CommandLineDtitk): """ Combines diffeomorphic and affine transforms - Example - ------- + Example + ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.ComposeXfmTask() - >>> node.inputs.in_df = 'ants_Warp.nii.gz' - >>> node.inputs.in_aff= 'ants_Affine.txt' - >>> node.run() # doctest: +SKIP - """ + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.ComposeXfmTask() + >>> node.inputs.in_df = 'ants_Warp.nii.gz' + >>> node.inputs.in_aff= 'ants_Affine.txt' + >>> node.run() # doctest: +SKIP + """ input_spec = ComposeXfmInputSpec output_spec = ComposeXfmOutputSpec _cmd = 'dfRightComposeAffine' @@ -222,173 +228,145 @@ def _list_outputs(self): class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): - in_tensor = traits.Str(desc='moving tensor', exists=True, mandatory=False, + in_tensor = File(desc='moving tensor', exists=True, position=0, argstr="-in %s") - in_xfm = traits.Str(desc='transform to apply', exists=True, - mandatory=False, - position=1, argstr="-trans %s") - in_target = traits.Str(desc='', exists=True, mandatory=False, position=2, + in_xfm = File(desc='transform to apply', exists=True, + position=1, argstr="-trans %s") + in_target = File(desc='', exists=True, position=2, argstr="-target %s") - out_file = traits.Str(desc='', exists=True, mandatory=False, position=3, + out_file = traits.Str(desc='', exists=True, position=3, argstr="-out %s", name_source="in_tensor", name_template="%s_diffeoxfmd.nii.gz") class diffeoSymTensor3DVolOutputSpec(TraitedSpec): - out_file = traits.File(desc='cheese', exists=True) + out_file = File(desc='cheese', exists=True) class diffeoSymTensor3DVolTask(CommandLineDtitk): """ Applies diffeomorphic transform to a tensor volume - Example - ------- + Example + ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.diffeoSymTensor3DVolTask() - >>> node.inputs.in_tensor = 'diffusion.nii' - >>> node.inputs.in_xfm = 'ants_Warp.nii.gz' - >>> node.run() # doctest: +SKIP - """ + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.diffeoSymTensor3DVolTask() + >>> node.inputs.in_tensor = 'diffusion.nii' + >>> node.inputs.in_xfm = 'ants_Warp.nii.gz' + >>> node.run() # doctest: +SKIP + """ input_spec = diffeoSymTensor3DVolInputSpec output_spec = diffeoSymTensor3DVolOutputSpec _cmd = 'deformationSymTensor3DVolume' - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.out_file - return outputs - class affSymTensor3DVolInputSpec(CommandLineInputSpec): - in_tensor = traits.Str(desc='moving tensor', exists=True, mandatory=False, + in_tensor = File(desc='moving tensor', exists=True, position=0, argstr="-in %s") - in_xfm = traits.Str(desc='transform to apply', exists=True, - mandatory=False, position=1, argstr="-trans %s") - in_target = traits.Str(desc='', exists=True, mandatory=False, position=2, + in_xfm = File(desc='transform to apply', exists=True, + position=1, argstr="-trans %s") + in_target = File(desc='', exists=True, position=2, argstr="-target %s") - out_file = traits.Str(desc='', exists=True, mandatory=False, position=3, + out_file = traits.Str(desc='', exists=True, position=3, argstr="-out %s", name_source="in_tensor", name_template="%s_affxfmd.nii.gz") class affSymTensor3DVolOutputSpec(TraitedSpec): - out_file = traits.File(desc='cheese', exists=True) + out_file = File(desc='cheese', exists=True) class affSymTensor3DVolTask(CommandLineDtitk): """ Applies affine transform to a tensor volume - Example - ------- + Example + ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.affSymTensor3DVolTask() - >>> node.inputs.in_tensor = 'diffusion.nii' - >>> node.inputs.in_xfm = 'ants_Affine.txt' - >>> node.run() # doctest: +SKIP - """ + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.affSymTensor3DVolTask() + >>> node.inputs.in_tensor = 'diffusion.nii' + >>> node.inputs.in_xfm = 'ants_Affine.txt' + >>> node.run() # doctest: +SKIP + """ input_spec = affSymTensor3DVolInputSpec output_spec = affSymTensor3DVolOutputSpec _cmd = 'affineSymTensor3DVolume' - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = os.path.abspath(self.inputs.out_file) - return outputs - class affScalarVolInputSpec(CommandLineInputSpec): - in_volume = traits.Str(desc='moving volume', exists=True, mandatory=False, + in_volume = File(desc='moving volume', exists=True, position=0, argstr="-in %s") - in_xfm = traits.Str(desc='transform to apply', exists=True, - mandatory=False, + in_xfm = File(desc='transform to apply', exists=True, position=1, argstr="-trans %s") - in_target = traits.Str(desc='', position=2, argstr="-target %s") - out_file = traits.Str(desc='', mandatory=False, position=3, + in_target = File(desc='', position=2, argstr="-target %s") + out_file = traits.Str(desc='', position=3, argstr="-out %s", name_source="in_volume", name_template="%s_affxfmd.nii.gz") class affScalarVolOutputSpec(TraitedSpec): - out_file = traits.File(desc='moved volume', exists=True) + out_file = File(desc='moved volume', exists=True) class affScalarVolTask(CommandLineDtitk): """ Applies affine transform to a scalar volume - Example - ------- + Example + ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.affScalarVolTask() - >>> node.inputs.in_volume = 'fa.nii.gz' - >>> node.inputs.in_xfm = 'ants_Affine.txt' - >>> node.run() # doctest: +SKIP - """ + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.affScalarVolTask() + >>> node.inputs.in_volume = 'fa.nii.gz' + >>> node.inputs.in_xfm = 'ants_Affine.txt' + >>> node.run() # doctest: +SKIP + """ input_spec = affScalarVolInputSpec output_spec = affScalarVolOutputSpec _cmd = 'affineScalarVolume' - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = os.path.abspath(self.inputs.out_file) - return outputs - class diffeoScalarVolInputSpec(CommandLineInputSpec): - in_volume = traits.Str(desc='moving volume', exists=True, mandatory=False, + in_volume = File(desc='moving volume', exists=True, position=0, argstr="-in %s") - in_xfm = traits.Str(desc='transform to apply', exists=True, - mandatory=False, + in_xfm = File(desc='transform to apply', exists=True, position=2, argstr="-trans %s") - in_target = traits.Str(desc='', exists=True, mandatory=False, position=3, + in_target = File(desc='', exists=True, position=3, argstr="-target %s") out_file = traits.Str(desc='', position=1, argstr="-out %s", name_source="in_volume", name_template="%s_diffeoxfmd.nii.gz") - in_vsize = traits.Str(desc='', exists=True, mandatory=False, position=4, + in_vsize = File(desc='', exists=True, position=4, argstr="-vsize %s") - in_flip = traits.Str(desc='', exists=True, mandatory=False, position=5, + in_flip = File(desc='', exists=True, position=5, argstr="-flip %s") - in_type = traits.Str(desc='', exists=True, mandatory=False, position=6, + in_type = File(desc='', exists=True, position=6, argstr="-type %s") - in_interp = traits.Str(desc='0 trilin, 1 NN', exists=True, mandatory=False, + in_interp = File(desc='0 trilin, 1 NN', exists=True, position=7, argstr="-interp %s") class diffeoScalarVolOutputSpec(TraitedSpec): - out_file = traits.File(desc='moved volume', exists=True) + out_file = File(desc='moved volume', exists=True) class diffeoScalarVolTask(CommandLineDtitk): """ Applies diffeomorphic transform to a scalar volume - Example - ------- + Example + ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.diffeoScalarVolTask() - >>> node.inputs.in_volume = 'fa.nii.gz' - >>> node.inputs.in_xfm = 'ants_Warp.nii.gz' - >>> node.run() # doctest: +SKIP - """ + >>> import nipype.interfaces.dtitk as dtitk + >>> node = dtitk.diffeoScalarVolTask() + >>> node.inputs.in_volume = 'fa.nii.gz' + >>> node.inputs.in_xfm = 'ants_Warp.nii.gz' + >>> node.run() # doctest: +SKIP + """ input_spec = diffeoScalarVolInputSpec output_spec = diffeoScalarVolOutputSpec _cmd = 'deformationScalarVolume' - - def _list_outputs(self): - outputs = self.output_spec().get() - if not isdefined(self.inputs.out_file): - self.inputs.out_file = fname_presuffix(self.inputs.in_volume, - suffix="_diffeoxfmd", - newpath=os.path.abspath( - ".")) - outputs['out_file'] = os.path.abspath(self.inputs.out_file) - return outputs diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index 86e0c08b8c..15b8077c4e 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -1,3 +1,14 @@ +# -*- coding: utf-8 -*- +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- +# vi: set ft=python sts=4 ts=4 sw=4 et: +"""DTITK utility interfaces + + Change directory to provide relative paths for doctests + >>> import os + >>> filepath = os.path.dirname( os.path.realpath( __file__ ) ) + >>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data')) + >>> os.chdir(datadir) +""" __author__ = 'kjordan' from ..base import TraitedSpec, CommandLineInputSpec, File, \ @@ -9,14 +20,14 @@ class TVAdjustOriginInputSpec(CommandLineInputSpec): in_file = File(desc="image to resample", exists=True, mandatory=True, position=0, argstr="-in %s") - out_file = traits.Str(genfile=True, desc='output path', position=1, - argstr="-out %s") - origin = traits.Str(desc='xyz voxel size', exists=True, mandatory=False, + out_file = traits.Str(desc='output path', position=1, argstr="-out %s", + namesource=['in_file'], name_template='%s_originzero') + origin = traits.Str(desc='xyz voxel size', position=4, argstr='-origin %s') class TVAdjustOriginOutputSpec(TraitedSpec): - out_file = traits.Str(exists=True) + out_file = File(exists=True) class TVAdjustOriginTask(CommandLineDtitk): @@ -35,41 +46,24 @@ class TVAdjustOriginTask(CommandLineDtitk): input_spec = TVAdjustOriginInputSpec output_spec = TVAdjustOriginOutputSpec _cmd = 'TVAdjustVoxelspace' - _suffix = "_originzero" - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.out_file - if not isdefined(self.inputs.out_file): - outputs["out_file"] = self._gen_fname(self.inputs.in_file, - suffix=self._suffix, - ext='.'+'.'.join( - self.inputs.in_file. - split(".")[1:])) - outputs["out_file"] = os.path.abspath(outputs["out_file"]) - return outputs - - def _gen_filename(self, name): - if name == "out_file": - return self._list_outputs()["out_file"] - return None class TVAdjustVoxSpInputSpec(CommandLineInputSpec): in_file = File(desc="image to resample", exists=True, mandatory=True, position=0, argstr="-in %s") out_file = traits.Str(genfile=True, desc='output path', position=1, - argstr="-out %s") - origin = traits.Str(desc='xyz voxel size', exists=True, mandatory=False, + argstr="-out %s", name_source='in_file', + name_template='%s_reslice', keep_extension=True) + origin = traits.Str(desc='xyz voxel size', mandatory=True, position=4, argstr='-origin %s') - target = traits.Str(desc='target volume', exists=True, mandatory=False, + target = traits.Str(desc='target volume', mandaotry=True, position=2, argstr="-target %s") - vsize = traits.Str(desc='resampled voxel size', exists=True, - mandatory=False, position=3, argstr="-vsize %s") + vsize = traits.Str(desc='resampled voxel size', mandatory=True, + position=3, argstr="-vsize %s") class TVAdjustVoxSpOutputSpec(TraitedSpec): - out_file = traits.Str(exists=True) + out_file = File(exists=True) class TVAdjustVoxSpTask(CommandLineDtitk): @@ -87,46 +81,26 @@ class TVAdjustVoxSpTask(CommandLineDtitk): input_spec = TVAdjustVoxSpInputSpec output_spec = TVAdjustVoxSpOutputSpec _cmd = 'TVAdjustVoxelspace' - _suffix = '_reslice' - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.out_file - if not isdefined(self.inputs.out_file): - outputs["out_file"] = self._gen_fname(self.inputs.in_file, - suffix=self._suffix, - ext='.'+'.'.join( - self.inputs.in_file. - split(".")[1:])) - outputs["out_file"] = os.path.abspath(outputs["out_file"]) - return outputs - - def _gen_filename(self, name): - if name == "out_file": - return self._list_outputs()["out_file"] - return None # TODO not using these yet... need to be tested - class SVAdjustVoxSpInputSpec(CommandLineInputSpec): - in_file = traits.Str(desc="image to resample", exists=True, + in_file = File(desc="image to resample", exists=True, mandatory=True, position=0, argstr="-in %s") - in_target = traits.Str(desc='target volume', exists=True, mandatory=False, + in_target = File(desc='target volume', mandatory=True, position=2, argstr="-target %s") - in_voxsz = traits.Str(desc='resampled voxel size', exists=True, - mandatory=False, position=3, argstr="-vsize %s") - out_file = traits.Str(desc='output path', exists=True, mandatory=False, - position=1, argstr="-out %s", - name_source="in_file", - name_template='%s_origmvd.nii.gz') - origin = traits.Str(desc='xyz voxel size', exists=True, mandatory=False, + in_voxsz = traits.Str(desc='resampled voxel size', mandatory=True, + position=3, argstr="-vsize %s") + out_file = traits.Str(desc='output path', position=1, argstr="-out %s", + name_source="in_file", name_template='%s_reslice', + keep_extension=True) + origin = traits.Str(desc='xyz voxel size', mandatory=True, position=4, argstr='-origin %s') class SVAdjustVoxSpOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) + out_file = File(exists=True) class SVAdjustVoxSpTask(CommandLineDtitk): @@ -144,41 +118,22 @@ class SVAdjustVoxSpTask(CommandLineDtitk): input_spec = SVAdjustVoxSpInputSpec output_spec = SVAdjustVoxSpOutputSpec _cmd = 'SVAdjustVoxelspace' - _suffix = '_reslice' - - def _gen_filename(self, name): - if name == "out_file": - return self._list_outputs()["out_file"] - return None - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.out_file - if not isdefined(self.inputs.out_file): - outputs["out_file"] = self._gen_filename(self.inputs.in_file, - suffix=self._suffix, - ext='.' + '.'.join( - self.inputs.in_file. - split(".")[1:])) - outputs["out_file"] = os.path.abspath(outputs["out_file"]) - return outputs class TVResampleInputSpec(CommandLineInputSpec): - in_file = traits.Str(desc="image to resample", exists=True, + in_file = File(desc="image to resample", exists=True, mandatory=True, position=0, argstr="-in %s") in_arraysz = traits.Str(desc='resampled array size', exists=True, - mandatory=False, position=1, argstr="-size %s") + position=1, argstr="-size %s") in_voxsz = traits.Str(desc='resampled voxel size', exists=True, - mandatory=False, position=2, argstr="-vsize %s") - out_file = traits.Str(desc='output path', exists=True, mandatory=False, - position=3, argstr="-out %s", - name_source="in_file", - name_template="%s_resampled.nii.gz") + position=2, argstr="-vsize %s") + out_file = traits.Str(desc='output path', position=3, argstr="-out %s", + name_source="in_file", name_template="%s_resampled", + keep_extesnion=True) class TVResampleOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) + out_file = File(exists=True) class TVResampleTask(CommandLineDtitk): @@ -196,42 +151,14 @@ class TVResampleTask(CommandLineDtitk): input_spec = TVResampleInputSpec output_spec = TVResampleOutputSpec _cmd = 'TVResample' - _suffix = '_resampled' - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.out_file - if not isdefined(self.inputs.out_file): - outputs["out_file"] = self._gen_fname(self.inputs.in_file, - suffix=self._suffix, - ext='.' + '.'.join( - self.inputs.in_file. - split(".")[1:])) - outputs["out_file"] = os.path.abspath(outputs["out_file"]) - return outputs - - def _gen_filename(self, name): - if name == "out_file": - return self._list_outputs()["out_file"] - return None -class SVResampleInputSpec(CommandLineInputSpec): - in_file = traits.Str(desc="image to resample", exists=True, - mandatory=True, position=0, argstr="-in %s") - in_arraysz = traits.Str(desc='resampled array size', exists=True, - mandatory=False, position=1, - argstr="-size %s") - in_voxsz = traits.Str(desc='resampled voxel size', exists=True, - mandatory=False, position=2, argstr="-vsize %s") - out_file = traits.Str(desc='output path', exists=True, mandatory=False, - position=3, argstr="-out %s", - name_source="in_file", - name_template="%s_resampled.nii.gz") +class SVResampleInputSpec(TVResampleInputSpec): + pass -class SVResampleOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) +class SVResampleOutputSpec(TVResampleOutputSpec): + pass class SVResampleTask(CommandLineDtitk): @@ -244,40 +171,23 @@ class SVResampleTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.SVResampleTask() >>> node.inputs.in_file = 'diffusion.nii' + >>> node.inputs.in_file = 'diffusion.nii' >>> node.run() # doctest: +SKIP """ input_spec = SVResampleInputSpec output_spec = SVResampleOutputSpec _cmd = 'SVResample' - _suffix = '_resampled' - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.out_file - if not isdefined(self.inputs.out_file): - outputs["out_file"] = self._gen_fname(self.inputs.in_file, - suffix=self._suffix, - ext='.' + '.'.join( - self.inputs.in_file. - split(".")[1:])) - outputs["out_file"] = os.path.abspath(outputs["out_file"]) - return outputs - - def _gen_filename(self, name): - if name == "out_file": - return self._list_outputs()["out_file"] - return None class TVtoolInputSpec(CommandLineInputSpec): - in_file = traits.Str(desc="image to resample", exists=True, - mandatory=False, position=0, argstr="-in %s") + in_file = File(desc="image to resample", exists=True, + position=0, argstr="-in %s") in_flag = traits.Enum('fa', 'tr', 'ad', 'rd', 'pd', 'rgb', exists=True, - mandatory=False, position=1, argstr="-%s", desc='') + position=1, argstr="-%s", desc='') class TVtoolOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) + out_file = File(exists=True) class TVtoolTask(CommandLineDtitk): @@ -317,17 +227,18 @@ def _gen_filename(self, name): class BinThreshInputSpec(CommandLineInputSpec): - in_file = traits.Str(desc='', exists=True, mandatory=False, position=0, + in_file = File(desc='', exists=True, position=0, argstr="%s") - out_file = traits.Str(desc='', exists=True, mandatory=False, position=1, - argstr="%s") - in_numbers = traits.Str(desc='LB UB inside_value outside_value', - exists=True, mandatory=False, position=2, - argstr="%s") + out_file = traits.Str(desc='', position=1, argstr="%s", + keep_extension=True, name_source='in_file', + name_template='%s_bin') + in_numbers = traits.List(traits.Float, minlen=4, maxlen=4, + desc='LB UB inside_value outside_value', + position=2, argstr="%s") class BinThreshOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) + out_file = File(exists=True) class BinThreshTask(CommandLineDtitk): @@ -340,28 +251,12 @@ class BinThreshTask(CommandLineDtitk): >>> import nipype.interfaces.dtitk as dtitk >>> node = dtitk.BinThreshTask() >>> node.inputs.in_file = 'diffusion.nii' - >>> node.inputs.in_numbers = '0 100 1 0' + >>> node.inputs.in_numbers = [0, 100, 1, 0] + >>> node.cmdline + 'BinaryThresholdImageFilter diffusion.nii diffusion_bin.nii 0.0 100.0 1.0 0.0' >>> node.run() # doctest: +SKIP """ input_spec = BinThreshInputSpec output_spec = BinThreshOutputSpec _cmd = 'BinaryThresholdImageFilter' - _suffix = '_bin' - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.out_file - if not isdefined(self.inputs.out_file): - outputs["out_file"] = self._gen_fname(self.inputs.in_file, - suffix=self._suffix, - ext='.'+'.'.join( - self.inputs.in_file. - split(".")[1:])) - outputs["out_file"] = os.path.abspath(outputs["out_file"]) - return outputs - - def _gen_filename(self, name): - if name == "out_file": - return self._list_outputs()["out_file"] - return None