Skip to content

[ENH] Addition of 3dHist from AFNI #1360

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 6 commits into from
Feb 11, 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
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Next release
============

* ENH: Added interfaces of AFNI (https://github.com/nipy/nipype/pull/1360)
* 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)
* TST: Cache APT in CircleCI (https://github.com/nipy/nipype/pull/1333)
Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/afni/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
Fourier, Allineate, Maskave, SkullStrip, TCat, Fim,
BlurInMask, Autobox, TCorrMap, Bandpass, Retroicor,
TCorrelate, TCorr1D, BrickStat, ROIStats, AutoTcorrelate,
AFNItoNIFTI, Eval, Means)
AFNItoNIFTI, Eval, Means, Hist)
from .svm import (SVMTest, SVMTrain)
78 changes: 74 additions & 4 deletions nipype/interfaces/afni/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
"""

import os
import os.path as op
import re
from warnings import warn

from .base import AFNICommand, AFNICommandInputSpec, AFNICommandOutputSpec
from .base import AFNICommand, AFNICommandInputSpec, AFNICommandOutputSpec, Info, no_afni
from ..base import CommandLineInputSpec, CommandLine, OutputMultiPath
from ..base import (Directory, TraitedSpec,
traits, isdefined, File, InputMultiPath, Undefined)
from ...utils.filemanip import (load_json, save_json, split_filename)
from ...utils.filemanip import fname_presuffix


class To3DInputSpec(AFNICommandInputSpec):
out_file = File(name_template="%s", desc='output image file name',
argstr='-prefix %s', name_source=["in_folder"])
Expand Down Expand Up @@ -1234,9 +1234,7 @@ class SkullStrip(AFNICommand):
output_spec = AFNICommandOutputSpec

def __init__(self, **inputs):
from .base import Info, no_afni
super(SkullStrip, self).__init__(**inputs)

if not no_afni():
v = Info.version()

Expand Down Expand Up @@ -2090,3 +2088,75 @@ class Means(AFNICommand):
_cmd = '3dMean'
input_spec = MeansInputSpec
output_spec = AFNICommandOutputSpec


class HistInputSpec(CommandLineInputSpec):
in_file = File(
desc='input file to 3dHist', argstr='-input %s', position=1, mandatory=True,
exists=True, copyfile=False)
out_file = File(
desc='Write histogram to niml file with this prefix', name_template='%s_hist',
keep_extension=False, argstr='-prefix %s', name_source=['in_file'])
showhist = traits.Bool(False, usedefault=True, desc='write a text visual histogram',
argstr='-showhist')
out_show = File(
name_template="%s_hist.out", desc='output image file name', keep_extension=False,
argstr="> %s", name_source="in_file", position=-1)
mask = File(desc='matrix to align input file', argstr='-mask %s', exists=True)
nbin = traits.Int(desc='number of bins', argstr='-nbin %d')
max_value = traits.Float(argstr='-max %f', desc='maximum intensity value')
min_value = traits.Float(argstr='-min %f', desc='minimum intensity value')
bin_width = traits.Float(argstr='-binwidth %f', desc='bin width')

class HistOutputSpec(TraitedSpec):
out_file = File(desc='output file', exists=True)
out_show = File(desc='output visual histogram')


class Hist(CommandLine):
"""Computes average of all voxels in the input dataset
which satisfy the criterion in the options list

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

Examples
========

>>> from nipype.interfaces import afni as afni
>>> hist = afni.Hist()
>>> hist.inputs.in_file = 'functional.nii'
>>> hist.cmdline
'3dHist -input functional.nii -prefix functional_hist'
>>> res = hist.run() # doctest: +SKIP

"""

_cmd = '3dHist'
input_spec = HistInputSpec
output_spec = HistOutputSpec
_redirect_x = True

def __init__(self, **inputs):
super(Hist, self).__init__(**inputs)
if not no_afni():
version = Info.version()

# As of AFNI 16.0.00, redirect_x is not needed
if isinstance(version[0], int) and version[0] > 15:
self._redirect_x = False

def _parse_inputs(self, skip=None):
if not self.inputs.showhist:
if skip is None:
skip = []
skip += ['out_show']
return super(Hist, self)._parse_inputs(skip=skip)


def _list_outputs(self):
outputs = super(Hist, self)._list_outputs()
outputs['out_file'] += '.niml.hist'
if not self.inputs.showhist:
outputs['out_show'] = Undefined
return outputs
62 changes: 62 additions & 0 deletions nipype/interfaces/afni/tests/test_auto_Hist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
from ....testing import assert_equal
from ..preprocess import Hist


def test_Hist_inputs():
input_map = dict(args=dict(argstr='%s',
),
bin_width=dict(argstr='-binwidth %f',
),
environ=dict(nohash=True,
usedefault=True,
),
ignore_exception=dict(nohash=True,
usedefault=True,
),
in_file=dict(argstr='-input %s',
copyfile=False,
mandatory=True,
position=1,
),
mask=dict(argstr='-mask %s',
),
max_value=dict(argstr='-max %f',
),
min_value=dict(argstr='-min %f',
),
nbin=dict(argstr='-nbin %d',
),
out_file=dict(argstr='-prefix %s',
keep_extension=False,
name_source=['in_file'],
name_template='%s_hist',
),
out_show=dict(argstr='> %s',
keep_extension=False,
name_source='in_file',
name_template='%s_hist.out',
position=-1,
),
showhist=dict(argstr='-showhist',
usedefault=True,
),
terminal_output=dict(nohash=True,
),
)
inputs = Hist.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_Hist_outputs():
output_map = dict(out_file=dict(),
out_show=dict(),
)
outputs = Hist.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