Skip to content

Commit e28dea5

Browse files
committed
add tckmap interface
1 parent 204aa89 commit e28dea5

File tree

16 files changed

+270
-60
lines changed

16 files changed

+270
-60
lines changed

nipype/interfaces/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,9 +1349,9 @@ def _terminal_output_update(self):
13491349
def set_default_terminal_output(cls, output_type):
13501350
"""Set the default terminal output for CommandLine Interfaces.
13511351
1352-
This method is used to set default terminal output for
1353-
CommandLine Interfaces. However, setting this will not
1354-
update the output type for any existing instances. For these,
1352+
This method is used to set default terminal output for
1353+
CommandLine Interfaces. However, setting this will not
1354+
update the output type for any existing instances. For these,
13551355
assign the <instance>.inputs.terminal_output.
13561356
"""
13571357

nipype/interfaces/dipy/tensors.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
def tensor_fitting(data, bvals, bvecs, mask_file=None):
3333
"""
3434
Use dipy to fit DTI
35-
35+
3636
Parameters
3737
----------
3838
in_file : str
@@ -58,7 +58,7 @@ def tensor_fitting(data, bvals, bvecs, mask_file=None):
5858

5959
# Load information about the gradients:
6060
gtab = grad.gradient_table(self.inputs.bvals, self.inputs.bvecs)
61-
61+
6262
# Fit it
6363
tenmodel = dti.TensorModel(gtab)
6464
return tenmodel.fit(data, mask), affine
@@ -84,7 +84,7 @@ class DTIOutputSpec(TraitedSpec):
8484
class DTI(BaseInterface):
8585
"""
8686
Calculates the diffusion tensor model parameters
87-
87+
8888
Example
8989
-------
9090
@@ -99,7 +99,7 @@ class DTI(BaseInterface):
9999
output_spec = DTIOutputSpec
100100

101101
def _run_interface(self, runtime):
102-
ten_fit, affine = tensor_fitting(self.inputs.in_file,
102+
ten_fit, affine = tensor_fitting(self.inputs.in_file,
103103
self.inputs.bvals,
104104
self.inputs.bvecs,
105105
self.inputs.mask_file)
@@ -124,7 +124,7 @@ def _gen_filename(self, name):
124124
def _gen_outfilename(self):
125125
_, name, _ = split_filename(self.inputs.in_file)
126126
return name + '_dti.nii'
127-
127+
128128

129129
class TensorModeInputSpec(TraitedSpec):
130130
in_file = File(exists=True, mandatory=True,

nipype/interfaces/fsl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
ImageStats, FilterRegressor, Overlay, Slicer,
1717
PlotTimeSeries, PlotMotionParams, ConvertXFM,
1818
SwapDimensions, PowerSpectrum, Reorient2Std,
19-
Complex, InvWarp, WarpUtils, ConvertWarp, WarpPoints,
19+
Complex, InvWarp, WarpUtils, ConvertWarp, WarpPoints,
2020
WarpPointsToStd, RobustFOV)
2121

2222
from .epi import (PrepareFieldmap, TOPUP, ApplyTOPUP, Eddy, EPIDeWarp,

nipype/interfaces/fsl/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ class RobustFOVInputSpec(FSLCommandInputSpec):
3636
desc='input filename',
3737
argstr='-i %s', position=0, mandatory=True)
3838
out_roi = File(desc="ROI volume output name", argstr="-r %s",
39-
name_source=['in_file'], hash_files=False,
39+
name_source=['in_file'], hash_files=False,
4040
name_template='%s_ROI')
41-
42-
41+
42+
4343
class RobustFOVOutputSpec(TraitedSpec):
4444
out_roi = File(exists=True, desc="ROI volume output name")
4545

@@ -48,7 +48,7 @@ class RobustFOV(FSLCommand):
4848
_cmd = 'robustfov'
4949
input_spec = RobustFOVInputSpec
5050
output_spec = RobustFOVOutputSpec
51-
51+
5252

5353
class ImageMeantsInputSpec(FSLCommandInputSpec):
5454
in_file = File(exists=True,

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, BrainMask, TensorMetrics
5+
from utils import Mesh2PVE, Generate5tt, BrainMask, TensorMetrics, ComputeTDI
66
from preprocess import ResponseSD, ACTPrepareFSL
77
from tracking import Tractography
88
from reconst import FitTensor, EstimateFOD
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from nipype.testing import assert_equal
3+
from nipype.interfaces.mrtrix3.utils import ComputeTDI
4+
5+
def test_ComputeTDI_inputs():
6+
input_map = dict(args=dict(argstr='%s',
7+
),
8+
contrast=dict(argstr='-constrast %s',
9+
),
10+
data_type=dict(argstr='-datatype %s',
11+
),
12+
dixel=dict(argstr='-dixel %s',
13+
),
14+
ends_only=dict(argstr='-ends_only',
15+
),
16+
environ=dict(nohash=True,
17+
usedefault=True,
18+
),
19+
fwhm_tck=dict(argstr='-fwhm_tck %f',
20+
),
21+
ignore_exception=dict(nohash=True,
22+
usedefault=True,
23+
),
24+
in_file=dict(argstr='%s',
25+
mandatory=True,
26+
position=-2,
27+
),
28+
in_map=dict(argstr='-image %s',
29+
),
30+
map_zero=dict(argstr='-map_zero',
31+
),
32+
max_tod=dict(argstr='-tod %d',
33+
),
34+
nthreads=dict(argstr='-nthreads %d',
35+
),
36+
out_file=dict(argstr='%s',
37+
position=-1,
38+
usedefault=True,
39+
),
40+
precise=dict(argstr='-precise',
41+
),
42+
reference=dict(argstr='-template %s',
43+
),
44+
stat_tck=dict(argstr='-stat_tck %s',
45+
),
46+
stat_vox=dict(argstr='-stat_vox %s',
47+
),
48+
tck_weights=dict(argstr='-tck_weights_in %s',
49+
),
50+
terminal_output=dict(nohash=True,
51+
),
52+
upsample=dict(argstr='-upsample %d',
53+
),
54+
use_dec=dict(argstr='-dec',
55+
),
56+
vox_size=dict(argstr='-vox %s',
57+
sep=',',
58+
),
59+
)
60+
inputs = ComputeTDI.input_spec()
61+
62+
for key, metadata in input_map.items():
63+
for metakey, value in metadata.items():
64+
yield assert_equal, getattr(inputs.traits()[key], metakey), value
65+
66+
def test_ComputeTDI_outputs():
67+
output_map = dict(out_file=dict(),
68+
)
69+
outputs = ComputeTDI.output_spec()
70+
71+
for key, metadata in output_map.items():
72+
for metakey, value in metadata.items():
73+
yield assert_equal, getattr(outputs.traits()[key], metakey), value
74+

nipype/interfaces/mrtrix3/utils.py

Lines changed: 137 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class TensorMetricsOutputSpec(TraitedSpec):
188188
class TensorMetrics(CommandLine):
189189

190190
"""
191-
Convert a mesh surface to a partial volume estimation image
191+
Compute metrics from tensors
192192
193193
194194
Example
@@ -215,3 +215,139 @@ def _list_outputs(self):
215215
outputs[k] = op.abspath(getattr(self.inputs, k))
216216

217217
return outputs
218+
219+
220+
class ComputeTDIInputSpec(CommandLineInputSpec):
221+
in_file = File(exists=True, argstr='%s', mandatory=True, position=-2,
222+
desc='input tractography')
223+
out_file = File('tdi.mif', argstr='%s', usedefault=True, position=-1,
224+
desc='output TDI file')
225+
reference = File(
226+
exists=True, argstr='-template %s', desc='a reference'
227+
'image to be used as template')
228+
vox_size = traits.List(traits.Int, argstr='-vox %s', sep=',',
229+
desc='voxel dimensions')
230+
data_type = traits.Enum('float', 'unsigned int', argstr='-datatype %s',
231+
desc='specify output image data type')
232+
use_dec = traits.Bool(argstr='-dec', desc='perform mapping in DEC space')
233+
dixel = File('dixels.txt', argstr='-dixel %s', desc='map streamlines to'
234+
'dixels within each voxel. Directions are stored as'
235+
'azimuth elevation pairs.')
236+
max_tod = traits.Int(argstr='-tod %d', desc='generate a Track Orientation '
237+
'Distribution (TOD) in each voxel.')
238+
239+
contrast = traits.Enum('tdi', 'length', 'invlength', 'scalar_map',
240+
'scalar_map_conut', 'fod_amp', 'curvature',
241+
argstr='-constrast %s', desc='define the desired '
242+
'form of contrast for the output image')
243+
in_map = File(exists=True, argstr='-image %s', desc='provide the'
244+
'scalar image map for generating images with '
245+
'\'scalar_map\' contrasts, or the SHs image for fod_amp')
246+
247+
stat_vox = traits.Enum('sum', 'min', 'mean', 'max', argstr='-stat_vox %s',
248+
desc='define the statistic for choosing the final'
249+
'voxel intesities for a given contrast')
250+
stat_tck = traits.Enum(
251+
'mean', 'sum', 'min', 'max', 'median', 'mean_nonzero', 'gaussian',
252+
'ends_min', 'ends_mean', 'ends_max', 'ends_prod',
253+
argstr='-stat_tck %s', desc='define the statistic for choosing '
254+
'the contribution to be made by each streamline as a function of'
255+
' the samples taken along their lengths.')
256+
257+
fwhm_tck = traits.Float(
258+
argstr='-fwhm_tck %f', desc='define the statistic for choosing the'
259+
' contribution to be made by each streamline as a function of the '
260+
'samples taken along their lengths')
261+
262+
map_zero = traits.Bool(
263+
argstr='-map_zero', desc='if a streamline has zero contribution based '
264+
'on the contrast & statistic, typically it is not mapped; use this '
265+
'option to still contribute to the map even if this is the case '
266+
'(these non-contributing voxels can then influence the mean value in '
267+
'each voxel of the map)')
268+
269+
upsample = traits.Int(argstr='-upsample %d', desc='upsample the tracks by'
270+
' some ratio using Hermite interpolation before '
271+
'mappping')
272+
273+
precise = traits.Bool(
274+
argstr='-precise', desc='use a more precise streamline mapping '
275+
'strategy, that accurately quantifies the length through each voxel '
276+
'(these lengths are then taken into account during TWI calculation)')
277+
ends_only = traits.Bool(argstr='-ends_only', desc='only map the streamline'
278+
' endpoints to the image')
279+
280+
tck_weights = File(exists=True, argstr='-tck_weights_in %s', desc='specify'
281+
' a text scalar file containing the streamline weights')
282+
nthreads = traits.Int(
283+
argstr='-nthreads %d', desc='number of threads. if zero, the number'
284+
' of available cpus will be used')
285+
286+
287+
class ComputeTDIOutputSpec(TraitedSpec):
288+
out_file = File(desc='output TDI file')
289+
290+
291+
class ComputeTDI(MRTrix3Base):
292+
293+
"""
294+
Use track data as a form of contrast for producing a high-resolution
295+
image.
296+
297+
.. admonition:: References
298+
299+
* For TDI or DEC TDI: Calamante, F.; Tournier, J.-D.; Jackson, G. D. &
300+
Connelly, A. Track-density imaging (TDI): Super-resolution white
301+
matter imaging using whole-brain track-density mapping. NeuroImage,
302+
2010, 53, 1233-1243
303+
304+
* If using -contrast length and -stat_vox mean: Pannek, K.; Mathias,
305+
J. L.; Bigler, E. D.; Brown, G.; Taylor, J. D. & Rose, S. E. The
306+
average pathlength map: A diffusion MRI tractography-derived index
307+
for studying brain pathology. NeuroImage, 2011, 55, 133-141
308+
309+
* If using -dixel option with TDI contrast only: Smith, R.E., Tournier,
310+
J-D., Calamante, F., Connelly, A. A novel paradigm for automated
311+
segmentation of very large whole-brain probabilistic tractography
312+
data sets. In proc. ISMRM, 2011, 19, 673
313+
314+
* If using -dixel option with any other contrast: Pannek, K., Raffelt,
315+
D., Salvado, O., Rose, S. Incorporating directional information in
316+
diffusion tractography derived maps: angular track imaging (ATI).
317+
In Proc. ISMRM, 2012, 20, 1912
318+
319+
* If using -tod option: Dhollander, T., Emsell, L., Van Hecke, W., Maes,
320+
F., Sunaert, S., Suetens, P. Track Orientation Density Imaging (TODI)
321+
and Track Orientation Distribution (TOD) based tractography.
322+
NeuroImage, 2014, 94, 312-336
323+
324+
* If using other contrasts / statistics: Calamante, F.; Tournier, J.-D.;
325+
Smith, R. E. & Connelly, A. A generalised framework for
326+
super-resolution track-weighted imaging. NeuroImage, 2012, 59,
327+
2494-2503
328+
329+
* If using -precise mapping option: Smith, R. E.; Tournier, J.-D.;
330+
Calamante, F. & Connelly, A. SIFT: Spherical-deconvolution informed
331+
filtering of tractograms. NeuroImage, 2013, 67, 298-312 (Appendix 3)
332+
333+
334+
335+
Example
336+
-------
337+
338+
>>> import nipype.interfaces.mrtrix3 as mrt
339+
>>> tdi = mrt.ComputeTDI()
340+
>>> tdi.inputs.in_file = 'dti.mif'
341+
>>> tdi.cmdline # doctest: +ELLIPSIS
342+
'tckmap dti.mif tdi.mif'
343+
>>> tdi.run() # doctest: +SKIP
344+
"""
345+
346+
_cmd = 'tckmap'
347+
input_spec = ComputeTDIInputSpec
348+
output_spec = ComputeTDIOutputSpec
349+
350+
def _list_outputs(self):
351+
outputs = self.output_spec().get()
352+
outputs['out_file'] = op.abspath(self.inputs.out_file)
353+
return outputs

0 commit comments

Comments
 (0)