-
Notifications
You must be signed in to change notification settings - Fork 535
Ants brain extraction interface #1231
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 3 commits
4474b3a
9905a02
8e5f0c4
55a5304
4f89a05
6c24260
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 |
---|---|---|
|
@@ -465,7 +465,7 @@ class antsCorticalThicknessInputSpec(ANTSCommandInputSpec): | |
'Requires single thread computation for complete reproducibility.')) | ||
|
||
|
||
class antsCorticalThicknessoutputSpec(TraitedSpec): | ||
class antsCorticalThicknessOutputSpec(TraitedSpec): | ||
BrainExtractionMask = File(exists=True, desc='brain extraction mask') | ||
BrainSegmentation = File(exists=True, desc='brain segmentaion image') | ||
BrainSegmentationN4 = File(exists=True, desc='N4 corrected image') | ||
|
@@ -503,7 +503,7 @@ class antsCorticalThickness(ANTSCommand): | |
""" | ||
|
||
input_spec = antsCorticalThicknessInputSpec | ||
output_spec = antsCorticalThicknessoutputSpec | ||
output_spec = antsCorticalThicknessOutputSpec | ||
_cmd = 'antsCorticalThickness.sh' | ||
|
||
def _format_arg(self, opt, spec, val): | ||
|
@@ -594,6 +594,105 @@ def _list_outputs(self): | |
return outputs | ||
|
||
|
||
class antsBrainExtractionInputSpec(ANTSCommandInputSpec): | ||
dimension = traits.Enum(3, 2, argstr='-d %d', usedefault=True, | ||
desc='image dimension (2 or 3)') | ||
anatomical_image = File(exists=True, argstr='-a %s', | ||
desc=('Structural image, typically T1. If more than one' | ||
'anatomical image is specified, subsequently specified' | ||
'images are used during the segmentation process. However,' | ||
'only the first image is used in the registration of priors.' | ||
'Our suggestion would be to specify the T1 as the first image.' | ||
'Anatomical template created using e.g. LPBA40 data set with' | ||
'buildtemplateparallel.sh in ANTs.'), | ||
mandatory=True) | ||
brain_template = File(exists=True, argstr='-e %s', | ||
desc=('Anatomical template created using e.g. LPBA40 data set with' | ||
'buildtemplateparallel.sh in ANTs.'), | ||
mandatory=True) | ||
brain_probability_mask = File(exists=True, argstr='-m %s', | ||
desc=('Brain probability mask created using e.g. LPBA40 data set which' | ||
'have brain masks defined, and warped to anatomical template and' | ||
'averaged resulting in a probability image.'), | ||
copyfile=False, mandatory=True) | ||
out_prefix = traits.Str('highres001_', argstr='-o %s', usedefault=True, | ||
desc=('Prefix that is prepended to all output' | ||
' files (default = highress001_)')) | ||
|
||
extraction_registration_mask = File(exists=True, argstr='-f %s', | ||
desc=('Mask (defined in the template space) used during' | ||
' registration for brain extraction.' | ||
'To limit the metric computation to a specific region.')) | ||
image_suffix = traits.Str('nii.gz', desc=('any of standard ITK formats,' | ||
' nii.gz is default'), | ||
argstr='-s %s', usedefault=True) | ||
use_random_seeding = traits.Enum(0, 1, argstr='-u %d', | ||
desc=('Use random number generated from system clock in Atropos' | ||
'(default = 1)')) | ||
keep_temporary_files = traits.Int(argstr='-k %d', | ||
desc='Keep brain extraction/segmentation warps, etc (default = 0).') | ||
use_floatingpoint_precision = traits.Enum(0, 1, argstr='-q %d', | ||
desc=('Use floating point precision ' | ||
'in registrations (default = 0)')) | ||
debug = traits.Bool(argstr='-z 1', | ||
desc=('If > 0, runs a faster version of the script.' | ||
'Only for testing. Implies -u 0.' | ||
'Requires single thread computation for complete reproducibility.')) | ||
|
||
|
||
class antsBrainExtractionOutputSpec(TraitedSpec): | ||
BrainExtractionMask = File(exists=True, desc='brain extraction mask') | ||
BrainExtractionBrain = File(exists=True, desc='brain extraction image') | ||
|
||
class antsBrainExtraction(ANTSCommand): | ||
""" | ||
Examples | ||
-------- | ||
>>> from nipype.interfaces.ants.segmentation import antsBrainExtraction | ||
>>> brainextraction = antsBrainExtraction() | ||
>>> brainextraction.inputs.dimension = 3 | ||
>>> brainextraction.inputs.anatomical_image ='T1.nii.gz' | ||
>>> brainextraction.inputs.brain_template = 'study_template.nii.gz' | ||
>>> brainextraction.inputs.brain_probability_mask ='ProbabilityMaskOfStudyTemplate.nii.gz' | ||
>>> brainextraction.cmdline | ||
'antsBrainExtraction.sh -a T1.nii.gz -m ProbabilityMaskOfStudyTemplate.nii.gz -e study_template.nii.gz -d 3 -s nii.gz -o highres001_ | ||
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 are missing a quotation mark at the end. This makes one of the tests to fail: https://travis-ci.org/nipy/nipype/jobs/87317019#L4110 |
||
""" | ||
input_spec = antsBrainExtractionInputSpec | ||
output_spec = antsBrainExtractionOutputSpec | ||
_cmd = 'antsBrainExtraction.sh' | ||
|
||
def _format_arg(self, opt, spec, val): | ||
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. There shouldn't be any need to overload 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 are right. got rid of the unnecessary overload! 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. still seeing the overloaded |
||
if opt == 'anatomical_image': | ||
retval = '-a %s' % val | ||
return retval | ||
if opt == 'brain_template': | ||
retval = '-e %s' % val | ||
return retval | ||
if opt == 'brain_probability_mask': | ||
retval = '-m %s' % val | ||
return retval | ||
if opt == 'out_prefix': | ||
retval = '-o %s' % val | ||
return retval | ||
return super(ANTSCommand, self)._format_arg(opt, spec, val) | ||
|
||
def _run_interface(self, runtime, correct_return_codes=[0]): | ||
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 function is also not necessary |
||
runtime = super(antsBrainExtraction, self)._run_interface(runtime) | ||
return runtime | ||
|
||
def _list_outputs(self): | ||
outputs = self._outputs().get() | ||
outputs['BrainExtractionMask'] = os.path.join(os.getcwd(), | ||
self.inputs.out_prefix + | ||
'BrainExtractionMask.' + | ||
self.inputs.image_suffix) | ||
outputs['BrainExtractionBrain'] = os.path.join(os.getcwd(), | ||
self.inputs.out_prefix + | ||
'BrainExtractionBrain.' + | ||
self.inputs.image_suffix) | ||
return outputs | ||
|
||
|
||
class JointFusionInputSpec(ANTSCommandInputSpec): | ||
dimension = traits.Enum(3, 2, 4, argstr='%d', position=0, usedefault=True, | ||
mandatory=True, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT | ||
from nipype.testing import assert_equal | ||
from nipype.interfaces.ants.segmentation import antsBrainExtraction | ||
|
||
|
||
def test_antsBrainExtraction_inputs(): | ||
input_map = dict(anatomical_image=dict(argstr='-a %s', | ||
mandatory=True, | ||
), | ||
args=dict(argstr='%s', | ||
), | ||
brain_probability_mask=dict(argstr='-m %s', | ||
copyfile=False, | ||
mandatory=True, | ||
), | ||
brain_template=dict(argstr='-e %s', | ||
mandatory=True, | ||
), | ||
debug=dict(argstr='-z 1', | ||
), | ||
dimension=dict(argstr='-d %d', | ||
usedefault=True, | ||
), | ||
environ=dict(nohash=True, | ||
usedefault=True, | ||
), | ||
extraction_registration_mask=dict(argstr='-f %s', | ||
), | ||
ignore_exception=dict(nohash=True, | ||
usedefault=True, | ||
), | ||
image_suffix=dict(argstr='-s %s', | ||
usedefault=True, | ||
), | ||
keep_temporary_files=dict(argstr='-k %d', | ||
), | ||
out_prefix=dict(argstr='-o %s', | ||
usedefault=True, | ||
), | ||
terminal_output=dict(nohash=True, | ||
), | ||
use_floatingpoint_precision=dict(argstr='-q %d', | ||
), | ||
use_random_seeding=dict(argstr='-u %d', | ||
), | ||
) | ||
inputs = antsBrainExtraction.input_spec() | ||
|
||
for key, metadata in input_map.items(): | ||
for metakey, value in metadata.items(): | ||
yield assert_equal, getattr(inputs.traits()[key], metakey), value | ||
|
||
|
||
def test_antsBrainExtraction_outputs(): | ||
output_map = dict(BrainExtractionMask=dict(), | ||
BrainExtractionBrain=dict(), | ||
) | ||
outputs = antsBrainExtraction.output_spec() | ||
|
||
for key, metadata in output_map.items(): | ||
for metakey, value in metadata.items(): | ||
yield assert_equal, getattr(outputs.traits()[key], metakey), value |
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.
@hjmjohnson - do all ants commands now have this option, if so should this be moved to the base class?