@@ -37,11 +37,13 @@ class AtroposInputSpec(ANTSCommandInputSpec):
37
37
mrf_smoothing_factor = traits .Float (argstr = "%s" )
38
38
mrf_radius = traits .List (traits .Int (), requires = ['mrf_smoothing_factor' ])
39
39
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' ])
41
42
n_iterations = traits .Int (argstr = "%s" )
42
43
convergence_threshold = traits .Float (requires = ['n_iterations' ])
43
44
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' ])
45
47
out_classified_image_name = File (argstr = "%s" , genfile = True ,
46
48
hash_files = False )
47
49
save_posteriors = traits .Bool ()
@@ -93,17 +95,21 @@ class Atropos(ANTSCommand):
93
95
94
96
def _format_arg (self , opt , spec , val ):
95
97
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 )
97
100
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
100
105
if isdefined (self .inputs .prior_probability_threshold ):
101
106
retval += ",%g" % self .inputs .prior_probability_threshold
102
107
return retval + "]"
103
108
if opt == 'mrf_smoothing_factor' :
104
109
retval = "--mrf [%g" % val
105
110
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 ])
107
113
return retval + "]"
108
114
if opt == "icm_use_synchronous_update" :
109
115
retval = "--icm [%d" % val
@@ -153,11 +159,13 @@ def _gen_filename(self, name):
153
159
154
160
def _list_outputs (self ):
155
161
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' ))
157
164
if isdefined (self .inputs .save_posteriors ) and self .inputs .save_posteriors :
158
165
outputs ['posteriors' ] = []
159
166
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 )))
161
169
return outputs
162
170
163
171
@@ -268,7 +276,7 @@ class N4BiasFieldCorrection(ANTSCommand):
268
276
Examples
269
277
--------
270
278
271
- >>> import copy
279
+ >>> import copy
272
280
>>> from nipype.interfaces.ants import N4BiasFieldCorrection
273
281
>>> n4 = N4BiasFieldCorrection()
274
282
>>> n4.inputs.dimension = 3
@@ -282,7 +290,7 @@ class N4BiasFieldCorrection(ANTSCommand):
282
290
--convergence [ 50x50x30x20 ] --output structural_corrected.nii \
283
291
--shrink-factor 3'
284
292
285
- >>> n4_2 = copy.deepcopy(n4)
293
+ >>> n4_2 = copy.deepcopy(n4)
286
294
>>> n4_2.inputs.convergence_threshold = 1e-6
287
295
>>> n4_2.cmdline
288
296
'N4BiasFieldCorrection --bspline-fitting [ 300 ] \
@@ -328,7 +336,7 @@ def _gen_filename(self, name):
328
336
329
337
def _format_arg (self , name , trait_spec , value ):
330
338
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 ))):
332
340
bias_image = self ._gen_filename ('bias_image' )
333
341
output = self ._gen_filename ('output_image' )
334
342
newval = '[ %s, %s ]' % (output , bias_image )
@@ -360,10 +368,12 @@ def _parse_inputs(self, skip=None):
360
368
361
369
def _list_outputs (self ):
362
370
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' ))
364
373
365
374
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' ))
367
377
return outputs
368
378
369
379
@@ -386,7 +396,8 @@ class antsCorticalThicknessInputSpec(ANTSCommandInputSpec):
386
396
mandatory = True )
387
397
brain_probability_mask = File (exists = True , argstr = '-m %s' ,
388
398
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 )
390
401
out_prefix = traits .Str ('antsCT_' , argstr = '-o %s' , usedefault = True ,
391
402
desc = ('Prefix that is prepended to all output'
392
403
' files (default = antsCT_)' ))
@@ -458,11 +469,15 @@ class antsCorticalThicknessoutputSpec(TraitedSpec):
458
469
BrainSegmentationPosteriors = OutputMultiPath (File (exists = True ),
459
470
desc = 'Posterior probability images' )
460
471
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' )
462
474
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' )
466
481
CorticalThicknessNormedToTemplate = File (exists = True ,
467
482
desc = 'Normalized cortical thickness' )
468
483
BrainVolumes = File (exists = True , desc = 'Brain volumes as text' )
@@ -516,7 +531,8 @@ def _run_interface(self, runtime, correct_return_codes=[0]):
516
531
os .makedirs (priors_directory )
517
532
_ , _ , ext = split_filename (self .inputs .segmentation_priors [0 ])
518
533
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 )
520
536
if not (os .path .exists (target ) and os .path .realpath (target ) == os .path .abspath (f )):
521
537
copyfile (os .path .abspath (f ), target )
522
538
runtime = super (antsCorticalThickness , self )._run_interface (runtime )
@@ -566,9 +582,9 @@ def _list_outputs(self):
566
582
'SubjectToTemplateLogJacobian.' +
567
583
self .inputs .image_suffix )
568
584
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 )
572
588
outputs ['BrainVolumes' ] = os .path .join (os .getcwd (),
573
589
self .inputs .out_prefix +
574
590
'brainvols.csv' )
@@ -619,7 +635,8 @@ class JointFusionInputSpec(ANTSCommandInputSpec):
619
635
620
636
621
637
class 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
623
640
624
641
625
642
class JointFusion (ANTSCommand ):
@@ -640,16 +657,14 @@ class JointFusion(ANTSCommand):
640
657
... 'segmentation1.nii.gz',
641
658
... 'segmentation1.nii.gz']
642
659
>>> at.inputs.target_image = 'T1.nii'
643
- >>> at.inputs.patch_radius = [3,2,1]
644
- >>> at.inputs.search_radius = [1,2,3]
645
660
>>> 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'
649
662
650
663
>>> at.inputs.method = 'Joint'
651
664
>>> at.inputs.alpha = 0.5
652
665
>>> at.inputs.beta = 1
666
+ >>> at.inputs.patch_radius = [3,2,1]
667
+ >>> at.inputs.search_radius = [1,2,3]
653
668
>>> at.cmdline
654
669
'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'
655
670
"""
@@ -662,13 +677,21 @@ def _format_arg(self, opt, spec, val):
662
677
if '[' in val :
663
678
retval = '-m {0}' .format (val )
664
679
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 )
666
682
elif opt == 'patch_radius' :
667
683
retval = '-rp {0}' .format (self ._format_xarray (val ))
668
684
elif opt == 'search_radius' :
669
685
retval = '-rs {0}' .format (self ._format_xarray (val ))
670
686
else :
671
687
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 ))
673
690
return super (ANTSCommand , self )._format_arg (opt , spec , val )
674
691
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