Repository navigation
resolve GTDB taxid hash collisions deterministically - #7
Merged
Merged
Conversation
GTDB taxids are a 31bit hash of the taxon name or genome accession
number. With >1.1M keys in r232, 318 taxids were shared by two keys;
the entry written last silently replaced the other, which then could
not be found anymore, and in case of taxon names, its genomes got
attached to an unrelated node.
Taxids are now assigned jointly for all domains of a release: if several
keys hash to the same value, the alphabetically first keeps it, the
others get the first unused hash_to_int(f"{key}#{n}"), processed in
alphabetical order. Non-colliding taxids are unchanged and the result
only depends on the GTDB release. Bump DB_VERSION to trigger a rebuild
of existing databases.
There was a problem hiding this comment.
🟡 Changes recommended
Rebuilding from legacy dump archives can preserve collisions while marking the database current.
1 open finding
What changed in this PR
Resolves GTDB taxid hash collisions deterministically to prevent lost taxa and incorrect lineages, addressing issue #6.
Changes:
- Assigns unique taxids jointly across domains while preserving non-colliding IDs.
- Bumps the database version and versions the test cache.
- Adds allocation and real-release collision regression tests.
| File | Description |
|---|---|
| tests/test_gtdb.py | Tests deterministic allocation and collision handling. |
| tests/conftest.py | Includes database version in the test cache path. |
| omataxonomy/query.py | Bumps the database version to trigger rebuilding. |
| omataxonomy/gtdb.py | Resolves collisions across jointly processed domains. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Archives built before hash collisions were resolved still contain duplicated GTDB taxids. update_db only generates a new archive if none exists, so after the DB_VERSION bump an old omatax.tar.gz next to the database (or passed explicitly) would be loaded again, silently drop the colliding taxa and still be marked as up to date. load_tree_from_dump now raises a ValueError if nodes.dmp contains a taxid more than once, before the database is touched.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

GTDB taxids are a 31bit hash of the taxon name or genome accession
number. With >1.1M keys in r232, 318 taxids were shared by two keys;
the entry written last silently replaced the other, which then could
not be found anymore, and in case of taxon names, its genomes got
attached to an unrelated node.
Taxids are now assigned jointly for all domains of a release: if several
keys hash to the same value, the alphabetically first keeps it, the
others get the first unused hash_to_int(f"{key}#{n}"), processed in
alphabetical order. Non-colliding taxids are unchanged and the result
only depends on the GTDB release. Bump DB_VERSION to trigger a rebuild
of existing databases.
This should fix the issue #6