Skip to content

Commit 05c056c

Browse files
committed
substantially expand functionality of 3dROIstats interface
1 parent 494e224 commit 05c056c

File tree

1 file changed

+105
-16
lines changed

1 file changed

+105
-16
lines changed

nipype/interfaces/afni/preprocess.py

Lines changed: 105 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,22 +1802,99 @@ class QualityIndex(CommandLine):
18021802

18031803
class ROIStatsInputSpec(CommandLineInputSpec):
18041804
in_file = File(
1805-
desc='input file to 3dROIstats',
1805+
desc='input dataset',
18061806
argstr='%s',
1807-
position=-1,
1807+
position=-2,
18081808
mandatory=True,
18091809
exists=True)
1810-
mask = File(desc='input mask', argstr='-mask %s', position=3, exists=True)
1810+
mask_file = File(desc='input mask', argstr='-mask %s', exists=True)
18111811
mask_f2short = traits.Bool(
18121812
desc='Tells the program to convert a float mask to short integers, '
18131813
'by simple rounding.',
1814-
argstr='-mask_f2short',
1815-
position=2)
1816-
quiet = traits.Bool(desc='execute quietly', argstr='-quiet', position=1)
1814+
argstr='-mask_f2short')
1815+
num_roi = traits.Int(
1816+
desc='Forces the assumption that the mask dataset\'s ROIs are '
1817+
'denoted by 1 to n inclusive. Normally, the program '
1818+
'figures out the ROIs on its own. This option is '
1819+
'useful if a) you are certain that the mask dataset '
1820+
'has no values outside the range [0 n], b) there may '
1821+
'be some ROIs missing between [1 n] in the mask data-'
1822+
'set and c) you want those columns in the output any-'
1823+
'way so the output lines up with the output from other '
1824+
'invocations of 3dROIstats.',
1825+
argstr='-numroi %s')
1826+
zerofill = traits.Str(
1827+
requires=['num_roi'],
1828+
desc='For ROI labels not found, use the provided string instead of '
1829+
'a \'0\' in the output file. Only active if zerofill is active.',
1830+
argstr='-zerofill %s')
1831+
roisel = traits.File(
1832+
exists=True,
1833+
desc='Only considers ROIs denoted by values found in the specified '
1834+
'file. Note that the order of the ROIs as specified in the file '
1835+
'is not preserved. So an SEL.1D of \'2 8 20\' produces the same '
1836+
'output as \'8 20 2\'',
1837+
argstr='-roisel %s')
1838+
debug = traits.Bool(
1839+
desc='print debug information',
1840+
argstr='-debug')
1841+
quiet = traits.Bool(
1842+
desc='execute quietly',
1843+
argstr='-quiet')
1844+
nomeanout = traits.Bool(
1845+
desc='Do not include the (zero-inclusive) mean among computed stats',
1846+
argstr='-nomeanout')
1847+
nobriklab = traits.Bool(
1848+
desc='Do not print the sub-brick label next to its index',
1849+
argstr='-nobriklab')
1850+
format1D = traits.Bool(
1851+
xor=['format1DR'],
1852+
desc='Output results in a 1D format that includes commented labels',
1853+
argstr='-1Dformat')
1854+
format1DR = traits.Bool(
1855+
xor=['format1D'],
1856+
desc='Output results in a 1D format that includes uncommented '
1857+
'labels. May not work optimally with typical 1D functions, '
1858+
'but is useful for R functions.',
1859+
argstr='-1DRformat')
1860+
_stat_names = ['mean', 'sum', 'voxels', 'minmax', 'sigma', 'median',
1861+
'mode', 'summary', 'zerominmax', 'zerosigma', 'zeromedian',
1862+
'zeromode']
1863+
stat = InputMultiObject(
1864+
traits.Enum(_stat_names),
1865+
desc='statistics to compute. Options include: '
1866+
' * mean = Compute the mean using only non_zero voxels.'
1867+
' Implies the opposite for the mean computed '
1868+
' by default.'
1869+
' * median = Compute the median of nonzero voxels'
1870+
' * mode = Compute the mode of nonzero voxels. '
1871+
' (integral valued sets only)'
1872+
' * minmax = Compute the min/max of nonzero voxels'
1873+
' * sum = Compute the sum using only nonzero voxels.'
1874+
' * voxels = Compute the number of nonzero voxels'
1875+
' * sigma = Compute the standard deviation of nonzero '
1876+
' voxels'
1877+
'Statistics that include zero-valued voxels:'
1878+
' * zerominmax = Compute the min/max of all voxels.'
1879+
' * zerosigma = Compute the standard deviation of all voxels.'
1880+
' * zeromedian = Compute the median of all voxels.'
1881+
' * zeromode = Compute the mode of all voxels.'
1882+
' * summary = Only output a summary line with the grand '
1883+
' mean across all briks in the input dataset.'
1884+
' This option cannot be used with nomeanout.'
1885+
'More that one option can be specified.',
1886+
argstr='%s...')
1887+
out_file = File(
1888+
name_template='%s_roistat.1D',
1889+
desc='output file',
1890+
keep_extension=False,
1891+
argstr='> %s',
1892+
name_source='in_file',
1893+
position=-1)
18171894

18181895

18191896
class ROIStatsOutputSpec(TraitedSpec):
1820-
stats = File(desc='output tab separated values file', exists=True)
1897+
out_file = File(desc='output tab-separated values file', exists=True)
18211898

18221899

18231900
class ROIStats(AFNICommandBase):
@@ -1828,7 +1905,7 @@ class ROIStats(AFNICommandBase):
18281905
18291906
Examples
18301907
========
1831-
1908+
18321909
>>> from nipype.interfaces import afni
18331910
>>> roistats = afni.ROIStats()
18341911
>>> roistats.inputs.in_file = 'functional.nii'
@@ -1837,21 +1914,33 @@ class ROIStats(AFNICommandBase):
18371914
>>> roistats.cmdline
18381915
'3dROIstats -quiet -mask skeleton_mask.nii.gz functional.nii'
18391916
>>> res = roistats.run() # doctest: +SKIP
1840-
18411917
"""
1918+
18421919
_cmd = '3dROIstats'
18431920
_terminal_output = 'allatonce'
18441921
input_spec = ROIStatsInputSpec
18451922
output_spec = ROIStatsOutputSpec
18461923

1847-
def aggregate_outputs(self, runtime=None, needed_outputs=None):
1848-
outputs = self._outputs()
1849-
output_filename = 'roi_stats.csv'
1850-
with open(output_filename, 'w') as f:
1851-
f.write(runtime.stdout)
1924+
def _format_arg(self, name, spec, value):
18521925

1853-
outputs.stats = os.path.abspath(output_filename)
1854-
return outputs
1926+
_stat_dict = {
1927+
'mean': '-nzmean',
1928+
'median': '-nzmedian',
1929+
'mode': '-nzmode',
1930+
'minmax': '-nzminmax',
1931+
'sigma': '-nzsigma',
1932+
'voxels': '-nzvoxels',
1933+
'sum': '-nzsum',
1934+
'summary': '-summary',
1935+
'zerominmax': '-minmax',
1936+
'zeromedian': '-median',
1937+
'zerosigma': '-sigma',
1938+
'zeromode': '-mode'
1939+
}
1940+
if name == 'stat':
1941+
value = [_stat_dict[v] for v in value]
1942+
1943+
return super(ROIStats, self)._format_arg(name, spec, value)
18551944

18561945

18571946
class RetroicorInputSpec(AFNICommandInputSpec):

0 commit comments

Comments
 (0)