Skip to content

Commit 67d2657

Browse files
authored
Merge pull request #2590 from salma1601/afni_local_bistat
ENH: AFNI (3d)LocalBistat interface
2 parents 95c5f37 + 71fd6d3 commit 67d2657

File tree

3 files changed

+191
-3
lines changed

3 files changed

+191
-3
lines changed

nipype/interfaces/afni/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from .utils import (
1919
ABoverlap, AFNItoNIFTI, Autobox, Axialize, BrickStat, Bucket, Calc, Cat,
2020
CatMatvec, CenterMass, ConvertDset, Copy, Dot, Edge3, Eval, FWHMx,
21-
MaskTool, Merge, Notes, NwarpApply, NwarpAdjust, NwarpCat, OneDToolPy,
22-
Refit, Resample, TCat, TCatSubBrick, TStat, To3D, Unifize, Undump, ZCutUp,
23-
GCOR, Zcat, Zeropad)
21+
LocalBistat, MaskTool, Merge, Notes, NwarpApply, NwarpAdjust, NwarpCat,
22+
OneDToolPy, Refit, Resample, TCat, TCatSubBrick, TStat, To3D, Unifize,
23+
Undump, ZCutUp, GCOR, Zcat, Zeropad)
2424
from .model import (Deconvolve, Remlfit, Synthesize)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..utils import LocalBistat
4+
5+
6+
def test_LocalBistat_inputs():
7+
input_map = dict(
8+
args=dict(argstr='%s', ),
9+
automask=dict(
10+
argstr='-automask',
11+
xor=['weight_file'],
12+
),
13+
environ=dict(
14+
nohash=True,
15+
usedefault=True,
16+
),
17+
ignore_exception=dict(
18+
deprecated='1.0.0',
19+
nohash=True,
20+
usedefault=True,
21+
),
22+
in_file1=dict(
23+
argstr='%s',
24+
mandatory=True,
25+
position=-2,
26+
),
27+
in_file2=dict(
28+
argstr='%s',
29+
mandatory=True,
30+
position=-1,
31+
),
32+
mask_file=dict(argstr='-mask %s', ),
33+
neighborhood=dict(
34+
argstr="-nbhd '%s(%s)'",
35+
mandatory=True,
36+
),
37+
num_threads=dict(
38+
nohash=True,
39+
usedefault=True,
40+
),
41+
out_file=dict(
42+
argstr='-prefix %s',
43+
keep_extension=True,
44+
name_source='in_file1',
45+
name_template='%s_bistat',
46+
position=0,
47+
),
48+
outputtype=dict(),
49+
stat=dict(
50+
argstr='-stat %s...',
51+
mandatory=True,
52+
),
53+
terminal_output=dict(
54+
deprecated='1.0.0',
55+
nohash=True,
56+
),
57+
weight_file=dict(
58+
argstr='-weight %s',
59+
xor=['automask'],
60+
),
61+
)
62+
inputs = LocalBistat.input_spec()
63+
64+
for key, metadata in list(input_map.items()):
65+
for metakey, value in list(metadata.items()):
66+
assert getattr(inputs.traits()[key], metakey) == value
67+
def test_LocalBistat_outputs():
68+
output_map = dict(out_file=dict(), )
69+
outputs = LocalBistat.output_spec()
70+
71+
for key, metadata in list(output_map.items()):
72+
for metakey, value in list(metadata.items()):
73+
assert getattr(outputs.traits()[key], metakey) == value

nipype/interfaces/afni/utils.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,121 @@ def _list_outputs(self):
13381338
return outputs
13391339

13401340

1341+
class LocalBistatInputSpec(AFNICommandInputSpec):
1342+
in_file1 = File(
1343+
exists=True,
1344+
mandatory=True,
1345+
argstr='%s',
1346+
position=-2,
1347+
desc='Filename of the first image')
1348+
in_file2 = File(
1349+
exists=True,
1350+
mandatory=True,
1351+
argstr='%s',
1352+
position=-1,
1353+
desc='Filename of the second image')
1354+
neighborhood = traits.Either(
1355+
traits.Tuple(traits.Enum('SPHERE', 'RHDD', 'TOHD'), traits.Float()),
1356+
traits.Tuple(traits.Enum('RECT'), traits.Tuple(traits.Float(),
1357+
traits.Float(),
1358+
traits.Float())),
1359+
mandatory=True,
1360+
desc='The region around each voxel that will be extracted for '
1361+
'the statistics calculation. Possible regions are: '
1362+
'\'SPHERE\', \'RHDD\' (rhombic dodecahedron), \'TOHD\' '
1363+
'(truncated octahedron) with a given radius in mm or '
1364+
'\'RECT\' (rectangular block) with dimensions to specify in mm.',
1365+
argstr="-nbhd '%s(%s)'")
1366+
_stat_names = ['pearson', 'spearman', 'quadrant', 'mutinfo', 'normuti',
1367+
'jointent', 'hellinger', 'crU', 'crM', 'crA', 'L2slope',
1368+
'L1slope', 'num', 'ALL']
1369+
stat = InputMultiPath(
1370+
traits.Enum(_stat_names),
1371+
mandatory=True,
1372+
desc='statistics to compute. Possible names are :'
1373+
' * pearson = Pearson correlation coefficient'
1374+
' * spearman = Spearman correlation coefficient'
1375+
' * quadrant = Quadrant correlation coefficient'
1376+
' * mutinfo = Mutual Information'
1377+
' * normuti = Normalized Mutual Information'
1378+
' * jointent = Joint entropy'
1379+
' * hellinger= Hellinger metric'
1380+
' * crU = Correlation ratio (Unsymmetric)'
1381+
' * crM = Correlation ratio (symmetrized by Multiplication)'
1382+
' * crA = Correlation ratio (symmetrized by Addition)'
1383+
' * L2slope = slope of least-squares (L2) linear regression of '
1384+
' the data from dataset1 vs. the dataset2 '
1385+
' (i.e., d2 = a + b*d1 ==> this is \'b\')'
1386+
' * L1slope = slope of least-absolute-sum (L1) linear '
1387+
' regression of the data from dataset1 vs. '
1388+
' the dataset2'
1389+
' * num = number of the values in the region: '
1390+
' with the use of -mask or -automask, '
1391+
' the size of the region around any given '
1392+
' voxel will vary; this option lets you '
1393+
' map that size.'
1394+
' * ALL = all of the above, in that order'
1395+
'More than one option can be used.',
1396+
argstr='-stat %s...')
1397+
mask_file = traits.File(
1398+
exists=True,
1399+
desc='mask image file name. Voxels NOT in the mask will not be used '
1400+
'in the neighborhood of any voxel. Also, a voxel NOT in the mask '
1401+
'will have its statistic(s) computed as zero (0).',
1402+
argstr='-mask %s')
1403+
automask = traits.Bool(
1404+
desc='Compute the mask as in program 3dAutomask.',
1405+
argstr='-automask',
1406+
xor=['weight_file'])
1407+
weight_file = traits.File(
1408+
exists=True,
1409+
desc='File name of an image to use as a weight. Only applies to '
1410+
'\'pearson\' statistics.',
1411+
argstr='-weight %s',
1412+
xor=['automask'])
1413+
out_file = traits.File(
1414+
desc='Output dataset.',
1415+
argstr='-prefix %s',
1416+
name_source='in_file1',
1417+
name_template='%s_bistat',
1418+
keep_extension=True,
1419+
position=0)
1420+
1421+
1422+
class LocalBistat(AFNICommand):
1423+
"""3dLocalBistat - computes statistics between 2 datasets, at each voxel,
1424+
based on a local neighborhood of that voxel.
1425+
1426+
For complete details, see the `3dLocalBistat Documentation.
1427+
<https://afni.nimh.nih.gov/pub../pub/dist/doc/program_help/3dLocalBistat.html>`_
1428+
1429+
Examples
1430+
========
1431+
1432+
>>> from nipype.interfaces import afni
1433+
>>> bistat = afni.LocalBistat()
1434+
>>> bistat.inputs.in_file1 = 'functional.nii'
1435+
>>> bistat.inputs.in_file2 = 'structural.nii'
1436+
>>> bistat.inputs.neighborhood = ('SPHERE', 1.2)
1437+
>>> bistat.inputs.stat = 'pearson'
1438+
>>> bistat.inputs.outputtype = 'NIFTI'
1439+
>>> bistat.cmdline
1440+
"3dLocalBistat -prefix functional_bistat.nii -nbhd 'SPHERE(1.2)' -stat pearson functional.nii structural.nii"
1441+
>>> res = automask.run() # doctest: +SKIP
1442+
1443+
"""
1444+
1445+
_cmd = '3dLocalBistat'
1446+
input_spec = LocalBistatInputSpec
1447+
output_spec = AFNICommandOutputSpec
1448+
1449+
def _format_arg(self, name, spec, value):
1450+
if name == 'neighborhood' and value[0] == 'RECT':
1451+
value = ('RECT', '%s,%s,%s' % value[1])
1452+
1453+
return super(LocalBistat, self)._format_arg(name, spec, value)
1454+
1455+
13411456
class MaskToolInputSpec(AFNICommandInputSpec):
13421457
in_file = File(
13431458
desc='input file or files to 3dmask_tool',

0 commit comments

Comments
 (0)