From 160ccfab45bc6c7221943a0036a4af798b6625bc Mon Sep 17 00:00:00 2001 From: Zach Lindsey Date: Wed, 20 Mar 2024 16:08:40 -0500 Subject: [PATCH 1/3] change out_file behavior on Zeropad --- .../afni/tests/test_extra_Zeropad.py | 25 +++++++++++++++++++ nipype/interfaces/afni/utils.py | 9 ++++++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 nipype/interfaces/afni/tests/test_extra_Zeropad.py diff --git a/nipype/interfaces/afni/tests/test_extra_Zeropad.py b/nipype/interfaces/afni/tests/test_extra_Zeropad.py new file mode 100644 index 0000000000..d9cf1e20a0 --- /dev/null +++ b/nipype/interfaces/afni/tests/test_extra_Zeropad.py @@ -0,0 +1,25 @@ +from pathlib import Path +from nipype.interfaces.afni import Zeropad +from nipype.testing.fixtures import create_files_in_directory + + +def test_zeropad_handles_outfile_default(create_files_in_directory): + filelist, outdir = create_files_in_directory + zp = Zeropad(I=1) + zp.inputs.in_files = filelist[0] + + result = zp.run() + + assert (Path(outdir) / "zeropad+tlrc.BRIK").exists() + assert Path(result.outputs.out_file).name == "zeropad+tlrc.BRIK" + + +def test_zeropad_handles_outfile_specified_nii_gz(create_files_in_directory): + filelist, outdir = create_files_in_directory + zp = Zeropad(I=1, out_file="padded.nii.gz") + zp.inputs.in_files = filelist[0] + + result = zp.run() + + assert (Path(outdir) / "padded.nii.gz").exists() + assert Path(result.outputs.out_file).name == "padded.nii.gz" diff --git a/nipype/interfaces/afni/utils.py b/nipype/interfaces/afni/utils.py index 5fb1cd1e64..8a3f27040b 100644 --- a/nipype/interfaces/afni/utils.py +++ b/nipype/interfaces/afni/utils.py @@ -3391,7 +3391,6 @@ class ZeropadInputSpec(AFNICommandInputSpec): copyfile=False, ) out_file = File( - name_template="zeropad", desc="output dataset prefix name (default 'zeropad')", argstr="-prefix %s", ) @@ -3497,3 +3496,11 @@ class Zeropad(AFNICommand): _cmd = "3dZeropad" input_spec = ZeropadInputSpec output_spec = AFNICommandOutputSpec + + def _list_outputs(self): + out_file = getattr(self.inputs, "out_file") + + if not isdefined(out_file): + out_file = "zeropad+tlrc.BRIK" + + return {"out_file": out_file} From 1506a85d4456b056904088229eb5bc816fb45dc0 Mon Sep 17 00:00:00 2001 From: Zach Lindsey Date: Wed, 20 Mar 2024 17:10:23 -0500 Subject: [PATCH 2/3] add autotest --- nipype/interfaces/afni/tests/test_auto_Zeropad.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nipype/interfaces/afni/tests/test_auto_Zeropad.py b/nipype/interfaces/afni/tests/test_auto_Zeropad.py index 4d6742f21e..bd5cd1eb34 100644 --- a/nipype/interfaces/afni/tests/test_auto_Zeropad.py +++ b/nipype/interfaces/afni/tests/test_auto_Zeropad.py @@ -70,7 +70,6 @@ def test_Zeropad_inputs(): out_file=dict( argstr="-prefix %s", extensions=None, - name_template="zeropad", ), outputtype=dict(), z=dict( From 0953e5b50e666e61ef221b329cba42f2e4d8649c Mon Sep 17 00:00:00 2001 From: Zach Lindsey Date: Thu, 21 Mar 2024 09:58:11 -0500 Subject: [PATCH 3/3] convert out_files for AFNI 3dZeropad to absolute paths in list_outputs --- nipype/interfaces/afni/tests/test_extra_Zeropad.py | 14 ++++++++++++++ nipype/interfaces/afni/utils.py | 3 +-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/nipype/interfaces/afni/tests/test_extra_Zeropad.py b/nipype/interfaces/afni/tests/test_extra_Zeropad.py index d9cf1e20a0..086d65bbf9 100644 --- a/nipype/interfaces/afni/tests/test_extra_Zeropad.py +++ b/nipype/interfaces/afni/tests/test_extra_Zeropad.py @@ -1,4 +1,5 @@ from pathlib import Path +from nipype import Node from nipype.interfaces.afni import Zeropad from nipype.testing.fixtures import create_files_in_directory @@ -23,3 +24,16 @@ def test_zeropad_handles_outfile_specified_nii_gz(create_files_in_directory): assert (Path(outdir) / "padded.nii.gz").exists() assert Path(result.outputs.out_file).name == "padded.nii.gz" + + +def test_zeropad_keeps_file_after_node_run(create_files_in_directory): + filelist, outdir = create_files_in_directory + + zp = Node( + Zeropad(I=1, out_file="padded.nii.gz"), name="test_zeropad", base_dir=outdir + ) + zp.inputs.in_files = Path(outdir) / filelist[0] + + result = zp.run() + assert (Path(zp.output_dir()) / "padded.nii.gz").exists() + assert Path(result.outputs.out_file).name == "padded.nii.gz" diff --git a/nipype/interfaces/afni/utils.py b/nipype/interfaces/afni/utils.py index 8a3f27040b..f10ca43048 100644 --- a/nipype/interfaces/afni/utils.py +++ b/nipype/interfaces/afni/utils.py @@ -3502,5 +3502,4 @@ def _list_outputs(self): if not isdefined(out_file): out_file = "zeropad+tlrc.BRIK" - - return {"out_file": out_file} + return {"out_file": op.abspath(out_file)}