Skip to content

Commit 6608524

Browse files
committed
Modified FSL FLIRT interface to provide log support
In order that supporting logging for fdt_rotate_bvecs script, the verbose output of FLIRT is saved to file if the save_log input is provided.
1 parent e2718e9 commit 6608524

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

nipype/interfaces/fsl/preprocess.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@ class FLIRTInputSpec(FSLCommandInputSpec):
391391
out_matrix_file = File(argstr='-omat %s',
392392
desc='output affine matrix in 4x4 asciii format',
393393
genfile=True, position=3, hash_files=False)
394+
395+
out_log = File( desc='output log' )
396+
394397
in_matrix_file = File(argstr='-init %s', desc='input 4x4 affine matrix')
395398
apply_xfm = traits.Bool(argstr='-applyxfm', requires=['in_matrix_file'],
396399
desc='apply transformation supplied by in_matrix_file')
@@ -461,6 +464,8 @@ class FLIRTInputSpec(FSLCommandInputSpec):
461464
desc='do not use blurring on downsampling')
462465
rigid2D = traits.Bool(argstr='-2D',
463466
desc='use 2D rigid body mode - ignores dof')
467+
468+
save_log = traits.Bool(desc='save to log file')
464469
verbose = traits.Int(argstr='-verbose %d',
465470
desc='verbose mode, 0 is least')
466471

@@ -471,6 +476,7 @@ class FLIRTOutputSpec(TraitedSpec):
471476
out_matrix_file = File(exists=True,
472477
desc='path/name of calculated affine transform ' \
473478
'(if generated)')
479+
out_log = File(desc='path/name of output log (if generated)' )
474480

475481

476482
class FLIRT(FSLCommand):
@@ -508,14 +514,43 @@ def _list_outputs(self):
508514
outputs['out_file'] = os.path.abspath(outputs['out_file'])
509515

510516
outputs['out_matrix_file'] = self.inputs.out_matrix_file
517+
511518
# Generate an out_matrix file if one is not provided
512519
if not isdefined(outputs['out_matrix_file']):
513520
outputs['out_matrix_file'] = self._gen_fname(self.inputs.in_file,
514521
suffix='_flirt.mat',
515522
change_ext=False)
516523
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' )
517540
return outputs
518541

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+
519554
def _gen_filename(self, name):
520555
if name in ('out_file', 'out_matrix_file'):
521556
return self._list_outputs()[name]

0 commit comments

Comments
 (0)