Skip to content

Commit 50a8ec6

Browse files
authored
Merge pull request #1875 from mgxd/fix/flirt_xfm
enh: allow uses_qform in FLIRT, ApplyXFM interfaces
2 parents 103bf84 + f266c83 commit 50a8ec6

File tree

5 files changed

+28
-172
lines changed

5 files changed

+28
-172
lines changed

nipype/interfaces/fsl/preprocess.py

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

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

574580

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_ApplyXfm.py

Lines changed: 0 additions & 164 deletions
This file was deleted.

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
@@ -7,6 +7,7 @@
77

88
import os
99
import tempfile
10+
from copy import deepcopy
1011

1112
import pytest
1213
from nipype.utils.filemanip import split_filename, filename_to_list
@@ -220,12 +221,13 @@ def test_flirt(setup_flirt):
220221
flirter = fsl.FLIRT()
221222
# infile not specified
222223
with pytest.raises(ValueError):
223-
flirter.run()
224+
flirter.cmdline
224225
flirter.inputs.in_file = infile
225226
# reference not specified
226227
with pytest.raises(ValueError):
227-
flirter.run()
228+
flirter.cmdline
228229
flirter.inputs.reference = reffile
230+
229231
# Generate outfile and outmatrix
230232
pth, fname, ext = split_filename(infile)
231233
outfile = fsl_name(flirter, '%s_flirt' % fname)
@@ -234,6 +236,20 @@ def test_flirt(setup_flirt):
234236
outfile, outmat)
235237
assert flirter.cmdline == realcmd
236238

239+
# test apply_xfm option
240+
axfm = deepcopy(flirter)
241+
axfm.inputs.apply_xfm = True
242+
# in_matrix_file or uses_qform must be defined
243+
with pytest.raises(RuntimeError): axfm.cmdline
244+
axfm2 = deepcopy(axfm)
245+
# test uses_qform
246+
axfm.inputs.uses_qform = True
247+
assert axfm.cmdline == (realcmd + ' -applyxfm -usesqform')
248+
# test in_matrix_file
249+
axfm2.inputs.in_matrix_file = reffile
250+
assert axfm2.cmdline == (realcmd + ' -applyxfm -init %s' % reffile)
251+
252+
237253
_, tmpfile = tempfile.mkstemp(suffix='.nii', dir=tmpdir)
238254
# Loop over all inputs, set a reasonable value and make sure the
239255
# cmdline is updated correctly.

0 commit comments

Comments
 (0)