Skip to content

Commit befd4f8

Browse files
committed
Merge pull request #1352 from BRAINSia/FixMRIsConvert
FIX: Fixes the 'out_file' and out_datatype inputs for MRIsConvert.
2 parents 70a5128 + e7b4c53 commit befd4f8

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

nipype/interfaces/freesurfer/tests/test_auto_MRIsConvert.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ def test_MRIsConvert_inputs():
3030
),
3131
origname=dict(argstr='-o %s',
3232
),
33-
out_datatype=dict(mandatory=True,
33+
out_datatype=dict(xor=['out_file'],
3434
),
35-
out_file=dict(argstr='./%s',
35+
out_file=dict(argstr='%s',
3636
genfile=True,
3737
position=-1,
38+
xor=['out_datatype'],
3839
),
3940
parcstats_file=dict(argstr='--parcstats %s',
4041
),

nipype/interfaces/freesurfer/utils.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -814,10 +814,12 @@ class MRIsConvertInputSpec(FSTraitedSpec):
814814
origname = traits.String(argstr="-o %s", desc="read orig positions")
815815

816816
in_file = File(exists=True, mandatory=True, position=-2, argstr='%s', desc='File to read/convert')
817-
out_file = File(argstr='./%s', position=-1, genfile=True, desc='output filename or True to generate one')
818-
# Not really sure why the ./ is necessary but the module fails without it
817+
out_file = File(argstr='%s', position=-1, genfile=True,
818+
xor=['out_datatype'], mandatory=True,
819+
desc='output filename or True to generate one')
819820

820-
out_datatype = traits.Enum("ico", "tri", "stl", "vtk", "gii", "mgh", "mgz", mandatory=True,
821+
out_datatype = traits.Enum("ico", "tri", "stl", "vtk", "gii", "mgh", "mgz",
822+
xor=['out_file'], mandatory=True,
821823
desc="These file formats are supported: ASCII: .asc"
822824
"ICO: .ico, .tri GEO: .geo STL: .stl VTK: .vtk GIFTI: .gii MGH surface-encoded 'volume': .mgh, .mgz")
823825

@@ -846,19 +848,26 @@ class MRIsConvert(FSCommand):
846848
input_spec = MRIsConvertInputSpec
847849
output_spec = MRIsConvertOutputSpec
848850

851+
def _format_arg(self, name, spec, value):
852+
if name == "out_file" and not os.path.isabs(value):
853+
value = os.path.abspath(value)
854+
return super(MRIsConvert, self)._format_arg(name, spec, value)
855+
849856
def _list_outputs(self):
850857
outputs = self.output_spec().get()
851858
outputs["converted"] = os.path.abspath(self._gen_outfilename())
852859
return outputs
853860

854861
def _gen_filename(self, name):
855862
if name is 'out_file':
856-
return self._gen_outfilename()
863+
return os.path.abspath(self._gen_outfilename())
857864
else:
858865
return None
859866

860867
def _gen_outfilename(self):
861-
if isdefined(self.inputs.annot_file):
868+
if isdefined(self.inputs.out_file):
869+
return self.inputs.out_file
870+
elif isdefined(self.inputs.annot_file):
862871
_, name, ext = split_filename(self.inputs.annot_file)
863872
elif isdefined(self.inputs.parcstats_file):
864873
_, name, ext = split_filename(self.inputs.parcstats_file)

0 commit comments

Comments
 (0)