Skip to content

Commit 1188b50

Browse files
authored
Merge pull request #1806 from mgxd/fix/mnibias
fix: MNIBiasCorrection smart out_file
2 parents 0620aba + da1bd76 commit 1188b50

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

nipype/interfaces/freesurfer/preprocess.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,11 +1503,11 @@ class MNIBiasCorrectionInputSpec(FSTraitedSpec):
15031503
# mandatory
15041504
in_file = File(exists=True, mandatory=True, argstr="--i %s",
15051505
desc="input volume. Input can be any format accepted by mri_convert.")
1506+
# optional
15061507
out_file = File(argstr="--o %s", name_source=['in_file'],
15071508
name_template='%s_output', hash_files=False, keep_extension=True,
15081509
desc="output volume. Output can be any format accepted by mri_convert. " +
15091510
"If the output format is COR, then the directory must exist.")
1510-
# optional
15111511
iterations = traits.Int(4, argstr="--n %d",
15121512
desc="Number of iterations to run nu_correct. Default is 4. This is the number of times " +
15131513
"that nu_correct is repeated (ie, using the output from the previous run as the input for " +
@@ -1528,7 +1528,7 @@ class MNIBiasCorrectionInputSpec(FSTraitedSpec):
15281528
desc="Shrink parameter for finer sampling (default is 4)")
15291529

15301530
class MNIBiasCorrectionOutputSpec(TraitedSpec):
1531-
out_file = File(desc="output volume")
1531+
out_file = File(exists=True, desc="output volume")
15321532

15331533

15341534
class MNIBiasCorrection(FSCommand):
@@ -1563,11 +1563,6 @@ class MNIBiasCorrection(FSCommand):
15631563
input_spec = MNIBiasCorrectionInputSpec
15641564
output_spec = MNIBiasCorrectionOutputSpec
15651565

1566-
def _list_outputs(self):
1567-
outputs = self._outputs().get()
1568-
outputs["out_file"] = os.path.abspath(self.inputs.out_file)
1569-
return outputs
1570-
15711566

15721567
class WatershedSkullStripInputSpec(FSTraitedSpec):
15731568
# required

nipype/interfaces/freesurfer/tests/test_preprocess.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,31 @@ def test_synthesizeflash(create_files_in_directory):
8585
syn2 = freesurfer.SynthesizeFLASH(t1_image=filelist[0], pd_image=filelist[1], flip_angle=20, te=5, tr=25)
8686
assert syn2.cmdline == ('mri_synthesize 25.00 20.00 5.000 %s %s %s'
8787
% (filelist[0], filelist[1], os.path.join(outdir, 'synth-flash_20.mgz')))
88+
89+
@pytest.mark.skipif(freesurfer.no_freesurfer(), reason="freesurfer is not installed")
90+
def test_mandatory_outvol(create_files_in_directory):
91+
filelist, outdir = create_files_in_directory
92+
mni = freesurfer.MNIBiasCorrection()
93+
94+
# make sure command gets called
95+
assert mni.cmd == "mri_nu_correct.mni"
96+
97+
# test raising error with mandatory args absent
98+
with pytest.raises(ValueError): mni.cmdline
99+
100+
# test with minimal args
101+
mni.inputs.in_file = filelist[0]
102+
assert mni.cmdline == ('mri_nu_correct.mni --i %s --o %s_output.mgz'
103+
% (filelist[0], filelist[0].replace('.mgz', '')))
104+
105+
# test with custom outfile
106+
mni.inputs.out_file = 'new_corrected_file.mgz'
107+
assert mni.cmdline == ('mri_nu_correct.mni --i %s --o new_corrected_file.mgz'
108+
% (filelist[0]))
109+
110+
# constructor based tests
111+
mni2 = freesurfer.MNIBiasCorrection(in_file=filelist[0],
112+
out_file='bias_corrected_output',
113+
iterations=4)
114+
assert mni2.cmdline == ('mri_nu_correct.mni --i %s --n 4 --o bias_corrected_output.mgz'
115+
% filelist[0])

0 commit comments

Comments
 (0)