diff --git a/nipype/interfaces/fsl/__init__.py b/nipype/interfaces/fsl/__init__.py old mode 100644 new mode 100755 index b2f524b3be..977d1da245 --- a/nipype/interfaces/fsl/__init__.py +++ b/nipype/interfaces/fsl/__init__.py @@ -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, diff --git a/nipype/interfaces/fsl/preprocess.py b/nipype/interfaces/fsl/preprocess.py old mode 100644 new mode 100755 index 1f3137085e..77658ad20e --- a/nipype/interfaces/fsl/preprocess.py +++ b/nipype/interfaces/fsl/preprocess.py @@ -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) + 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")