-
Notifications
You must be signed in to change notification settings - Fork 533
ENH: AFNI (3d)LocalBistat interface #2590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT | ||
from __future__ import unicode_literals | ||
from ..utils import LocalBistat | ||
|
||
|
||
def test_LocalBistat_inputs(): | ||
input_map = dict( | ||
args=dict(argstr='%s', ), | ||
automask=dict(), | ||
environ=dict( | ||
nohash=True, | ||
usedefault=True, | ||
), | ||
ignore_exception=dict( | ||
deprecated='1.0.0', | ||
nohash=True, | ||
usedefault=True, | ||
), | ||
in_files=dict( | ||
argstr='%s', | ||
mandatory=True, | ||
position=-1, | ||
), | ||
mask_file=dict( | ||
argstr='-weight %s', | ||
xor=['automask'], | ||
), | ||
neighborhood=dict( | ||
argstr='-nbhd %s', | ||
mandatory=True, | ||
), | ||
num_threads=dict( | ||
nohash=True, | ||
usedefault=True, | ||
), | ||
out_file=dict( | ||
argstr='-prefix %s', | ||
keep_extension=True, | ||
name_source='in_files', | ||
name_template='%s_bistat', | ||
position=0, | ||
), | ||
outputtype=dict(), | ||
stat=dict( | ||
argstr='-stat %s', | ||
mandatory=True, | ||
), | ||
terminal_output=dict( | ||
deprecated='1.0.0', | ||
nohash=True, | ||
), | ||
) | ||
inputs = LocalBistat.input_spec() | ||
|
||
for key, metadata in list(input_map.items()): | ||
for metakey, value in list(metadata.items()): | ||
assert getattr(inputs.traits()[key], metakey) == value | ||
def test_LocalBistat_outputs(): | ||
output_map = dict(out_file=dict(), ) | ||
outputs = LocalBistat.output_spec() | ||
|
||
for key, metadata in list(output_map.items()): | ||
for metakey, value in list(metadata.items()): | ||
assert getattr(outputs.traits()[key], metakey) == value |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1338,6 +1338,124 @@ def _list_outputs(self): | |
return outputs | ||
|
||
|
||
class LocalBistatInputSpec(AFNICommandInputSpec): | ||
in_files = InputMultiPath( | ||
File(exists=True), | ||
minlen=2, | ||
maxlen=2, | ||
mandatory=True, | ||
argstr='%s', | ||
position=-1, | ||
desc='Filenames of the 2 images to compute statistics between') | ||
neighborhood = traits.Either( | ||
traits.Tuple(traits.Enum('SPHERE', 'RHDD', 'TOHD'), traits.Float()), | ||
traits.Tuple(traits.Enum('RECT'), traits.Tuple(traits.Float(), | ||
traits.Float(), | ||
traits.Float())), | ||
mandatory=True, | ||
desc='The region around each voxel that will be extracted for ' | ||
'the statistics calculation. Possible regions are: ' | ||
'\'SPHERE\', \'RHDD\' (rhombic dodecahedron), \'TOHD\' ' | ||
'(truncated octahedron) with a given radius in mm or ' | ||
'\'RECT\' (rectangular block) with dimensions to specify in mm.', | ||
argstr='-nbhd %s') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about: argstr='-nbhd %s(%s)' Related to a comment below. |
||
_stat_names = ['pearson', 'spearman', 'quadrant', 'mutinfo', 'normuti', | ||
'jointent', 'hellinger', 'crU', 'crM', 'crA', 'L2slope', | ||
'L1slope', 'num', 'ALL'] | ||
stat = traits.Either( | ||
traits.Enum(*_stat_names), traits.List(traits.Enum(_stat_names)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this not work? stat = traits.MultiPath(traits.Enum(_stat_names), ...) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure I understand: traits does not seem to have a `MultiPath
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, sorry. I meant |
||
mandatory=True, | ||
desc='statistics to compute. Possible names are :' | ||
' * pearson = Pearson correlation coefficient' | ||
' * spearman = Spearman correlation coefficient' | ||
' * quadrant = Quadrant correlation coefficient' | ||
' * mutinfo = Mutual Information' | ||
' * normuti = Normalized Mutual Information' | ||
' * jointent = Joint entropy' | ||
' * hellinger= Hellinger metric' | ||
' * crU = Correlation ratio (Unsymmetric)' | ||
' * crM = Correlation ratio (symmetrized by Multiplication)' | ||
' * crA = Correlation ratio (symmetrized by Addition)' | ||
' * L2slope = slope of least-squares (L2) linear regression of ' | ||
' the data from dataset1 vs. the dataset2 ' | ||
' (i.e., d2 = a + b*d1 ==> this is \'b\')' | ||
' * L1slope = slope of least-absolute-sum (L1) linear ' | ||
' regression of the data from dataset1 vs. ' | ||
' the dataset2' | ||
' * num = number of the values in the region: ' | ||
' with the use of -mask or -automask, ' | ||
' the size of the region around any given ' | ||
' voxel will vary; this option lets you ' | ||
' map that size.' | ||
' * ALL = all of the above, in that order' | ||
'More than one option can be used.', | ||
argstr='-stat %s') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. try There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes it works, thanks ! |
||
mask_file = traits.File( | ||
exists=True, | ||
desc='mask image file name. Voxels NOT in the mask will not be used ' | ||
'in the neighborhood of any voxel. Also, a voxel NOT in the mask ' | ||
'will have its statistic(s) computed as zero (0).', | ||
argstr='-mask %s') | ||
automask = traits.Bool( | ||
desc='Compute the mask as in program 3dAutomask.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should there be an |
||
mask_file = traits.File( | ||
exists=True, | ||
desc='File name of an image to use as a weight. Only applies to ' | ||
'\'pearson\' statistics.', | ||
argstr='-weight %s', | ||
xor=['automask']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have two |
||
out_file = traits.File( | ||
desc='Output dataset.', | ||
argstr='-prefix %s', | ||
name_source='in_files', | ||
name_template='%s_bistat', | ||
keep_extension=True, | ||
position=0) | ||
|
||
|
||
class LocalBistat(AFNICommand): | ||
"""3dLocalBistat - computes statistics between 2 datasets, at each voxel, | ||
based on a local neighborhood of that voxel. | ||
|
||
For complete details, see the `3dLocalBistat Documentation. | ||
<https://afni.nimh.nih.gov/pub../pub/dist/doc/program_help/3dLocalBistat.html>`_ | ||
|
||
Examples | ||
======== | ||
|
||
>>> from nipype.interfaces import afni | ||
>>> bistat = afni.LocalBistat() | ||
>>> bistat.inputs.in_files = ['functional.nii', 'structural.nii'] | ||
>>> bistat.inputs.neighborhood = ('SPHERE', 1.2) | ||
>>> bistat.inputs.stat = 'pearson' | ||
>>> bistat.inputs.outputtype = 'NIFTI' | ||
>>> bistat.cmdline | ||
"3dLocalBistat -prefix functional_bistat.nii -nbhd 'SPHERE(1.2)' -stat pearson functional.nii structural.nii" | ||
>>> res = automask.run() # doctest: +SKIP | ||
|
||
""" | ||
|
||
_cmd = '3dLocalBistat' | ||
input_spec = LocalBistatInputSpec | ||
output_spec = AFNICommandOutputSpec | ||
|
||
def _format_arg(self, name, spec, value): | ||
if name == 'neighborhood': | ||
region_name, region_size = value | ||
if region_name == 'RECT': | ||
return spec.argstr % ( | ||
"'{0}({1})'".format(region_name, ','.join(region_size))) | ||
else: | ||
return spec.argstr % ( | ||
"'{0}({1})'".format(region_name, region_size)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the if name == 'neighborhood' and value[0] == 'RECT':
value = ('RECT', '%s,%s,%s' % value[1]) (Letting |
||
if name == 'stat': | ||
if isinstance(value, (str, bytes)): | ||
return spec.argstr % value | ||
else: | ||
return ' '.join([spec.argstr % v for v in value]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty sure you can drop this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
this doesn't seem to work: it doesn't repeat the option '-stat' before each value bistat.inputs.stat = ['pearson', 'ALL'] gives There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @salma1601 - if you change the |
||
return super(LocalBistat, self)._format_arg(name, spec, value) | ||
|
||
|
||
class MaskToolInputSpec(AFNICommandInputSpec): | ||
in_file = File( | ||
desc='input file or files to 3dmask_tool', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should just be
traits.List
, notInputMultiPath
.And out of curiosity, is it more likely that people will want to pass in a list of two files or want separate names for each file (e.g.
in_file1
,in_file2
)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may be separate names are more suitable, you are right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the plan to split this into two traits, or leave it as one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry I forgot this, I am doing it