@@ -1802,28 +1802,109 @@ 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 (desc = 'input mask' , argstr = '-mask %s' , position = 3 , exists = True ,
1811
+ deprecated = '1.1.4' , new_name = 'mask_file' )
1812
+ mask_file = File (desc = 'input mask' , argstr = '-mask %s' , exists = True )
1811
1813
mask_f2short = traits .Bool (
1812
1814
desc = 'Tells the program to convert a float mask to short integers, '
1813
1815
'by simple rounding.' ,
1814
- argstr = '-mask_f2short' ,
1815
- position = 2 )
1816
- quiet = traits .Bool (desc = 'execute quietly' , argstr = '-quiet' , position = 1 )
1816
+ argstr = '-mask_f2short' )
1817
+ num_roi = traits .Int (
1818
+ desc = 'Forces the assumption that the mask dataset\' s ROIs are '
1819
+ 'denoted by 1 to n inclusive. Normally, the program '
1820
+ 'figures out the ROIs on its own. This option is '
1821
+ 'useful if a) you are certain that the mask dataset '
1822
+ 'has no values outside the range [0 n], b) there may '
1823
+ 'be some ROIs missing between [1 n] in the mask data-'
1824
+ 'set and c) you want those columns in the output any-'
1825
+ 'way so the output lines up with the output from other '
1826
+ 'invocations of 3dROIstats.' ,
1827
+ argstr = '-numroi %s' )
1828
+ zerofill = traits .Str (
1829
+ requires = ['num_roi' ],
1830
+ desc = 'For ROI labels not found, use the provided string instead of '
1831
+ 'a \' 0\' in the output file. Only active if `num_roi` is '
1832
+ 'enabled.' ,
1833
+ argstr = '-zerofill %s' )
1834
+ roisel = traits .File (
1835
+ exists = True ,
1836
+ desc = 'Only considers ROIs denoted by values found in the specified '
1837
+ 'file. Note that the order of the ROIs as specified in the file '
1838
+ 'is not preserved. So an SEL.1D of \' 2 8 20\' produces the same '
1839
+ 'output as \' 8 20 2\' ' ,
1840
+ argstr = '-roisel %s' )
1841
+ debug = traits .Bool (
1842
+ desc = 'print debug information' ,
1843
+ argstr = '-debug' )
1844
+ quiet = traits .Bool (
1845
+ desc = 'execute quietly' ,
1846
+ argstr = '-quiet' )
1847
+ nomeanout = traits .Bool (
1848
+ desc = 'Do not include the (zero-inclusive) mean among computed stats' ,
1849
+ argstr = '-nomeanout' )
1850
+ nobriklab = traits .Bool (
1851
+ desc = 'Do not print the sub-brick label next to its index' ,
1852
+ argstr = '-nobriklab' )
1853
+ format1D = traits .Bool (
1854
+ xor = ['format1DR' ],
1855
+ desc = 'Output results in a 1D format that includes commented labels' ,
1856
+ argstr = '-1Dformat' )
1857
+ format1DR = traits .Bool (
1858
+ xor = ['format1D' ],
1859
+ desc = 'Output results in a 1D format that includes uncommented '
1860
+ 'labels. May not work optimally with typical 1D functions, '
1861
+ 'but is useful for R functions.' ,
1862
+ argstr = '-1DRformat' )
1863
+ _stat_names = ['mean' , 'sum' , 'voxels' , 'minmax' , 'sigma' , 'median' ,
1864
+ 'mode' , 'summary' , 'zerominmax' , 'zerosigma' , 'zeromedian' ,
1865
+ 'zeromode' ]
1866
+ stat = InputMultiObject (
1867
+ traits .Enum (_stat_names ),
1868
+ desc = 'statistics to compute. Options include: '
1869
+ ' * mean = Compute the mean using only non_zero voxels.'
1870
+ ' Implies the opposite for the mean computed '
1871
+ ' by default.\n '
1872
+ ' * median = Compute the median of nonzero voxels\n '
1873
+ ' * mode = Compute the mode of nonzero voxels.'
1874
+ ' (integral valued sets only)\n '
1875
+ ' * minmax = Compute the min/max of nonzero voxels\n '
1876
+ ' * sum = Compute the sum using only nonzero voxels.\n '
1877
+ ' * voxels = Compute the number of nonzero voxels\n '
1878
+ ' * sigma = Compute the standard deviation of nonzero'
1879
+ ' voxels\n '
1880
+ 'Statistics that include zero-valued voxels:\n '
1881
+ ' * zerominmax = Compute the min/max of all voxels.\n '
1882
+ ' * zerosigma = Compute the standard deviation of all'
1883
+ ' voxels.\n '
1884
+ ' * zeromedian = Compute the median of all voxels.\n '
1885
+ ' * zeromode = Compute the mode of all voxels.\n '
1886
+ ' * summary = Only output a summary line with the grand '
1887
+ ' mean across all briks in the input dataset.'
1888
+ ' This option cannot be used with nomeanout.\n '
1889
+ 'More that one option can be specified.' ,
1890
+ argstr = '%s...' )
1891
+ out_file = File (
1892
+ name_template = '%s_roistat.1D' ,
1893
+ desc = 'output file' ,
1894
+ keep_extension = False ,
1895
+ argstr = '> %s' ,
1896
+ name_source = 'in_file' ,
1897
+ position = - 1 )
1817
1898
1818
1899
1819
1900
class ROIStatsOutputSpec (TraitedSpec ):
1820
- stats = File (desc = 'output tab separated values file' , exists = True )
1901
+ out_file = File (desc = 'output tab- separated values file' , exists = True )
1821
1902
1822
1903
1823
1904
class ROIStats (AFNICommandBase ):
1824
1905
"""Display statistics over masked regions
1825
1906
1826
- For complete details, see the `3dROIstats Documentation.
1907
+ For complete details, see the `3dROIstats Documentation
1827
1908
<https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dROIstats.html>`_
1828
1909
1829
1910
Examples
@@ -1832,10 +1913,11 @@ class ROIStats(AFNICommandBase):
1832
1913
>>> from nipype.interfaces import afni
1833
1914
>>> roistats = afni.ROIStats()
1834
1915
>>> roistats.inputs.in_file = 'functional.nii'
1835
- >>> roistats.inputs.mask = 'skeleton_mask.nii.gz'
1836
- >>> roistats.inputs.quiet = True
1916
+ >>> roistats.inputs.mask_file = 'skeleton_mask.nii.gz'
1917
+ >>> roistats.inputs.stat = ['mean', 'median', 'voxels']
1918
+ >>> roistats.inputs.nomeanout = True
1837
1919
>>> roistats.cmdline
1838
- '3dROIstats -quiet - mask skeleton_mask.nii.gz functional.nii'
1920
+ '3dROIstats -mask skeleton_mask.nii.gz -nomeanout -nzmean -nzmedian -nzvoxels functional.nii > functional_roistat.1D '
1839
1921
>>> res = roistats.run() # doctest: +SKIP
1840
1922
1841
1923
"""
@@ -1844,14 +1926,24 @@ class ROIStats(AFNICommandBase):
1844
1926
input_spec = ROIStatsInputSpec
1845
1927
output_spec = ROIStatsOutputSpec
1846
1928
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 )
1852
-
1853
- outputs .stats = os .path .abspath (output_filename )
1854
- return outputs
1929
+ def _format_arg (self , name , spec , value ):
1930
+ _stat_dict = {
1931
+ 'mean' : '-nzmean' ,
1932
+ 'median' : '-nzmedian' ,
1933
+ 'mode' : '-nzmode' ,
1934
+ 'minmax' : '-nzminmax' ,
1935
+ 'sigma' : '-nzsigma' ,
1936
+ 'voxels' : '-nzvoxels' ,
1937
+ 'sum' : '-nzsum' ,
1938
+ 'summary' : '-summary' ,
1939
+ 'zerominmax' : '-minmax' ,
1940
+ 'zeromedian' : '-median' ,
1941
+ 'zerosigma' : '-sigma' ,
1942
+ 'zeromode' : '-mode'
1943
+ }
1944
+ if name == 'stat' :
1945
+ value = [_stat_dict [v ] for v in value ]
1946
+ return super (ROIStats , self )._format_arg (name , spec , value )
1855
1947
1856
1948
1857
1949
class RetroicorInputSpec (AFNICommandInputSpec ):
0 commit comments