Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 16 additions & 33 deletions nipype/interfaces/afni/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
from nipype.utils.filemanip import fname_presuffix
from .base import AFNICommand, AFNICommandInputSpec,\
AFNICommandOutputSpec
from nipype.interfaces.base import CommandLineInputSpec, CommandLine
from nipype.interfaces.base import CommandLineInputSpec, CommandLine,\
OutputMultiPath

warn = warnings.warn
warnings.filterwarnings('always', category=UserWarning)
Expand Down Expand Up @@ -1380,7 +1381,7 @@ def aggregate_outputs(self, runtime=None, needed_outputs=None):
return outputs


class ROIStatsInputSpec(AFNICommandInputSpec):
class ROIStatsInputSpec(CommandLineInputSpec):
in_file = File(desc='input file to 3dROIstats',
argstr='%s',
position=-1,
Expand All @@ -1402,12 +1403,18 @@ class ROIStatsInputSpec(AFNICommandInputSpec):
argstr='-quiet',
position=1)

terminal_output = traits.Enum('allatonce',
desc=('Control terminal output:'
'`allatonce` - waits till command is '
'finished to display output'),
nohash=True, mandatory=True, usedefault=True)


class ROIStatsOutputSpec(TraitedSpec):
stats = File(desc='output', exists=True)
stats = File(desc='output tab separated values file', exists=True)


class ROIStats(AFNICommand):
class ROIStats(CommandLine):
"""Display statistics over masked regions

For complete details, see the `3dROIstats Documentation.
Expand All @@ -1429,37 +1436,13 @@ class ROIStats(AFNICommand):
output_spec = ROIStatsOutputSpec

def aggregate_outputs(self, runtime=None, needed_outputs=None):

outputs = self._outputs()
output_filename = "roi_stats.csv"
f = open(output_filename, "w")
f.write(runtime.stdout)
f.close()

outfile = os.path.join(os.getcwd(), 'stat_result.json')

if runtime is None:
try:
stats = load_json(outfile)['stat']
except IOError:
return self.run().outputs
else:
stats = []
for line in runtime.stdout.split('\n'):
if line:
values = line.split()
if len(values) > 1:
stats.append([float(val) for val in values])
else:
stats.extend([float(val) for val in values])

if len(stats) == 1:
stats = stats[0]
of = os.path.join(os.getcwd(), 'TS.1D')
f = open(of, 'w')

for st in stats:
f.write(str(st) + '\n')
f.close()
save_json(outfile, dict(stat=of))
outputs.stats = of

outputs.stats = os.path.abspath(output_filename)
return outputs


Expand Down
6 changes: 1 addition & 5 deletions nipype/interfaces/afni/tests/test_auto_ROIStats.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@ def test_ROIStats_inputs():
input_map = dict(ignore_exception=dict(nohash=True,
usedefault=True,
),
out_file=dict(name_source=['in_file'],
name_template='%s_afni',
argstr='-prefix %s',
),
args=dict(argstr='%s',
),
mask=dict(position=3,
argstr='-mask %s',
),
outputtype=dict(),
quiet=dict(position=1,
argstr='-quiet',
),
terminal_output=dict(mandatory=True,
nohash=True,
usedefault=True,
),
environ=dict(nohash=True,
usedefault=True,
Expand Down