From f46fb75574d9102b72c4b7067302155d0306035b Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Wed, 11 Jun 2014 12:32:41 +0200 Subject: [PATCH] Bugfix in FUGUE and doctest added FUGUE interface was adding wrong parameter in forward warping mode. Added the missing doctest of the interface. --- CHANGES | 1 + nipype/interfaces/fsl/preprocess.py | 41 ++++++++++++------- .../interfaces/fsl/tests/test_auto_FUGUE.py | 1 - 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/CHANGES b/CHANGES index f4ebb73be0..4fb242cb24 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,7 @@ Next Release ============ +* FIX: FUGUE interface was adding wrong parameter in forward warping mode. * API: Interfaces to external packages are no longer available in the top-level ``nipype`` namespace, and must be imported directly (e.g. ``from nipype.interfaces import fsl``). * ENH: New ANTs interface: ApplyTransformsToPoints * ENH: New FreeSurfer workflow: create_skullstripped_recon_flow() diff --git a/nipype/interfaces/fsl/preprocess.py b/nipype/interfaces/fsl/preprocess.py index 0d82b258ba..0592948017 100644 --- a/nipype/interfaces/fsl/preprocess.py +++ b/nipype/interfaces/fsl/preprocess.py @@ -678,17 +678,17 @@ def _list_outputs(self): '_variance.ext', cwd=cwd) outputs['std_img'] = self._gen_fname(outputs['out_file'] + '_sigma.ext', cwd=cwd) - + # The mean image created if -stats option is specified ('meanvol') - # is missing the top and bottom slices. Therefore we only expose the - # mean image created by -meanvol option ('mean_reg') which isn't + # is missing the top and bottom slices. Therefore we only expose the + # mean image created by -meanvol option ('mean_reg') which isn't # corrupted. # Note that the same problem holds for the std and variance image. - + if isdefined(self.inputs.mean_vol) and self.inputs.mean_vol: outputs['mean_img'] = self._gen_fname(outputs['out_file'] + '_mean_reg.ext', cwd=cwd) - + if isdefined(self.inputs.save_mats) and self.inputs.save_mats: _, filename = os.path.split(outputs['out_file']) matpathname = os.path.join(cwd, filename + '.mat') @@ -1159,9 +1159,8 @@ def _gen_filename(self, name): class FUGUEInputSpec(FSLCommandInputSpec): in_file = File(exists=True, argstr='--in=%s', desc='filename of input volume') - unwarped_file = File( - argstr='--unwarp=%s', genfile=True, - desc='apply unwarping and save as filename', hash_files=False) + unwarped_file = File(argstr='--unwarp=%s', desc='apply unwarping and save as filename', + hash_files=False) forward_warping = traits.Bool( False, usedefault=True, desc='apply forward warping instead of unwarping') @@ -1242,7 +1241,16 @@ class FUGUE(FSLCommand): Examples -------- - Please insert examples for use of this command + >>> from nipype.interfaces.fsl.preprocess import FUGUE + >>> fugue = FUGUE() + >>> fugue.inputs.forward_warping = True + >>> fugue.inputs.in_file = 'epi.nii' + >>> fugue.inputs.mask_file = 'epi_mask.nii' + >>> fugue.inputs.shift_in_file = 'image.nii' # Previously computed with fugue as well + >>> fugue.inputs.unwarp_direction = 'y' + >>> fugue.cmdline #doctest: +ELLIPSIS + 'fugue --in=epi.nii --mask=epi_mask.nii --loadshift=image.nii --unwarpdir=y --warp=.../epi_warped.nii.gz' + >>> fugue.run() #doctest: +SKIP """ @@ -1257,10 +1265,14 @@ def __init__(self, **kwargs): def _list_outputs(self): outputs = self._outputs().get() - if self.inputs.forward_warping: + + if isdefined(self.inputs.forward_warping) and self.inputs.forward_warping: out_field = 'warped_file' + self.inputs.unwarped_file = Undefined + outputs.pop('unwarped_file') else: out_field = 'unwarped_file' + outputs.pop('warped_file') out_file = getattr(self.inputs, out_field) if not isdefined(out_file): @@ -1279,10 +1291,11 @@ def _list_outputs(self): return outputs def _gen_filename(self, name): - if name == 'unwarped_file' and not self.inputs.forward_warping: - return self._list_outputs()['unwarped_file'] - if name == 'warped_file' and self.inputs.forward_warping: - return self._list_outputs()['warped_file'] + is_fwd = isdefined(self.inputs.forward_warping) and self.inputs.forward_warping + + if (is_fwd and name=='warped_file') or (not is_fwd and name=='unwarped_file'): + return self._list_outputs()[name] + return None def _parse_inputs(self, skip=None): diff --git a/nipype/interfaces/fsl/tests/test_auto_FUGUE.py b/nipype/interfaces/fsl/tests/test_auto_FUGUE.py index d27a0f9d27..4de0f52fcf 100644 --- a/nipype/interfaces/fsl/tests/test_auto_FUGUE.py +++ b/nipype/interfaces/fsl/tests/test_auto_FUGUE.py @@ -79,7 +79,6 @@ def test_FUGUE_inputs(): unwarp_direction=dict(argstr='--unwarpdir=%s', ), unwarped_file=dict(argstr='--unwarp=%s', - genfile=True, hash_files=False, ), warped_file=dict(argstr='--warp=%s',