8
8
"""
9
9
from nipype .interfaces .base import (CommandLineInputSpec , CommandLine , traits ,
10
10
TraitedSpec , File , StdOutCommandLine ,
11
- StdOutCommandLineInputSpec )
11
+ StdOutCommandLineInputSpec , isdefined )
12
12
from nipype .utils .filemanip import split_filename
13
13
import os
14
14
@@ -49,7 +49,7 @@ class DTIFit(StdOutCommandLine):
49
49
>>> import nipype.interfaces.camino as cmon
50
50
>>> fit = cmon.DTIFit()
51
51
>>> fit.inputs.scheme_file = 'A.scheme'
52
- >>> fit.inputs.in_file = 'tensor_fitted_data.Bfloat '
52
+ >>> fit.inputs.in_file = 'tensor_fitted_data.Bdouble '
53
53
>>> fit.run() # doctest: +SKIP
54
54
"""
55
55
_cmd = 'dtfit'
@@ -65,6 +65,107 @@ def _gen_outfilename(self):
65
65
_ , name , _ = split_filename (self .inputs .in_file )
66
66
return name + '_DT.Bdouble'
67
67
68
+ class DTMetricInputSpec (CommandLineInputSpec ):
69
+ eigen_data = File (exists = True , argstr = '-inputfile %s' , mandatory = True ,
70
+ desc = 'voxel-order data filename' )
71
+
72
+ metric = traits .Enum ('fa' ,'md' ,'rd' ,'l1' , 'l2' , 'l3' , 'tr' , 'ra' , '2dfa' ,'cl' ,'cp' ,'cs' ,
73
+ argstr = '-stat %s' , mandatory = True ,
74
+ desc = ('Specifies the metric to compute. Possible choices are: '
75
+ '"fa", "md", "rd", "l1", "l2", "l3", "tr", "ra", "2dfa", "cl", "cp" or "cs".' ))
76
+
77
+ inputdatatype = traits .Enum ('double' , 'float' , 'long' , 'int' , 'short' , 'char' ,
78
+ argstr = '-inputdatatype %s' , usedefault = True ,
79
+ desc = ('Specifies the data type of the input data. '
80
+ 'The data type can be any of the following strings: '
81
+ '"char", "short", "int", "long", "float" or "double".'
82
+ 'Default is double data type' ))
83
+
84
+ outputdatatype = traits .Enum ('double' , 'float' , 'long' , 'int' , 'short' , 'char' ,
85
+ argstr = '-outputdatatype %s' , usedefault = True ,
86
+ desc = ('Specifies the data type of the output data. '
87
+ 'The data type can be any of the following strings: '
88
+ '"char", "short", "int", "long", "float" or "double".'
89
+ 'Default is double data type' ))
90
+
91
+ data_header = File (argstr = '-header %s' , exists = True ,
92
+ desc = ('A Nifti .nii or .nii.gz file containing the header information. '
93
+ 'Usually this will be the header of the raw data file from which '
94
+ 'the diffusion tensors were reconstructed.' ))
95
+
96
+ outputfile = File (argstr = '-outputfile %s' , genfile = True ,
97
+ desc = ('Output name. Output will be a .nii.gz file if data_header is provided and'
98
+ 'in voxel order with outputdatatype datatype (default: double) otherwise.' ))
99
+
100
+ class DTMetricOutputSpec (TraitedSpec ):
101
+ metric_stats = File (exists = True , desc = 'Diffusion Tensor statistics of the chosen metric' )
102
+
103
+ class DTMetric (CommandLine ):
104
+ """
105
+ Computes tensor metric statistics based on the eigenvalues l1 >= l2 >= l3
106
+ typically obtained from ComputeEigensystem.
107
+
108
+ The full list of statistics is:
109
+
110
+ <cl> = (l1 - l2) / l1 , a measure of linearity
111
+ <cp> = (l2 - l3) / l1 , a measure of planarity
112
+ <cs> = l3 / l1 , a measure of isotropy
113
+ with: cl + cp + cs = 1
114
+
115
+ <l1> = first eigenvalue
116
+ <l2> = second eigenvalue
117
+ <l3> = third eigenvalue
118
+
119
+ <tr> = l1 + l2 + l3
120
+ <md> = tr / 3
121
+ <rd> = (l2 + l3) / 2
122
+ <fa> = fractional anisotropy. (Basser et al, J Magn Reson B 1996)
123
+ <ra> = relative anisotropy (Basser et al, J Magn Reson B 1996)
124
+
125
+ <2dfa> = 2D FA of the two minor eigenvalues l2 and l3
126
+ i.e. sqrt( 2 * [(l2 - <l>)^2 + (l3 - <l>)^2] / (l2^2 + l3^2) )
127
+ with: <l> = (l2 + l3) / 2
128
+
129
+ Example
130
+ -------
131
+ Compute the CP planar metric as float data type.
132
+
133
+ >>> import nipype.interfaces.camino as cam
134
+ >>> dtmetric = cam.DTMetric()
135
+ >>> dtmetric.inputs.eigen_data = 'dteig.Bdouble'
136
+ >>> dtmetric.inputs.metric = 'cp'
137
+ >>> dtmetric.inputs.outputdatatype = 'float'
138
+ >>> dtmetric.run() # doctest: +SKIP
139
+ """
140
+ _cmd = 'dtshape'
141
+ input_spec = DTMetricInputSpec
142
+ output_spec = DTMetricOutputSpec
143
+
144
+ def _list_outputs (self ):
145
+ outputs = self .output_spec ().get ()
146
+ outputs ['metric_stats' ] = os .path .abspath (self ._gen_outfilename ())
147
+ return outputs
148
+
149
+ def _gen_outfilename (self ):
150
+ return self ._gen_outputfile ()
151
+
152
+ def _gen_outputfile (self ):
153
+ outputfile = self .inputs .outputfile
154
+ if not isdefined (outputfile ):
155
+ outputfile = self ._gen_filename ('outputfile' )
156
+ return outputfile
157
+
158
+ def _gen_filename (self , name ):
159
+ if name == 'outputfile' :
160
+ _ , name , _ = split_filename (self .inputs .eigen_data )
161
+ metric = self .inputs .metric
162
+ datatype = self .inputs .outputdatatype
163
+ if isdefined (self .inputs .data_header ):
164
+ filename = name + '_' + metric + '.nii.gz'
165
+ else :
166
+ filename = name + '_' + metric + '.B' + datatype
167
+ return filename
168
+
68
169
class ModelFitInputSpec (StdOutCommandLineInputSpec ):
69
170
def _gen_model_options (): #@NoSelf
70
171
"""
@@ -134,7 +235,7 @@ class ModelFit(StdOutCommandLine):
134
235
>>> fit = cmon.ModelFit()
135
236
>>> fit.model = 'dt'
136
237
>>> fit.inputs.scheme_file = 'A.scheme'
137
- >>> fit.inputs.in_file = 'tensor_fitted_data.Bfloat '
238
+ >>> fit.inputs.in_file = 'tensor_fitted_data.Bdouble '
138
239
>>> fit.run() # doctest: +SKIP
139
240
"""
140
241
_cmd = 'modelfit'
@@ -381,7 +482,7 @@ class TrackDT(Track):
381
482
382
483
>>> import nipype.interfaces.camino as cmon
383
484
>>> track = cmon.TrackDT()
384
- >>> track.inputs.in_file = 'tensor_fitted_data.Bfloat '
485
+ >>> track.inputs.in_file = 'tensor_fitted_data.Bdouble '
385
486
>>> track.inputs.seed_file = 'seed_mask.nii'
386
487
>>> track.run() # doctest: +SKIP
387
488
"""
@@ -447,7 +548,7 @@ class TrackBayesDirac(Track):
447
548
448
549
>>> import nipype.interfaces.camino as cmon
449
550
>>> track = cmon.TrackBayesDirac()
450
- >>> track.inputs.in_file = 'tensor_fitted_data.Bfloat '
551
+ >>> track.inputs.in_file = 'tensor_fitted_data.Bdouble '
451
552
>>> track.inputs.seed_file = 'seed_mask.nii'
452
553
>>> track.inputs.scheme_file = 'bvecs.scheme'
453
554
>>> track.run() # doctest: +SKIP
@@ -547,7 +648,7 @@ class ComputeMeanDiffusivity(StdOutCommandLine):
547
648
548
649
>>> import nipype.interfaces.camino as cmon
549
650
>>> md = cmon.ComputeMeanDiffusivity()
550
- >>> md.inputs.in_file = 'tensor_fitted_data.Bfloat '
651
+ >>> md.inputs.in_file = 'tensor_fitted_data.Bdouble '
551
652
>>> md.inputs.scheme_file = 'A.scheme'
552
653
>>> md.run() # doctest: +SKIP
553
654
"""
@@ -606,7 +707,7 @@ class ComputeFractionalAnisotropy(StdOutCommandLine):
606
707
607
708
>>> import nipype.interfaces.camino as cmon
608
709
>>> fa = cmon.ComputeFractionalAnisotropy()
609
- >>> fa.inputs.in_file = 'tensor_fitted_data.Bfloat '
710
+ >>> fa.inputs.in_file = 'tensor_fitted_data.Bdouble '
610
711
>>> fa.inputs.scheme_file = 'A.scheme'
611
712
>>> fa.run() # doctest: +SKIP
612
713
"""
@@ -667,7 +768,7 @@ class ComputeTensorTrace(StdOutCommandLine):
667
768
668
769
>>> import nipype.interfaces.camino as cmon
669
770
>>> trace = cmon.ComputeTensorTrace()
670
- >>> trace.inputs.in_file = 'tensor_fitted_data.Bfloat '
771
+ >>> trace.inputs.in_file = 'tensor_fitted_data.Bdouble '
671
772
>>> trace.inputs.scheme_file = 'A.scheme'
672
773
>>> trace.run() # doctest: +SKIP
673
774
"""
@@ -690,11 +791,21 @@ class ComputeEigensystemInputSpec(StdOutCommandLineInputSpec):
690
791
691
792
inputmodel = traits .Enum ('dt' , 'multitensor' , argstr = '-inputmodel %s' , desc = 'Specifies the model that the input data contains parameters for. Possible model types are: "dt" (diffusion-tensor data) and "multitensor"' )
692
793
693
- maxcomponents = traits .Int (argstr = '-maxcomponents %s ' , desc = 'The maximum number of tensor components in a voxel of the input data.' )
794
+ maxcomponents = traits .Int (argstr = '-maxcomponents %d ' , desc = 'The maximum number of tensor components in a voxel of the input data.' )
694
795
695
- inputdatatype = traits .Enum ("double" , "char" , "short" , "int" , "long" , "float" , argstr = '-inputdatatype %s' , desc = 'Specifies the data type of the input file. The data type can be any of the following strings: "char", "short", "int", "long", "float" or "double".' )
796
+ inputdatatype = traits .Enum ('double' , 'float' , 'long' , 'int' , 'short' , 'char' ,
797
+ argstr = '-inputdatatype %s' , usedefault = True ,
798
+ desc = ('Specifies the data type of the input data. '
799
+ 'The data type can be any of the following strings: '
800
+ '"char", "short", "int", "long", "float" or "double".'
801
+ 'Default is double data type' ))
696
802
697
- outputdatatype = traits .Enum ("double" , "char" , "short" , "int" , "long" , "float" , argstr = '-outputdatatype %s' , desc = 'Specifies the data type of the output data. The data type can be any of the following strings: "char", "short", "int", "long", "float" or "double".' )
803
+ outputdatatype = traits .Enum ('double' , 'float' , 'long' , 'int' , 'short' , 'char' ,
804
+ argstr = '-outputdatatype %s' , usedefault = True ,
805
+ desc = ('Specifies the data type of the output data. '
806
+ 'The data type can be any of the following strings: '
807
+ '"char", "short", "int", "long", "float" or "double".'
808
+ 'Default is double data type' ))
698
809
699
810
class ComputeEigensystemOutputSpec (TraitedSpec ):
700
811
eigen = File (exists = True , desc = 'Trace of the diffusion tensor' )
@@ -716,7 +827,7 @@ class ComputeEigensystem(StdOutCommandLine):
716
827
717
828
>>> import nipype.interfaces.camino as cmon
718
829
>>> dteig = cmon.ComputeEigensystem()
719
- >>> dteig.inputs.in_file = 'tensor_fitted_data.Bfloat '
830
+ >>> dteig.inputs.in_file = 'tensor_fitted_data.Bdouble '
720
831
>>> dteig.run() # doctest: +SKIP
721
832
"""
722
833
_cmd = 'dteig'
@@ -730,4 +841,5 @@ def _list_outputs(self):
730
841
731
842
def _gen_outfilename (self ):
732
843
_ , name , _ = split_filename (self .inputs .in_file )
733
- return name + "_Eigen.img" #Need to change to self.inputs.outputdatatype
844
+ datatype = self .inputs .outputdatatype
845
+ return name + '_eig.B' + datatype
0 commit comments