19
19
from nipype .utils .filemanip import fname_presuffix
20
20
from .base import AFNICommand , AFNICommandInputSpec ,\
21
21
AFNICommandOutputSpec
22
- from nipype .interfaces .base import CommandLineInputSpec , CommandLine
22
+ from nipype .interfaces .base import CommandLineInputSpec , CommandLine ,\
23
+ OutputMultiPath
23
24
24
25
warn = warnings .warn
25
26
warnings .filterwarnings ('always' , category = UserWarning )
@@ -1380,7 +1381,7 @@ def aggregate_outputs(self, runtime=None, needed_outputs=None):
1380
1381
return outputs
1381
1382
1382
1383
1383
- class ROIStatsInputSpec (AFNICommandInputSpec ):
1384
+ class ROIStatsInputSpec (CommandLineInputSpec ):
1384
1385
in_file = File (desc = 'input file to 3dROIstats' ,
1385
1386
argstr = '%s' ,
1386
1387
position = - 1 ,
@@ -1404,10 +1405,10 @@ class ROIStatsInputSpec(AFNICommandInputSpec):
1404
1405
1405
1406
1406
1407
class ROIStatsOutputSpec (TraitedSpec ):
1407
- stats = File ( desc = 'output' , exists = True )
1408
+ stats = OutputMultiPath ( traits . Float (), desc = 'output' , exists = True )
1408
1409
1409
1410
1410
- class ROIStats (AFNICommand ):
1411
+ class ROIStats (CommandLine ):
1411
1412
"""Display statistics over masked regions
1412
1413
1413
1414
For complete details, see the `3dROIstats Documentation.
@@ -1431,35 +1432,13 @@ class ROIStats(AFNICommand):
1431
1432
def aggregate_outputs (self , runtime = None , needed_outputs = None ):
1432
1433
1433
1434
outputs = self ._outputs ()
1434
-
1435
- outfile = os .path .join (os .getcwd (), 'stat_result.json' )
1436
-
1437
- if runtime is None :
1438
- try :
1439
- stats = load_json (outfile )['stat' ]
1440
- except IOError :
1441
- return self .run ().outputs
1442
- else :
1443
- stats = []
1444
- for line in runtime .stdout .split ('\n ' ):
1445
- if line :
1446
- values = line .split ()
1447
- if len (values ) > 1 :
1448
- stats .append ([float (val ) for val in values ])
1449
- else :
1450
- stats .extend ([float (val ) for val in values ])
1451
-
1452
- if len (stats ) == 1 :
1453
- stats = stats [0 ]
1454
- of = os .path .join (os .getcwd (), 'TS.1D' )
1455
- f = open (of , 'w' )
1456
-
1457
- for st in stats :
1458
- f .write (str (st ) + '\n ' )
1459
- f .close ()
1460
- save_json (outfile , dict (stat = of ))
1461
- outputs .stats = of
1462
-
1435
+ stats = []
1436
+ for line in runtime .stdout .split ('\n ' ):
1437
+ if line and not line .startswith ("File" ):
1438
+ values = line .split ()
1439
+ stats += [float (val ) for val in values [2 :]]
1440
+
1441
+ outputs .stats = stats
1463
1442
return outputs
1464
1443
1465
1444
0 commit comments