@@ -391,6 +391,9 @@ class FLIRTInputSpec(FSLCommandInputSpec):
391
391
out_matrix_file = File (argstr = '-omat %s' ,
392
392
desc = 'output affine matrix in 4x4 asciii format' ,
393
393
genfile = True , position = 3 , hash_files = False )
394
+
395
+ out_log = File ( desc = 'output log' )
396
+
394
397
in_matrix_file = File (argstr = '-init %s' , desc = 'input 4x4 affine matrix' )
395
398
apply_xfm = traits .Bool (argstr = '-applyxfm' , requires = ['in_matrix_file' ],
396
399
desc = 'apply transformation supplied by in_matrix_file' )
@@ -461,6 +464,8 @@ class FLIRTInputSpec(FSLCommandInputSpec):
461
464
desc = 'do not use blurring on downsampling' )
462
465
rigid2D = traits .Bool (argstr = '-2D' ,
463
466
desc = 'use 2D rigid body mode - ignores dof' )
467
+
468
+ save_log = traits .Bool (desc = 'save to log file' )
464
469
verbose = traits .Int (argstr = '-verbose %d' ,
465
470
desc = 'verbose mode, 0 is least' )
466
471
@@ -471,6 +476,7 @@ class FLIRTOutputSpec(TraitedSpec):
471
476
out_matrix_file = File (exists = True ,
472
477
desc = 'path/name of calculated affine transform ' \
473
478
'(if generated)' )
479
+ out_log = File (desc = 'path/name of output log (if generated)' )
474
480
475
481
476
482
class FLIRT (FSLCommand ):
@@ -508,14 +514,43 @@ def _list_outputs(self):
508
514
outputs ['out_file' ] = os .path .abspath (outputs ['out_file' ])
509
515
510
516
outputs ['out_matrix_file' ] = self .inputs .out_matrix_file
517
+
511
518
# Generate an out_matrix file if one is not provided
512
519
if not isdefined (outputs ['out_matrix_file' ]):
513
520
outputs ['out_matrix_file' ] = self ._gen_fname (self .inputs .in_file ,
514
521
suffix = '_flirt.mat' ,
515
522
change_ext = False )
516
523
outputs ['out_matrix_file' ] = os .path .abspath (outputs ['out_matrix_file' ])
524
+
525
+ if isdefined ( self .inputs .save_log ) and self .inputs .save_log :
526
+ outputs ['out_log' ] = self .inputs .out_log
527
+ # Generate an out_log file if one is not provided
528
+ if not isdefined ( outputs ['out_log' ]):
529
+ outputs ['out_log' ] = self ._gen_fname ( self .inputs .in_file ,
530
+ suffix = '_flirt.log' ,
531
+ change_ext = False )
532
+ outputs ['out_log' ] = os .path .abspath ( outputs ['out_log' ] )
533
+ return outputs
534
+
535
+ def aggregate_outputs (self , runtime = None , needed_outputs = None ):
536
+ outputs = super (FLIRT ,self ).aggregate_outputs (runtime = runtime , needed_outputs = needed_outputs )
537
+ if isdefined ( self .inputs .save_log ) and self .inputs .save_log :
538
+ with open (outputs .out_log , "a" ) as text_file :
539
+ text_file .write (runtime .stdout + '\n ' )
517
540
return outputs
518
541
542
+ def _parse_inputs (self , skip = None ):
543
+ skip = []
544
+
545
+ if isdefined ( self .inputs .save_log ) and self .inputs .save_log :
546
+ if not isdefined ( self .inputs .verbose ) or self .inputs .verbose == 0 :
547
+ self .inputs .verbose = 1
548
+
549
+ skip .append ( 'save_log' )
550
+
551
+ return super (FLIRT ,self )._parse_inputs (skip = skip )
552
+
553
+
519
554
def _gen_filename (self , name ):
520
555
if name in ('out_file' , 'out_matrix_file' ):
521
556
return self ._list_outputs ()[name ]
0 commit comments