Skip to content

Commit 6835d5d

Browse files
authored
Merge pull request #3309 from ZviBaratz/bet
FIX: BET raising "No image files match: ..." with very long file names
2 parents 98aea61 + 489a48d commit 6835d5d

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

nipype/interfaces/fsl/preprocess.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class BETInputSpec(FSLCommandInputSpec):
3535
argstr="%s",
3636
position=0,
3737
mandatory=True,
38+
copyfile=False,
3839
)
3940
out_file = File(
4041
desc="name of output skull stripped image",
@@ -164,15 +165,27 @@ def _run_interface(self, runtime):
164165
self.raise_exception(runtime)
165166
return runtime
166167

168+
def _format_arg(self, name, spec, value):
169+
formatted = super(BET, self)._format_arg(name, spec, value)
170+
if name == "in_file":
171+
# Convert to relative path to prevent BET failure
172+
# with long paths.
173+
return op.relpath(formatted, start=os.getcwd())
174+
return formatted
175+
167176
def _gen_outfilename(self):
168177
out_file = self.inputs.out_file
178+
# Generate default output filename if non specified.
169179
if not isdefined(out_file) and isdefined(self.inputs.in_file):
170180
out_file = self._gen_fname(self.inputs.in_file, suffix="_brain")
171-
return os.path.abspath(out_file)
181+
# Convert to relative path to prevent BET failure
182+
# with long paths.
183+
return op.relpath(out_file, start=os.getcwd())
184+
return out_file
172185

173186
def _list_outputs(self):
174187
outputs = self.output_spec().get()
175-
outputs["out_file"] = self._gen_outfilename()
188+
outputs["out_file"] = os.path.abspath(self._gen_outfilename())
176189

177190
basename = os.path.basename(outputs["out_file"])
178191
cwd = os.path.dirname(outputs["out_file"])
@@ -1309,10 +1322,7 @@ def _list_outputs(self):
13091322

13101323
if key == "out_intensitymap_file" and isdefined(outputs[key]):
13111324
basename = FNIRT.intensitymap_file_basename(outputs[key])
1312-
outputs[key] = [
1313-
outputs[key],
1314-
"%s.txt" % basename,
1315-
]
1325+
outputs[key] = [outputs[key], "%s.txt" % basename]
13161326
return outputs
13171327

13181328
def _format_arg(self, name, spec, value):

nipype/interfaces/fsl/tests/test_preprocess.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def setup_infile(tmpdir):
3131
@pytest.mark.skipif(no_fsl(), reason="fsl is not installed")
3232
def test_bet(setup_infile):
3333
tmp_infile, tp_dir = setup_infile
34+
# BET converts the in_file path to be relative to prevent
35+
# failure with long paths.
36+
tmp_infile = os.path.relpath(tmp_infile, start=os.getcwd())
3437
better = fsl.BET()
3538
assert better.cmd == "bet"
3639

@@ -41,8 +44,7 @@ def test_bet(setup_infile):
4144
# Test generated outfile name
4245
better.inputs.in_file = tmp_infile
4346
outfile = fsl_name(better, "foo_brain")
44-
outpath = os.path.join(os.getcwd(), outfile)
45-
realcmd = "bet %s %s" % (tmp_infile, outpath)
47+
realcmd = "bet %s %s" % (tmp_infile, outfile)
4648
assert better.cmdline == realcmd
4749
# Test specified outfile name
4850
outfile = fsl_name(better, "/newdata/bar")
@@ -79,12 +81,11 @@ def func():
7981
# test each of our arguments
8082
better = fsl.BET()
8183
outfile = fsl_name(better, "foo_brain")
82-
outpath = os.path.join(os.getcwd(), outfile)
8384
for name, settings in list(opt_map.items()):
8485
better = fsl.BET(**{name: settings[1]})
8586
# Add mandatory input
8687
better.inputs.in_file = tmp_infile
87-
realcmd = " ".join([better.cmd, tmp_infile, outpath, settings[0]])
88+
realcmd = " ".join([better.cmd, tmp_infile, outfile, settings[0]])
8889
assert better.cmdline == realcmd
8990

9091

0 commit comments

Comments
 (0)