|
10 | 10 | """
|
11 | 11 |
|
12 | 12 | import os
|
| 13 | +import os.path as op |
13 | 14 | import re
|
14 | 15 | from warnings import warn
|
15 | 16 |
|
16 |
| -from .base import AFNICommand, AFNICommandInputSpec, AFNICommandOutputSpec |
| 17 | +from .base import AFNICommand, AFNICommandInputSpec, AFNICommandOutputSpec, Info, no_afni |
17 | 18 | from ..base import CommandLineInputSpec, CommandLine, OutputMultiPath
|
18 | 19 | from ..base import (Directory, TraitedSpec,
|
19 | 20 | traits, isdefined, File, InputMultiPath, Undefined)
|
20 | 21 | from ...utils.filemanip import (load_json, save_json, split_filename)
|
21 | 22 | from ...utils.filemanip import fname_presuffix
|
22 | 23 |
|
23 |
| - |
24 | 24 | class To3DInputSpec(AFNICommandInputSpec):
|
25 | 25 | out_file = File(name_template="%s", desc='output image file name',
|
26 | 26 | argstr='-prefix %s', name_source=["in_folder"])
|
@@ -1234,9 +1234,7 @@ class SkullStrip(AFNICommand):
|
1234 | 1234 | output_spec = AFNICommandOutputSpec
|
1235 | 1235 |
|
1236 | 1236 | def __init__(self, **inputs):
|
1237 |
| - from .base import Info, no_afni |
1238 | 1237 | super(SkullStrip, self).__init__(**inputs)
|
1239 |
| - |
1240 | 1238 | if not no_afni():
|
1241 | 1239 | v = Info.version()
|
1242 | 1240 |
|
@@ -2090,3 +2088,75 @@ class Means(AFNICommand):
|
2090 | 2088 | _cmd = '3dMean'
|
2091 | 2089 | input_spec = MeansInputSpec
|
2092 | 2090 | output_spec = AFNICommandOutputSpec
|
| 2091 | + |
| 2092 | + |
| 2093 | +class HistInputSpec(CommandLineInputSpec): |
| 2094 | + in_file = File( |
| 2095 | + desc='input file to 3dHist', argstr='-input %s', position=1, mandatory=True, |
| 2096 | + exists=True, copyfile=False) |
| 2097 | + out_file = File( |
| 2098 | + desc='Write histogram to niml file with this prefix', name_template='%s_hist', |
| 2099 | + keep_extension=False, argstr='-prefix %s', name_source=['in_file']) |
| 2100 | + showhist = traits.Bool(False, usedefault=True, desc='write a text visual histogram', |
| 2101 | + argstr='-showhist') |
| 2102 | + out_show = File( |
| 2103 | + name_template="%s_hist.out", desc='output image file name', keep_extension=False, |
| 2104 | + argstr="> %s", name_source="in_file", position=-1) |
| 2105 | + mask = File(desc='matrix to align input file', argstr='-mask %s', exists=True) |
| 2106 | + nbin = traits.Int(desc='number of bins', argstr='-nbin %d') |
| 2107 | + max_value = traits.Float(argstr='-max %f', desc='maximum intensity value') |
| 2108 | + min_value = traits.Float(argstr='-min %f', desc='minimum intensity value') |
| 2109 | + bin_width = traits.Float(argstr='-binwidth %f', desc='bin width') |
| 2110 | + |
| 2111 | +class HistOutputSpec(TraitedSpec): |
| 2112 | + out_file = File(desc='output file', exists=True) |
| 2113 | + out_show = File(desc='output visual histogram') |
| 2114 | + |
| 2115 | + |
| 2116 | +class Hist(CommandLine): |
| 2117 | + """Computes average of all voxels in the input dataset |
| 2118 | + which satisfy the criterion in the options list |
| 2119 | +
|
| 2120 | + For complete details, see the `3dHist Documentation. |
| 2121 | + <http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dHist.html>`_ |
| 2122 | +
|
| 2123 | + Examples |
| 2124 | + ======== |
| 2125 | +
|
| 2126 | + >>> from nipype.interfaces import afni as afni |
| 2127 | + >>> hist = afni.Hist() |
| 2128 | + >>> hist.inputs.in_file = 'functional.nii' |
| 2129 | + >>> hist.cmdline |
| 2130 | + '3dHist -input functional.nii -prefix functional_hist' |
| 2131 | + >>> res = hist.run() # doctest: +SKIP |
| 2132 | +
|
| 2133 | + """ |
| 2134 | + |
| 2135 | + _cmd = '3dHist' |
| 2136 | + input_spec = HistInputSpec |
| 2137 | + output_spec = HistOutputSpec |
| 2138 | + _redirect_x = True |
| 2139 | + |
| 2140 | + def __init__(self, **inputs): |
| 2141 | + super(Hist, self).__init__(**inputs) |
| 2142 | + if not no_afni(): |
| 2143 | + version = Info.version() |
| 2144 | + |
| 2145 | + # As of AFNI 16.0.00, redirect_x is not needed |
| 2146 | + if isinstance(version[0], int) and version[0] > 15: |
| 2147 | + self._redirect_x = False |
| 2148 | + |
| 2149 | + def _parse_inputs(self, skip=None): |
| 2150 | + if not self.inputs.showhist: |
| 2151 | + if skip is None: |
| 2152 | + skip = [] |
| 2153 | + skip += ['out_show'] |
| 2154 | + return super(Hist, self)._parse_inputs(skip=skip) |
| 2155 | + |
| 2156 | + |
| 2157 | + def _list_outputs(self): |
| 2158 | + outputs = super(Hist, self)._list_outputs() |
| 2159 | + outputs['out_file'] += '.niml.hist' |
| 2160 | + if not self.inputs.showhist: |
| 2161 | + outputs['out_show'] = Undefined |
| 2162 | + return outputs |
0 commit comments