Skip to content

Commit 5fbdd95

Browse files
committed
3DROIstats fix
1 parent b4bc351 commit 5fbdd95

File tree

1 file changed

+12
-33
lines changed

1 file changed

+12
-33
lines changed

nipype/interfaces/afni/preprocess.py

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
from nipype.utils.filemanip import fname_presuffix
2020
from .base import AFNICommand, AFNICommandInputSpec,\
2121
AFNICommandOutputSpec
22-
from nipype.interfaces.base import CommandLineInputSpec, CommandLine
22+
from nipype.interfaces.base import CommandLineInputSpec, CommandLine,\
23+
OutputMultiPath
2324

2425
warn = warnings.warn
2526
warnings.filterwarnings('always', category=UserWarning)
@@ -1380,7 +1381,7 @@ def aggregate_outputs(self, runtime=None, needed_outputs=None):
13801381
return outputs
13811382

13821383

1383-
class ROIStatsInputSpec(AFNICommandInputSpec):
1384+
class ROIStatsInputSpec(CommandLineInputSpec):
13841385
in_file = File(desc='input file to 3dROIstats',
13851386
argstr='%s',
13861387
position=-1,
@@ -1404,10 +1405,10 @@ class ROIStatsInputSpec(AFNICommandInputSpec):
14041405

14051406

14061407
class ROIStatsOutputSpec(TraitedSpec):
1407-
stats = File(desc='output', exists=True)
1408+
stats = OutputMultiPath(traits.Float(), desc='output', exists=True)
14081409

14091410

1410-
class ROIStats(AFNICommand):
1411+
class ROIStats(CommandLine):
14111412
"""Display statistics over masked regions
14121413
14131414
For complete details, see the `3dROIstats Documentation.
@@ -1431,35 +1432,13 @@ class ROIStats(AFNICommand):
14311432
def aggregate_outputs(self, runtime=None, needed_outputs=None):
14321433

14331434
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
14631442
return outputs
14641443

14651444

0 commit comments

Comments
 (0)