@@ -37,11 +37,13 @@ class AtroposInputSpec(ANTSCommandInputSpec):
3737 mrf_smoothing_factor = traits .Float (argstr = "%s" )
3838 mrf_radius = traits .List (traits .Int (), requires = ['mrf_smoothing_factor' ])
3939 icm_use_synchronous_update = traits .Bool (argstr = "%s" )
40- maximum_number_of_icm_terations = traits .Int (requires = ['icm_use_synchronous_update' ])
40+ maximum_number_of_icm_terations = traits .Int (
41+ requires = ['icm_use_synchronous_update' ])
4142 n_iterations = traits .Int (argstr = "%s" )
4243 convergence_threshold = traits .Float (requires = ['n_iterations' ])
4344 posterior_formulation = traits .Str (argstr = "%s" )
44- use_mixture_model_proportions = traits .Bool (requires = ['posterior_formulation' ])
45+ use_mixture_model_proportions = traits .Bool (
46+ requires = ['posterior_formulation' ])
4547 out_classified_image_name = File (argstr = "%s" , genfile = True ,
4648 hash_files = False )
4749 save_posteriors = traits .Bool ()
@@ -93,17 +95,21 @@ class Atropos(ANTSCommand):
9395
9496 def _format_arg (self , opt , spec , val ):
9597 if opt == 'initialization' :
96- retval = "--initialization %s[%d" % (val , self .inputs .number_of_tissue_classes )
98+ retval = "--initialization %s[%d" % (val ,
99+ self .inputs .number_of_tissue_classes )
97100 if val == "PriorProbabilityImages" :
98- _ , _ , ext = split_filename (self .inputs .prior_probability_images [0 ])
99- retval += ",priors/priorProbImages%02d" + ext + ",%g" % self .inputs .prior_weighting
101+ _ , _ , ext = split_filename (
102+ self .inputs .prior_probability_images [0 ])
103+ retval += ",priors/priorProbImages%02d" + \
104+ ext + ",%g" % self .inputs .prior_weighting
100105 if isdefined (self .inputs .prior_probability_threshold ):
101106 retval += ",%g" % self .inputs .prior_probability_threshold
102107 return retval + "]"
103108 if opt == 'mrf_smoothing_factor' :
104109 retval = "--mrf [%g" % val
105110 if isdefined (self .inputs .mrf_radius ):
106- retval += ",%s" % 'x' .join ([str (s ) for s in self .inputs .mrf_radius ])
111+ retval += ",%s" % 'x' .join ([str (s )
112+ for s in self .inputs .mrf_radius ])
107113 return retval + "]"
108114 if opt == "icm_use_synchronous_update" :
109115 retval = "--icm [%d" % val
@@ -153,11 +159,13 @@ def _gen_filename(self, name):
153159
154160 def _list_outputs (self ):
155161 outputs = self ._outputs ().get ()
156- outputs ['classified_image' ] = os .path .abspath (self ._gen_filename ('out_classified_image_name' ))
162+ outputs ['classified_image' ] = os .path .abspath (
163+ self ._gen_filename ('out_classified_image_name' ))
157164 if isdefined (self .inputs .save_posteriors ) and self .inputs .save_posteriors :
158165 outputs ['posteriors' ] = []
159166 for i in range (self .inputs .number_of_tissue_classes ):
160- outputs ['posteriors' ].append (os .path .abspath (self .inputs .output_posteriors_name_template % (i + 1 )))
167+ outputs ['posteriors' ].append (os .path .abspath (
168+ self .inputs .output_posteriors_name_template % (i + 1 )))
161169 return outputs
162170
163171
@@ -268,7 +276,7 @@ class N4BiasFieldCorrection(ANTSCommand):
268276 Examples
269277 --------
270278
271- >>> import copy
279+ >>> import copy
272280 >>> from nipype.interfaces.ants import N4BiasFieldCorrection
273281 >>> n4 = N4BiasFieldCorrection()
274282 >>> n4.inputs.dimension = 3
@@ -282,7 +290,7 @@ class N4BiasFieldCorrection(ANTSCommand):
282290 --convergence [ 50x50x30x20 ] --output structural_corrected.nii \
283291 --shrink-factor 3'
284292
285- >>> n4_2 = copy.deepcopy(n4)
293+ >>> n4_2 = copy.deepcopy(n4)
286294 >>> n4_2.inputs.convergence_threshold = 1e-6
287295 >>> n4_2.cmdline
288296 'N4BiasFieldCorrection --bspline-fitting [ 300 ] \
@@ -328,7 +336,7 @@ def _gen_filename(self, name):
328336
329337 def _format_arg (self , name , trait_spec , value ):
330338 if ((name == 'output_image' ) and
331- (self .inputs .save_bias or isdefined (self .inputs .bias_image ))):
339+ (self .inputs .save_bias or isdefined (self .inputs .bias_image ))):
332340 bias_image = self ._gen_filename ('bias_image' )
333341 output = self ._gen_filename ('output_image' )
334342 newval = '[ %s, %s ]' % (output , bias_image )
@@ -360,10 +368,12 @@ def _parse_inputs(self, skip=None):
360368
361369 def _list_outputs (self ):
362370 outputs = self ._outputs ().get ()
363- outputs ['output_image' ] = os .path .abspath (self ._gen_filename ('output_image' ))
371+ outputs ['output_image' ] = os .path .abspath (
372+ self ._gen_filename ('output_image' ))
364373
365374 if self .inputs .save_bias or isdefined (self .inputs .bias_image ):
366- outputs ['bias_image' ] = os .path .abspath (self ._gen_filename ('bias_image' ))
375+ outputs ['bias_image' ] = os .path .abspath (
376+ self ._gen_filename ('bias_image' ))
367377 return outputs
368378
369379
@@ -386,7 +396,8 @@ class antsCorticalThicknessInputSpec(ANTSCommandInputSpec):
386396 mandatory = True )
387397 brain_probability_mask = File (exists = True , argstr = '-m %s' ,
388398 desc = 'brain probability mask in template space' , copyfile = False , mandatory = True )
389- segmentation_priors = InputMultiPath (File (exists = True ), argstr = '-p %s' , mandatory = True )
399+ segmentation_priors = InputMultiPath (
400+ File (exists = True ), argstr = '-p %s' , mandatory = True )
390401 out_prefix = traits .Str ('antsCT_' , argstr = '-o %s' , usedefault = True ,
391402 desc = ('Prefix that is prepended to all output'
392403 ' files (default = antsCT_)' ))
@@ -458,11 +469,15 @@ class antsCorticalThicknessoutputSpec(TraitedSpec):
458469 BrainSegmentationPosteriors = OutputMultiPath (File (exists = True ),
459470 desc = 'Posterior probability images' )
460471 CorticalThickness = File (exists = True , desc = 'cortical thickness file' )
461- TemplateToSubject1GenericAffine = File (exists = True , desc = 'Template to subject affine' )
472+ TemplateToSubject1GenericAffine = File (
473+ exists = True , desc = 'Template to subject affine' )
462474 TemplateToSubject0Warp = File (exists = True , desc = 'Template to subject warp' )
463- SubjectToTemplate1Warp = File (exists = True , desc = 'Template to subject inverse warp' )
464- SubjectToTemplate0GenericAffine = File (exists = True , desc = 'Template to subject inverse affine' )
465- SubjectToTemplateLogJacobian = File (exists = True , desc = 'Template to subject log jacobian' )
475+ SubjectToTemplate1Warp = File (
476+ exists = True , desc = 'Template to subject inverse warp' )
477+ SubjectToTemplate0GenericAffine = File (
478+ exists = True , desc = 'Template to subject inverse affine' )
479+ SubjectToTemplateLogJacobian = File (
480+ exists = True , desc = 'Template to subject log jacobian' )
466481 CorticalThicknessNormedToTemplate = File (exists = True ,
467482 desc = 'Normalized cortical thickness' )
468483 BrainVolumes = File (exists = True , desc = 'Brain volumes as text' )
@@ -516,7 +531,8 @@ def _run_interface(self, runtime, correct_return_codes=[0]):
516531 os .makedirs (priors_directory )
517532 _ , _ , ext = split_filename (self .inputs .segmentation_priors [0 ])
518533 for i , f in enumerate (self .inputs .segmentation_priors ):
519- target = os .path .join (priors_directory , 'BrainSegmentationPrior%02d' % (i + 1 ) + ext )
534+ target = os .path .join (
535+ priors_directory , 'BrainSegmentationPrior%02d' % (i + 1 ) + ext )
520536 if not (os .path .exists (target ) and os .path .realpath (target ) == os .path .abspath (f )):
521537 copyfile (os .path .abspath (f ), target )
522538 runtime = super (antsCorticalThickness , self )._run_interface (runtime )
@@ -566,9 +582,9 @@ def _list_outputs(self):
566582 'SubjectToTemplateLogJacobian.' +
567583 self .inputs .image_suffix )
568584 outputs ['CorticalThicknessNormedToTemplate' ] = os .path .join (os .getcwd (),
569- self .inputs .out_prefix +
570- 'CorticalThickness.' +
571- self .inputs .image_suffix )
585+ self .inputs .out_prefix +
586+ 'CorticalThickness.' +
587+ self .inputs .image_suffix )
572588 outputs ['BrainVolumes' ] = os .path .join (os .getcwd (),
573589 self .inputs .out_prefix +
574590 'brainvols.csv' )
@@ -619,7 +635,8 @@ class JointFusionInputSpec(ANTSCommandInputSpec):
619635
620636
621637class JointFusionOutputSpec (TraitedSpec ):
622- output_label_image = File (exists = True , desc = 'Output fusion label map image' )
638+ output_label_image = File (exists = True )
639+ # TODO: optional outputs - output_posteriors, output_voting_weights
623640
624641
625642class JointFusion (ANTSCommand ):
@@ -640,16 +657,14 @@ class JointFusion(ANTSCommand):
640657 ... 'segmentation1.nii.gz',
641658 ... 'segmentation1.nii.gz']
642659 >>> at.inputs.target_image = 'T1.nii'
643- >>> at.inputs.patch_radius = [3,2,1]
644- >>> at.inputs.search_radius = [1,2,3]
645660 >>> at.cmdline
646- 'jointfusion 3 1 -m Joint[0.1,2] -rp 3x2x1 -rs 1x2x3 -tg T1.nii -g im1.nii -g im2.nii -g im3.nii -l segmentation0.nii.gz -l segmentation1.nii.gz -l segmentation1.nii.gz fusion_labelimage_output.nii'
647-
648- Alternately, you can specify the voting method and parameters more 'Pythonically':
661+ 'jointfusion 3 1 -m Joint[0.1,2] -tg T1.nii -g im1.nii -g im2.nii -g im3.nii -l segmentation0.nii.gz -l segmentation1.nii.gz -l segmentation1.nii.gz fusion_labelimage_output.nii'
649662
650663 >>> at.inputs.method = 'Joint'
651664 >>> at.inputs.alpha = 0.5
652665 >>> at.inputs.beta = 1
666+ >>> at.inputs.patch_radius = [3,2,1]
667+ >>> at.inputs.search_radius = [1,2,3]
653668 >>> at.cmdline
654669 'jointfusion 3 1 -m Joint[0.5,1] -rp 3x2x1 -rs 1x2x3 -tg T1.nii -g im1.nii -g im2.nii -g im3.nii -l segmentation0.nii.gz -l segmentation1.nii.gz -l segmentation1.nii.gz fusion_labelimage_output.nii'
655670 """
@@ -662,13 +677,21 @@ def _format_arg(self, opt, spec, val):
662677 if '[' in val :
663678 retval = '-m {0}' .format (val )
664679 else :
665- retval = '-m {0}[{1},{2}]' .format (self .inputs .method , self .inputs .alpha , self .inputs .beta )
680+ retval = '-m {0}[{1},{2}]' .format (
681+ self .inputs .method , self .inputs .alpha , self .inputs .beta )
666682 elif opt == 'patch_radius' :
667683 retval = '-rp {0}' .format (self ._format_xarray (val ))
668684 elif opt == 'search_radius' :
669685 retval = '-rs {0}' .format (self ._format_xarray (val ))
670686 else :
671687 if opt == 'warped_intensity_images' :
672- assert len (val ) == len (self .inputs .warped_label_images ), "Number of intensity images and label maps must be the same"
688+ assert len (val ) == self .inputs .modalities * len (self .inputs .warped_label_images ), "Number of intensity images and label maps must be the same {0}!={1}" .format (
689+ len (val ), len (self .inputs .warped_label_images ))
673690 return super (ANTSCommand , self )._format_arg (opt , spec , val )
674691 return retval
692+
693+ def _list_outputs (self ):
694+ outputs = self ._outputs ().get ()
695+ outputs ['output_label_image' ] = os .path .abspath (
696+ self .inputs .output_label_image )
697+ return outputs
0 commit comments