Skip to content

FIX: BET raising "No image files match: ..." with very long file names #3309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions nipype/interfaces/fsl/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -164,15 +165,27 @@ 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")
return os.path.abspath(out_file)
# Convert to relative path to prevent BET failure
# with long paths.
return op.relpath(out_file, start=os.getcwd())
return out_file

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"])
Expand Down Expand Up @@ -1309,10 +1322,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):
Expand Down
9 changes: 5 additions & 4 deletions nipype/interfaces/fsl/tests/test_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -41,8 +44,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")
Expand Down Expand Up @@ -79,12 +81,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


Expand Down