Skip to content

Commit e4a94ca

Browse files
committed
add AFNI interface LocalBistat
1 parent eb4d8b4 commit e4a94ca

File tree

3 files changed

+185
-3
lines changed

3 files changed

+185
-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: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
environ=dict(
11+
nohash=True,
12+
usedefault=True,
13+
),
14+
ignore_exception=dict(
15+
deprecated='1.0.0',
16+
nohash=True,
17+
usedefault=True,
18+
),
19+
in_files=dict(
20+
argstr='%s',
21+
mandatory=True,
22+
position=-1,
23+
),
24+
mask_file=dict(
25+
argstr='-weight %s',
26+
xor=['automask'],
27+
),
28+
neighborhood=dict(
29+
argstr='-nbhd %s',
30+
mandatory=True,
31+
),
32+
num_threads=dict(
33+
nohash=True,
34+
usedefault=True,
35+
),
36+
out_file=dict(
37+
argstr='-prefix %s',
38+
keep_extension=True,
39+
name_source='in_files',
40+
name_template='%s_bistat',
41+
position=0,
42+
),
43+
outputtype=dict(),
44+
stat=dict(
45+
argstr='-stat %s',
46+
mandatory=True,
47+
),
48+
terminal_output=dict(
49+
deprecated='1.0.0',
50+
nohash=True,
51+
),
52+
)
53+
inputs = LocalBistat.input_spec()
54+
55+
for key, metadata in list(input_map.items()):
56+
for metakey, value in list(metadata.items()):
57+
assert getattr(inputs.traits()[key], metakey) == value
58+
def test_LocalBistat_outputs():
59+
output_map = dict(out_file=dict(), )
60+
outputs = LocalBistat.output_spec()
61+
62+
for key, metadata in list(output_map.items()):
63+
for metakey, value in list(metadata.items()):
64+
assert getattr(outputs.traits()[key], metakey) == value

nipype/interfaces/afni/utils.py

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

13401340

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

0 commit comments

Comments
 (0)