Skip to content

WIP: antsRegistrationSyNQuick.sh wrapper #1392

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions nipype/interfaces/ants/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -975,3 +975,89 @@ def _list_outputs(self):
if len(self.inputs.save_state):
outputs['save_state'] = os.path.abspath(self.inputs.save_state)
return outputs





Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too many empty spaces (only 2 necessary)

class RegistrationSynQuickInputSpec(ANTSCommandInputSpec):
dimension = traits.Enum(3, 2, argstr='-d %d',
usedefault=True, desc='image dimension (2 or 3)')
fixed_image = InputMultiPath(File(exists=True), mandatory=True, argstr='-f %s',
desc='Fixed image or source image or reference image')
moving_image = InputMultiPath(File(exists=True), mandatory=True, argstr='-m %s',
desc='Moving image or target image')
output_prefix = traits.Str("transform", usedefault=True, argstr='-o %s',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Str from nipype base. (add from ..base import Str on the top, and then use Str instead of traits.Str here).

desc="A prefix that is prepended to all output files")

# todo ANTSCommandInputSpec already has this, but I can't figure out how to set it without defining it again
num_threads = traits.Int(default_value=1, desc='Number of threads (default = 1)', argstr='-n %d')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure, but I think you can do traits.Int(1, desc ... here.


transform_type = traits.Enum('s', 't', 'r', 'a', 'sr', 'b', 'br', argstr='-t %s',
desc='transform type\n\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use block strings:

transform_type = traits.Enum('s', 't', 'r', 'a', 'sr', 'b', 'br', argstr='-t %s',
                             usedefault=True, desc="""\
transform type -
t:  translation
r:  rigid
a: rigid + affine
s:  rigid + affine + deformable syn (default)
sr: rigid + deformable syn
b:  rigid + affine + deformable b-spline syn
br: rigid + deformable b-spline syn""")

t: translation\
r: rigid \n\
a: rigid + affine\n\
s: rigid + affine + deformable syn (default)\
sr: rigid + deformable syn\
b: rigid + affine + deformable b-spline syn\n\
br: rigid + deformable b-spline syn',
usedefault=True)

use_histogram_matching = traits.Bool(default=False, argstr='-j %s',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

traits.Bool(False, argstr ...)

additionally: you may remove the _format_arg for this input setting argstr='-j %d'

desc='use histogram matching')
histogram_bins = traits.Int(default_value=32, argstr='-r %d',
desc='histogram bins for mutual information in SyN stage \
(default = 32)')
spline_distance = traits.Int(default_value=26, argstr='-s %d',
desc='spline distance for deformable B-spline SyN transform \
(default = 26)')
precision_type = traits.Enum('double', 'float', argstr='-p %s',
desc='precision type (default = double)', usedefault=True)


class RegistrationSynQuickOutputSpec(TraitedSpec):
warped_image = File(exists=True, desc="Warped image")
inverse_warped_image = File(exists=True, desc="Inverse warped image")
out_matrix = File(exists=True, desc='Affine matrix')
forward_warp_field = File(exists=True, desc='Forward warp field')
inverse_warp_field = File(exists=True, desc='Inverse warp field')


class RegistrationSynQuick(ANTSCommand):
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing brief summary

Examples
--------

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing doctest

"""
# todo examples

_cmd = 'antsRegistrationSynQuick.sh'
input_spec = RegistrationSynQuickInputSpec
output_spec = RegistrationSynQuickOutputSpec

def _format_arg(self, name, spec, value):
if name == 'use_histogram_matching':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use argstr='-j %d' and remove this

if isdefined(self.inputs.use_histogram_matching):
return spec.argstr % {False: '0', True: '1'}[value]

elif name == 'precision_type':
if isdefined(self.inputs.precision_type):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is always True since this trait has usedefault=True

return spec.argstr % {'float': 'f', 'double': 'd'}[value]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

                return spec.argstr % value[0]

return super(RegistrationSynQuick, self)._format_arg(name, spec, value)

def _list_outputs(self):
outputs = self.output_spec().get()
outputs['warped_image'] = os.path.abspath(self.inputs.output_prefix + 'Warped.nii.gz')
outputs['inverse_warped_image'] = os.path.abspath(
self.inputs.output_prefix + 'InverseWarped.nii.gz')
outputs['out_matrix'] = os.path.abspath(self.inputs.output_prefix + '0GenericAffine.mat')

# todo in the case of linear transformation-only there won't be fields. is there a more elegant way to specify that?
if self.inputs.transform_type not in ('t', 'r', 'a'):
outputs['forward_warp_field'] = os.path.abspath(
self.inputs.output_prefix + '1Warp.nii.gz')
outputs['inverse_warp_field'] = os.path.abspath(
self.inputs.output_prefix + '1InverseWarp.nii.gz')
return outputs