Skip to content

Commit 248e589

Browse files
committed
Updated MRtrix3 interfaces
1 parent c15ba6b commit 248e589

File tree

9 files changed

+89
-520
lines changed

9 files changed

+89
-520
lines changed

nipype/interfaces/mrtrix3/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# vi: set ft=python sts=4 ts=4 sw=4 et:
44
# -*- coding: utf-8 -*-
55

6-
from .utils import (Mesh2PVE, Generate5tt, Generate5ttFSL, BrainMask, TensorMetrics,
6+
from .utils import (Mesh2PVE, Generate5tt, BrainMask, TensorMetrics,
77
ComputeTDI, TCK2VTK, MRMath, MRConvert, DWIExtract)
8-
from .preprocess import DWI2Response, ResponseSD, ACTPrepareFSL, ReplaceFSwithFIRST
8+
from .preprocess import ResponseSD, ACTPrepareFSL, ReplaceFSwithFIRST
99
from .tracking import Tractography
10-
from .reconst import DWI2FOD, FitTensor, EstimateFOD
10+
from .reconst import FitTensor, EstimateFOD
1111
from .connectivity import LabelConfig, BuildConnectome

nipype/interfaces/mrtrix3/preprocess.py

Lines changed: 6 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from .base import MRTrix3BaseInputSpec, MRTrix3Base
2222

2323

24-
class DWI2ResponseInputSpec(MRTrix3BaseInputSpec):
24+
class ResponseSDInputSpec(MRTrix3BaseInputSpec):
2525
algorithm = traits.Enum('msmt_5tt','dhollander','tournier','tax', argstr='%s', position=-6,
2626
mandatory=True, desc='response estimation algorithm (multi-tissue)')
2727
dwi_file = File(exists=True, argstr='%s', position=-5,
@@ -37,13 +37,13 @@ class DWI2ResponseInputSpec(MRTrix3BaseInputSpec):
3737
desc='maximum harmonic degree of response function')
3838

3939

40-
class DWI2ResponseOutputSpec(TraitedSpec):
40+
class ResponseSDOutputSpec(TraitedSpec):
4141
wm_file = File(argstr='%s', desc='output WM response text file')
4242
gm_file = File(argstr='%s', desc='output GM response text file')
4343
csf_file = File(argstr='%s', desc='output CSF response text file')
4444

4545

46-
class DWI2Response(MRTrix3Base):
46+
class ResponseSD(MRTrix3Base):
4747

4848
"""
4949
Estimate response function(s) for spherical deconvolution using the specified algorithm.
@@ -52,7 +52,7 @@ class DWI2Response(MRTrix3Base):
5252
-------
5353
5454
>>> import nipype.interfaces.mrtrix3 as mrt
55-
>>> resp = mrt.DWI2Response()
55+
>>> resp = mrt.ResponseSD()
5656
>>> resp.inputs.dwi_file = 'dwi.mif'
5757
>>> resp.inputs.algorithm = 'tournier'
5858
>>> resp.inputs.grad_fsl = ('bvecs', 'bvals')
@@ -62,8 +62,8 @@ class DWI2Response(MRTrix3Base):
6262
"""
6363

6464
_cmd = 'dwi2response'
65-
input_spec = DWI2ResponseInputSpec
66-
output_spec = DWI2ResponseOutputSpec
65+
input_spec = ResponseSDInputSpec
66+
output_spec = ResponseSDOutputSpec
6767

6868
def _list_outputs(self):
6969
outputs = self.output_spec().get()
@@ -75,99 +75,6 @@ def _list_outputs(self):
7575
return outputs
7676

7777

78-
class ResponseSDInputSpec(MRTrix3BaseInputSpec):
79-
in_file = File(exists=True, argstr='%s', mandatory=True, position=-2,
80-
desc='input diffusion weighted images')
81-
82-
out_file = File(
83-
'response.txt', argstr='%s', mandatory=True, position=-1,
84-
usedefault=True, desc='output file containing SH coefficients')
85-
86-
# DW Shell selection options
87-
shell = traits.List(traits.Float, sep=',', argstr='-shell %s',
88-
desc='specify one or more dw gradient shells')
89-
in_mask = File(exists=True, argstr='-mask %s',
90-
desc='provide initial mask image')
91-
max_sh = traits.Int(8, argstr='-lmax %d',
92-
desc='maximum harmonic degree of response function')
93-
out_sf = File('sf_mask.nii.gz', argstr='-sf %s',
94-
desc='write a mask containing single-fibre voxels')
95-
test_all = traits.Bool(False, argstr='-test_all',
96-
desc='re-test all voxels at every iteration')
97-
98-
# Optimization
99-
iterations = traits.Int(0, argstr='-max_iters %d',
100-
desc='maximum number of iterations per pass')
101-
max_change = traits.Float(
102-
argstr='-max_change %f',
103-
desc=('maximum percentile change in any response function coefficient;'
104-
' if no individual coefficient changes by more than this '
105-
'fraction, the algorithm is terminated.'))
106-
107-
# Thresholds
108-
vol_ratio = traits.Float(
109-
.15, argstr='-volume_ratio %f',
110-
desc=('maximal volume ratio between the sum of all other positive'
111-
' lobes in the voxel and the largest FOD lobe'))
112-
disp_mult = traits.Float(
113-
1., argstr='-dispersion_multiplier %f',
114-
desc=('dispersion of FOD lobe must not exceed some threshold as '
115-
'determined by this multiplier and the FOD dispersion in other '
116-
'single-fibre voxels. The threshold is: (mean + (multiplier * '
117-
'(mean - min))); default = 1.0. Criterion is only applied in '
118-
'second pass of RF estimation.'))
119-
int_mult = traits.Float(
120-
2., argstr='-integral_multiplier %f',
121-
desc=('integral of FOD lobe must not be outside some range as '
122-
'determined by this multiplier and FOD lobe integral in other'
123-
' single-fibre voxels. The range is: (mean +- (multiplier * '
124-
'stdev)); default = 2.0. Criterion is only applied in second '
125-
'pass of RF estimation.'))
126-
127-
128-
class ResponseSDOutputSpec(TraitedSpec):
129-
out_file = File(exists=True, desc='the output response file')
130-
out_sf = File(desc=('mask containing single-fibre voxels'))
131-
132-
133-
class ResponseSD(MRTrix3Base):
134-
135-
"""
136-
Generate an appropriate response function from the image data for
137-
spherical deconvolution. (previous MRTrix releases)
138-
139-
.. [1] Tax, C. M.; Jeurissen, B.; Vos, S. B.; Viergever, M. A. and
140-
Leemans, A., Recursive calibration of the fiber response function
141-
for spherical deconvolution of diffusion MRI data. NeuroImage,
142-
2014, 86, 67-80
143-
144-
145-
Example
146-
-------
147-
148-
>>> import nipype.interfaces.mrtrix3 as mrt
149-
>>> resp = mrt.ResponseSD()
150-
>>> resp.inputs.in_file = 'dwi.mif'
151-
>>> resp.inputs.in_mask = 'mask.nii.gz'
152-
>>> resp.inputs.grad_fsl = ('bvecs', 'bvals')
153-
>>> resp.cmdline # doctest: +ELLIPSIS
154-
'dwi2response -fslgrad bvecs bvals -mask mask.nii.gz dwi.mif response.txt'
155-
>>> resp.run() # doctest: +SKIP
156-
"""
157-
158-
_cmd = 'dwi2response'
159-
input_spec = ResponseSDInputSpec
160-
output_spec = ResponseSDOutputSpec
161-
162-
def _list_outputs(self):
163-
outputs = self.output_spec().get()
164-
outputs['out_file'] = op.abspath(self.inputs.out_file)
165-
166-
if isdefined(self.inputs.out_sf):
167-
outputs['out_sf'] = op.abspath(self.inputs.out_sf)
168-
return outputs
169-
170-
17178
class ACTPrepareFSLInputSpec(CommandLineInputSpec):
17279
in_file = File(exists=True, argstr='%s', mandatory=True, position=-2,
17380
desc='input anatomical image')

nipype/interfaces/mrtrix3/reconst.py

Lines changed: 17 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def _list_outputs(self):
7373
return outputs
7474

7575

76-
class DWI2FODInputSpec(MRTrix3BaseInputSpec):
76+
class EstimateFODInputSpec(MRTrix3BaseInputSpec):
7777
algorithm = traits.Enum('csd','msmt_csd', argstr='%s', position=-8,
7878
mandatory=True, desc='FOD algorithm')
7979
dwi_file = File(exists=True, argstr='%s', position=-7,
@@ -88,150 +88,41 @@ class DWI2FODInputSpec(MRTrix3BaseInputSpec):
8888
csf_odf = File('csf.mif', argstr='%s', position=-1, desc='output CSF ODF')
8989
mask_file = File(exists=True, argstr='-mask %s', desc='mask image')
9090

91-
92-
class DWI2FODOutputSpec(TraitedSpec):
93-
wm_odf = File(argstr='%s', desc='output WM ODF')
94-
gm_odf = File(argstr='%s', desc='output GM ODF')
95-
csf_odf = File(argstr='%s', desc='output CSF ODF')
96-
97-
98-
class DWI2FOD(MRTrix3Base):
99-
100-
"""
101-
Estimate fibre orientation distributions from diffusion data using spherical deconvolution
102-
103-
Example
104-
-------
105-
106-
>>> import nipype.interfaces.mrtrix3 as mrt
107-
>>> fod = mrt.DWI2FOD()
108-
>>> fod.inputs.algorithm = 'csd'
109-
>>> fod.inputs.dwi_file = 'dwi.mif'
110-
>>> fod.inputs.wm_txt = 'wm.txt'
111-
>>> fod.inputs.grad_fsl = ('bvecs', 'bvals')
112-
>>> fod.cmdline # doctest: +ELLIPSIS
113-
'dwi2fod -fslgrad bvecs bvals csd dwi.mif wm.txt wm.mif'
114-
>>> fod.run() # doctest: +SKIP
115-
"""
116-
117-
_cmd = 'dwi2fod'
118-
input_spec = DWI2FODInputSpec
119-
output_spec = DWI2FODOutputSpec
120-
121-
def _list_outputs(self):
122-
outputs = self.output_spec().get()
123-
outputs['wm_odf'] = op.abspath(self.inputs.wm_odf)
124-
if self.inputs.gm_odf!=Undefined:
125-
outputs['gm_odf'] = op.abspath(self.inputs.gm_odf)
126-
if self.inputs.csf_odf!=Undefined:
127-
outputs['csf_odf'] = op.abspath(self.inputs.csf_odf)
128-
return outputs
129-
130-
131-
class EstimateFODInputSpec(MRTrix3BaseInputSpec):
132-
in_file = File(exists=True, argstr='%s', mandatory=True, position=-3,
133-
desc='input diffusion weighted images')
134-
response = File(
135-
exists=True, argstr='%s', mandatory=True, position=-2,
136-
desc=('a text file containing the diffusion-weighted signal response '
137-
'function coefficients for a single fibre population'))
138-
out_file = File(
139-
'fods.mif', argstr='%s', mandatory=True, position=-1,
140-
usedefault=True, desc=('the output spherical harmonics coefficients'
141-
' image'))
142-
14391
# DW Shell selection options
14492
shell = traits.List(traits.Float, sep=',', argstr='-shell %s',
14593
desc='specify one or more dw gradient shells')
146-
147-
# Spherical deconvolution options
14894
max_sh = traits.Int(8, argstr='-lmax %d',
14995
desc='maximum harmonic degree of response function')
150-
in_mask = File(exists=True, argstr='-mask %s',
151-
desc='provide initial mask image')
15296
in_dirs = File(
15397
exists=True, argstr='-directions %s',
15498
desc=('specify the directions over which to apply the non-negativity '
15599
'constraint (by default, the built-in 300 direction set is '
156100
'used). These should be supplied as a text file containing the '
157101
'[ az el ] pairs for the directions.'))
158-
sh_filter = File(
159-
exists=True, argstr='-filter %s',
160-
desc=('the linear frequency filtering parameters used for the initial '
161-
'linear spherical deconvolution step (default = [ 1 1 1 0 0 ]). '
162-
'These should be supplied as a text file containing the '
163-
'filtering coefficients for each even harmonic order.'))
164-
165-
neg_lambda = traits.Float(
166-
1.0, argstr='-neg_lambda %f',
167-
desc=('the regularisation parameter lambda that controls the strength'
168-
' of the non-negativity constraint'))
169-
thres = traits.Float(
170-
0.0, argstr='-threshold %f',
171-
desc=('the threshold below which the amplitude of the FOD is assumed '
172-
'to be zero, expressed as an absolute amplitude'))
173-
174-
n_iter = traits.Int(
175-
50, argstr='-niter %d', desc=('the maximum number of iterations '
176-
'to perform for each voxel'))
177102

178103

179104
class EstimateFODOutputSpec(TraitedSpec):
180-
out_file = File(exists=True, desc='the output response file')
105+
wm_odf = File(argstr='%s', desc='output WM ODF')
106+
gm_odf = File(argstr='%s', desc='output GM ODF')
107+
csf_odf = File(argstr='%s', desc='output CSF ODF')
181108

182109

183110
class EstimateFOD(MRTrix3Base):
184111

185112
"""
186-
Convert diffusion-weighted images to tensor images
187-
(previous MRTrix releases)
188-
189-
Note that this program makes use of implied symmetries in the diffusion
190-
profile. First, the fact the signal attenuation profile is real implies
191-
that it has conjugate symmetry, i.e. Y(l,-m) = Y(l,m)* (where * denotes
192-
the complex conjugate). Second, the diffusion profile should be
193-
antipodally symmetric (i.e. S(x) = S(-x)), implying that all odd l
194-
components should be zero. Therefore, this program only computes the even
195-
elements.
196-
197-
Note that the spherical harmonics equations used here differ slightly from
198-
those conventionally used, in that the (-1)^m factor has been omitted.
199-
This should be taken into account in all subsequent calculations.
200-
The spherical harmonic coefficients are stored as follows. First, since
201-
the signal attenuation profile is real, it has conjugate symmetry, i.e.
202-
Y(l,-m) = Y(l,m)* (where * denotes the complex conjugate). Second, the
203-
diffusion profile should be antipodally symmetric (i.e. S(x) = S(-x)),
204-
implying that all odd l components should be zero. Therefore, only the
205-
even elements are computed.
206-
207-
Note that the spherical harmonics equations used here differ slightly from
208-
those conventionally used, in that the (-1)^m factor has been omitted.
209-
This should be taken into account in all subsequent calculations.
210-
Each volume in the output image corresponds to a different spherical
211-
harmonic component. Each volume will correspond to the following:
212-
213-
volume 0: l = 0, m = 0
214-
volume 1: l = 2, m = -2 (imaginary part of m=2 SH)
215-
volume 2: l = 2, m = -1 (imaginary part of m=1 SH)
216-
volume 3: l = 2, m = 0
217-
volume 4: l = 2, m = 1 (real part of m=1 SH)
218-
volume 5: l = 2, m = 2 (real part of m=2 SH)
219-
etc...
220-
221-
113+
Estimate fibre orientation distributions from diffusion data using spherical deconvolution
222114
223115
Example
224116
-------
225117
226118
>>> import nipype.interfaces.mrtrix3 as mrt
227119
>>> fod = mrt.EstimateFOD()
228-
>>> fod.inputs.in_file = 'dwi.mif'
229-
>>> fod.inputs.response = 'response.txt'
230-
>>> fod.inputs.in_mask = 'mask.nii.gz'
120+
>>> fod.inputs.algorithm = 'csd'
121+
>>> fod.inputs.dwi_file = 'dwi.mif'
122+
>>> fod.inputs.wm_txt = 'wm.txt'
231123
>>> fod.inputs.grad_fsl = ('bvecs', 'bvals')
232124
>>> fod.cmdline # doctest: +ELLIPSIS
233-
'dwi2fod -fslgrad bvecs bvals -mask mask.nii.gz dwi.mif response.txt\
234-
fods.mif'
125+
'dwi2fod -fslgrad bvecs bvals csd dwi.mif wm.txt wm.mif'
235126
>>> fod.run() # doctest: +SKIP
236127
"""
237128

@@ -241,5 +132,12 @@ class EstimateFOD(MRTrix3Base):
241132

242133
def _list_outputs(self):
243134
outputs = self.output_spec().get()
244-
outputs['out_file'] = op.abspath(self.inputs.out_file)
135+
outputs['wm_odf'] = op.abspath(self.inputs.wm_odf)
136+
if self.inputs.gm_odf!=Undefined:
137+
outputs['gm_odf'] = op.abspath(self.inputs.gm_odf)
138+
if self.inputs.csf_odf!=Undefined:
139+
outputs['csf_odf'] = op.abspath(self.inputs.csf_odf)
245140
return outputs
141+
142+
143+

0 commit comments

Comments
 (0)