Skip to content

Commit d95296e

Browse files
committed
Merge pull request #712 from chrisfilo/fix/afni_stats
Fix/afni stats
2 parents 42a9f28 + ecd0d83 commit d95296e

File tree

2 files changed

+17
-38
lines changed

2 files changed

+17
-38
lines changed

nipype/interfaces/afni/preprocess.py

Lines changed: 16 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)
@@ -1443,7 +1444,7 @@ def aggregate_outputs(self, runtime=None, needed_outputs=None):
14431444
return outputs
14441445

14451446

1446-
class ROIStatsInputSpec(AFNICommandInputSpec):
1447+
class ROIStatsInputSpec(CommandLineInputSpec):
14471448
in_file = File(desc='input file to 3dROIstats',
14481449
argstr='%s',
14491450
position=-1,
@@ -1465,12 +1466,18 @@ class ROIStatsInputSpec(AFNICommandInputSpec):
14651466
argstr='-quiet',
14661467
position=1)
14671468

1469+
terminal_output = traits.Enum('allatonce',
1470+
desc=('Control terminal output:'
1471+
'`allatonce` - waits till command is '
1472+
'finished to display output'),
1473+
nohash=True, mandatory=True, usedefault=True)
1474+
14681475

14691476
class ROIStatsOutputSpec(TraitedSpec):
1470-
stats = File(desc='output', exists=True)
1477+
stats = File(desc='output tab separated values file', exists=True)
14711478

14721479

1473-
class ROIStats(AFNICommand):
1480+
class ROIStats(CommandLine):
14741481
"""Display statistics over masked regions
14751482
14761483
For complete details, see the `3dROIstats Documentation.
@@ -1492,37 +1499,13 @@ class ROIStats(AFNICommand):
14921499
output_spec = ROIStatsOutputSpec
14931500

14941501
def aggregate_outputs(self, runtime=None, needed_outputs=None):
1495-
14961502
outputs = self._outputs()
1503+
output_filename = "roi_stats.csv"
1504+
f = open(output_filename, "w")
1505+
f.write(runtime.stdout)
1506+
f.close()
14971507

1498-
outfile = os.path.join(os.getcwd(), 'stat_result.json')
1499-
1500-
if runtime is None:
1501-
try:
1502-
stats = load_json(outfile)['stat']
1503-
except IOError:
1504-
return self.run().outputs
1505-
else:
1506-
stats = []
1507-
for line in runtime.stdout.split('\n'):
1508-
if line:
1509-
values = line.split()
1510-
if len(values) > 1:
1511-
stats.append([float(val) for val in values])
1512-
else:
1513-
stats.extend([float(val) for val in values])
1514-
1515-
if len(stats) == 1:
1516-
stats = stats[0]
1517-
of = os.path.join(os.getcwd(), 'TS.1D')
1518-
f = open(of, 'w')
1519-
1520-
for st in stats:
1521-
f.write(str(st) + '\n')
1522-
f.close()
1523-
save_json(outfile, dict(stat=of))
1524-
outputs.stats = of
1525-
1508+
outputs.stats = os.path.abspath(output_filename)
15261509
return outputs
15271510

15281511

nipype/interfaces/afni/tests/test_auto_ROIStats.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,17 @@ def test_ROIStats_inputs():
55
input_map = dict(ignore_exception=dict(nohash=True,
66
usedefault=True,
77
),
8-
out_file=dict(name_source=['in_file'],
9-
name_template='%s_afni',
10-
argstr='-prefix %s',
11-
),
128
args=dict(argstr='%s',
139
),
1410
mask=dict(position=3,
1511
argstr='-mask %s',
1612
),
17-
outputtype=dict(),
1813
quiet=dict(position=1,
1914
argstr='-quiet',
2015
),
2116
terminal_output=dict(mandatory=True,
2217
nohash=True,
18+
usedefault=True,
2319
),
2420
environ=dict(nohash=True,
2521
usedefault=True,

0 commit comments

Comments
 (0)