From 83828578cfd991d9140c5e22d995b78fc4256241 Mon Sep 17 00:00:00 2001 From: Zvi Baratz Date: Thu, 4 Mar 2021 08:13:41 +0200 Subject: [PATCH 1/6] Added copyfile=False metadata to BETInputSpec in_file specification and applied black formatting. --- nipype/interfaces/fsl/preprocess.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/nipype/interfaces/fsl/preprocess.py b/nipype/interfaces/fsl/preprocess.py index f2fbe8c079..f54b6c6e18 100644 --- a/nipype/interfaces/fsl/preprocess.py +++ b/nipype/interfaces/fsl/preprocess.py @@ -35,6 +35,7 @@ class BETInputSpec(FSLCommandInputSpec): argstr="%s", position=0, mandatory=True, + copyfile=False, ) out_file = File( desc="name of output skull stripped image", @@ -1309,10 +1310,7 @@ def _list_outputs(self): if key == "out_intensitymap_file" and isdefined(outputs[key]): basename = FNIRT.intensitymap_file_basename(outputs[key]) - outputs[key] = [ - outputs[key], - "%s.txt" % basename, - ] + outputs[key] = [outputs[key], "%s.txt" % basename] return outputs def _format_arg(self, name, spec, value): From 6c889e518314615963cf85ceffaac4c2ed46ca5d Mon Sep 17 00:00:00 2001 From: Zvi Baratz Date: Thu, 4 Mar 2021 09:56:12 +0200 Subject: [PATCH 2/6] Changed BET interface to generate relative and list absolute out_file path. --- nipype/interfaces/fsl/preprocess.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nipype/interfaces/fsl/preprocess.py b/nipype/interfaces/fsl/preprocess.py index f54b6c6e18..64bc8ad54c 100644 --- a/nipype/interfaces/fsl/preprocess.py +++ b/nipype/interfaces/fsl/preprocess.py @@ -169,11 +169,11 @@ def _gen_outfilename(self): out_file = self.inputs.out_file if not isdefined(out_file) and isdefined(self.inputs.in_file): out_file = self._gen_fname(self.inputs.in_file, suffix="_brain") - return os.path.abspath(out_file) + return op.relpath(out_file, start=os.getcwd()) def _list_outputs(self): outputs = self.output_spec().get() - outputs["out_file"] = self._gen_outfilename() + outputs["out_file"] = os.path.abspath(self._gen_outfilename()) basename = os.path.basename(outputs["out_file"]) cwd = os.path.dirname(outputs["out_file"]) From 7a42b631c8a0991852dfdd5176b8c3bcd4bd36f4 Mon Sep 17 00:00:00 2001 From: Zvi Baratz Date: Thu, 4 Mar 2021 10:37:51 +0200 Subject: [PATCH 3/6] Updated BET tests to assert relative out_file path. --- nipype/interfaces/fsl/tests/test_preprocess.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/nipype/interfaces/fsl/tests/test_preprocess.py b/nipype/interfaces/fsl/tests/test_preprocess.py index 438f3f0ec4..dd4d827ce7 100644 --- a/nipype/interfaces/fsl/tests/test_preprocess.py +++ b/nipype/interfaces/fsl/tests/test_preprocess.py @@ -41,8 +41,7 @@ def test_bet(setup_infile): # Test generated outfile name better.inputs.in_file = tmp_infile outfile = fsl_name(better, "foo_brain") - outpath = os.path.join(os.getcwd(), outfile) - realcmd = "bet %s %s" % (tmp_infile, outpath) + realcmd = "bet %s %s" % (tmp_infile, outfile) assert better.cmdline == realcmd # Test specified outfile name outfile = fsl_name(better, "/newdata/bar") @@ -79,12 +78,11 @@ def func(): # test each of our arguments better = fsl.BET() outfile = fsl_name(better, "foo_brain") - outpath = os.path.join(os.getcwd(), outfile) for name, settings in list(opt_map.items()): better = fsl.BET(**{name: settings[1]}) # Add mandatory input better.inputs.in_file = tmp_infile - realcmd = " ".join([better.cmd, tmp_infile, outpath, settings[0]]) + realcmd = " ".join([better.cmd, tmp_infile, outfile, settings[0]]) assert better.cmdline == realcmd From e66bc41eb1b6636be3c84e1b006ebf4411982644 Mon Sep 17 00:00:00 2001 From: Zvi Baratz Date: Thu, 4 Mar 2021 10:56:33 +0200 Subject: [PATCH 4/6] Changed BET interface's _gen_outfilename() to return relative path only for generated out_file. --- nipype/interfaces/fsl/preprocess.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nipype/interfaces/fsl/preprocess.py b/nipype/interfaces/fsl/preprocess.py index 64bc8ad54c..0f7e402445 100644 --- a/nipype/interfaces/fsl/preprocess.py +++ b/nipype/interfaces/fsl/preprocess.py @@ -169,7 +169,8 @@ def _gen_outfilename(self): out_file = self.inputs.out_file if not isdefined(out_file) and isdefined(self.inputs.in_file): out_file = self._gen_fname(self.inputs.in_file, suffix="_brain") - return op.relpath(out_file, start=os.getcwd()) + return op.relpath(out_file, start=os.getcwd()) + return out_file def _list_outputs(self): outputs = self.output_spec().get() From 6fec887755154d3fda209c4492eafa8798d62cfd Mon Sep 17 00:00:00 2001 From: Zvi Baratz Date: Wed, 10 Mar 2021 09:59:33 +0200 Subject: [PATCH 5/6] Added BET's in_file conversion to relative path. --- nipype/interfaces/fsl/preprocess.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/nipype/interfaces/fsl/preprocess.py b/nipype/interfaces/fsl/preprocess.py index 0f7e402445..54a41be039 100644 --- a/nipype/interfaces/fsl/preprocess.py +++ b/nipype/interfaces/fsl/preprocess.py @@ -165,10 +165,21 @@ def _run_interface(self, runtime): self.raise_exception(runtime) return runtime + def _format_arg(self, name, spec, value): + formatted = super(BET, self)._format_arg(name, spec, value) + if name == "in_file": + # Convert to relative path to prevent BET failure + # with long paths. + return op.relpath(formatted, start=os.getcwd()) + return formatted + def _gen_outfilename(self): out_file = self.inputs.out_file + # Generate default output filename if non specified. if not isdefined(out_file) and isdefined(self.inputs.in_file): out_file = self._gen_fname(self.inputs.in_file, suffix="_brain") + # Convert to relative path to prevent BET failure + # with long paths. return op.relpath(out_file, start=os.getcwd()) return out_file From 489a48d968947bc7b210296fd4669a0f1e72c151 Mon Sep 17 00:00:00 2001 From: Zvi Baratz Date: Wed, 10 Mar 2021 10:33:49 +0200 Subject: [PATCH 6/6] Trying to fix test_bet to assert the relative path. --- nipype/interfaces/fsl/tests/test_preprocess.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nipype/interfaces/fsl/tests/test_preprocess.py b/nipype/interfaces/fsl/tests/test_preprocess.py index dd4d827ce7..6b1b6cb610 100644 --- a/nipype/interfaces/fsl/tests/test_preprocess.py +++ b/nipype/interfaces/fsl/tests/test_preprocess.py @@ -31,6 +31,9 @@ def setup_infile(tmpdir): @pytest.mark.skipif(no_fsl(), reason="fsl is not installed") def test_bet(setup_infile): tmp_infile, tp_dir = setup_infile + # BET converts the in_file path to be relative to prevent + # failure with long paths. + tmp_infile = os.path.relpath(tmp_infile, start=os.getcwd()) better = fsl.BET() assert better.cmd == "bet"