Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9db438f
Merge remote-tracking branch 'upstream/master'
mick-d Oct 15, 2013
a9c41c7
Merge remote-tracking branch 'upstream/master'
mick-d Oct 15, 2013
59d2fd4
AFNI issue
mick-d Oct 19, 2013
5360d04
Merge remote-tracking branch 'upstream/master'
mick-d Oct 19, 2013
930c756
AFNI fixed by latest master
mick-d Oct 19, 2013
9b22a64
New interface for Camino dtshape. Minor correction to Camino ComputeE…
mick-d Oct 27, 2013
25bf37b
Correct PEP8
mick-d Oct 30, 2013
83a925a
Merge remote-tracking branch 'upstream/master' into camino
Nov 9, 2013
e09fc2d
Add header option for camino.dti.DTMetric
mick-d Nov 9, 2013
bf7f5bc
Merge remote-tracking branch 'upstream/master' into camino
mick-d Nov 15, 2013
446118a
Merge remote-tracking branch 'origin/camino' into camino
mick-d Nov 15, 2013
fa9ccdc
Camino update
mick-d Nov 18, 2013
f717526
Merge branch 'camino' of https://github.com/mick-d/nipype into camino
mick-d Nov 18, 2013
26c8280
Commiting again same thing
mick-d Nov 18, 2013
7001996
Merge branch 'camino' of github.com:mick-d/nipype into camino
mick-d Nov 18, 2013
38e1cc4
Merge remote-tracking branch 'upstream/master'
mick-d Nov 18, 2013
ca19159
New interface for Camino dtshape. Minor correction to Camino ComputeE…
mick-d Oct 27, 2013
1af343e
Correct PEP8
mick-d Oct 30, 2013
b22f5cc
Add header option for camino.dti.DTMetric
mick-d Nov 9, 2013
4516073
Camino update
mick-d Nov 18, 2013
508c797
Merge branch 'camino' of github.com:mick-d/nipype into camino
mick-d Nov 18, 2013
fe65593
fix: auto test
satra Nov 19, 2013
6d30d9a
Merge pull request #1 from satra/tst/mike
mick-d Nov 20, 2013
ae52aa8
Autotest file of camino/dti.py DTMetric interface
mick-d Nov 20, 2013
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nipype/interfaces/camino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
from .dti import (DTIFit, ModelFit, DTLUTGen, PicoPDFs, Track, TrackPICo,
TrackBayesDirac, TrackDT, TrackBallStick, TrackBootstrap,
ComputeFractionalAnisotropy, ComputeMeanDiffusivity,
ComputeTensorTrace, ComputeEigensystem)
ComputeTensorTrace, ComputeEigensystem, DTMetric)
from .calib import (SFPICOCalibData, SFLUTGen)
from .odf import (QBallMX, LinRecon, SFPeaks)
2 changes: 1 addition & 1 deletion nipype/interfaces/camino/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ class AnalyzeHeader(StdOutCommandLine):

>>> import nipype.interfaces.camino as cmon
>>> hdr = cmon.AnalyzeHeader()
>>> hdr.inputs.in_file = 'tensor_fitted_data.Bfloat'
>>> hdr.inputs.in_file = 'tensor_fitted_data.Bdouble'
>>> hdr.inputs.scheme_file = 'A.scheme'
>>> hdr.inputs.data_dims = [256,256,256]
>>> hdr.inputs.voxel_dims = [1,1,1]
Expand Down
138 changes: 125 additions & 13 deletions nipype/interfaces/camino/dti.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""
from nipype.interfaces.base import (CommandLineInputSpec, CommandLine, traits,
TraitedSpec, File, StdOutCommandLine,
StdOutCommandLineInputSpec)
StdOutCommandLineInputSpec, isdefined)
from nipype.utils.filemanip import split_filename
import os

Expand Down Expand Up @@ -49,7 +49,7 @@ class DTIFit(StdOutCommandLine):
>>> import nipype.interfaces.camino as cmon
>>> fit = cmon.DTIFit()
>>> fit.inputs.scheme_file = 'A.scheme'
>>> fit.inputs.in_file = 'tensor_fitted_data.Bfloat'
>>> fit.inputs.in_file = 'tensor_fitted_data.Bdouble'
>>> fit.run() # doctest: +SKIP
"""
_cmd = 'dtfit'
Expand All @@ -65,6 +65,107 @@ def _gen_outfilename(self):
_, name , _ = split_filename(self.inputs.in_file)
return name + '_DT.Bdouble'

class DTMetricInputSpec(CommandLineInputSpec):
eigen_data = File(exists=True, argstr='-inputfile %s', mandatory=True,
desc='voxel-order data filename')

metric = traits.Enum('fa','md','rd','l1', 'l2', 'l3', 'tr', 'ra', '2dfa','cl','cp','cs',
argstr='-stat %s', mandatory=True,
desc=('Specifies the metric to compute. Possible choices are: '
'"fa", "md", "rd", "l1", "l2", "l3", "tr", "ra", "2dfa", "cl", "cp" or "cs".'))

inputdatatype = traits.Enum('double', 'float', 'long', 'int', 'short', 'char',
argstr='-inputdatatype %s', usedefault=True,
desc=('Specifies the data type of the input data. '
'The data type can be any of the following strings: '
'"char", "short", "int", "long", "float" or "double".'
'Default is double data type'))

outputdatatype = traits.Enum('double', 'float', 'long', 'int', 'short', 'char',
argstr='-outputdatatype %s', usedefault=True,
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".'
'Default is double data type'))

data_header = File(argstr='-header %s', exists=True,
desc=('A Nifti .nii or .nii.gz file containing the header information. '
'Usually this will be the header of the raw data file from which '
'the diffusion tensors were reconstructed.'))

outputfile = File(argstr='-outputfile %s', genfile=True,
desc=('Output name. Output will be a .nii.gz file if data_header is provided and'
'in voxel order with outputdatatype datatype (default: double) otherwise.'))

class DTMetricOutputSpec(TraitedSpec):
metric_stats = File(exists=True, desc='Diffusion Tensor statistics of the chosen metric')

class DTMetric(CommandLine):
"""
Computes tensor metric statistics based on the eigenvalues l1 >= l2 >= l3
typically obtained from ComputeEigensystem.

The full list of statistics is:

<cl> = (l1 - l2) / l1 , a measure of linearity
<cp> = (l2 - l3) / l1 , a measure of planarity
<cs> = l3 / l1 , a measure of isotropy
with: cl + cp + cs = 1

<l1> = first eigenvalue
<l2> = second eigenvalue
<l3> = third eigenvalue

<tr> = l1 + l2 + l3
<md> = tr / 3
<rd> = (l2 + l3) / 2
<fa> = fractional anisotropy. (Basser et al, J Magn Reson B 1996)
<ra> = relative anisotropy (Basser et al, J Magn Reson B 1996)

<2dfa> = 2D FA of the two minor eigenvalues l2 and l3
i.e. sqrt( 2 * [(l2 - <l>)^2 + (l3 - <l>)^2] / (l2^2 + l3^2) )
with: <l> = (l2 + l3) / 2

Example
-------
Compute the CP planar metric as float data type.

>>> import nipype.interfaces.camino as cam
>>> dtmetric = cam.DTMetric()
>>> dtmetric.inputs.eigen_data = 'dteig.Bdouble'
>>> dtmetric.inputs.metric = 'cp'
>>> dtmetric.inputs.outputdatatype = 'float'
>>> dtmetric.run() # doctest: +SKIP
"""
_cmd = 'dtshape'
input_spec=DTMetricInputSpec
output_spec=DTMetricOutputSpec

def _list_outputs(self):
outputs = self.output_spec().get()
outputs['metric_stats'] = os.path.abspath(self._gen_outfilename())
return outputs

def _gen_outfilename(self):
return self._gen_outputfile()

def _gen_outputfile(self):
outputfile = self.inputs.outputfile
if not isdefined(outputfile):
outputfile = self._gen_filename('outputfile')
return outputfile

def _gen_filename(self, name):
if name == 'outputfile':
_, name , _ = split_filename(self.inputs.eigen_data)
metric = self.inputs.metric
datatype= self.inputs.outputdatatype
if isdefined(self.inputs.data_header):
filename = name + '_' + metric + '.nii.gz'
else:
filename = name + '_' + metric + '.B' + datatype
return filename

class ModelFitInputSpec(StdOutCommandLineInputSpec):
def _gen_model_options(): #@NoSelf
"""
Expand Down Expand Up @@ -134,7 +235,7 @@ class ModelFit(StdOutCommandLine):
>>> fit = cmon.ModelFit()
>>> fit.model = 'dt'
>>> fit.inputs.scheme_file = 'A.scheme'
>>> fit.inputs.in_file = 'tensor_fitted_data.Bfloat'
>>> fit.inputs.in_file = 'tensor_fitted_data.Bdouble'
>>> fit.run() # doctest: +SKIP
"""
_cmd = 'modelfit'
Expand Down Expand Up @@ -381,7 +482,7 @@ class TrackDT(Track):

>>> import nipype.interfaces.camino as cmon
>>> track = cmon.TrackDT()
>>> track.inputs.in_file = 'tensor_fitted_data.Bfloat'
>>> track.inputs.in_file = 'tensor_fitted_data.Bdouble'
>>> track.inputs.seed_file = 'seed_mask.nii'
>>> track.run() # doctest: +SKIP
"""
Expand Down Expand Up @@ -447,7 +548,7 @@ class TrackBayesDirac(Track):

>>> import nipype.interfaces.camino as cmon
>>> track = cmon.TrackBayesDirac()
>>> track.inputs.in_file = 'tensor_fitted_data.Bfloat'
>>> track.inputs.in_file = 'tensor_fitted_data.Bdouble'
>>> track.inputs.seed_file = 'seed_mask.nii'
>>> track.inputs.scheme_file = 'bvecs.scheme'
>>> track.run() # doctest: +SKIP
Expand Down Expand Up @@ -547,7 +648,7 @@ class ComputeMeanDiffusivity(StdOutCommandLine):

>>> import nipype.interfaces.camino as cmon
>>> md = cmon.ComputeMeanDiffusivity()
>>> md.inputs.in_file = 'tensor_fitted_data.Bfloat'
>>> md.inputs.in_file = 'tensor_fitted_data.Bdouble'
>>> md.inputs.scheme_file = 'A.scheme'
>>> md.run() # doctest: +SKIP
"""
Expand Down Expand Up @@ -606,7 +707,7 @@ class ComputeFractionalAnisotropy(StdOutCommandLine):

>>> import nipype.interfaces.camino as cmon
>>> fa = cmon.ComputeFractionalAnisotropy()
>>> fa.inputs.in_file = 'tensor_fitted_data.Bfloat'
>>> fa.inputs.in_file = 'tensor_fitted_data.Bdouble'
>>> fa.inputs.scheme_file = 'A.scheme'
>>> fa.run() # doctest: +SKIP
"""
Expand Down Expand Up @@ -667,7 +768,7 @@ class ComputeTensorTrace(StdOutCommandLine):

>>> import nipype.interfaces.camino as cmon
>>> trace = cmon.ComputeTensorTrace()
>>> trace.inputs.in_file = 'tensor_fitted_data.Bfloat'
>>> trace.inputs.in_file = 'tensor_fitted_data.Bdouble'
>>> trace.inputs.scheme_file = 'A.scheme'
>>> trace.run() # doctest: +SKIP
"""
Expand All @@ -690,11 +791,21 @@ class ComputeEigensystemInputSpec(StdOutCommandLineInputSpec):

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"')

maxcomponents = traits.Int(argstr='-maxcomponents %s', desc='The maximum number of tensor components in a voxel of the input data.')
maxcomponents = traits.Int(argstr='-maxcomponents %d', desc='The maximum number of tensor components in a voxel of the input data.')

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".')
inputdatatype = traits.Enum('double', 'float', 'long', 'int', 'short', 'char',
argstr='-inputdatatype %s', usedefault=True,
desc=('Specifies the data type of the input data. '
'The data type can be any of the following strings: '
'"char", "short", "int", "long", "float" or "double".'
'Default is double data type'))

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".')
outputdatatype = traits.Enum('double', 'float', 'long', 'int', 'short', 'char',
argstr='-outputdatatype %s', usedefault=True,
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".'
'Default is double data type'))

class ComputeEigensystemOutputSpec(TraitedSpec):
eigen = File(exists=True, desc='Trace of the diffusion tensor')
Expand All @@ -716,7 +827,7 @@ class ComputeEigensystem(StdOutCommandLine):

>>> import nipype.interfaces.camino as cmon
>>> dteig = cmon.ComputeEigensystem()
>>> dteig.inputs.in_file = 'tensor_fitted_data.Bfloat'
>>> dteig.inputs.in_file = 'tensor_fitted_data.Bdouble'
>>> dteig.run() # doctest: +SKIP
"""
_cmd = 'dteig'
Expand All @@ -730,4 +841,5 @@ def _list_outputs(self):

def _gen_outfilename(self):
_, name , _ = split_filename(self.inputs.in_file)
return name + "_Eigen.img" #Need to change to self.inputs.outputdatatype
datatype= self.inputs.outputdatatype
return name + '_eig.B' + datatype
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ def test_ComputeEigensystem_inputs():
),
inputmodel=dict(argstr='-inputmodel %s',
),
outputdatatype=dict(argstr='-outputdatatype %s',
outputdatatype=dict(usedefault=True,
argstr='-outputdatatype %s',
),
args=dict(argstr='%s',
),
inputdatatype=dict(argstr='-inputdatatype %s',
inputdatatype=dict(usedefault=True,
argstr='-inputdatatype %s',
),
maxcomponents=dict(argstr='-maxcomponents %s',
maxcomponents=dict(argstr='-maxcomponents %d',
),
environ=dict(nohash=True,
usedefault=True,
Expand Down
46 changes: 46 additions & 0 deletions nipype/interfaces/camino/tests/test_auto_DTMetric.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
from nipype.testing import assert_equal
from nipype.interfaces.camino.dti import DTMetric
def test_DTMetric_inputs():
input_map = dict(ignore_exception=dict(nohash=True,
usedefault=True,
),
outputfile=dict(argstr='-outputfile %s',
genfile=True,
),
outputdatatype=dict(usedefault=True,
argstr='-outputdatatype %s',
),
metric=dict(mandatory=True,
argstr='-stat %s',
),
args=dict(argstr='%s',
),
inputdatatype=dict(usedefault=True,
argstr='-inputdatatype %s',
),
terminal_output=dict(mandatory=True,
nohash=True,
),
environ=dict(nohash=True,
usedefault=True,
),
eigen_data=dict(mandatory=True,
argstr='-inputfile %s',
),
data_header=dict(argstr='-header %s',
),
)
inputs = DTMetric.input_spec()

for key, metadata in input_map.items():
for metakey, value in metadata.items():
yield assert_equal, getattr(inputs.traits()[key], metakey), value
def test_DTMetric_outputs():
output_map = dict(metric_stats=dict(),
)
outputs = DTMetric.output_spec()

for key, metadata in output_map.items():
for metakey, value in metadata.items():
yield assert_equal, getattr(outputs.traits()[key], metakey), value
Empty file.