diff --git a/nipype/interfaces/freesurfer/preprocess.py b/nipype/interfaces/freesurfer/preprocess.py index 02ae960c5b..abc6e5b51d 100644 --- a/nipype/interfaces/freesurfer/preprocess.py +++ b/nipype/interfaces/freesurfer/preprocess.py @@ -1503,11 +1503,11 @@ class MNIBiasCorrectionInputSpec(FSTraitedSpec): # mandatory in_file = File(exists=True, mandatory=True, argstr="--i %s", desc="input volume. Input can be any format accepted by mri_convert.") + # optional out_file = File(argstr="--o %s", name_source=['in_file'], name_template='%s_output', hash_files=False, keep_extension=True, desc="output volume. Output can be any format accepted by mri_convert. " + "If the output format is COR, then the directory must exist.") - # optional iterations = traits.Int(4, argstr="--n %d", desc="Number of iterations to run nu_correct. Default is 4. This is the number of times " + "that nu_correct is repeated (ie, using the output from the previous run as the input for " + @@ -1528,7 +1528,7 @@ class MNIBiasCorrectionInputSpec(FSTraitedSpec): desc="Shrink parameter for finer sampling (default is 4)") class MNIBiasCorrectionOutputSpec(TraitedSpec): - out_file = File(desc="output volume") + out_file = File(exists=True, desc="output volume") class MNIBiasCorrection(FSCommand): @@ -1563,11 +1563,6 @@ class MNIBiasCorrection(FSCommand): input_spec = MNIBiasCorrectionInputSpec output_spec = MNIBiasCorrectionOutputSpec - def _list_outputs(self): - outputs = self._outputs().get() - outputs["out_file"] = os.path.abspath(self.inputs.out_file) - return outputs - class WatershedSkullStripInputSpec(FSTraitedSpec): # required diff --git a/nipype/interfaces/freesurfer/tests/test_preprocess.py b/nipype/interfaces/freesurfer/tests/test_preprocess.py index da6ba65fc3..60a51e3a86 100644 --- a/nipype/interfaces/freesurfer/tests/test_preprocess.py +++ b/nipype/interfaces/freesurfer/tests/test_preprocess.py @@ -85,3 +85,31 @@ def test_synthesizeflash(create_files_in_directory): syn2 = freesurfer.SynthesizeFLASH(t1_image=filelist[0], pd_image=filelist[1], flip_angle=20, te=5, tr=25) assert syn2.cmdline == ('mri_synthesize 25.00 20.00 5.000 %s %s %s' % (filelist[0], filelist[1], os.path.join(outdir, 'synth-flash_20.mgz'))) + +@pytest.mark.skipif(freesurfer.no_freesurfer(), reason="freesurfer is not installed") +def test_mandatory_outvol(create_files_in_directory): + filelist, outdir = create_files_in_directory + mni = freesurfer.MNIBiasCorrection() + + # make sure command gets called + assert mni.cmd == "mri_nu_correct.mni" + + # test raising error with mandatory args absent + with pytest.raises(ValueError): mni.cmdline + + # test with minimal args + mni.inputs.in_file = filelist[0] + assert mni.cmdline == ('mri_nu_correct.mni --i %s --o %s_output.mgz' + % (filelist[0], filelist[0].replace('.mgz', ''))) + + # test with custom outfile + mni.inputs.out_file = 'new_corrected_file.mgz' + assert mni.cmdline == ('mri_nu_correct.mni --i %s --o new_corrected_file.mgz' + % (filelist[0])) + + # constructor based tests + mni2 = freesurfer.MNIBiasCorrection(in_file=filelist[0], + out_file='bias_corrected_output', + iterations=4) + assert mni2.cmdline == ('mri_nu_correct.mni --i %s --n 4 --o bias_corrected_output.mgz' + % filelist[0])