diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index 1d26bef587..595605e38b 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -2510,7 +2510,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/afni/tests/test_auto_TProject.py b/nipype/interfaces/afni/tests/test_auto_TProject.py index 25a47142b9..ffca499ea5 100644 --- a/nipype/interfaces/afni/tests/test_auto_TProject.py +++ b/nipype/interfaces/afni/tests/test_auto_TProject.py @@ -32,10 +32,7 @@ def test_TProject_inputs(): mandatory=True, position=1, ), - mask=dict( - argstr='-mask %s', - exist=True, - ), + mask=dict(argstr='-mask %s', ), noblock=dict(argstr='-noblock', ), norm=dict(argstr='-norm', ), num_threads=dict( diff --git a/nipype/interfaces/dtitk/__init__.py b/nipype/interfaces/dtitk/__init__.py index e3f3cb7aab..a41c09e588 100644 --- a/nipype/interfaces/dtitk/__init__.py +++ b/nipype/interfaces/dtitk/__init__.py @@ -6,10 +6,8 @@ """ # from .base import () -from .registration import (RigidTask, AffineTask, DiffeoTask, - ComposeXfmTask, diffeoSymTensor3DVolTask, - affSymTensor3DVolTask, affScalarVolTask, - diffeoScalarVolTask) -from .utils import (TVAdjustOriginTask, TVAdjustVoxSpTask, - SVAdjustVoxSpTask, TVResampleTask, SVResampleTask, - TVtoolTask, BinThreshTask) +from .registration import (Rigid, Affine, Diffeo, + ComposeXfm, DiffeoSymTensor3DVol, AffSymTensor3DVol, + AffScalarVol, DiffeoScalarVol) +from .utils import (TVAdjustVoxSp, SVAdjustVoxSp, TVResample, SVResample, + TVtool, BinThresh) diff --git a/nipype/interfaces/dtitk/base.py b/nipype/interfaces/dtitk/base.py index b14ad5ed23..069016e7f3 100644 --- a/nipype/interfaces/dtitk/base.py +++ b/nipype/interfaces/dtitk/base.py @@ -13,6 +13,12 @@ * Rigid Tensor Registration * Affine Tensor Registration * Diffeomorphic Tensor Registration +* Combine affiine and diffeomorphic transforms +* Application of transform to tensor and scalar volumes +* Threshold and Binarize +* Adjusting the voxel space of tensor and scalar volumes +* Resampling tensor and scalar volumes +* Calculation of tensor metrics from tensor volume Examples -------- @@ -28,10 +34,26 @@ from ...utils.filemanip import fname_presuffix from ..base import CommandLine from nipype.interfaces.fsl.base import Info +import warnings LOGGER = logging.getLogger('interface') +class DTITKRenameMixin(object): + def __init__(self, *args, **kwargs): + classes = [cls.__name__ for cls in self.__class__.mro()] + dep_name = classes[0] + rename_idx = classes.index('DTITKRenameMixin') + new_name = classes[rename_idx + 1] + warnings.warn('The {} interface has been renamed to {}\n' + 'Please see the documentation for DTI-TK ' + 'interfaces, as some inputs have been ' + 'added or renamed for clarity.' + ''.format(dep_name, new_name), + DeprecationWarning) + super(DTITKRenameMixin, self).__init__(*args, **kwargs) + + class CommandLineDtitk(CommandLine): def _gen_fname(self, basename, cwd=None, suffix=None, change_ext=True, diff --git a/nipype/interfaces/dtitk/registration.py b/nipype/interfaces/dtitk/registration.py index 3dd1c068c8..6aa40d4201 100644 --- a/nipype/interfaces/dtitk/registration.py +++ b/nipype/interfaces/dtitk/registration.py @@ -1,394 +1,489 @@ -from ..base import TraitedSpec, CommandLineInputSpec, traits, isdefined -from ...utils.filemanip import fname_presuffix +# -*- 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 + +DTI-TK developed by Gary Hui Zhang, gary.zhang@ucl.ac.uk +For additional help, visit http://dti-tk.sf.net + +The high-dimensional tensor-based DTI registration algorithm + +Zhang, H., Avants, B.B, Yushkevich, P.A., Woo, J.H., Wang, S., McCluskey, L.H., + Elman, L.B., Melhem, E.R., Gee, J.C., High-dimensional spatial normalization + of diffusion tensor images improves the detection of white matter differences + in amyotrophic lateral sclerosis, IEEE Transactions on Medical Imaging, + 26(11):1585-1597, November 2007. PMID: 18041273. + +The original piecewise-affine tensor-based DTI registration algorithm at the +core of DTI-TK + +Zhang, H., Yushkevich, P.A., Alexander, D.C., Gee, J.C., Deformable + registration of diffusion tensor MR images with explicit orientation + optimization, Medical Image Analysis, 10(5):764-785, October 2006. PMID: + 16899392. + +""" + +from ..base import TraitedSpec, CommandLineInputSpec, traits, File, isdefined +from ...utils.filemanip import fname_presuffix, split_filename +from .base import CommandLineDtitk, DTITKRenameMixin import os -from .base import CommandLineDtitk + +__docformat__ = 'restructuredtext' 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 tensor volume", exists=True, + mandatory=True, position=0, argstr="%s", copyfile=False) + moving_file = File(desc="moving tensor volume", 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", - desc="dist between samp points (mm)", - default_value=4) - samplingY = traits.Float(mandatory=True, position=4, argstr="%s", - desc="dist between samp points (mm)", - default_value=4) - samplingZ = traits.Float(mandatory=True, position=5, argstr="%s", - desc="dist between samp points (mm)", - 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", - desc="to initialize with existing xfm set as 1", - default_value=1) + desc="similarity metric", usedefault=True) + sampling_xyz = traits.Tuple((4, 4, 4), mandatory=True, position=3, + argstr="%g %g %g", usedefault=True, + desc="dist between samp points (mm) (x,y,z)") + ftol = traits.Float(mandatory=True, position=4, argstr="%g", + desc="cost function tolerance", default_value=0.01, + usedefault=True) + initialize_xfm = File(copyfile=True, desc="Initialize w/DTITK-FORMAT" + "affine", position=5, argstr="%s", exists=True) class RigidOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) - out_file_xfm = traits.File(exists=True) - - -class RigidTask(CommandLineDtitk): + out_file = File(exists=True) + out_file_xfm = File(exists=True) + + +class Rigid(CommandLineDtitk): + """Performs rigid registration between two tensor volumes + + Example + ------- + + >>> from nipype.interfaces import dtitk + >>> node = dtitk.Rigid() + >>> node.inputs.fixed_file = 'im1.nii' + >>> node.inputs.moving_file = 'im2.nii' + >>> node.inputs.similarity_metric = 'EDS' + >>> node.inputs.sampling_xyz = (4,4,4) + >>> node.inputs.ftol = 0.01 + >>> node.cmdline + 'dti_rigid_reg im1.nii im2.nii EDS 4 4 4 0.01' + >>> 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' + '''def _format_arg(self, name, spec, value): + if name == 'initialize_xfm': + value = 1 + return super(Rigid, self)._format_arg(name, spec, value)''' + + def _run_interface(self, runtime): + runtime = super(Rigid, self)._run_interface(runtime) + if '''.aff doesn't exist or can't be opened''' in runtime.stderr: + self.raise_exception(runtime) + return runtime + def _list_outputs(self): outputs = self.output_spec().get() - outputs['out_file_xfm'] = self.inputs.moving_file.replace('.nii.gz', - '.aff') - outputs['out_file'] = self.inputs.moving_file.replace('.nii.gz', - '_aff.nii.gz') + moving = self.inputs.moving_file + outputs['out_file_xfm'] = fname_presuffix(moving, suffix='.aff', + use_ext=False) + outputs['out_file'] = fname_presuffix(moving, suffix='_aff') return outputs -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, - mandatory=True, position=2, argstr="%s", - desc="similarity metric") - samplingX = traits.Float(mandatory=True, position=3, argstr="%s", - desc="dist between samp points (mm)", - default_value=4) - samplingY = traits.Float(mandatory=True, position=4, argstr="%s", - desc="dist between samp points (mm)", - default_value=4) - samplingZ = traits.Float(mandatory=True, position=5, argstr="%s", - desc="dist between samp points (mm)", - 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", - 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) - - -class AffineTask(CommandLineDtitk): +class Affine(Rigid): + """Performs affine registration between two tensor volumes + + Example + ------- + + >>> from nipype.interfaces import dtitk + >>> node = dtitk.Affine() + >>> node.inputs.fixed_file = 'im1.nii' + >>> node.inputs.moving_file = 'im2.nii' + >>> node.inputs.similarity_metric = 'EDS' + >>> node.inputs.sampling_xyz = (4,4,4) + >>> node.inputs.ftol = 0.01 + >>> node.inputs.initialize_xfm = 'im_affine.aff' + >>> node.cmdline + 'dti_affine_reg im1.nii im2.nii EDS 4 4 4 0.01 im_affine.aff' + >>> 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' - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file_xfm'] = self.inputs.moving_file.replace('.nii.gz', - '.aff') - outputs['out_file'] = self.inputs.moving_file.replace('.nii.gz', - '_aff.nii.gz') - return outputs - 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") - legacy = traits.Float(desc="legacy parameter; always set to 1", - exists=True, mandatory=True, - position=3, default_value=1, argstr="%s") - n_iters = traits.Float(desc="number of iterations", - exists=True, mandatory=True, - position=4, default_value=6, argstr="%s") - ftol = traits.Float(desc="iteration for the optimization to stop", - exists=True, mandatory=True, - position=5, default_value=0.002, argstr="%s") + fixed_file = File(desc="fixed tensor volume", + exists=True, position=0, argstr="%s") + moving_file = File(desc="moving tensor volume", + exists=True, position=1, argstr="%s", copyfile=False) + mask_file = File(desc="mask", exists=True, position=2, argstr="%s") + legacy = traits.Enum(1, desc="legacy parameter; always set to 1", + usedefault=True, mandatory=True, + position=3, argstr="%d") + n_iters = traits.Int(6, desc="number of iterations", + mandatory=True, + position=4, argstr="%d", usedefault=True) + ftol = traits.Float(0.002, desc="iteration for the optimization to stop", + mandatory=True, position=5, argstr="%g", + usedefault=True) class DiffeoOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) - out_file_xfm = traits.File(exists=True) - - -class DiffeoTask(CommandLineDtitk): + out_file = File(exists=True) + out_file_xfm = File(exists=True) + + +class Diffeo(CommandLineDtitk): + """Performs diffeomorphic registration between two tensor volumes + + Example + ------- + + >>> from nipype.interfaces import dtitk + >>> node = dtitk.Diffeo() + >>> node.inputs.fixed_file = 'im1.nii' + >>> node.inputs.moving_file = 'im2.nii' + >>> node.inputs.mask_file = 'mask.nii' + >>> node.inputs.legacy = 1 + >>> node.inputs.n_iters = 6 + >>> node.inputs.ftol = 0.002 + >>> node.cmdline + 'dti_diffeomorphic_reg im1.nii im2.nii mask.nii 1 6 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' def _list_outputs(self): outputs = self.output_spec().get() - outputs['out_file_xfm'] = self.inputs.moving_file.replace( - '.nii.gz', '_diffeo.df.nii.gz') - outputs['out_file'] = self.inputs.moving_file.replace( - '.nii.gz', '_diffeo.nii.gz') + moving = self.inputs.moving_file + outputs['out_file_xfm'] = fname_presuffix(moving, suffix='_diffeo.df') + outputs['out_file'] = fname_presuffix(moving, suffix='_diffeo') return outputs 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, - position=0, argstr="-aff %s") - out_file = traits.Str(desc='output_path', exists=True, mandatory=False, - position=2, argstr="-out %s", name_source="in_df", - name_template="%s_comboaff.nii.gz") + in_df = File(desc='diffeomorphic warp file', exists=True, + argstr="-df %s", mandatory=True) + in_aff = File(desc='affine transform file', exists=True, + argstr="-aff %s", mandatory=True) + out_file = File(desc='output path', + argstr="-out %s", genfile=True) class ComposeXfmOutputSpec(TraitedSpec): - out_file = traits.File(desc='cheese', exists=True) + out_file = File(exists=True) -class ComposeXfmTask(CommandLineDtitk): +class ComposeXfm(CommandLineDtitk): """ Combines diffeomorphic and affine transforms - 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 - """ + Example + ------- + + >>> from nipype.interfaces import dtitk + >>> node = dtitk.ComposeXfm() + >>> node.inputs.in_df = 'im_warp.df.nii' + >>> node.inputs.in_aff= 'im_affine.aff' + >>> node.cmdline + 'dfRightComposeAffine -aff im_affine.aff -df im_warp.df.nii -out + im_warp_affdf.df.nii' + >>> node.run() # doctest: +SKIP + """ input_spec = ComposeXfmInputSpec output_spec = ComposeXfmOutputSpec _cmd = 'dfRightComposeAffine' def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.in_df.replace('.df.nii.gz', - '_combo.df.nii.gz') + outputs = self._outputs().get() + out_file = self.inputs.out_file + if not isdefined(out_file): + out_file = self._gen_filename('out_file') + outputs['out_file'] = os.path.abspath(out_file) return outputs + def _gen_filename(self, name): + if name != 'out_file': + return + path, base, ext = split_filename(self.inputs.in_df) + suffix = '_affdf' + if base.endswith('.df'): + suffix += '.df' + base = base[:-3] + return fname_presuffix(base, suffix=suffix + ext, use_ext=False) + + +class AffSymTensor3DVolInputSpec(CommandLineInputSpec): + in_file = File(desc='moving tensor volume', exists=True, + argstr="-in %s", mandatory=True) + out_file = File(desc='output filename', + argstr="-out %s", name_source="in_file", + name_template="%s_affxfmd", keep_extension=True) + transform = File(exists=True, argstr="-trans %s", + xor=['target', 'translation', 'euler', 'deformation'], + desc='transform to apply: specify an input transformation' + ' file; parameters input will be ignored',) + interpolation = traits.Enum('LEI', 'EI', usedefault=True, + argstr="-interp %s", + desc='Log Euclidean/Euclidean Interpolation') + reorient = traits.Enum('PPD', 'NO', 'FS', argstr='-reorient %s', + usedefault=True, desc='Reorientation strategy: ' + 'preservation of principal direction, no ' + 'reorientation, or finite strain') + target = File(exists=True, argstr="-target %s", xor=['transform'], + desc='output volume specification read from the target ' + 'volume if specified') + translation = traits.Tuple((traits.Float(), traits.Float(), + traits.Float()), + desc='translation (x,y,z) in mm', + argstr='-translation %g %g %g', + xor=['transform']) + euler = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='(theta, phi, psi) in degrees', + xor=['transform'], argstr='-euler %g %g %g') + deformation = traits.Tuple((traits.Float(),) * 6, + desc='(xx,yy,zz,xy,yz,xz)', xor=['transform'], + argstr='-deformation %g %g %g %g %g %g') + + +class AffSymTensor3DVolOutputSpec(TraitedSpec): + out_file = File(exists=True) + + +class AffSymTensor3DVol(CommandLineDtitk): + """ + Applies affine transform to a tensor volume -class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec): - in_tensor = traits.Str(desc='moving tensor', exists=True, mandatory=False, - 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, - argstr="-target %s") - out_file = traits.Str(desc='', exists=True, mandatory=False, position=3, - argstr="-out %s", name_source="in_tensor", - name_template="%s_diffeoxfmd.nii.gz") + Example + ------- + + >>> from nipype.interfaces import dtitk + >>> node = dtitk.AffSymTensor3DVol() + >>> node.inputs.in_file = 'im1.nii' + >>> node.inputs.transform = 'im_affine.aff' + >>> node.cmdline + 'affineSymTensor3DVolume -in im1.nii -interp LEI -out im1_affxfmd.nii + -reorient PPD -trans im_affine.aff' + >>> node.run() # doctest: +SKIP + """ + input_spec = AffSymTensor3DVolInputSpec + output_spec = AffSymTensor3DVolOutputSpec + _cmd = 'affineSymTensor3DVolume' -class diffeoSymTensor3DVolOutputSpec(TraitedSpec): - out_file = traits.File(desc='cheese', exists=True) +class AffScalarVolInputSpec(CommandLineInputSpec): + in_file = File(desc='moving scalar volume', exists=True, + argstr="-in %s", mandatory=True) + out_file = File(desc='output filename', + argstr="-out %s", name_source="in_file", + name_template="%s_affxfmd", keep_extension=True) + transform = File(exists=True, argstr="-trans %s", + xor=['target', 'translation', 'euler', 'deformation'], + desc='transform to apply: specify an input transformation' + ' file; parameters input will be ignored',) + interpolation = traits.Enum('trilinear', 'NN', + usedefault=True, argstr="-interp %s", + desc='trilinear or nearest neighbor' + ' interpolation') + target = File(exists=True, argstr="-target %s", xor=['transform'], + desc='output volume specification read from the target ' + 'volume if specified') + translation = traits.Tuple((traits.Float(), traits.Float(), + traits.Float()), + desc='translation (x,y,z) in mm', + argstr='-translation %g %g %g', + xor=['transform']) + euler = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='(theta, phi, psi) in degrees', + xor=['transform'], argstr='-euler %g %g %g') + deformation = traits.Tuple((traits.Float(),) * 6, + desc='(xx,yy,zz,xy,yz,xz)', xor=['transform'], + argstr='-deformation %g %g %g %g %g %g') + + +class AffScalarVolOutputSpec(TraitedSpec): + out_file = File(desc='moved volume', exists=True) + + +class AffScalarVol(CommandLineDtitk): + """ + Applies affine transform to a scalar volume + Example + ------- + + >>> from nipype.interfaces import dtitk + >>> node = dtitk.AffScalarVol() + >>> node.inputs.in_file = 'im1.nii' + >>> node.inputs.transform = 'im_affine.aff' + >>> node.cmdline + 'affineScalarVolume -in im1.nii -interp 0 -out im1_affxfmd.nii -trans + im_affine.aff' + >>> node.run() # doctest: +SKIP + """ + input_spec = AffScalarVolInputSpec + output_spec = AffScalarVolOutputSpec + _cmd = 'affineScalarVolume' -class diffeoSymTensor3DVolTask(CommandLineDtitk): + def _format_arg(self, name, spec, value): + if name == 'interpolation': + value = {'trilinear': 0, 'NN': 1}[value] + return super(AffScalarVol, self)._format_arg(name, spec, value) + + +class DiffeoSymTensor3DVolInputSpec(CommandLineInputSpec): + in_file = File(desc='moving tensor volume', exists=True, + argstr="-in %s", mandatory=True) + out_file = File(desc='output filename', + argstr="-out %s", name_source="in_file", + name_template="%s_diffeoxfmd", keep_extension=True) + transform = File(exists=True, argstr="-trans %s", + mandatory=True, desc='transform to apply') + df = traits.Str('FD', argstr="-df %s", usedefault=True) + interpolation = traits.Enum('LEI', 'EI', usedefault=True, + argstr="-interp %s", + desc='Log Euclidean/Euclidean Interpolation') + reorient = traits.Enum('PPD', 'FS', argstr='-reorient %s', + usedefault=True, desc='Reorientation strategy: ' + 'preservation of principal direction or finite ' + 'strain') + target = File(exists=True, argstr="-target %s", xor=['voxel_size'], + desc='output volume specification read from the target ' + 'volume if specified') + voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='xyz voxel size (superseded by target)', + argstr="-vsize %g %g %g", xor=['target']) + flip = traits.Tuple((traits.Int(), traits.Int(), traits.Int()), + argstr="-flip %d %d %d") + resampling_type = traits.Enum('backward', 'forward', + desc='use backward or forward resampling', + argstr="-type %s") + + +class DiffeoSymTensor3DVolOutputSpec(TraitedSpec): + out_file = File(exists=True) + + +class DiffeoSymTensor3DVol(CommandLineDtitk): """ Applies diffeomorphic transform to a tensor volume - 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 - """ + Example + ------- + + >>> from nipype.interfaces import dtitk + >>> node = dtitk.DiffeoSymTensor3DVol() + >>> node.inputs.in_file = 'im1.nii' + >>> node.inputs.transform = 'im_warp.df.nii' + >>> node.cmdline + 'deformationSymTensor3DVolume -df FD -in im1.nii -interp LEI -out + im1_diffeoxfmd.nii -reorient PPD -trans im_warp.df.nii' + >>> node.run() # doctest: +SKIP + """ - input_spec = diffeoSymTensor3DVolInputSpec - output_spec = diffeoSymTensor3DVolOutputSpec + 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 + def _format_arg(self, name, spec, value): + if name == 'resampling_type': + value = {'forward': 0, 'backward': 1}[value] + return super(DiffeoSymTensor3DVol, self)._format_arg(name, spec, value) + + +class DiffeoScalarVolInputSpec(CommandLineInputSpec): + in_file = File(desc='moving scalar volume', exists=True, + argstr="-in %s", mandatory=True) + out_file = File(desc='output filename', + argstr="-out %s", name_source="in_file", + name_template="%s_diffeoxfmd", keep_extension=True) + transform = File(exists=True, argstr="-trans %s", + mandatory=True, desc='transform to apply') + target = File(exists=True, argstr="-target %s", xor=['voxel_size'], + desc='output volume specification read from the target ' + 'volume if specified') + voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='xyz voxel size (superseded by target)', + argstr="-vsize %g %g %g", xor=['target']) + flip = traits.Tuple((traits.Int(), traits.Int(), traits.Int()), + argstr="-flip %d %d %d") + resampling_type = traits.Enum('backward', 'forward', + desc='use backward or forward resampling', + argstr="-type %s") + interpolation = traits.Enum('trilinear', 'NN', + desc='trilinear, or nearest neighbor', + argstr="-interp %s", + usedefault=True) + + +class DiffeoScalarVolOutputSpec(TraitedSpec): + out_file = File(desc='moved volume', exists=True) + + +class DiffeoScalarVol(CommandLineDtitk): + """ + Applies diffeomorphic transform to a scalar volume + Example + ------- + + >>> from nipype.interfaces import dtitk + >>> node = dtitk.DiffeoScalarVol() + >>> node.inputs.in_file = 'im1.nii' + >>> node.inputs.transform = 'im_warp.df.nii' + >>> node.cmdline + 'deformationScalarVolume -in im1.nii -interp 0 -out im1_diffeoxfmd.nii + -trans im_warp.df.nii' + >>> node.run() # doctest: +SKIP + """ -class affSymTensor3DVolInputSpec(CommandLineInputSpec): - in_tensor = traits.Str(desc='moving tensor', exists=True, mandatory=False, - 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, - argstr="-target %s") - out_file = traits.Str(desc='', exists=True, mandatory=False, position=3, - argstr="-out %s", name_source="in_tensor", - name_template="%s_affxfmd.nii.gz") + input_spec = DiffeoScalarVolInputSpec + output_spec = DiffeoScalarVolOutputSpec + _cmd = 'deformationScalarVolume' + def _format_arg(self, name, spec, value): + if name == 'resampling_type': + value = {'forward': 0, 'backward': 1}[value] + elif name == 'interpolation': + value = {'trilinear': 0, 'NN': 1}[value] + return super(DiffeoScalarVol, self)._format_arg(name, spec, value) -class affSymTensor3DVolOutputSpec(TraitedSpec): - out_file = traits.File(desc='cheese', exists=True) +class RigidTask(DTITKRenameMixin, Rigid): + pass -class affSymTensor3DVolTask(CommandLineDtitk): - """ - Applies affine transform to a tensor volume - 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 - """ - input_spec = affSymTensor3DVolInputSpec - output_spec = affSymTensor3DVolOutputSpec - _cmd = 'affineSymTensor3DVolume' +class AffineTask(DTITKRenameMixin, Affine): + pass - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = os.path.abspath(self.inputs.out_file) - return outputs +class DiffeoTask(DTITKRenameMixin, Diffeo): + pass -class affScalarVolInputSpec(CommandLineInputSpec): - in_volume = traits.Str(desc='moving volume', exists=True, mandatory=False, - 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='', position=2, argstr="-target %s") - out_file = traits.Str(desc='', mandatory=False, position=3, - argstr="-out %s", name_source="in_volume", - name_template="%s_affxfmd.nii.gz") +class ComposeXfmTask(DTITKRenameMixin, ComposeXfm): + pass -class affScalarVolOutputSpec(TraitedSpec): - out_file = traits.File(desc='moved volume', exists=True) +class affScalarVolTask(DTITKRenameMixin, AffScalarVol): + pass -class affScalarVolTask(CommandLineDtitk): - """ - Applies affine transform to a scalar volume - 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 - """ - input_spec = affScalarVolInputSpec - output_spec = affScalarVolOutputSpec - _cmd = 'affineScalarVolume' +class affSymTensor3DVolTask(DTITKRenameMixin, AffSymTensor3DVol): + pass - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = os.path.abspath(self.inputs.out_file) - return outputs +class diffeoScalarVolTask(DTITKRenameMixin, DiffeoScalarVol): + pass -class diffeoScalarVolInputSpec(CommandLineInputSpec): - in_volume = traits.Str(desc='moving volume', exists=True, mandatory=False, - position=0, argstr="-in %s") - in_xfm = traits.Str(desc='transform to apply', exists=True, - mandatory=False, - position=2, argstr="-trans %s") - in_target = traits.Str(desc='', exists=True, mandatory=False, 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, - argstr="-vsize %s") - in_flip = traits.Str(desc='', exists=True, mandatory=False, position=5, - argstr="-flip %s") - in_type = traits.Str(desc='', exists=True, mandatory=False, position=6, - argstr="-type %s") - in_interp = traits.Str(desc='0 trilin, 1 NN', exists=True, mandatory=False, - position=7, argstr="-interp %s") - - -class diffeoScalarVolOutputSpec(TraitedSpec): - out_file = traits.File(desc='moved volume', exists=True) - - -class diffeoScalarVolTask(CommandLineDtitk): - """ - Applies diffeomorphic transform to a scalar volume - 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 - """ - - 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 +class diffeoSymTensor3DVolTask(DTITKRenameMixin, DiffeoSymTensor3DVol): + pass diff --git a/nipype/interfaces/dtitk/tests/test_auto_Affine.py b/nipype/interfaces/dtitk/tests/test_auto_Affine.py new file mode 100644 index 0000000000..8a80801ba9 --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_Affine.py @@ -0,0 +1,72 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..registration import Affine + + +def test_Affine_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + fixed_file=dict( + argstr='%s', + copyfile=False, + mandatory=True, + position=0, + ), + ftol=dict( + argstr='%g', + mandatory=True, + position=4, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + initialize_xfm=dict( + argstr='%s', + copyfile=True, + position=5, + ), + moving_file=dict( + argstr='%s', + copyfile=False, + mandatory=True, + position=1, + ), + sampling_xyz=dict( + argstr='%g %g %g', + mandatory=True, + position=3, + usedefault=True, + ), + similarity_metric=dict( + argstr='%s', + mandatory=True, + position=2, + usedefault=True, + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + ) + inputs = Affine.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(inputs.traits()[key], metakey) == value +def test_Affine_outputs(): + output_map = dict( + out_file=dict(), + out_file_xfm=dict(), + ) + outputs = Affine.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_AffineTask.py b/nipype/interfaces/dtitk/tests/test_auto_AffineTask.py index cff7d1c0d1..c7de1d31c8 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_AffineTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_AffineTask.py @@ -12,56 +12,48 @@ def test_AffineTask_inputs(): ), fixed_file=dict( argstr='%s', - exists=True, + copyfile=False, mandatory=True, position=0, ), ftol=dict( - argstr='%s', + argstr='%g', mandatory=True, - position=6, + position=4, + usedefault=True, ), ignore_exception=dict( deprecated='1.0.0', nohash=True, usedefault=True, ), + initialize_xfm=dict( + argstr='%s', + copyfile=True, + position=5, + ), moving_file=dict( argstr='%s', - exists=True, + copyfile=False, mandatory=True, position=1, ), - samplingX=dict( - argstr='%s', + sampling_xyz=dict( + argstr='%g %g %g', mandatory=True, position=3, - ), - samplingY=dict( - argstr='%s', - mandatory=True, - position=4, - ), - samplingZ=dict( - argstr='%s', - mandatory=True, - position=5, + usedefault=True, ), similarity_metric=dict( argstr='%s', - exists=True, mandatory=True, position=2, + usedefault=True, ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), - useInTrans=dict( - argstr='%s', - mandatory=False, - position=7, - ), ) inputs = AffineTask.input_spec() diff --git a/nipype/interfaces/dtitk/tests/test_auto_BinThresh.py b/nipype/interfaces/dtitk/tests/test_auto_BinThresh.py new file mode 100644 index 0000000000..1004dd42cb --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_BinThresh.py @@ -0,0 +1,68 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..utils import BinThresh + + +def test_BinThresh_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='%s', + mandatory=True, + position=0, + ), + inside_value=dict( + argstr='%g', + mandatory=True, + position=4, + usedefault=True, + ), + lower_bound=dict( + argstr='%g', + mandatory=True, + position=2, + ), + out_file=dict( + argstr='%s', + keep_extension=True, + name_source='in_file', + name_template='%s_thrbin', + position=1, + ), + outside_value=dict( + argstr='%g', + mandatory=True, + position=5, + usedefault=True, + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + upper_bound=dict( + argstr='%g', + mandatory=True, + position=3, + ), + ) + inputs = BinThresh.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(inputs.traits()[key], metakey) == value +def test_BinThresh_outputs(): + output_map = dict(out_file=dict(), ) + outputs = BinThresh.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_BinThreshTask.py b/nipype/interfaces/dtitk/tests/test_auto_BinThreshTASK.py similarity index 66% rename from nipype/interfaces/dtitk/tests/test_auto_BinThreshTask.py rename to nipype/interfaces/dtitk/tests/test_auto_BinThreshTASK.py index 028a820bae..1f49ddce43 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_BinThreshTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_BinThreshTASK.py @@ -17,26 +17,42 @@ def test_BinThreshTask_inputs(): ), in_file=dict( argstr='%s', - exists=True, - mandatory=False, + mandatory=True, position=0, ), - in_numbers=dict( - argstr='%s', - exists=True, - mandatory=False, + inside_value=dict( + argstr='%g', + mandatory=True, + position=4, + usedefault=True, + ), + lower_bound=dict( + argstr='%g', + mandatory=True, position=2, ), out_file=dict( argstr='%s', - exists=True, - mandatory=False, + keep_extension=True, + name_source='in_file', + name_template='%s_thrbin', position=1, ), + outside_value=dict( + argstr='%g', + mandatory=True, + position=5, + usedefault=True, + ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), + upper_bound=dict( + argstr='%g', + mandatory=True, + position=3, + ), ) inputs = BinThreshTask.input_spec() diff --git a/nipype/interfaces/dtitk/tests/test_auto_ComposeXfm.py b/nipype/interfaces/dtitk/tests/test_auto_ComposeXfm.py new file mode 100644 index 0000000000..9ee4c44650 --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_ComposeXfm.py @@ -0,0 +1,46 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..registration import ComposeXfm + + +def test_ComposeXfm_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_aff=dict( + argstr='-aff %s', + mandatory=True, + ), + in_df=dict( + argstr='-df %s', + mandatory=True, + ), + out_file=dict( + argstr='-out %s', + genfile=True, + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + ) + inputs = ComposeXfm.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(inputs.traits()[key], metakey) == value +def test_ComposeXfm_outputs(): + output_map = dict(out_file=dict(), ) + outputs = ComposeXfm.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_ComposeXfmTask.py b/nipype/interfaces/dtitk/tests/test_auto_ComposeXfmTask.py index ec5d2153ea..0166be1c37 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_ComposeXfmTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_ComposeXfmTask.py @@ -17,23 +17,15 @@ def test_ComposeXfmTask_inputs(): ), in_aff=dict( argstr='-aff %s', - exists=True, - mandatory=False, - position=0, + mandatory=True, ), in_df=dict( argstr='-df %s', - exists=True, - mandatory=False, - position=1, + mandatory=True, ), out_file=dict( argstr='-out %s', - exists=True, - mandatory=False, - name_source='in_df', - name_template='%s_comboaff.nii.gz', - position=2, + genfile=True, ), terminal_output=dict( deprecated='1.0.0', diff --git a/nipype/interfaces/dtitk/tests/test_auto_Diffeo.py b/nipype/interfaces/dtitk/tests/test_auto_Diffeo.py new file mode 100644 index 0000000000..a389d22bf9 --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_Diffeo.py @@ -0,0 +1,68 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..registration import Diffeo + + +def test_Diffeo_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + fixed_file=dict( + argstr='%s', + position=0, + ), + ftol=dict( + argstr='%g', + mandatory=True, + position=5, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + legacy=dict( + argstr='%d', + mandatory=True, + position=3, + usedefault=True, + ), + mask_file=dict( + argstr='%s', + position=2, + ), + moving_file=dict( + argstr='%s', + copyfile=False, + position=1, + ), + n_iters=dict( + argstr='%d', + mandatory=True, + position=4, + usedefault=True, + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + ) + inputs = Diffeo.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(inputs.traits()[key], metakey) == value +def test_Diffeo_outputs(): + output_map = dict( + out_file=dict(), + out_file_xfm=dict(), + ) + outputs = Diffeo.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_DiffeoTask.py b/nipype/interfaces/dtitk/tests/test_auto_DiffeoTask.py index a0bc0a580b..0129f7d70c 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_DiffeoTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_DiffeoTask.py @@ -12,15 +12,13 @@ def test_DiffeoTask_inputs(): ), fixed_file=dict( argstr='%s', - exists=True, - mandatory=False, position=0, ), ftol=dict( - argstr='%s', - exists=True, + argstr='%g', mandatory=True, position=5, + usedefault=True, ), ignore_exception=dict( deprecated='1.0.0', @@ -28,28 +26,25 @@ def test_DiffeoTask_inputs(): usedefault=True, ), legacy=dict( - argstr='%s', - exists=True, + argstr='%d', mandatory=True, position=3, + usedefault=True, ), - mask=dict( + mask_file=dict( argstr='%s', - exists=True, - mandatory=False, position=2, ), moving_file=dict( argstr='%s', - exists=True, - mandatory=False, + copyfile=False, position=1, ), n_iters=dict( - argstr='%s', - exists=True, + argstr='%d', mandatory=True, position=4, + usedefault=True, ), terminal_output=dict( deprecated='1.0.0', diff --git a/nipype/interfaces/dtitk/tests/test_auto_Rigid.py b/nipype/interfaces/dtitk/tests/test_auto_Rigid.py new file mode 100644 index 0000000000..8ffc827e61 --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_Rigid.py @@ -0,0 +1,72 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..registration import Rigid + + +def test_Rigid_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + fixed_file=dict( + argstr='%s', + copyfile=False, + mandatory=True, + position=0, + ), + ftol=dict( + argstr='%g', + mandatory=True, + position=4, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + initialize_xfm=dict( + argstr='%s', + copyfile=True, + position=5, + ), + moving_file=dict( + argstr='%s', + copyfile=False, + mandatory=True, + position=1, + ), + sampling_xyz=dict( + argstr='%g %g %g', + mandatory=True, + position=3, + usedefault=True, + ), + similarity_metric=dict( + argstr='%s', + mandatory=True, + position=2, + usedefault=True, + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + ) + inputs = Rigid.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(inputs.traits()[key], metakey) == value +def test_Rigid_outputs(): + output_map = dict( + out_file=dict(), + out_file_xfm=dict(), + ) + outputs = Rigid.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_RigidTask.py b/nipype/interfaces/dtitk/tests/test_auto_RigidTask.py index fbe65d92f2..a2747184da 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_RigidTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_RigidTask.py @@ -12,56 +12,48 @@ def test_RigidTask_inputs(): ), fixed_file=dict( argstr='%s', - exists=True, + copyfile=False, mandatory=True, position=0, ), ftol=dict( - argstr='%s', + argstr='%g', mandatory=True, - position=6, + position=4, + usedefault=True, ), ignore_exception=dict( deprecated='1.0.0', nohash=True, usedefault=True, ), + initialize_xfm=dict( + argstr='%s', + copyfile=True, + position=5, + ), moving_file=dict( argstr='%s', - exists=True, + copyfile=False, mandatory=True, position=1, ), - samplingX=dict( - argstr='%s', + sampling_xyz=dict( + argstr='%g %g %g', mandatory=True, position=3, - ), - samplingY=dict( - argstr='%s', - mandatory=True, - position=4, - ), - samplingZ=dict( - argstr='%s', - mandatory=True, - position=5, + usedefault=True, ), similarity_metric=dict( argstr='%s', - exists=True, mandatory=True, position=2, + usedefault=True, ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), - useInTrans=dict( - argstr='%s', - mandatory=False, - position=7, - ), ) inputs = RigidTask.input_spec() diff --git a/nipype/interfaces/dtitk/tests/test_auto_SVAdjustVoxSp.py b/nipype/interfaces/dtitk/tests/test_auto_SVAdjustVoxSp.py new file mode 100644 index 0000000000..3fefd1044d --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_SVAdjustVoxSp.py @@ -0,0 +1,56 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..utils import SVAdjustVoxSp + + +def test_SVAdjustVoxSp_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='-in %s', + mandatory=True, + ), + origin=dict( + argstr='-origin %g %g %g', + xor=['target_file'], + ), + out_file=dict( + argstr='-out %s', + keep_extension=True, + name_source='in_file', + name_template='%s_avs', + ), + target_file=dict( + argstr='-target %s', + xor=['voxel_size', 'origin'], + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target_file'], + ), + ) + inputs = SVAdjustVoxSp.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(inputs.traits()[key], metakey) == value +def test_SVAdjustVoxSp_outputs(): + output_map = dict(out_file=dict(), ) + outputs = SVAdjustVoxSp.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_SVAdjustVoxSpTask.py b/nipype/interfaces/dtitk/tests/test_auto_SVAdjustVoxSpTask.py index d60b203ffa..88f328d80b 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_SVAdjustVoxSpTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_SVAdjustVoxSpTask.py @@ -17,40 +17,30 @@ def test_SVAdjustVoxSpTask_inputs(): ), in_file=dict( argstr='-in %s', - exists=True, mandatory=True, - position=0, - ), - in_target=dict( - argstr='-target %s', - exists=True, - mandatory=False, - position=2, - ), - in_voxsz=dict( - argstr='-vsize %s', - exists=True, - mandatory=False, - position=3, ), origin=dict( - argstr='-origin %s', - exists=True, - mandatory=False, - position=4, + argstr='-origin %g %g %g', + xor=['target_file'], ), out_file=dict( argstr='-out %s', - exists=True, - mandatory=False, + keep_extension=True, name_source='in_file', - name_template='%s_origmvd.nii.gz', - position=1, + name_template='%s_avs', + ), + target_file=dict( + argstr='-target %s', + xor=['voxel_size', 'origin'], ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target_file'], + ), ) inputs = SVAdjustVoxSpTask.input_spec() diff --git a/nipype/interfaces/dtitk/tests/test_auto_SVResample.py b/nipype/interfaces/dtitk/tests/test_auto_SVResample.py new file mode 100644 index 0000000000..e11f4e111e --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_SVResample.py @@ -0,0 +1,61 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..utils import SVResample + + +def test_SVResample_inputs(): + input_map = dict( + align=dict(argstr='-align %s', ), + args=dict(argstr='%s', ), + array_size=dict( + argstr='-size %d %d %d', + xor=['target_file'], + ), + environ=dict( + nohash=True, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='-in %s', + mandatory=True, + ), + origin=dict( + argstr='-origin %g %g %g', + xor=['target_file'], + ), + out_file=dict( + argstr='-out %s', + keep_extension=True, + name_source='in_file', + name_template='%s_resampled', + ), + target_file=dict( + argstr='-target %s', + xor=['array_size', 'voxel_size', 'origin'], + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target_file'], + ), + ) + inputs = SVResample.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(inputs.traits()[key], metakey) == value +def test_SVResample_outputs(): + output_map = dict(out_file=dict(), ) + outputs = SVResample.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_SVResampleTask.py b/nipype/interfaces/dtitk/tests/test_auto_SVResampleTask.py index 64f4cadb60..8058c94435 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_SVResampleTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_SVResampleTask.py @@ -5,7 +5,12 @@ def test_SVResampleTask_inputs(): input_map = dict( + align=dict(argstr='-align %s', ), args=dict(argstr='%s', ), + array_size=dict( + argstr='-size %d %d %d', + xor=['target_file'], + ), environ=dict( nohash=True, usedefault=True, @@ -15,36 +20,32 @@ def test_SVResampleTask_inputs(): nohash=True, usedefault=True, ), - in_arraysz=dict( - argstr='-size %s', - exists=True, - mandatory=False, - position=1, - ), in_file=dict( argstr='-in %s', - exists=True, mandatory=True, - position=0, ), - in_voxsz=dict( - argstr='-vsize %s', - exists=True, - mandatory=False, - position=2, + origin=dict( + argstr='-origin %g %g %g', + xor=['target_file'], ), out_file=dict( argstr='-out %s', - exists=True, - mandatory=False, + keep_extension=True, name_source='in_file', - name_template='%s_resampled.nii.gz', - position=3, + name_template='%s_resampled', + ), + target_file=dict( + argstr='-target %s', + xor=['array_size', 'voxel_size', 'origin'], ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target_file'], + ), ) inputs = SVResampleTask.input_spec() diff --git a/nipype/interfaces/dtitk/tests/test_auto_TVAdjustOriginTask.py b/nipype/interfaces/dtitk/tests/test_auto_TVAdjustOriginTask.py index bad6039007..a111687d26 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_TVAdjustOriginTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_TVAdjustOriginTask.py @@ -18,23 +18,29 @@ def test_TVAdjustOriginTask_inputs(): in_file=dict( argstr='-in %s', mandatory=True, - position=0, ), origin=dict( - argstr='-origin %s', - exists=True, - mandatory=False, - position=4, + argstr='-origin %g %g %g', + xor=['target_file'], ), out_file=dict( argstr='-out %s', - genfile=True, - position=1, + keep_extension=True, + name_source='in_file', + name_template='%s_avs', + ), + target_file=dict( + argstr='-target %s', + xor=['voxel_size', 'origin'], ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target_file'], + ), ) inputs = TVAdjustOriginTask.input_spec() @@ -42,7 +48,7 @@ def test_TVAdjustOriginTask_inputs(): for metakey, value in list(metadata.items()): assert getattr(inputs.traits()[key], metakey) == value def test_TVAdjustOriginTask_outputs(): - output_map = dict(out_file=dict(exists=True, ), ) + output_map = dict(out_file=dict(), ) outputs = TVAdjustOriginTask.output_spec() for key, metadata in list(output_map.items()): diff --git a/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSp.py b/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSp.py new file mode 100644 index 0000000000..34d8c2bf4f --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSp.py @@ -0,0 +1,56 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..utils import TVAdjustVoxSp + + +def test_TVAdjustVoxSp_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='-in %s', + mandatory=True, + ), + origin=dict( + argstr='-origin %g %g %g', + xor=['target_file'], + ), + out_file=dict( + argstr='-out %s', + keep_extension=True, + name_source='in_file', + name_template='%s_avs', + ), + target_file=dict( + argstr='-target %s', + xor=['voxel_size', 'origin'], + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target_file'], + ), + ) + inputs = TVAdjustVoxSp.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(inputs.traits()[key], metakey) == value +def test_TVAdjustVoxSp_outputs(): + output_map = dict(out_file=dict(), ) + outputs = TVAdjustVoxSp.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSpTask.py b/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSpTask.py index 2da57d8862..7d4c3d6e7b 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSpTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_TVAdjustVoxSpTask.py @@ -18,34 +18,28 @@ def test_TVAdjustVoxSpTask_inputs(): in_file=dict( argstr='-in %s', mandatory=True, - position=0, ), origin=dict( - argstr='-origin %s', - exists=True, - mandatory=False, - position=4, + argstr='-origin %g %g %g', + xor=['target_file'], ), out_file=dict( argstr='-out %s', - genfile=True, - position=1, + keep_extension=True, + name_source='in_file', + name_template='%s_avs', ), - target=dict( + target_file=dict( argstr='-target %s', - exists=True, - mandatory=False, - position=2, + xor=['voxel_size', 'origin'], ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), - vsize=dict( - argstr='-vsize %s', - exists=True, - mandatory=False, - position=3, + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target_file'], ), ) inputs = TVAdjustVoxSpTask.input_spec() @@ -54,7 +48,7 @@ def test_TVAdjustVoxSpTask_inputs(): for metakey, value in list(metadata.items()): assert getattr(inputs.traits()[key], metakey) == value def test_TVAdjustVoxSpTask_outputs(): - output_map = dict(out_file=dict(exists=True, ), ) + output_map = dict(out_file=dict(), ) outputs = TVAdjustVoxSpTask.output_spec() for key, metadata in list(output_map.items()): diff --git a/nipype/interfaces/dtitk/tests/test_auto_TVResample.py b/nipype/interfaces/dtitk/tests/test_auto_TVResample.py new file mode 100644 index 0000000000..6a1a01a594 --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_TVResample.py @@ -0,0 +1,62 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..utils import TVResample + + +def test_TVResample_inputs(): + input_map = dict( + align=dict(argstr='-align %s', ), + args=dict(argstr='%s', ), + array_size=dict( + argstr='-size %d %d %d', + xor=['target_file'], + ), + environ=dict( + nohash=True, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='-in %s', + mandatory=True, + ), + interpolation=dict(argstr='-interp %s', ), + origin=dict( + argstr='-origin %g %g %g', + xor=['target_file'], + ), + out_file=dict( + argstr='-out %s', + keep_extension=True, + name_source='in_file', + name_template='%s_resampled', + ), + target_file=dict( + argstr='-target %s', + xor=['array_size', 'voxel_size', 'origin'], + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target_file'], + ), + ) + inputs = TVResample.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(inputs.traits()[key], metakey) == value +def test_TVResample_outputs(): + output_map = dict(out_file=dict(), ) + outputs = TVResample.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_TVResampleTask.py b/nipype/interfaces/dtitk/tests/test_auto_TVResampleTask.py index 044e8f67d2..43ae1cd842 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_TVResampleTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_TVResampleTask.py @@ -5,7 +5,12 @@ def test_TVResampleTask_inputs(): input_map = dict( + align=dict(argstr='-align %s', ), args=dict(argstr='%s', ), + array_size=dict( + argstr='-size %d %d %d', + xor=['target_file'], + ), environ=dict( nohash=True, usedefault=True, @@ -15,36 +20,33 @@ def test_TVResampleTask_inputs(): nohash=True, usedefault=True, ), - in_arraysz=dict( - argstr='-size %s', - exists=True, - mandatory=False, - position=1, - ), in_file=dict( argstr='-in %s', - exists=True, mandatory=True, - position=0, ), - in_voxsz=dict( - argstr='-vsize %s', - exists=True, - mandatory=False, - position=2, + interpolation=dict(argstr='-interp %s', ), + origin=dict( + argstr='-origin %g %g %g', + xor=['target_file'], ), out_file=dict( argstr='-out %s', - exists=True, - mandatory=False, + keep_extension=True, name_source='in_file', - name_template='%s_resampled.nii.gz', - position=3, + name_template='%s_resampled', + ), + target_file=dict( + argstr='-target %s', + xor=['array_size', 'voxel_size', 'origin'], ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target_file'], + ), ) inputs = TVResampleTask.input_spec() diff --git a/nipype/interfaces/dtitk/tests/test_auto_TVtool.py b/nipype/interfaces/dtitk/tests/test_auto_TVtool.py new file mode 100644 index 0000000000..a1eceb7549 --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_TVtool.py @@ -0,0 +1,43 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..utils import TVtool + + +def test_TVtool_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='-in %s', + mandatory=True, + ), + in_flag=dict(argstr='-%s', ), + out_file=dict( + argstr='-out %s', + genfile=True, + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + ) + inputs = TVtool.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(inputs.traits()[key], metakey) == value +def test_TVtool_outputs(): + output_map = dict(out_file=dict(), ) + outputs = TVtool.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_TVtoolTask.py b/nipype/interfaces/dtitk/tests/test_auto_TVtoolTask.py index 8fb0ce055a..cebbdc96a7 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_TVtoolTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_TVtoolTask.py @@ -17,15 +17,12 @@ def test_TVtoolTask_inputs(): ), in_file=dict( argstr='-in %s', - exists=True, - mandatory=False, - position=0, + mandatory=True, ), - in_flag=dict( - argstr='-%s', - exists=True, - mandatory=False, - position=1, + in_flag=dict(argstr='-%s', ), + out_file=dict( + argstr='-out %s', + genfile=True, ), terminal_output=dict( deprecated='1.0.0', diff --git a/nipype/interfaces/dtitk/tests/test_auto_affScalarVol.py b/nipype/interfaces/dtitk/tests/test_auto_affScalarVol.py new file mode 100644 index 0000000000..b9c01c4933 --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_affScalarVol.py @@ -0,0 +1,68 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..registration import AffScalarVol + + +def test_AffScalarVol_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + deformation=dict( + argstr='-deformation %g %g %g %g %g %g', + xor=['transform'], + ), + environ=dict( + nohash=True, + usedefault=True, + ), + euler=dict( + argstr='-euler %g %g %g', + xor=['transform'], + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='-in %s', + mandatory=True, + ), + interpolation=dict( + argstr='-interp %s', + usedefault=True, + ), + out_file=dict( + argstr='-out %s', + keep_extension=True, + name_source='in_file', + name_template='%s_affxfmd', + ), + target=dict( + argstr='-target %s', + xor=['transform'], + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + transform=dict( + argstr='-trans %s', + xor=['target', 'translation', 'euler', 'deformation'], + ), + translation=dict( + argstr='-translation %g %g %g', + xor=['transform'], + ), + ) + inputs = AffScalarVol.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(inputs.traits()[key], metakey) == value +def test_AffScalarVol_outputs(): + output_map = dict(out_file=dict(), ) + outputs = AffScalarVol.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_affScalarVolTask.py b/nipype/interfaces/dtitk/tests/test_auto_affScalarVolTask.py index 02d22b1820..e0d45372c2 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_affScalarVolTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_affScalarVolTask.py @@ -6,42 +6,53 @@ def test_affScalarVolTask_inputs(): input_map = dict( args=dict(argstr='%s', ), + deformation=dict( + argstr='-deformation %g %g %g %g %g %g', + xor=['transform'], + ), environ=dict( nohash=True, usedefault=True, ), + euler=dict( + argstr='-euler %g %g %g', + xor=['transform'], + ), ignore_exception=dict( deprecated='1.0.0', nohash=True, usedefault=True, ), - in_target=dict( - argstr='-target %s', - position=2, - ), - in_volume=dict( + in_file=dict( argstr='-in %s', - exists=True, - mandatory=False, - position=0, + mandatory=True, ), - in_xfm=dict( - argstr='-trans %s', - exists=True, - mandatory=False, - position=1, + interpolation=dict( + argstr='-interp %s', + usedefault=True, ), out_file=dict( argstr='-out %s', - mandatory=False, - name_source='in_volume', - name_template='%s_affxfmd.nii.gz', - position=3, + keep_extension=True, + name_source='in_file', + name_template='%s_affxfmd', + ), + target=dict( + argstr='-target %s', + xor=['transform'], ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), + transform=dict( + argstr='-trans %s', + xor=['target', 'translation', 'euler', 'deformation'], + ), + translation=dict( + argstr='-translation %g %g %g', + xor=['transform'], + ), ) inputs = affScalarVolTask.input_spec() diff --git a/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVol.py b/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVol.py new file mode 100644 index 0000000000..8004a09add --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVol.py @@ -0,0 +1,72 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..registration import AffSymTensor3DVol + + +def test_AffSymTensor3DVol_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + deformation=dict( + argstr='-deformation %g %g %g %g %g %g', + xor=['transform'], + ), + environ=dict( + nohash=True, + usedefault=True, + ), + euler=dict( + argstr='-euler %g %g %g', + xor=['transform'], + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='-in %s', + mandatory=True, + ), + interpolation=dict( + argstr='-interp %s', + usedefault=True, + ), + out_file=dict( + argstr='-out %s', + keep_extension=True, + name_source='in_file', + name_template='%s_affxfmd', + ), + reorient=dict( + argstr='-reorient %s', + usedefault=True, + ), + target=dict( + argstr='-target %s', + xor=['transform'], + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + transform=dict( + argstr='-trans %s', + xor=['target', 'translation', 'euler', 'deformation'], + ), + translation=dict( + argstr='-translation %g %g %g', + xor=['transform'], + ), + ) + inputs = AffSymTensor3DVol.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(inputs.traits()[key], metakey) == value +def test_AffSymTensor3DVol_outputs(): + output_map = dict(out_file=dict(), ) + outputs = AffSymTensor3DVol.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVolTask.py b/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVolTask.py index 40198fa9e7..9b9502a4d7 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVolTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_affSymTensor3DVolTask.py @@ -6,45 +6,57 @@ def test_affSymTensor3DVolTask_inputs(): input_map = dict( args=dict(argstr='%s', ), + deformation=dict( + argstr='-deformation %g %g %g %g %g %g', + xor=['transform'], + ), environ=dict( nohash=True, usedefault=True, ), + euler=dict( + argstr='-euler %g %g %g', + xor=['transform'], + ), ignore_exception=dict( deprecated='1.0.0', nohash=True, usedefault=True, ), - in_target=dict( - argstr='-target %s', - exists=True, - mandatory=False, - position=2, - ), - in_tensor=dict( + in_file=dict( argstr='-in %s', - exists=True, - mandatory=False, - position=0, + mandatory=True, ), - in_xfm=dict( - argstr='-trans %s', - exists=True, - mandatory=False, - position=1, + interpolation=dict( + argstr='-interp %s', + usedefault=True, ), out_file=dict( argstr='-out %s', - exists=True, - mandatory=False, - name_source='in_tensor', - name_template='%s_affxfmd.nii.gz', - position=3, + keep_extension=True, + name_source='in_file', + name_template='%s_affxfmd', + ), + reorient=dict( + argstr='-reorient %s', + usedefault=True, + ), + target=dict( + argstr='-target %s', + xor=['transform'], ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), + transform=dict( + argstr='-trans %s', + xor=['target', 'translation', 'euler', 'deformation'], + ), + translation=dict( + argstr='-translation %g %g %g', + xor=['transform'], + ), ) inputs = affSymTensor3DVolTask.input_spec() diff --git a/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVol.py b/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVol.py new file mode 100644 index 0000000000..86512dfa26 --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVol.py @@ -0,0 +1,62 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..registration import DiffeoScalarVol + + +def test_DiffeoScalarVol_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + flip=dict(argstr='-flip %d %d %d', ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='-in %s', + mandatory=True, + ), + interpolation=dict( + argstr='-interp %s', + usedefault=True, + ), + out_file=dict( + argstr='-out %s', + keep_extension=True, + name_source='in_file', + name_template='%s_diffeoxfmd', + ), + resampling_type=dict(argstr='-type %s', ), + target=dict( + argstr='-target %s', + xor=['voxel_size'], + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + transform=dict( + argstr='-trans %s', + mandatory=True, + ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target'], + ), + ) + inputs = DiffeoScalarVol.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(inputs.traits()[key], metakey) == value +def test_DiffeoScalarVol_outputs(): + output_map = dict(out_file=dict(), ) + outputs = DiffeoScalarVol.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVolTask.py b/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVolTask.py index 5b02f34984..b3ef9827a6 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVolTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_diffeoScalarVolTask.py @@ -10,63 +10,43 @@ def test_diffeoScalarVolTask_inputs(): nohash=True, usedefault=True, ), + flip=dict(argstr='-flip %d %d %d', ), ignore_exception=dict( deprecated='1.0.0', nohash=True, usedefault=True, ), - in_flip=dict( - argstr='-flip %s', - exists=True, - mandatory=False, - position=5, - ), - in_interp=dict( - argstr='-interp %s', - exists=True, - mandatory=False, - position=7, - ), - in_target=dict( - argstr='-target %s', - exists=True, - mandatory=False, - position=3, - ), - in_type=dict( - argstr='-type %s', - exists=True, - mandatory=False, - position=6, - ), - in_volume=dict( + in_file=dict( argstr='-in %s', - exists=True, - mandatory=False, - position=0, + mandatory=True, ), - in_vsize=dict( - argstr='-vsize %s', - exists=True, - mandatory=False, - position=4, - ), - in_xfm=dict( - argstr='-trans %s', - exists=True, - mandatory=False, - position=2, + interpolation=dict( + argstr='-interp %s', + usedefault=True, ), out_file=dict( argstr='-out %s', - name_source='in_volume', - name_template='%s_diffeoxfmd.nii.gz', - position=1, + keep_extension=True, + name_source='in_file', + name_template='%s_diffeoxfmd', + ), + resampling_type=dict(argstr='-type %s', ), + target=dict( + argstr='-target %s', + xor=['voxel_size'], ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), + transform=dict( + argstr='-trans %s', + mandatory=True, + ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target'], + ), ) inputs = diffeoScalarVolTask.input_spec() diff --git a/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVol.py b/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVol.py new file mode 100644 index 0000000000..31a516a7c9 --- /dev/null +++ b/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVol.py @@ -0,0 +1,70 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..registration import DiffeoSymTensor3DVol + + +def test_DiffeoSymTensor3DVol_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + df=dict( + argstr='-df %s', + usedefault=True, + ), + environ=dict( + nohash=True, + usedefault=True, + ), + flip=dict(argstr='-flip %d %d %d', ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='-in %s', + mandatory=True, + ), + interpolation=dict( + argstr='-interp %s', + usedefault=True, + ), + out_file=dict( + argstr='-out %s', + keep_extension=True, + name_source='in_file', + name_template='%s_diffeoxfmd', + ), + reorient=dict( + argstr='-reorient %s', + usedefault=True, + ), + resampling_type=dict(argstr='-type %s', ), + target=dict( + argstr='-target %s', + xor=['voxel_size'], + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + transform=dict( + argstr='-trans %s', + mandatory=True, + ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target'], + ), + ) + inputs = DiffeoSymTensor3DVol.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(inputs.traits()[key], metakey) == value +def test_DiffeoSymTensor3DVol_outputs(): + output_map = dict(out_file=dict(), ) + outputs = DiffeoSymTensor3DVol.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVolTask.py b/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVolTask.py index 7f3926c71b..a380fcabc6 100644 --- a/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVolTask.py +++ b/nipype/interfaces/dtitk/tests/test_auto_diffeoSymTensor3DVolTask.py @@ -6,45 +6,55 @@ def test_diffeoSymTensor3DVolTask_inputs(): input_map = dict( args=dict(argstr='%s', ), + df=dict( + argstr='-df %s', + usedefault=True, + ), environ=dict( nohash=True, usedefault=True, ), + flip=dict(argstr='-flip %d %d %d', ), ignore_exception=dict( deprecated='1.0.0', nohash=True, usedefault=True, ), - in_target=dict( - argstr='-target %s', - exists=True, - mandatory=False, - position=2, - ), - in_tensor=dict( + in_file=dict( argstr='-in %s', - exists=True, - mandatory=False, - position=0, + mandatory=True, ), - in_xfm=dict( - argstr='-trans %s', - exists=True, - mandatory=False, - position=1, + interpolation=dict( + argstr='-interp %s', + usedefault=True, ), out_file=dict( argstr='-out %s', - exists=True, - mandatory=False, - name_source='in_tensor', - name_template='%s_diffeoxfmd.nii.gz', - position=3, + keep_extension=True, + name_source='in_file', + name_template='%s_diffeoxfmd', + ), + reorient=dict( + argstr='-reorient %s', + usedefault=True, + ), + resampling_type=dict(argstr='-type %s', ), + target=dict( + argstr='-target %s', + xor=['voxel_size'], ), terminal_output=dict( deprecated='1.0.0', nohash=True, ), + transform=dict( + argstr='-trans %s', + mandatory=True, + ), + voxel_size=dict( + argstr='-vsize %g %g %g', + xor=['target'], + ), ) inputs = diffeoSymTensor3DVolTask.input_spec() diff --git a/nipype/interfaces/dtitk/utils.py b/nipype/interfaces/dtitk/utils.py index 86e0c08b8c..274ea2914e 100644 --- a/nipype/interfaces/dtitk/utils.py +++ b/nipype/interfaces/dtitk/utils.py @@ -1,296 +1,240 @@ -__author__ = 'kjordan' - -from ..base import TraitedSpec, CommandLineInputSpec, File, \ - traits, isdefined -import os -from .base import CommandLineDtitk - - -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, - position=4, argstr='-origin %s') +# -*- 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 +DTI-TK developed by Gary Hui Zhang, gary.zhang@ucl.ac.uk +For additional help, visit http://dti-tk.sf.net -class TVAdjustOriginOutputSpec(TraitedSpec): - out_file = traits.Str(exists=True) +The high-dimensional tensor-based DTI registration algorithm +Zhang, H., Avants, B.B, Yushkevich, P.A., Woo, J.H., Wang, S., McCluskey, L.H., +Elman, L.B., Melhem, E.R., Gee, J.C., High-dimensional spatial normalization of +diffusion tensor images improves the detection of white matter differences in +amyotrophic lateral sclerosis, IEEE Transactions on Medical Imaging, +26(11):1585-1597, November 2007. PMID: 18041273. -class TVAdjustOriginTask(CommandLineDtitk): - """ - Moves the origin of a tensor volume to zero - - Example - ------- +The original piecewise-affine tensor-based DTI registration algorithm at the +core of DTI-TK - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.TVAdjustOriginTask() - >>> node.inputs.in_file = 'diffusion.nii' - >>> node.run() # doctest: +SKIP - """ +Zhang, H., Yushkevich, P.A., Alexander, D.C., Gee, J.C., Deformable +registration of diffusion tensor MR images with explicit orientation +optimization, Medical Image Analysis, 10(5):764-785, October 2006. PMID: +16899392. - 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 +from ..base import TraitedSpec, CommandLineInputSpec, File, traits, isdefined +from ...utils.filemanip import fname_presuffix +from .base import CommandLineDtitk, DTITKRenameMixin +import os - def _gen_filename(self, name): - if name == "out_file": - return self._list_outputs()["out_file"] - return None +__docformat__ = 'restructuredtext' 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, - position=4, argstr='-origin %s') - target = traits.Str(desc='target volume', exists=True, mandatory=False, - position=2, argstr="-target %s") - vsize = traits.Str(desc='resampled voxel size', exists=True, - mandatory=False, position=3, argstr="-vsize %s") + in_file = File(desc="tensor volume to modify", exists=True, + mandatory=True, argstr="-in %s") + out_file = File(desc='output path', + argstr="-out %s", name_source='in_file', + name_template='%s_avs', keep_extension=True) + target_file = File(desc='target volume to match', + argstr="-target %s", + xor=['voxel_size', 'origin']) + voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='xyz voxel size (superseded by target)', + argstr="-vsize %g %g %g", xor=['target_file']) + origin = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='xyz origin (superseded by target)', + argstr='-origin %g %g %g', + xor=['target_file']) class TVAdjustVoxSpOutputSpec(TraitedSpec): - out_file = traits.Str(exists=True) + out_file = File(exists=True) -class TVAdjustVoxSpTask(CommandLineDtitk): +class TVAdjustVoxSp(CommandLineDtitk): """ Adjusts the voxel space of a tensor volume Example ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.TVAdjustVoxSpTask() - >>> node.inputs.in_file = 'diffusion.nii' + >>> from nipype.interfaces import dtitk + >>> node = dtitk.TVAdjustVoxSp() + >>> node.inputs.in_file = 'im1.nii' + >>> node.inputs.target_file = 'im2.nii' + >>> node.cmdline + 'TVAdjustVoxelspace -in im1.nii -out im1_avs.nii -target im2.nii' >>> node.run() # doctest: +SKIP """ 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, - mandatory=True, position=0, argstr="-in %s") - in_target = traits.Str(desc='target volume', exists=True, mandatory=False, - 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, - position=4, argstr='-origin %s') + in_file = File(desc="scalar volume to modify", exists=True, + mandatory=True, argstr="-in %s") + out_file = File(desc='output path', argstr="-out %s", + name_source="in_file", name_template='%s_avs', + keep_extension=True) + target_file = File(desc='target volume to match', + argstr="-target %s", xor=['voxel_size', 'origin']) + voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='xyz voxel size (superseded by target)', + argstr="-vsize %g %g %g", xor=['target_file']) + origin = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='xyz origin (superseded by target)', + argstr='-origin %g %g %g', + xor=['target_file']) class SVAdjustVoxSpOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) + out_file = File(exists=True) -class SVAdjustVoxSpTask(CommandLineDtitk): +class SVAdjustVoxSp(CommandLineDtitk): """ Adjusts the voxel space of a scalar volume Example ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.SVAdjustVoxSpTask() - >>> node.inputs.in_file = 'diffusion.nii.gz' + >>> from nipype.interfaces import dtitk + >>> node = dtitk.SVAdjustVoxSp() + >>> node.inputs.in_file = 'im1.nii' + >>> node.inputs.target_file = 'im2.nii' + >>> node.cmdline + 'SVAdjustVoxelspace -in im1.nii -out im1_avs.nii -target im2.nii' >>> node.run() # doctest: +SKIP """ 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, - 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") + in_file = File(desc="tensor volume to resample", exists=True, + mandatory=True, argstr="-in %s") + out_file = File(desc='output path', + name_source="in_file", name_template="%s_resampled", + keep_extension=True, argstr="-out %s") + target_file = File(desc='specs read from the target volume', + argstr="-target %s", + xor=['array_size', 'voxel_size', 'origin']) + align = traits.Enum('center', 'origin', argstr="-align %s", + desc='how to align output volume to input volume') + interpolation = traits.Enum('LEI', 'EI', argstr="-interp %s", + desc='Log Euclidean Euclidean Interpolation') + array_size = traits.Tuple((traits.Int(), traits.Int(), traits.Int()), + desc='resampled array size', xor=['target_file'], + argstr="-size %d %d %d") + voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='resampled voxel size', xor=['target_file'], + argstr="-vsize %g %g %g") + origin = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='xyz origin', xor=['target_file'], + argstr='-origin %g %g %g') class TVResampleOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) + out_file = File(exists=True) -class TVResampleTask(CommandLineDtitk): +class TVResample(CommandLineDtitk): """ Resamples a tensor volume Example ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.TVResampleTask() - >>> node.inputs.in_file = 'diffusion.nii.gz' + >>> from nipype.interfaces import dtitk + >>> node = dtitk.TVResample() + >>> node.inputs.in_file = 'im1.nii' + >>> node.inputs.target_file = 'im2.nii' + >>> node.cmdline + 'TVResample -in im1.nii -out im1_resampled.nii -target im2.nii' >>> node.run() # doctest: +SKIP """ 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") + in_file = File(desc="image to resample", exists=True, + mandatory=True, argstr="-in %s") + out_file = File(desc='output path', + name_source="in_file", name_template="%s_resampled", + keep_extension=True, argstr="-out %s") + target_file = File(desc='specs read from the target volume', + argstr="-target %s", + xor=['array_size', 'voxel_size', 'origin']) + align = traits.Enum('center', 'origin', argstr="-align %s", + desc='how to align output volume to input volume') + array_size = traits.Tuple((traits.Int(), traits.Int(), traits.Int()), + desc='resampled array size', xor=['target_file'], + argstr="-size %d %d %d") + voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='resampled voxel size', xor=['target_file'], + argstr="-vsize %g %g %g") + origin = traits.Tuple((traits.Float(), traits.Float(), traits.Float()), + desc='xyz origin', xor=['target_file'], + argstr='-origin %g %g %g') class SVResampleOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) + out_file = File(exists=True) -class SVResampleTask(CommandLineDtitk): +class SVResample(CommandLineDtitk): """ Resamples a scalar volume Example ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.SVResampleTask() - >>> node.inputs.in_file = 'diffusion.nii' + >>> from nipype.interfaces import dtitk + >>> node = dtitk.SVResample() + >>> node.inputs.in_file = 'im1.nii' + >>> node.inputs.target_file = 'im2.nii' + >>> node.cmdline + 'SVResample -in im1.nii -out im1_resampled.nii -target im2.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_flag = traits.Enum('fa', 'tr', 'ad', 'rd', 'pd', 'rgb', exists=True, - mandatory=False, position=1, argstr="-%s", desc='') + in_file = File(desc="scalar volume to resample", exists=True, + argstr="-in %s", mandatory=True) + '''NOTE: there are a lot more options here; not implementing all of them''' + in_flag = traits.Enum('fa', 'tr', 'ad', 'rd', 'pd', 'rgb', + argstr="-%s", desc='') + out_file = File(argstr="-out %s", genfile=True) class TVtoolOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) + out_file = File() -class TVtoolTask(CommandLineDtitk): +class TVtool(CommandLineDtitk): """ Calculates a tensor metric volume from a tensor volume Example ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.TVtoolTask() - >>> node.inputs.in_file = 'diffusion.nii' + >>> from nipype.interfaces import dtitk + >>> node = dtitk.TVtool() + >>> node.inputs.in_file = 'im1.nii' >>> node.inputs.in_flag = 'fa' + >>> node.cmdline + 'TVtool -in im1.nii -fa -out im1_fa.nii' >>> node.run() # doctest: +SKIP """ input_spec = TVtoolInputSpec @@ -298,70 +242,92 @@ class TVtoolTask(CommandLineDtitk): _cmd = 'TVtool' def _list_outputs(self): - _suffix = self.inputs.in_flag - 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=_suffix, - ext='.' + '.'.join( - self.inputs.in_file. - split(".")[1:])) - outputs["out_file"] = os.path.abspath(outputs["out_file"]) + outputs = self._outputs().get() + out_file = self.inputs.out_file + if not isdefined(out_file): + out_file = self._gen_filename('out_file') + outputs['out_file'] = os.path.abspath(out_file) return outputs def _gen_filename(self, name): - if name == "out_file": - return self._list_outputs()["out_file"] - return None + if name != 'out_file': + return + return fname_presuffix(os.path.basename(self.inputs.in_file), + suffix='_' + self.inputs.in_flag) + + +'''Note: SVTool not implemented at this time''' class BinThreshInputSpec(CommandLineInputSpec): - in_file = traits.Str(desc='', exists=True, mandatory=False, 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") + in_file = File(desc='Image to threshold/binarize', exists=True, + position=0, argstr="%s", mandatory=True) + out_file = File(desc='output path', position=1, argstr="%s", + keep_extension=True, name_source='in_file', + name_template='%s_thrbin') + lower_bound = traits.Float(0.01, position=2, argstr="%g", mandatory=True, + desc='lower bound of binarization range') + upper_bound = traits.Float(100, position=3, argstr="%g", mandatory=True, + desc='upper bound of binarization range') + inside_value = traits.Float(1, position=4, argstr="%g", usedefault=True, + mandatory=True, desc='value for voxels in ' + 'binarization range') + outside_value = traits.Float(0, position=5, argstr="%g", usedefault=True, + mandatory=True, desc='value for voxels' + 'outside of binarization range') class BinThreshOutputSpec(TraitedSpec): - out_file = traits.File(exists=True) + out_file = File(exists=True) -class BinThreshTask(CommandLineDtitk): +class BinThresh(CommandLineDtitk): """ - Binarizes an image based on parameters + Binarizes an image - Example - ------- + Example + ------- - >>> import nipype.interfaces.dtitk as dtitk - >>> node = dtitk.BinThreshTask() - >>> node.inputs.in_file = 'diffusion.nii' - >>> node.inputs.in_numbers = '0 100 1 0' - >>> node.run() # doctest: +SKIP - """ + >>> from nipype.interfaces import dtitk + >>> node = dtitk.BinThresh() + >>> node.inputs.in_file = 'im1.nii' + >>> node.inputs.lower_bound = 0 + >>> node.inputs.upper_bound = 100 + >>> node.inputs.inside_value = 1 + >>> node.inputs.outside_value = 0 + >>> node.cmdline + 'BinaryThresholdImageFilter im1.nii im1_thrbin.nii 0 100 1 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 +class BinThreshTask(DTITKRenameMixin, BinThresh): + pass + + +class SVAdjustVoxSpTask(DTITKRenameMixin, SVAdjustVoxSp): + pass + + +class SVResampleTask(DTITKRenameMixin, SVResample): + pass + + +class TVAdjustOriginTask(DTITKRenameMixin, TVAdjustVoxSp): + pass + + +class TVAdjustVoxSpTask(DTITKRenameMixin, TVAdjustVoxSp): + pass + + +class TVResampleTask(DTITKRenameMixin, TVResample): + pass + + +class TVtoolTask(DTITKRenameMixin, TVtool): + pass diff --git a/nipype/testing/data/im_affine.aff b/nipype/testing/data/im_affine.aff new file mode 100644 index 0000000000..e69de29bb2 diff --git a/nipype/testing/data/im_warp.df.nii b/nipype/testing/data/im_warp.df.nii new file mode 100644 index 0000000000..e69de29bb2 diff --git a/nipype/workflows/dmri/dtitk/__init__.py b/nipype/workflows/dmri/dtitk/__init__.py new file mode 100644 index 0000000000..02dbf25549 --- /dev/null +++ b/nipype/workflows/dmri/dtitk/__init__.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +# 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: + +from __future__ import absolute_import +from .tensor_registration import (affine_tensor_pipeline, + diffeomorphic_tensor_pipeline) diff --git a/nipype/workflows/dmri/dtitk/tensor_registration.py b/nipype/workflows/dmri/dtitk/tensor_registration.py new file mode 100644 index 0000000000..c4d3d32484 --- /dev/null +++ b/nipype/workflows/dmri/dtitk/tensor_registration.py @@ -0,0 +1,127 @@ +# -*- coding: utf-8 -*- +# 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: + +from ....pipeline import engine as pe +from ....interfaces import utility as niu +from ....interfaces import dtitk + + +def affine_tensor_pipeline(name='AffTen'): + + """ + Workflow that performs a linear registration + (Rigid followed by Affine) + + Example + ------- + + >>> from nipype.workflows.dmri.dtitk.tensor_registration import affine_tensor_pipeline + >>> affine = affine_tensor_pipeline() + >>> affine.inputs.inputnode.fixed_file = 'im1.nii' + >>> affine.inputs.inputnode.moving_file = 'im2.nii' + >>> affine.run() # doctest: +SKIP + + + """ + inputnode = pe.Node(niu.IdentityInterface( + fields=['fixed_file', 'moving_file']), + name='inputnode') + outputnode = pe.Node(niu.IdentityInterface( + fields=['out_file', 'out_file_xfm']), + name='outputnode') + + rigid_node = pe.Node(dtitk.Rigid(), name='rigid_node') + affine_node = pe.Node(dtitk.Affine(), name='affine_node') + + wf = pe.Workflow(name=name) + + wf.connect(inputnode, 'fixed_file', rigid_node, 'fixed_file') + wf.connect(inputnode, 'moving_file', rigid_node, 'moving_file') + wf.connect(rigid_node, 'out_file_xfm', affine_node, 'initialize_xfm') + wf.connect(inputnode, 'fixed_file', affine_node, 'fixed_file') + wf.connect(inputnode, 'moving_file', affine_node, 'moving_file') + wf.connect(affine_node, 'out_file', outputnode, 'out_file') + wf.connect(affine_node, 'out_file_xfm', outputnode, 'out_file_xfm') + + return wf + + +def diffeomorphic_tensor_pipeline(name='DiffeoTen', + params={'array_size': (128, 128, 64)}): + """ + Workflow that performs a diffeomorphic registration + (Rigid and Affine follwed by Diffeomorphic) + Note: the requirements for a diffeomorphic registration specify that + the dimension 0 is a power of 2 so images are resliced prior to + registration + + Example + ------- + + >>> from nipype.workflows.dmri.dtitk.tensor_registration import diffeomorphic_tensor_pipeline + >>> diffeo = diffeomorphic_tensor_pipeline() + >>> diffeo.inputs.inputnode.fixed_file = 'im1.nii' + >>> diffeo.inputs.inputnode.moving_file = 'im2.nii' + >>> diffeo.run() # doctest: +SKIP + + + """ + inputnode = pe.Node(niu.IdentityInterface( + fields=['fixed_file', 'moving_file']), + name='inputnode') + outputnode = pe.Node(niu.IdentityInterface( + fields=['out_file', 'out_file_xfm', + 'fixed_resliced', 'moving_resliced']), + name='outputnode') + + reslice_node_pow2 = pe.Node(dtitk.TVResample( + origin=(0, 0, 0), + array_size=params['array_size']), + name='reslice_node_pow2') + reslice_node_moving = pe.Node(dtitk.TVResample(), + name='reslice_node_moving') + mask_node = pe.Node(dtitk.BinThresh(lower_bound=0.01, upper_bound=100, + inside_value=1, outside_value=0), + name='mask_node') + rigid_node = pe.Node(dtitk.Rigid(), name='rigid_node') + affine_node = pe.Node(dtitk.Affine(), name='affine_node') + diffeo_node = pe.Node(dtitk.Diffeo(n_iters=6, ftol=0.002), + name='diffeo_node') + compose_xfm_node = pe.Node(dtitk.ComposeXfm(), name='compose_xfm_node') + apply_xfm_node = pe.Node(dtitk.DiffeoSymTensor3DVol(), + name='apply_xfm_node') + + wf = pe.Workflow(name=name) + + # Reslice input images + wf.connect(inputnode, 'fixed_file', reslice_node_pow2, 'in_file') + wf.connect(reslice_node_pow2, 'out_file', + reslice_node_moving, 'target_file') + wf.connect(inputnode, 'moving_file', reslice_node_moving, 'in_file') + # Rigid registration + wf.connect(reslice_node_pow2, 'out_file', rigid_node, 'fixed_file') + wf.connect(reslice_node_moving, 'out_file', rigid_node, 'moving_file') + # Affine registration + wf.connect(rigid_node, 'out_file_xfm', affine_node, 'initialize_xfm') + wf.connect(reslice_node_pow2, 'out_file', affine_node, 'fixed_file') + wf.connect(reslice_node_moving, 'out_file', affine_node, 'moving_file') + # Diffeo registration + wf.connect(reslice_node_pow2, 'out_file', mask_node, 'in_file') + wf.connect(reslice_node_pow2, 'out_file', diffeo_node, 'fixed_file') + wf.connect(affine_node, 'out_file', diffeo_node, 'moving_file') + wf.connect(mask_node, 'out_file', diffeo_node, 'mask_file') + # Compose transform + wf.connect(diffeo_node, 'out_file_xfm', compose_xfm_node, 'in_df') + wf.connect(affine_node, 'out_file_xfm', compose_xfm_node, 'in_aff') + # Apply transform + wf.connect(reslice_node_moving, 'out_file', apply_xfm_node, 'in_file') + wf.connect(compose_xfm_node, 'out_file', apply_xfm_node, 'transform') + # Send to output + wf.connect(apply_xfm_node, 'out_file', outputnode, 'out_file') + wf.connect(compose_xfm_node, 'out_file', outputnode, 'out_file_xfm') + wf.connect(reslice_node_pow2, 'out_file', outputnode, 'fixed_resliced') + wf.connect(reslice_node_moving, 'out_file', outputnode, 'moving_resliced') + + return wf