Skip to content

Commit 9d63943

Browse files
authored
Merge pull request #2033 from oesteban/enh/afni-gcor
[ENH] Add AFNI's interface to GCOR computation
2 parents a45001b + 0f1fb6c commit 9d63943

File tree

3 files changed

+108
-1
lines changed

3 files changed

+108
-1
lines changed

nipype/interfaces/afni/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
from .utils import (AFNItoNIFTI, Autobox, BrickStat, Calc, Copy,
2121
Eval, FWHMx,
2222
MaskTool, Merge, Notes, Refit, Resample, TCat, TStat, To3D,
23-
Unifize, ZCutUp,)
23+
Unifize, ZCutUp, GCOR,)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..utils import GCOR
4+
5+
6+
def test_GCOR_inputs():
7+
input_map = dict(args=dict(argstr='%s',
8+
),
9+
environ=dict(nohash=True,
10+
usedefault=True,
11+
),
12+
ignore_exception=dict(nohash=True,
13+
usedefault=True,
14+
),
15+
in_file=dict(argstr='-input %s',
16+
copyfile=False,
17+
mandatory=True,
18+
position=-1,
19+
),
20+
mask=dict(argstr='-mask %s',
21+
copyfile=False,
22+
),
23+
nfirst=dict(argstr='-nfirst %d',
24+
),
25+
no_demean=dict(argstr='-no_demean',
26+
),
27+
terminal_output=dict(nohash=True,
28+
),
29+
)
30+
inputs = GCOR.input_spec()
31+
32+
for key, metadata in list(input_map.items()):
33+
for metakey, value in list(metadata.items()):
34+
assert getattr(inputs.traits()[key], metakey) == value
35+
36+
37+
def test_GCOR_outputs():
38+
output_map = dict(out=dict(),
39+
)
40+
outputs = GCOR.output_spec()
41+
42+
for key, metadata in list(output_map.items()):
43+
for metakey, value in list(metadata.items()):
44+
assert getattr(outputs.traits()[key], metakey) == value

nipype/interfaces/afni/utils.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,3 +1378,66 @@ class ZCutUp(AFNICommand):
13781378
_cmd = '3dZcutup'
13791379
input_spec = ZCutUpInputSpec
13801380
output_spec = AFNICommandOutputSpec
1381+
1382+
1383+
class GCORInputSpec(CommandLineInputSpec):
1384+
in_file = File(
1385+
desc='input dataset to compute the GCOR over',
1386+
argstr='-input %s',
1387+
position=-1,
1388+
mandatory=True,
1389+
exists=True,
1390+
copyfile=False)
1391+
1392+
mask = File(
1393+
desc='mask dataset, for restricting the computation',
1394+
argstr='-mask %s',
1395+
exists=True,
1396+
copyfile=False)
1397+
1398+
nfirst = traits.Int(0, argstr='-nfirst %d',
1399+
desc='specify number of initial TRs to ignore')
1400+
no_demean = traits.Bool(False, argstr='-no_demean',
1401+
desc='do not (need to) demean as first step')
1402+
1403+
1404+
class GCOROutputSpec(TraitedSpec):
1405+
out = traits.Float(desc='global correlation value')
1406+
1407+
1408+
class GCOR(CommandLine):
1409+
"""
1410+
Computes the average correlation between every voxel
1411+
and ever other voxel, over any give mask.
1412+
1413+
1414+
For complete details, see the `@compute_gcor Documentation.
1415+
<https://afni.nimh.nih.gov/pub/dist/doc/program_help/@compute_gcor.html>`_
1416+
1417+
Examples
1418+
========
1419+
1420+
>>> from nipype.interfaces import afni
1421+
>>> gcor = afni.GCOR()
1422+
>>> gcor.inputs.in_file = 'structural.nii'
1423+
>>> gcor.inputs.nfirst = 4
1424+
>>> gcor.cmdline # doctest: +ALLOW_UNICODE
1425+
'@compute_gcor -nfirst 4 -input structural.nii'
1426+
>>> res = gcor.run() # doctest: +SKIP
1427+
1428+
"""
1429+
1430+
_cmd = '@compute_gcor'
1431+
input_spec = GCORInputSpec
1432+
output_spec = GCOROutputSpec
1433+
1434+
def _run_interface(self, runtime):
1435+
runtime = super(GCOR, self)._run_interface(runtime)
1436+
1437+
gcor_line = [line.strip() for line in runtime.stdout.split('\n')
1438+
if line.strip().startswith('GCOR = ')][-1]
1439+
setattr(self, '_gcor', float(gcor_line[len('GCOR = '):]))
1440+
return runtime
1441+
1442+
def _list_outputs(self):
1443+
return {'out': getattr(self, '_gcor')}

0 commit comments

Comments
 (0)