Skip to content

Commit 5d80df3

Browse files
committed
[ENH] Add AFNI's interface to GCOR computation
This PR adds the wrapper for the ``@compute_gcor`` tool.
1 parent cda3fdc commit 5d80df3

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-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,)

nipype/interfaces/afni/utils.py

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

0 commit comments

Comments
 (0)