Skip to content

Commit 85a51a1

Browse files
committed
Add dwi2mask, fix auto tests
1 parent 0f45bc9 commit 85a51a1

File tree

5 files changed

+105
-4
lines changed

5 files changed

+105
-4
lines changed

nipype/interfaces/mrtrix3/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
33
# -*- coding: utf-8 -*-
44

5-
from utils import Mesh2PVE, Generate5tt
5+
from utils import Mesh2PVE, Generate5tt, BrainMask
66
from preprocess import ResponseSD, ACTPrepareFSL
77
from tracking import Tractography
88
from reconst import FitTensor, EstimateFOD

nipype/interfaces/mrtrix3/reconst.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,12 @@ class EstimateFOD(CommandLine):
201201
>>> import nipype.interfaces.mrtrix3 as mrt
202202
>>> fod = mrt.EstimateFOD()
203203
>>> fod.inputs.in_file = 'dwi.mif'
204+
>>> fod.inputs.response = 'response.txt'
204205
>>> fod.inputs.in_mask = 'mask.nii.gz'
205206
>>> fod.inputs.grad_fsl = ('bvecs', 'bvals')
206207
>>> fod.cmdline # doctest: +ELLIPSIS
207-
'dwi2fod -fslgrad bvecs bvals -mask mask.nii.gz dwi.mif fods.mif'
208+
'dwi2fod -fslgrad bvecs bvals -mask mask.nii.gz dwi.mif response.txt\
209+
fods.mif'
208210
>>> fod.run() # doctest: +SKIP
209211
"""
210212

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from nipype.testing import assert_equal
3+
from nipype.interfaces.mrtrix3.utils import BrainMask
4+
5+
def test_BrainMask_inputs():
6+
input_map = dict(args=dict(argstr='%s',
7+
),
8+
bval_scale=dict(argstr='-bvalue_scaling %s',
9+
),
10+
environ=dict(nohash=True,
11+
usedefault=True,
12+
),
13+
grad_file=dict(argstr='-grad %s',
14+
),
15+
grad_fsl=dict(argstr='-fslgrad %s %s',
16+
),
17+
ignore_exception=dict(nohash=True,
18+
usedefault=True,
19+
),
20+
in_file=dict(argstr='%s',
21+
mandatory=True,
22+
position=-2,
23+
),
24+
out_file=dict(argstr='%s',
25+
mandatory=True,
26+
position=-1,
27+
usedefault=True,
28+
),
29+
terminal_output=dict(nohash=True,
30+
),
31+
)
32+
inputs = BrainMask.input_spec()
33+
34+
for key, metadata in input_map.items():
35+
for metakey, value in metadata.items():
36+
yield assert_equal, getattr(inputs.traits()[key], metakey), value
37+
38+
def test_BrainMask_outputs():
39+
output_map = dict(out_file=dict(),
40+
)
41+
outputs = BrainMask.output_spec()
42+
43+
for key, metadata in output_map.items():
44+
for metakey, value in metadata.items():
45+
yield assert_equal, getattr(outputs.traits()[key], metakey), value
46+

nipype/interfaces/mrtrix3/utils.py

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,64 @@
2222
from nipype.interfaces.traits_extension import isdefined
2323

2424

25+
class BrainMaskInputSpec(CommandLineInputSpec):
26+
in_file = File(exists=True, argstr='%s', mandatory=True, position=-2,
27+
desc='input diffusion weighted images')
28+
out_file = File(
29+
'brainmask.mif', argstr='%s', mandatory=True, position=-1,
30+
usedefault=True, desc='output brain mask')
31+
# DW gradient table import options
32+
grad_file = File(exists=True, argstr='-grad %s',
33+
desc='dw gradient scheme (MRTrix format')
34+
grad_fsl = traits.Tuple(
35+
File(exists=True), File(exists=True), argstr='-fslgrad %s %s',
36+
desc='(bvecs, bvals) dw gradient scheme (FSL format')
37+
bval_scale = traits.Enum(
38+
'yes', 'no', argstr='-bvalue_scaling %s',
39+
desc=('specifies whether the b - values should be scaled by the square'
40+
' of the corresponding DW gradient norm, as often required for '
41+
'multishell or DSI DW acquisition schemes. The default action '
42+
'can also be set in the MRtrix config file, under the '
43+
'BValueScaling entry. Valid choices are yes / no, true / '
44+
'false, 0 / 1 (default: true).'))
45+
46+
class BrainMaskOutputSpec(TraitedSpec):
47+
out_file = File(exists=True, desc='the output response file')
48+
49+
50+
class BrainMask(CommandLine):
51+
52+
"""
53+
Convert a mesh surface to a partial volume estimation image
54+
55+
56+
Example
57+
-------
58+
59+
>>> import nipype.interfaces.mrtrix3 as mrt
60+
>>> bmsk = mrt.BrainMask()
61+
>>> bmsk.inputs.in_file = 'dwi.mif'
62+
>>> bmsk.cmdline # doctest: +ELLIPSIS
63+
'dwi2mask dwi.mif brainmask.mif'
64+
>>> bmsk.run() # doctest: +SKIP
65+
"""
66+
67+
_cmd = 'dwi2mask'
68+
input_spec = BrainMaskInputSpec
69+
output_spec = BrainMaskOutputSpec
70+
71+
def _list_outputs(self):
72+
outputs = self.output_spec().get()
73+
outputs['out_file'] = op.abspath(self.inputs.out_file)
74+
return outputs
75+
76+
77+
2578
class Mesh2PVEInputSpec(CommandLineInputSpec):
2679
in_file = File(exists=True, argstr='%s', mandatory=True, position=-3,
27-
desc='input diffusion weighted images')
80+
desc='input mesh')
2881
reference = File(exists=True, argstr='%s', mandatory=True, position=-2,
29-
desc='input diffusion weighted images')
82+
desc='input reference image')
3083
in_first = File(
3184
exists=True, argstr='-first %s',
3285
desc='indicates that the mesh file is provided by FSL FIRST')

nipype/testing/data/response.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)