Skip to content

Handle NCBI taxdump members with a leading './' (fixes #810)#813

Open
apoorvdarshan wants to merge 1 commit into
etetoolkit:ete4from
apoorvdarshan:fix-taxdump-dotslash-810
Open

Handle NCBI taxdump members with a leading './' (fixes #810)#813
apoorvdarshan wants to merge 1 commit into
etetoolkit:ete4from
apoorvdarshan:fix-taxdump-dotslash-810

Conversation

@apoorvdarshan

Copy link
Copy Markdown

Summary

NCBITaxa(taxdump_file=...) fails when the taxdump tarball is created with GNU tar (e.g. tar -c -C dir .), because such archives name their members with a leading ./ (./names.dmp, ./nodes.dmp, ./merged.dmp). The code in ete4/ncbi_taxonomy/ncbiquery.py looked those members up by their bare name, so tarfile raised:

KeyError: "filename 'names.dmp' not found"

This reproduces on the current ete4 branch (commit 9562dfb, the same one referenced in #810).

Fix

Add a small extractfile_dmp(tar, name) helper that first tries the bare member name and, on KeyError, falls back to the './'-prefixed name. It is used at the three .dmp extraction sites (names.dmp, nodes.dmp, merged.dmp). The change is localized and does not affect the existing (non-prefixed) tarballs.

Tests

Added test_extract_dmp_with_leading_dotslash in tests/test_ncbiquery.py, parametrized over both plain and './'-prefixed members. It builds a minimal in-memory taxdump, runs update_db, and checks the resulting database. The './' case fails on main/ete4 before the fix (KeyError) and passes after. The full test_ncbiquery.py suite (9 tests) passes.

Fixes #810.

Disclosure: prepared with AI assistance; reviewed and verified locally.

Tarballs created with GNU tar (e.g. `tar -c -C dir .`) name their
members like `./names.dmp`, `./nodes.dmp` and `./merged.dmp`. The
extractfile() lookups used the bare name and raised
`KeyError: "filename 'names.dmp' not found"`, so
NCBITaxa(taxdump_file=...) failed to build the database.

Add a small extractfile_dmp() helper that falls back to the
'./'-prefixed member name, and use it at the three .dmp call sites.
Add a regression test covering both plain and './'-prefixed tarballs.

Fixes etetoolkit#810.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to retrieve files from tar when the name of the inside files start with ./

1 participant