@@ -1802,22 +1802,99 @@ class QualityIndex(CommandLine):
1802
1802
1803
1803
class ROIStatsInputSpec (CommandLineInputSpec ):
1804
1804
in_file = File (
1805
- desc = 'input file to 3dROIstats ' ,
1805
+ desc = 'input dataset ' ,
1806
1806
argstr = '%s' ,
1807
- position = - 1 ,
1807
+ position = - 2 ,
1808
1808
mandatory = True ,
1809
1809
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 )
1811
1811
mask_f2short = traits .Bool (
1812
1812
desc = 'Tells the program to convert a float mask to short integers, '
1813
1813
'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 )
1817
1894
1818
1895
1819
1896
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 )
1821
1898
1822
1899
1823
1900
class ROIStats (AFNICommandBase ):
@@ -1828,7 +1905,7 @@ class ROIStats(AFNICommandBase):
1828
1905
1829
1906
Examples
1830
1907
========
1831
-
1908
+
1832
1909
>>> from nipype.interfaces import afni
1833
1910
>>> roistats = afni.ROIStats()
1834
1911
>>> roistats.inputs.in_file = 'functional.nii'
@@ -1837,21 +1914,33 @@ class ROIStats(AFNICommandBase):
1837
1914
>>> roistats.cmdline
1838
1915
'3dROIstats -quiet -mask skeleton_mask.nii.gz functional.nii'
1839
1916
>>> res = roistats.run() # doctest: +SKIP
1840
-
1841
1917
"""
1918
+
1842
1919
_cmd = '3dROIstats'
1843
1920
_terminal_output = 'allatonce'
1844
1921
input_spec = ROIStatsInputSpec
1845
1922
output_spec = ROIStatsOutputSpec
1846
1923
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 ):
1852
1925
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 )
1855
1944
1856
1945
1857
1946
class RetroicorInputSpec (AFNICommandInputSpec ):
0 commit comments