|
17 | 17 | import re
|
18 | 18 | import shutil
|
19 | 19 |
|
| 20 | +from ... import logging |
20 | 21 | from ...utils.filemanip import fname_presuffix, split_filename
|
21 | 22 | from ..base import (TraitedSpec, File, traits, OutputMultiPath, isdefined,
|
22 | 23 | CommandLine, CommandLineInputSpec)
|
|
37 | 38 | 'nifti1', 'nii', 'niigz']
|
38 | 39 | implicit_filetypes = ['gii']
|
39 | 40 |
|
| 41 | +logger = logging.getLogger('interface') |
40 | 42 |
|
41 | 43 | def copy2subjdir(cls, in_file, folder=None, basename=None, subject_id=None):
|
42 | 44 | """Method to copy an input to the subjects directory"""
|
@@ -222,8 +224,19 @@ def _format_arg(self, name, spec, value):
|
222 | 224 | return spec.argstr % self.inputs.subject_id
|
223 | 225 | if name in ["hits_file", "vox_file"]:
|
224 | 226 | return spec.argstr % self._get_outfilename(name)
|
225 |
| - if name == "out_type" and value in implicit_filetypes: |
226 |
| - return "" |
| 227 | + if name == "out_type": |
| 228 | + if isdefined(self.inputs.out_file): |
| 229 | + _, base, ext = split_filename(self._get_outfilename()) |
| 230 | + if ext != filemap[value]: |
| 231 | + if ext in filemap.values(): |
| 232 | + raise ValueError( |
| 233 | + "Cannot create {} file with extension " |
| 234 | + "{}".format(value, ext)) |
| 235 | + else: |
| 236 | + logger.warn("Creating {} file with extension {}: " |
| 237 | + "{}{}".format(value, ext, base, ext)) |
| 238 | + if value in implicit_filetypes: |
| 239 | + return "" |
227 | 240 | return super(SampleToSurface, self)._format_arg(name, spec, value)
|
228 | 241 |
|
229 | 242 | def _get_outfilename(self, opt="out_file"):
|
@@ -401,8 +414,19 @@ class SurfaceTransform(FSCommand):
|
401 | 414 | output_spec = SurfaceTransformOutputSpec
|
402 | 415 |
|
403 | 416 | def _format_arg(self, name, spec, value):
|
404 |
| - if name == "target_type" and value in implicit_filetypes: |
405 |
| - return "" |
| 417 | + if name == "target_type": |
| 418 | + if isdefined(self.inputs.out_file): |
| 419 | + _, base, ext = split_filename(self._list_outputs()['out_file']) |
| 420 | + if ext != filemap[value]: |
| 421 | + if ext in filemap.values(): |
| 422 | + raise ValueError( |
| 423 | + "Cannot create {} file with extension " |
| 424 | + "{}".format(value, ext)) |
| 425 | + else: |
| 426 | + logger.warn("Creating {} file with extension {}: " |
| 427 | + "{}{}".format(value, ext, base, ext)) |
| 428 | + if value in implicit_filetypes: |
| 429 | + return "" |
406 | 430 | return super(SurfaceTransform, self)._format_arg(name, spec, value)
|
407 | 431 |
|
408 | 432 | def _list_outputs(self):
|
|
0 commit comments