Skip to content

Commit 35a9b0b

Browse files
committed
Merge branch 'fix/flirt_xfm' of github.com:mgxd/nipype into fix/flirt_xfm
2 parents 8e65903 + 50e1dfc commit 35a9b0b

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

nipype/interfaces/fsl/preprocess.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,9 @@ class FLIRTInputSpec(FSLCommandInputSpec):
400400
name_template='%s_flirt.log', desc='output log')
401401
in_matrix_file = File(argstr='-init %s', desc='input 4x4 affine matrix')
402402
apply_xfm = traits.Bool(
403-
argstr='-applyxfm', requires=['in_matrix_file'],
404-
desc='apply transformation supplied by in_matrix_file')
403+
argstr='-applyxfm',
404+
desc=('apply transformation supplied by in_matrix_file or uses_qform to'
405+
' use the affine matrix stored in the reference header'))
405406
apply_isoxfm = traits.Float(
406407
argstr='-applyisoxfm %f', xor=['apply_xfm'],
407408
desc='as applyxfm but forces isotropic resampling')
@@ -561,13 +562,18 @@ def _parse_inputs(self, skip=None):
561562
if isdefined(self.inputs.save_log) and self.inputs.save_log:
562563
if not isdefined(self.inputs.verbose) or self.inputs.verbose == 0:
563564
self.inputs.verbose = 1
565+
if isdefined(self.inputs.apply_xfm) and self.inputs.apply_xfm:
566+
if not self.inputs.in_matrix_file or not self.inputs.uses_qform:
567+
raise RuntimeError('Argument apply_xfm requires in_matrix_file '
568+
'or uses_qform arguments to run')
564569
skip.append('save_log')
565570
return super(FLIRT, self)._parse_inputs(skip=skip)
566571

567572
class ApplyXFMInputSpec(FLIRTInputSpec):
568573
apply_xfm = traits.Bool(
569-
True, argstr='-applyxfm', requires=['in_matrix_file'],
570-
desc='apply transformation supplied by in_matrix_file',
574+
True, argstr='-applyxfm',
575+
desc=('apply transformation supplied by in_matrix_file or uses_qform to'
576+
' use the affine matrix stored in the reference header'),
571577
usedefault=True)
572578

573579

nipype/interfaces/fsl/tests/test_auto_ApplyXFM.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ def test_ApplyXFM_inputs():
1010
xor=['apply_xfm'],
1111
),
1212
apply_xfm=dict(argstr='-applyxfm',
13-
requires=['in_matrix_file'],
1413
usedefault=True,
1514
),
1615
args=dict(argstr='%s',

nipype/interfaces/fsl/tests/test_auto_FLIRT.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ def test_FLIRT_inputs():
1010
xor=['apply_xfm'],
1111
),
1212
apply_xfm=dict(argstr='-applyxfm',
13-
requires=['in_matrix_file'],
1413
),
1514
args=dict(argstr='%s',
1615
),

nipype/interfaces/fsl/tests/test_preprocess.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,28 @@ def test_flirt(setup_flirt):
220220
flirter = fsl.FLIRT()
221221
# infile not specified
222222
with pytest.raises(ValueError):
223-
flirter.run()
223+
flirter.cmdline
224224
flirter.inputs.in_file = infile
225225
# reference not specified
226226
with pytest.raises(ValueError):
227-
flirter.run()
227+
flirter.cmdline
228228
flirter.inputs.reference = reffile
229+
230+
# test apply_xfm option
231+
axfm = flirter
232+
axfm.inputs.apply_xfm = True
233+
# in_matrix_file or uses_qform must be defined
234+
with pytest.raises(RuntimeError): axfm.cmdline
235+
axfm2 = axfm
236+
# test uses_qform
237+
axfm.inputs.uses_qform = True
238+
assert axfm.cmdline == ('flirt -in %s -ref %s -applyxfm -usesqform' % (
239+
infile, reffile))
240+
# test in_matrix_file
241+
axfm2.inputs.in_matrix_file = reffile
242+
assert axfm2.cmdline == ('flirt -in %s -ref %s -applyxfm -init %s' % (
243+
infile, reffile, reffile))
244+
229245
# Generate outfile and outmatrix
230246
pth, fname, ext = split_filename(infile)
231247
outfile = fsl_name(flirter, '%s_flirt' % fname)

0 commit comments

Comments
 (0)