Skip to content

[ENH] Added two AFNI interfaces #1382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

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 CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Next release
* ENH: New interfaces in dipy: RESTORE, EstimateResponseSH, CSD and StreamlineTractography
(https://github.com/nipy/nipype/pull/1090)
* ENH: Added interfaces of AFNI (https://github.com/nipy/nipype/pull/1360,
https://github.com/nipy/nipype/pull/1361)
https://github.com/nipy/nipype/pull/1361, https://github.com/nipy/nipype/pull/1382)
* ENH: Provides a Nipype wrapper for antsJointFusion (https://github.com/nipy/nipype/pull/1351)
* ENH: Added support for PETPVC (https://github.com/nipy/nipype/pull/1335)
* ENH: Merge S3DataSink into DataSink, added AWS documentation (https://github.com/nipy/nipype/pull/1316)
Expand Down
3 changes: 2 additions & 1 deletion nipype/interfaces/afni/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
Fourier, Allineate, Maskave, SkullStrip, TCat, Fim,
BlurInMask, Autobox, TCorrMap, Bandpass, Retroicor,
TCorrelate, TCorr1D, BrickStat, ROIStats, AutoTcorrelate,
AFNItoNIFTI, Eval, Means, Hist, FWHMx)
AFNItoNIFTI, Eval, Means, Hist, FWHMx, OutlierCount,
QualityIndex)
from .svm import (SVMTest, SVMTrain)
133 changes: 131 additions & 2 deletions nipype/interfaces/afni/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

from .base import (AFNICommandBase, AFNICommand, AFNICommandInputSpec, AFNICommandOutputSpec,
Info, no_afni)
from ..base import CommandLineInputSpec
from ..base import (Directory, TraitedSpec,
from ..base import (CommandLineInputSpec, CommandLine, Directory, TraitedSpec,
traits, isdefined, File, InputMultiPath, Undefined)
from ...external.six import string_types
from ...utils.filemanip import (load_json, save_json, split_filename)
Expand Down Expand Up @@ -2372,3 +2371,133 @@ def _list_outputs(self):

outputs['fwhm'] = tuple(sout)
return outputs


class OutlierCountInputSpec(CommandLineInputSpec):
in_file = File(argstr='%s', mandatory=True, exists=True, position=-2, desc='input dataset')
mask = File(exists=True, argstr='-mask %s', xor=['autoclip', 'automask'],
desc='only count voxels within the given mask')
qthr = traits.Range(value=1e-3, low=0.0, high=1.0, argstr='-qthr %.5f',
desc='indicate a value for q to compute alpha')

autoclip = traits.Bool(False, usedefault=True, argstr='-autoclip', xor=['in_file'],
desc='clip off small voxels')
automask = traits.Bool(False, usedefault=True, argstr='-automask', xor=['in_file'],
desc='clip off small voxels')

fraction = traits.Bool(False, usedefault=True, argstr='-fraction',
desc='write out the fraction of masked voxels'
' which are outliers at each timepoint')
interval = traits.Bool(False, usedefault=True, argstr='-range',
desc='write out the median + 3.5 MAD of outlier'
' count with each timepoint')
save_outliers = traits.Bool(False, usedefault=True, desc='enables out_file option')
outliers_file = File(
name_template="%s_outliers", argstr='-save %s', name_source=["in_file"],
output_name='out_outliers', keep_extension=True, desc='output image file name')

polort = traits.Int(argstr='-polort %d',
desc='detrend each voxel timeseries with polynomials')
legendre = traits.Bool(False, usedefault=True, argstr='-legendre',
desc='use Legendre polynomials')
out_file = File(
name_template='%s_outliers', name_source=['in_file'], argstr='> %s',
keep_extension=False, position=-1, desc='capture standard output')


class OutlierCountOutputSpec(TraitedSpec):
out_outliers = File(exists=True, desc='output image file name')
out_file = File(
name_template='%s_tqual', name_source=['in_file'], argstr='> %s',
keep_extension=False, position=-1, desc='capture standard output')


class OutlierCount(CommandLine):
"""Create a 3D dataset from 2D image files using AFNI to3d command

For complete details, see the `to3d Documentation
<http://afni.nimh.nih.gov/pub/dist/doc/program_help/to3d.html>`_

Examples
========

>>> from nipype.interfaces import afni
>>> toutcount = afni.OutlierCount()
>>> toutcount.inputs.in_file = 'functional.nii'
>>> toutcount.cmdline #doctest: +ELLIPSIS
'3dToutcount functional.nii > functional_outliers'
>>> res = toutcount.run() #doctest: +SKIP

"""

_cmd = '3dToutcount'
input_spec = OutlierCountInputSpec
output_spec = OutlierCountOutputSpec

def _parse_inputs(self, skip=None):
if skip is None:
skip = []

if not self.inputs.save_outliers:
skip += ['outliers_file']
return super(OutlierCount, self)._parse_inputs(skip)

def _list_outputs(self):
outputs = self.output_spec().get()
if self.inputs.save_outliers:
outputs['out_outliers'] = op.abspath(self.inputs.outliers_file)
outputs['out_file'] = op.abspath(self.inputs.out_file)
return outputs


class QualityIndexInputSpec(CommandLineInputSpec):
in_file = File(argstr='%s', mandatory=True, exists=True, position=-2, desc='input dataset')
mask = File(exists=True, argstr='-mask %s', xor=['autoclip', 'automask'],
desc='compute correlation only across masked voxels')
spearman = traits.Bool(False, usedefault=True, argstr='-spearman',
desc='Quality index is 1 minus the Spearman (rank) '
'correlation coefficient of each sub-brick '
'with the median sub-brick. (default)')
quadrant = traits.Bool(False, usedefault=True, argstr='-quadrant',
desc='Similar to -spearman, but using 1 minus the '
'quadrant correlation coefficient as the '
'quality index.')
autoclip = traits.Bool(False, usedefault=True, argstr='-autoclip', xor=['mask'],
desc='clip off small voxels')
automask = traits.Bool(False, usedefault=True, argstr='-automask', xor=['mask'],
desc='clip off small voxels')
clip = traits.Float(argstr='-clip %f', desc='clip off values below')

interval = traits.Bool(False, usedefault=True, argstr='-range',
desc='write out the median + 3.5 MAD of outlier'
' count with each timepoint')
out_file = File(
name_template='%s_tqual', name_source=['in_file'], argstr='> %s',
keep_extension=False, position=-1, desc='capture standard output')


class QualityIndexOutputSpec(TraitedSpec):
out_file = File(desc='file containing the caputured standard output')


class QualityIndex(CommandLine):
"""Create a 3D dataset from 2D image files using AFNI to3d command

For complete details, see the `to3d Documentation
<http://afni.nimh.nih.gov/pub/dist/doc/program_help/to3d.html>`_

Examples
========

>>> from nipype.interfaces import afni
>>> tqual = afni.QualityIndex()
>>> tqual.inputs.in_file = 'functional.nii'
>>> tqual.cmdline #doctest: +ELLIPSIS
'3dTqual functional.nii > functional_tqual'
>>> res = tqual.run() #doctest: +SKIP

"""

_cmd = '3dTqual'
input_spec = QualityIndexInputSpec
output_spec = QualityIndexOutputSpec
80 changes: 80 additions & 0 deletions nipype/interfaces/afni/tests/test_auto_OutlierCount.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
from ....testing import assert_equal
from ..preprocess import OutlierCount


def test_OutlierCount_inputs():
input_map = dict(args=dict(argstr='%s',
),
autoclip=dict(argstr='-autoclip',
usedefault=True,
xor=['in_file'],
),
automask=dict(argstr='-automask',
usedefault=True,
xor=['in_file'],
),
environ=dict(nohash=True,
usedefault=True,
),
fraction=dict(argstr='-fraction',
usedefault=True,
),
ignore_exception=dict(nohash=True,
usedefault=True,
),
in_file=dict(argstr='%s',
mandatory=True,
position=-2,
),
interval=dict(argstr='-range',
usedefault=True,
),
legendre=dict(argstr='-legendre',
usedefault=True,
),
mask=dict(argstr='-mask %s',
xor=['autoclip', 'automask'],
),
out_file=dict(argstr='> %s',
keep_extension=False,
name_source=['in_file'],
name_template='%s_outliers',
position=-1,
),
outliers_file=dict(argstr='-save %s',
keep_extension=True,
name_source=['in_file'],
name_template='%s_outliers',
output_name='out_outliers',
),
polort=dict(argstr='-polort %d',
),
qthr=dict(argstr='-qthr %.5f',
),
save_outliers=dict(usedefault=True,
),
terminal_output=dict(nohash=True,
),
)
inputs = OutlierCount.input_spec()

for key, metadata in list(input_map.items()):
for metakey, value in list(metadata.items()):
yield assert_equal, getattr(inputs.traits()[key], metakey), value


def test_OutlierCount_outputs():
output_map = dict(out_file=dict(argstr='> %s',
keep_extension=False,
name_source=['in_file'],
name_template='%s_tqual',
position=-1,
),
out_outliers=dict(),
)
outputs = OutlierCount.output_spec()

for key, metadata in list(output_map.items()):
for metakey, value in list(metadata.items()):
yield assert_equal, getattr(outputs.traits()[key], metakey), value
64 changes: 64 additions & 0 deletions nipype/interfaces/afni/tests/test_auto_QualityIndex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
from ....testing import assert_equal
from ..preprocess import QualityIndex


def test_QualityIndex_inputs():
input_map = dict(args=dict(argstr='%s',
),
autoclip=dict(argstr='-autoclip',
usedefault=True,
xor=['mask'],
),
automask=dict(argstr='-automask',
usedefault=True,
xor=['mask'],
),
clip=dict(argstr='-clip %f',
),
environ=dict(nohash=True,
usedefault=True,
),
ignore_exception=dict(nohash=True,
usedefault=True,
),
in_file=dict(argstr='%s',
mandatory=True,
position=-2,
),
interval=dict(argstr='-range',
usedefault=True,
),
mask=dict(argstr='-mask %s',
xor=['autoclip', 'automask'],
),
out_file=dict(argstr='> %s',
keep_extension=False,
name_source=['in_file'],
name_template='%s_tqual',
position=-1,
),
quadrant=dict(argstr='-quadrant',
usedefault=True,
),
spearman=dict(argstr='-spearman',
usedefault=True,
),
terminal_output=dict(nohash=True,
),
)
inputs = QualityIndex.input_spec()

for key, metadata in list(input_map.items()):
for metakey, value in list(metadata.items()):
yield assert_equal, getattr(inputs.traits()[key], metakey), value


def test_QualityIndex_outputs():
output_map = dict(out_file=dict(),
)
outputs = QualityIndex.output_spec()

for key, metadata in list(output_map.items()):
for metakey, value in list(metadata.items()):
yield assert_equal, getattr(outputs.traits()[key], metakey), value
4 changes: 3 additions & 1 deletion nipype/interfaces/freesurfer/tests/test_auto_MRIsConvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ def test_MRIsConvert_inputs():
),
origname=dict(argstr='-o %s',
),
out_datatype=dict(xor=['out_file'],
out_datatype=dict(mandatory=True,
xor=['out_file'],
),
out_file=dict(argstr='%s',
genfile=True,
mandatory=True,
position=-1,
xor=['out_datatype'],
),
Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/freesurfer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ def _format_arg(self, name, spec, value):
if name == "out_file" and not os.path.isabs(value):
value = os.path.abspath(value)
return super(MRIsConvert, self)._format_arg(name, spec, value)

def _list_outputs(self):
outputs = self.output_spec().get()
outputs["converted"] = os.path.abspath(self._gen_outfilename())
Expand Down