Skip to content

Commit 17c78bf

Browse files
committed
enh: updated FLIRT to use new name generation mechanism to match with doc example
1 parent d4f5e9d commit 17c78bf

File tree

2 files changed

+12
-55
lines changed

2 files changed

+12
-55
lines changed

nipype/interfaces/fsl/preprocess.py

Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -386,20 +386,19 @@ def _list_outputs(self):
386386
class FLIRTInputSpec(FSLCommandInputSpec):
387387
in_file = File(exists=True, argstr='-in %s', mandatory=True,
388388
position=0, desc='input file')
389-
# XXX Not clear if position is required for mandatory flirt inputs
390-
# since they are prefixed with argstrs. But doing it to follow
391-
# our previous convention and so we can test the generated command
392-
# line.
393389
reference = File(exists=True, argstr='-ref %s', mandatory=True,
394390
position=1, desc='reference file')
395391
out_file = File(argstr='-out %s', desc='registered output file',
396-
genfile=True, position=2, hash_files=False)
392+
name_source=['in_file'], name_template='%s_flirt',
393+
position=2, hash_files=False)
397394
out_matrix_file = File(argstr='-omat %s',
395+
name_source=['in_file'], keep_extension=True,
396+
name_template='%s_flirt.mat',
398397
desc='output affine matrix in 4x4 asciii format',
399-
genfile=True, position=3, hash_files=False)
400-
401-
out_log = File(desc='output log')
402-
398+
position=3, hash_files=False)
399+
out_log = File(name_source=['in_file'], keep_extension=True,
400+
requires=['save_log'],
401+
name_template='%s_flirt.log', desc='output log')
403402
in_matrix_file = File(argstr='-init %s', desc='input 4x4 affine matrix')
404403
apply_xfm = traits.Bool(argstr='-applyxfm', requires=['in_matrix_file'],
405404
desc='apply transformation supplied by in_matrix_file')
@@ -533,44 +532,15 @@ class FLIRT(FSLCommand):
533532
>>> flt = fsl.FLIRT(bins=640, cost_func='mutualinfo')
534533
>>> flt.inputs.in_file = example_data('structural.nii')
535534
>>> flt.inputs.reference = example_data('mni.nii')
536-
>>> flt.inputs.out_file = 'moved_subject.nii'
537-
>>> flt.inputs.out_matrix_file = 'subject_to_template.mat'
535+
>>> flt.cmdline #doctest: +ELLIPSIS
536+
'flirt -in .../structural.nii -ref .../mni.nii -out structural_flirt.nii.gz -omat structural_flirt.mat -bins 640 -searchcost mutualinfo'
538537
>>> res = flt.run() #doctest: +SKIP
539538
540539
"""
541540
_cmd = 'flirt'
542541
input_spec = FLIRTInputSpec
543542
output_spec = FLIRTOutputSpec
544543

545-
def _list_outputs(self):
546-
outputs = self.output_spec().get()
547-
outputs['out_file'] = self.inputs.out_file
548-
# Generate an out_file if one is not provided
549-
if not isdefined(outputs['out_file']):
550-
outputs['out_file'] = self._gen_fname(self.inputs.in_file,
551-
suffix='_flirt')
552-
outputs['out_file'] = os.path.abspath(outputs['out_file'])
553-
554-
outputs['out_matrix_file'] = self.inputs.out_matrix_file
555-
556-
# Generate an out_matrix file if one is not provided
557-
if not isdefined(outputs['out_matrix_file']):
558-
outputs['out_matrix_file'] = self._gen_fname(self.inputs.in_file,
559-
suffix='_flirt.mat',
560-
change_ext=False)
561-
outputs['out_matrix_file'] = os.path.abspath(
562-
outputs['out_matrix_file'])
563-
564-
if isdefined(self.inputs.save_log) and self.inputs.save_log:
565-
outputs['out_log'] = self.inputs.out_log
566-
# Generate an out_log file if one is not provided
567-
if not isdefined(outputs['out_log']):
568-
outputs['out_log'] = self._gen_fname(self.inputs.in_file,
569-
suffix='_flirt.log',
570-
change_ext=False)
571-
outputs['out_log'] = os.path.abspath(outputs['out_log'])
572-
return outputs
573-
574544
def aggregate_outputs(self, runtime=None, needed_outputs=None):
575545
outputs = super(FLIRT, self).aggregate_outputs(
576546
runtime=runtime, needed_outputs=needed_outputs)
@@ -581,21 +551,12 @@ def aggregate_outputs(self, runtime=None, needed_outputs=None):
581551

582552
def _parse_inputs(self, skip=None):
583553
skip = []
584-
585554
if isdefined(self.inputs.save_log) and self.inputs.save_log:
586555
if not isdefined(self.inputs.verbose) or self.inputs.verbose == 0:
587556
self.inputs.verbose = 1
588-
589557
skip.append('save_log')
590-
591558
return super(FLIRT, self)._parse_inputs(skip=skip)
592559

593-
def _gen_filename(self, name):
594-
if name in ('out_file', 'out_matrix_file'):
595-
return self._list_outputs()[name]
596-
else:
597-
return None
598-
599560

600561
class ApplyXfmInputSpec(FLIRTInputSpec):
601562
apply_xfm = traits.Bool(

nipype/interfaces/fsl/tests/test_preprocess.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,8 @@ def test_flirt():
204204
flirter.inputs.reference = reffile
205205
# Generate outfile and outmatrix
206206
pth, fname, ext = split_filename(infile)
207-
outfile = os.path.join(os.getcwd(),
208-
fsl_name(flirter, '%s_flirt' %fname))
207+
outfile = fsl_name(flirter, '%s_flirt' %fname)
209208
outmat = '%s_flirt.mat' % fname
210-
outmat = os.path.join(os.getcwd(), outmat)
211209
realcmd = 'flirt -in %s -ref %s -out %s -omat %s' % (infile, reffile,
212210
outfile, outmat)
213211
yield assert_equal, flirter.cmdline, realcmd
@@ -242,12 +240,10 @@ def test_flirt():
242240
cmdline = 'flirt -in %s -ref %s' % (infile, reffile)
243241
# Handle autogeneration of outfile
244242
pth, fname, ext = split_filename(infile)
245-
outfile = os.path.join(os.getcwd(),
246-
fsl_name(fsl.FLIRT(),'%s_flirt' % fname))
243+
outfile = fsl_name(fsl.FLIRT(),'%s_flirt' % fname)
247244
outfile = ' '.join(['-out', outfile])
248245
# Handle autogeneration of outmatrix
249246
outmatrix = '%s_flirt.mat' % fname
250-
outmatrix = os.path.join(os.getcwd(), outmatrix)
251247
outmatrix = ' '.join(['-omat', outmatrix])
252248
# Build command line
253249
cmdline = ' '.join([cmdline, outfile, outmatrix, param])

0 commit comments

Comments
 (0)