Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nipype/interfaces/fsl/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""

from .base import (FSLCommand, Info, check_fsl, no_fsl, no_fsl_course_data)
from .preprocess import (FAST, FLIRT, ApplyXfm, BET, MCFLIRT, FNIRT, ApplyWarp,
from .preprocess import (FAST, FLIRT, ApplyXfm, ApplyXfm4D, BET, MCFLIRT, FNIRT, ApplyWarp,
SliceTimer, SUSAN, PRELUDE, FUGUE, FIRST)
from .model import (Level1Design, FEAT, FEATModel, FILMGLS, FEATRegister,
FLAMEO, ContrastMgr, MultipleRegressDesign, L2Model, SMM,
Expand Down
56 changes: 56 additions & 0 deletions nipype/interfaces/fsl/preprocess.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,62 @@ class ApplyXfm(FLIRT):
input_spec = ApplyXfmInputSpec


class ApplyXfm4DInputSpec(FSLCommandInputSpec):
in_file = File(exists=True, position=0, argstr='%s', mandatory=True, desc="timeseries to motion-correct")
ref_vol = File(exists=True, position=1, argstr='%s', mandatory=True, desc="volume with final FOV and resolution")
out_file = File(exists=True, position=2, argstr='%s', genfile=True, desc="file to write", hash_files=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this one shouldn't have exists=True and should also have hash_files=False so that out_file doesn't get hashed if it exists.

i think the logic of this interface can be simplified greatly by using name_source and name_template

http://nipype.readthedocs.org/en/latest/devel/cmd_interface_devel.html#creating-outputs-on-the-fly

trans_file = File(argstr='%s', position=3, desc="single tranformation matrix", xor=["trans_dir"], requires=["single_matrix"])
trans_dir = File(argstr='%s', position=3, desc="folder of transformation matricies", xor=["tans_file"])
single_matrix = traits.Bool(argstr='-singlematrix', desc="true if applying one volume to all timepoints")
four_digit = traits.Bool(argstr='-fourdigit', desc="true mat names have four digits not five")
user_prefix = traits.Str(argstr='-userprefix %s', desc="supplied prefix if mats don't start with 'MAT_'")


class ApplyXfm4DOutputSpec(TraitedSpec):
out_file = File(exists=True, desc="transform applied timeseries")

class ApplyXfm4D(FSLCommand):
"""
Wraps the applyxfm4D command line tool for applying one 3D transform to every volume in a 4D image OR
a directory of 3D tansforms to a 4D image of the same length.

Examples
---------
>>> import nipype.interfaces.fsl as fsl
>>> from nipype.testing import example_data
>>> applyxfm4d = fsl.ApplyXfm4D()
>>> applyxfm4d.inputs.in_file = example_data('functional.nii')
>>> applyxfm4d.inputs.in_matrix_file = example_data('functional_mcf.mat')
>>> applyxfm4d.inputs.out_file = 'newfile.nii'
>>> applyxfm4d.inputs.reference = example_data('functional_mcf.nii')
>>> result = applyxfm.run() # doctest: +SKIP

"""

_cmd = 'applyxfm4D'
input_spec = ApplyXfm4DInputSpec
output_spec = ApplyXfm4DOutputSpec

def _list_outputs(self):
cwd = os.getcwd()
outputs = self._outputs().get()
outputs['out_file'] = self._gen_outfilename()
return outputs

def _gen_filename(self, name):
if name == 'out_file':
return self._gen_outfilename()
return None

def _gen_outfilename(self):
out_file = self.inputs.out_file
if isdefined(out_file):
out_file = os.path.realpath(out_file)
if not isdefined(out_file) and isdefined(self.inputs.in_file):
out_file = self._gen_fname(self.inputs.in_file, suffix='_warp4D')
return os.path.abspath(out_file)


class MCFLIRTInputSpec(FSLCommandInputSpec):
in_file = File(exists=True, position=0, argstr="-in %s", mandatory=True,
desc="timeseries to motion-correct")
Expand Down