|
21 | 21 | from ...utils.filemanip import fname_presuffix, split_filename |
22 | 22 | from ..base import (TraitedSpec, File, traits, OutputMultiPath, isdefined, |
23 | 23 | CommandLine, CommandLineInputSpec) |
24 | | -from .base import (FSCommand, FSTraitedSpec, |
| 24 | +from .base import (FSCommand, FSTraitedSpec, FSSurfaceCommand, |
25 | 25 | FSScriptCommand, FSScriptOutputSpec, |
26 | 26 | FSTraitedSpecOpenMP, FSCommandOpenMP) |
27 | 27 | __docformat__ = 'restructuredtext' |
@@ -954,6 +954,77 @@ def _gen_outfilename(self): |
954 | 954 | return name + ext + "_converted." + self.inputs.out_datatype |
955 | 955 |
|
956 | 956 |
|
| 957 | +class MRIsCombineInputSpec(FSTraitedSpec): |
| 958 | + """ |
| 959 | + Uses Freesurfer's mris_convert to combine two surface files into one. |
| 960 | + """ |
| 961 | + in_files = traits.List(File(Exists=True), maxlen=2, minlen=2, |
| 962 | + mandatory=True, position=1, argstr='--combinesurfs %s', |
| 963 | + desc='Two surfaces to be combined.') |
| 964 | + out_file = File(argstr='%s', position=-1, genfile=True, |
| 965 | + mandatory=True, |
| 966 | + desc='Output filename. Combined surfaces from in_files.') |
| 967 | + |
| 968 | + |
| 969 | +class MRIsCombineOutputSpec(TraitedSpec): |
| 970 | + """ |
| 971 | + Uses Freesurfer's mris_convert to combine two surface files into one. |
| 972 | + """ |
| 973 | + out_file = File(exists=True, desc='Output filename. Combined surfaces from ' |
| 974 | + 'in_files.') |
| 975 | + |
| 976 | + |
| 977 | +class MRIsCombine(FSSurfaceCommand): |
| 978 | + """ |
| 979 | + Uses Freesurfer's mris_convert to combine two surface files into one. |
| 980 | +
|
| 981 | + For complete details, see the `mris_convert Documentation. |
| 982 | + <https://surfer.nmr.mgh.harvard.edu/fswiki/mris_convert>`_ |
| 983 | +
|
| 984 | + If given an out_file that does not begin with 'lh.' or 'rh.', |
| 985 | + mris_convert will prepend 'lh.' to the file name. |
| 986 | + To avoid this behavior, consider setting out_file = './<filename>', or |
| 987 | + leaving out_file blank. |
| 988 | +
|
| 989 | + Example |
| 990 | + ------- |
| 991 | +
|
| 992 | + >>> import nipype.interfaces.freesurfer as fs |
| 993 | + >>> mris = fs.MRIsCombine() |
| 994 | + >>> mris.inputs.in_files = ['lh.pial', 'rh.pial'] |
| 995 | + >>> mris.inputs.out_file = 'bh.pial' |
| 996 | + >>> mris.cmdline # doctest: +ALLOW_UNICODE |
| 997 | + 'mris_convert --combinesurfs lh.pial rh.pial bh.pial' |
| 998 | + >>> mris.run() # doctest: +SKIP |
| 999 | + """ |
| 1000 | + _cmd = 'mris_convert' |
| 1001 | + input_spec = MRIsCombineInputSpec |
| 1002 | + output_spec = MRIsCombineOutputSpec |
| 1003 | + |
| 1004 | + def _list_outputs(self): |
| 1005 | + outputs = self._outputs().get() |
| 1006 | + outputs['out_file'] = self._associated_file(self.inputs.in_files[0], |
| 1007 | + self.inputs.out_file) |
| 1008 | + return outputs |
| 1009 | + |
| 1010 | + @staticmethod |
| 1011 | + def _associated_file(in_file, out_name): |
| 1012 | + """Unlike the standard _associated_file, which uses the prefix from |
| 1013 | + in_file, in MRIsCombine, it uses 'lh.' as the prefix for the output |
| 1014 | + file no matter what the inputs are. |
| 1015 | + """ |
| 1016 | + path, base = os.path.split(out_name) |
| 1017 | + if path == '': |
| 1018 | + hemis = ('lh.', 'rh.') |
| 1019 | + if base[:3] not in hemis: |
| 1020 | + base = 'lh.' + base |
| 1021 | + return os.path.abspath(os.path.join(path, base)) |
| 1022 | + |
| 1023 | + def _normalize_filenames(self): |
| 1024 | + if isdefined(self.inputs.out_file): |
| 1025 | + self.inputs.out_file = os.path.abspath(self.inputs.out_file) |
| 1026 | + |
| 1027 | + |
957 | 1028 | class MRITessellateInputSpec(FSTraitedSpec): |
958 | 1029 | """ |
959 | 1030 | Uses Freesurfer's mri_tessellate to create surfaces by tessellating a given input volume |
|
0 commit comments