Skip to content

FIX: Improve output handling in DWIDenoise and DWIBiasCorrect #2978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions nipype/interfaces/mrtrix3/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ class MRTrix3BaseInputSpec(CommandLineInputSpec):
grad_file = File(
exists=True,
argstr='-grad %s',
desc='dw gradient scheme (MRTrix format')
desc='dw gradient scheme (MRTrix format)',
xor=['grad_fsl'])
grad_fsl = traits.Tuple(
File(exists=True),
File(exists=True),
argstr='-fslgrad %s %s',
desc='(bvecs, bvals) dw gradient scheme (FSL format')
desc='(bvecs, bvals) dw gradient scheme (FSL format)',
xor=['grad_file'])
bval_scale = traits.Enum(
'yes',
'no',
Expand Down
68 changes: 24 additions & 44 deletions nipype/interfaces/mrtrix3/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,27 @@ class DWIDenoiseInputSpec(MRTrix3BaseInputSpec):
argstr='-mask %s',
position=1,
desc='mask image')
extent = traits.Tuple((traits.Int, traits.Int, traits.Int),
extent = traits.Tuple(
(traits.Int, traits.Int, traits.Int),
argstr='-extent %d,%d,%d',
desc='set the window size of the denoising filter. (default = 5,5,5)')
noise = File(
argstr='-noise %s',
desc='the output noise map')
out_file = File(name_template='%s_denoised',
name_template='%s_noise',
name_source='in_file',
keep_extension=True,
desc='the output noise map',
genfile=True)
out_file = File(
argstr='%s',
position=-1,
name_template='%s_denoised',
name_source='in_file',
keep_extension=True,
desc='the output denoised DWI image',
genfile=True)


class DWIDenoiseOutputSpec(TraitedSpec):
noise = File(desc='the output noise map', exists=True)
out_file = File(desc='the output denoised DWI image', exists=True)
Expand Down Expand Up @@ -67,22 +74,16 @@ class DWIDenoise(MRTrix3Base):
>>> denoise = mrt.DWIDenoise()
>>> denoise.inputs.in_file = 'dwi.mif'
>>> denoise.inputs.mask = 'mask.mif'
>>> denoise.inputs.noise = 'noise.mif'
>>> denoise.cmdline # doctest: +ELLIPSIS
'dwidenoise -mask mask.mif dwi.mif dwi_denoised.mif'
'dwidenoise -mask mask.mif -noise noise.mif dwi.mif dwi_denoised.mif'
>>> denoise.run() # doctest: +SKIP
"""

_cmd = 'dwidenoise'
input_spec = DWIDenoiseInputSpec
output_spec = DWIDenoiseOutputSpec

def _list_outputs(self):
outputs = self.output_spec().get()
outputs['out_file'] = op.abspath(self.inputs.out_file)
if self.inputs.noise != Undefined:
outputs['noise'] = op.abspath(self.inputs.noise)
return outputs


class MRDeGibbsInputSpec(MRTrix3BaseInputSpec):
in_file = File(
Expand All @@ -92,32 +93,29 @@ class MRDeGibbsInputSpec(MRTrix3BaseInputSpec):
mandatory=True,
desc='input DWI image')
axes = traits.ListInt(
default_value=[0,1],
usedefault=True,
[0,1],
sep=',',
minlen=2,
maxlen=2,
argstr='-axes %s',
desc='indicate the plane in which the data was acquired (axial = 0,1; '
'coronal = 0,2; sagittal = 1,2')
nshifts = traits.Int(
default_value=20,
usedefault=True,
20,
argstr='-nshifts %d',
desc='discretization of subpixel spacing (default = 20)')
minW = traits.Int(
default_value=1,
usedefault=True,
1,
argstr='-minW %d',
desc='left border of window used for total variation (TV) computation '
'(default = 1)')
maxW = traits.Int(
default_value=3,
usedefault=True,
3,
argstr='-maxW %d',
desc='right border of window used for total variation (TV) computation '
'(default = 3)')
out_file = File(name_template='%s_unr',
out_file = File(
name_template='%s_unr',
name_source='in_file',
keep_extension=True,
argstr='%s',
Expand Down Expand Up @@ -160,7 +158,7 @@ class MRDeGibbs(MRTrix3Base):
>>> unring = mrt.MRDeGibbs()
>>> unring.inputs.in_file = 'dwi.mif'
>>> unring.cmdline
'mrdegibbs -axes 0,1 -maxW 3 -minW 1 -nshifts 20 dwi.mif dwi_unr.mif'
'mrdegibbs dwi.mif dwi_unr.mif'
>>> unring.run() # doctest: +SKIP
"""

Expand All @@ -179,31 +177,19 @@ class DWIBiasCorrectInputSpec(MRTrix3BaseInputSpec):
in_mask = File(
argstr='-mask %s',
desc='input mask image for bias field estimation')
_xor_methods = ('use_ants', 'use_fsl')
use_ants = traits.Bool(
default_value=True,
usedefault=True,
argstr='-ants',
desc='use ANTS N4 to estimate the inhomogeneity field',
xor=_xor_methods)
xor=['use_fsl'])
use_fsl = traits.Bool(
argstr='-fsl',
desc='use FSL FAST to estimate the inhomogeneity field',
xor=_xor_methods,
min_ver='5.0.10')
_xor_grads = ('mrtrix_grad', 'fsl_grad')
mrtrix_grad = File(
argstr='-grad %s',
desc='diffusion gradient table in MRtrix format',
xor=_xor_grads)
fsl_grad = File(
argstr='-fslgrad %s %s',
desc='diffusion gradient table in FSL bvecs/bvals format',
xor=_xor_grads)
xor=['use_ants'])
bias = File(
argstr='-bias %s',
desc='bias field')
out_file = File(name_template='%s_biascorr',
out_file = File(
name_template='%s_biascorr',
name_source='in_file',
keep_extension=True,
argstr='%s',
Expand All @@ -228,6 +214,7 @@ class DWIBiasCorrect(MRTrix3Base):
>>> import nipype.interfaces.mrtrix3 as mrt
>>> bias_correct = mrt.DWIBiasCorrect()
>>> bias_correct.inputs.in_file = 'dwi.mif'
>>> bias_correct.inputs.use_ants = True
>>> bias_correct.cmdline
'dwibiascorrect -ants dwi.mif dwi_biascorr.mif'
>>> bias_correct.run() # doctest: +SKIP
Expand All @@ -237,13 +224,6 @@ class DWIBiasCorrect(MRTrix3Base):
input_spec = DWIBiasCorrectInputSpec
output_spec = DWIBiasCorrectOutputSpec

def _list_outputs(self):
outputs = self.output_spec().get()
outputs['out_file'] = op.abspath(self.inputs.out_file)
if self.inputs.bias != Undefined:
outputs['bias'] = op.abspath(self.inputs.bias)
return outputs


class ResponseSDInputSpec(MRTrix3BaseInputSpec):
algorithm = traits.Enum(
Expand Down
22 changes: 7 additions & 15 deletions nipype/interfaces/mrtrix3/tests/test_auto_DWIBiasCorrect.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ def test_DWIBiasCorrect_inputs():
nohash=True,
usedefault=True,
),
fsl_grad=dict(
argstr='-fslgrad %s %s',
extensions=None,
xor=('mrtrix_grad', 'fsl_grad'),
),
grad_file=dict(
argstr='-grad %s',
extensions=None,
xor=['grad_fsl'],
),
grad_fsl=dict(
argstr='-fslgrad %s %s',
xor=['grad_file'],
),
grad_fsl=dict(argstr='-fslgrad %s %s', ),
in_bval=dict(extensions=None, ),
in_bvec=dict(
argstr='-fslgrad %s %s',
Expand All @@ -40,11 +39,6 @@ def test_DWIBiasCorrect_inputs():
argstr='-mask %s',
extensions=None,
),
mrtrix_grad=dict(
argstr='-grad %s',
extensions=None,
xor=('mrtrix_grad', 'fsl_grad'),
),
nthreads=dict(
argstr='-nthreads %d',
nohash=True,
Expand All @@ -60,13 +54,11 @@ def test_DWIBiasCorrect_inputs():
),
use_ants=dict(
argstr='-ants',
usedefault=True,
xor=('use_ants', 'use_fsl'),
xor=['use_fsl'],
),
use_fsl=dict(
argstr='-fsl',
min_ver='5.0.10',
xor=('use_ants', 'use_fsl'),
xor=['use_ants'],
),
)
inputs = DWIBiasCorrect.input_spec()
Expand Down
10 changes: 9 additions & 1 deletion nipype/interfaces/mrtrix3/tests/test_auto_DWIDenoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ def test_DWIDenoise_inputs():
grad_file=dict(
argstr='-grad %s',
extensions=None,
xor=['grad_fsl'],
),
grad_fsl=dict(
argstr='-fslgrad %s %s',
xor=['grad_file'],
),
grad_fsl=dict(argstr='-fslgrad %s %s', ),
in_bval=dict(extensions=None, ),
in_bvec=dict(
argstr='-fslgrad %s %s',
Expand All @@ -36,6 +40,10 @@ def test_DWIDenoise_inputs():
noise=dict(
argstr='-noise %s',
extensions=None,
genfile=True,
keep_extension=True,
name_source='in_file',
name_template='%s_noise',
),
nthreads=dict(
argstr='-nthreads %d',
Expand Down
22 changes: 8 additions & 14 deletions nipype/interfaces/mrtrix3/tests/test_auto_MRDeGibbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def test_MRDeGibbs_inputs():
maxlen=2,
minlen=2,
sep=',',
usedefault=True,
),
bval_scale=dict(argstr='-bvalue_scaling %s', ),
environ=dict(
Expand All @@ -21,8 +20,12 @@ def test_MRDeGibbs_inputs():
grad_file=dict(
argstr='-grad %s',
extensions=None,
xor=['grad_fsl'],
),
grad_fsl=dict(
argstr='-fslgrad %s %s',
xor=['grad_file'],
),
grad_fsl=dict(argstr='-fslgrad %s %s', ),
in_bval=dict(extensions=None, ),
in_bvec=dict(
argstr='-fslgrad %s %s',
Expand All @@ -34,18 +37,9 @@ def test_MRDeGibbs_inputs():
mandatory=True,
position=-2,
),
maxW=dict(
argstr='-maxW %d',
usedefault=True,
),
minW=dict(
argstr='-minW %d',
usedefault=True,
),
nshifts=dict(
argstr='-nshifts %d',
usedefault=True,
),
maxW=dict(argstr='-maxW %d', ),
minW=dict(argstr='-minW %d', ),
nshifts=dict(argstr='-nshifts %d', ),
nthreads=dict(
argstr='-nthreads %d',
nohash=True,
Expand Down