Skip to content

NCBI taxonomy without pitfalls

The NCBI taxonomy is the one that most profilers and classifiers use, and it is harder to use than it looks. It was made for every sequence in GenBank, not for a profiling database; its ids change; its ranks changed in 2024 and 2025; two thirds of its species are placeholders. This page lists what goes wrong when you parse it yourself and what omnitax does about each, with the code. The numbers are those of the dump of 2026-11-26 (ncbi:2026-11-26, built with ncbi+assemblies+gtdb:232).

Why it is hard is well described by people who built profilers on it: Shaw, Thoughts on metagenomic profiling (there is no "the RefSeq database": complete or scaffold? reference or representative? the continuous release or a snapshot? and names change between taxonomy versions, so results of different versions do not compare) and the CosmosID note on GTDB and NCBI (two taxonomies of one set of genomes that do not map one to one). Related tools: TaxonKit, taxid-changelog, gtdb-taxdump and ictv-taxdump.

1. Four files and a mapping

A taxonomy is nodes.dmp (id, parent, rank and ten more columns), names.dmp (every name of every node, with a class: scientific name, synonym, common name, authority, ...), merged.dmp (old id to new id) and delnodes.dmp (deleted ids), fields separated by \t|\t. Sequences are mapped to taxids by accession2taxid (several files, over a gigabyte each) or, for genomes, by the assembly summaries.

omnitax parses all of it, once, into one SQLite file; after that nothing is parsed again:

omnitax build -o taxonomies.sqlite ncbi          # the current dump; ncbi:2025-06-01 for a dated one
import omnitax
ncbi = omnitax.open("taxonomies.sqlite", "ncbi")
ncbi["562"].lineage()                 # root ... Escherichia coli, with every node's attributes
ncbi["562"].names                     # [("Escherichia coli", "name"), ("E. coli", "common name"), ...]

The attributes of nodes.dmp (division, genetic codes, hidden, specified_species, ...) are kept in Taxon.attrs; division.dmp and gencode.dmp are in ncbi.meta. Genome accessions come from the assembly summaries (the taxid of each assembly), not from accession2taxid, which omnitax does not read (below).

2. Taxids change: merged and deleted

A taxid is merged into another when two taxa are synonymised, and deleted when a taxon is removed. A table keyed by taxids that is older than your taxonomy refers to ids that no longer exist.

ncbi.get("662101")           # an old id: the node it was merged into (the current one, 562)
ncbi.many(["562", "gone"])   # one batch; unknown and deleted ids give None

Every store resolves merged ids the same way (through chains of merges, at most 100 steps), under the id you asked for. The genome links of a taxonomy are resolved when it is built: a link on a merged id is moved to the current node, one on a deleted id is dropped (see links may carry old taxids).

Taxids are reused, too. NCBI's paper says taxids "will never be reused to identify a different taxon", but the taxid-changelog (a month-by-month history of the taxonomy) records deleted ids coming back (REUSE_DEL) and merged ids becoming independent again (REUSE_MER). For example 1637691 was deleted in 2015-04, reused in 2015-05 for Escherichia sp. MAR and merged into 562 in 2015-11. The changelog's author found the reused deleted ids he checked went to the same taxon, but a merged id that is a live taxon in a later dump is a different thing from the same id in an old snapshot. What omnitax does: an id that is a node is that node; only ids that are not nodes are looked up in merged.dmp. So an old table whose ids were reused is read, silently, as the new taxon, and resolving old ids through the merged table alone is not always safe. The way to find out is to compare two dated versions: build both into one file (omnitax build ncbi:2019-01-01 ncbi:2026-11-01) and compare the names and lineages of your ids:

old, new = omnitax.open("taxonomies.sqlite", "ncbi:2019-01-01"), omnitax.open("taxonomies.sqlite", "ncbi:2026-11-01")
changed = [i for i in ids if (a := old.get(i)) and (b := new.get(i)) and a.name != b.name]   # the same id, another taxon (or a renamed one)

A diff of two versions of one taxonomy is not in omnitax yet.

3. Placeholders: informal species

Two thirds of NCBI's species nodes are not species (1,684,348 of 2,515,473 in the dump of 2026-11). "Escherichia sp. 4", "Xanthomonadaceae bacterium", "uncultured Bacteroidales bacterium" are placeholders for sequences that were only classified to a genus or a family; nodes.dmp marks them specified_species = 0. They say nothing below the rank they hang from, but counted as species they swell the species counts, are answers that are not names, and vote against the real genus.

ncbi["1343180"].attrs["specified_species"]                          # False: "Escherichia sp. 4"
ncbi["1343180"].closest(["species", "genus"], formal=True)          # skips it: the genus Escherichia
ncbi.consensus(ids, ranks=omnitax.GTDB_RANKS, formal=True)          # an answer that is never a placeholder
gtdb.translate("g__Arenimonas", ncbi)                               # placeholders abstain below their rank (the defaults of GTDB -> NCBI: min_informative=0.2, ranks=GTDB_RANKS)

See Translation for the rule and its benchmark.

4. Unclassified and environmental subtrees

Three nodes collect sequences that are not taxa: unclassified sequences (12908), other sequences (28384) and environmental samples (48479), and "unclassified X" and "environmental samples" nodes sit under real groups. They are not evidence for or against a taxon:

ncbi.uninformative                                    # ("12908", "28384", "48479"): the NCBI loader writes them into the taxonomy's metadata, `meta["uninformative"]`
ncbi.consensus(ids, exclude=ncbi.uninformative)       # their members do not vote
gtdb.translate("g__Escherichia", ncbi)                # for GTDB -> NCBI this exclusion is the default; other conversions exclude nothing unless you pass exclude=

(With min_informative the votes lifted from "unclassified X" nodes go to the nearest ancestor of the ranks in use.)

5. Ranks changed in 2024 and 2025

  • Kingdoms inside the domains (2024). NCBI gave the prokaryotes kingdoms (Pseudomonadati, Bacillati, Thermoproteati, ...): the lineage of E. coli is now domain Bacteria, kingdom Pseudomonadati, phylum Pseudomonadota. A lineage "by the seven ranks" skips the kingdom, a lineage "by every rank" has eight.
  • Domain replaces superkingdom (March 2025). New ranks in NCBI Taxonomy: "domain" for Archaea, Bacteria and Eukaryota; "acellular root" for Viruses and "cellular root" for cellular organisms; a new rank realm (six viral groups at first, ten in the dump of 2026-11). A dump before March 2025 says superkingdom.

omnitax reads superkingdom as domain in every dump, so lineages of old and new dumps have the same ranks (the nodes of the roots keep theirs):

ncbi.ranks                          # {"domain": 3, "kingdom": 22, "realm": 10, "acellular root": 1, "cellular root": 1, ...}
ncbi["562"].lineage(ranks=omnitax.GTDB_RANKS)                # one slot per rank, None where there is none: no kingdom
ncbi["562"].lineage(ranks=["domain", "kingdom", "phylum"])   # your own ladder: every function that needs ranks takes ranks=

GTDB_RANKS is GTDB's seven ranks (it also defines lineage_string()'s d__...;s__ format). It is not a universal ladder: it has no kingdom, which eukaryotes and, now, NCBI's prokaryotes have. To give an old tool superkingdom back, omnitax export-taxdump --rank domain=superkingdom writes it.

6. Homonyms and unique names

The same name can name two taxa: Morus is the mulberry genus (3497) and the gannet genus (37577). NCBI disambiguates in names.dmp with a unique name (Morus <eudicots>, Morus <birds>); the scientific names are the same.

ncbi.lookup(["Morus"])                                                   # {"Morus": [Taxon 3497, Taxon 37577]}: all of them, never a guess
ncbi.search("Morus <birds>", match="exact", classes=["unique name"])     # the unique name finds one: 37577

A name that names two taxa is ambiguous everywhere in omnitax: omnitax annotate --by name leaves it empty (or takes the best with --ambiguous first: the ranking first, then the smaller id) and counts it.

7. Accessions: accession2taxid and assembly summaries

A sequence accession finds a taxid in accession2taxid (nucl_gb: 2.5 GB, nucl_wgs: 6.3 GB, and the dead ones), an assembly accession in the assembly summaries (assembly_summary_refseq.txt and assembly_summary_genbank.txt, one line per assembly, with the taxid and the species taxid). omnitax reads the summaries (ncbi+assemblies), as links of kind genome, and GTDB's metadata for the taxid of each GTDB genome (ncbi+gtdb:232); sequence accessions are a kind of link (seq) that no loader fills from accession2taxid yet.

ncbi.link("GCF_000005845.2")                   # Linked(key, taxon=Escherichia coli str. K-12 ..., name, source="ncbi-assemblies", kind="genome", attrs={...})

Two sources may disagree about an assembly (the summary is the current taxid, GTDB's metadata the one at its release): both are kept, with their source; a lookup in all of them is ambiguous when they differ, and sources= picks (see link sources).

8. Continuous releases and snapshots

RefSeq has a continuous release and discrete ones, and the taxonomy changes monthly. A result is only reproducible against a version, and comparing results across versions compares names that changed:

  • The taxonomy is archived: the new_taxdump of the first of every month since 2018-12-01 (and the current one). In omnitax a version is a date, ncbi:2025-06-01, and several can live in one file.
  • The assembly summaries are not archived. NCBI keeps no older copy, so a build of ncbi+assemblies cannot be redone for a past date; omnitax records the sha256 of every file it read (ncbi.provenance, ncbi.link_sources["ncbi-assemblies"].provenance), so that you can tell which snapshot a result came from, not rebuild it.
  • Say the versions: a profile is the pair (genomes, taxonomy), and Taxonomy.provenance has what built the file. A fixed benchmark taxonomy (CAMI used a RefSeq and taxonomy snapshot of 2019-01-08) is a dated version of a file you keep.

9. What defines "a RefSeq database"

There is no standard one: complete genomes only? reference or representative? latest versions? bacteria only? The assembly summaries have the columns that answer this, and omnitax keeps them on every genome link (Link.attrs, see what is stored); a selection is then a filter over the links:

# complete, latest, representative-or-reference bacterial genomes of RefSeq
chosen = [g for g in ncbi.store.rows().links
          if g.source == "ncbi-assemblies" and g.key.startswith("GCF_") and (a := g.attrs)
          and a.get("assembly_level") == "Complete Genome" and a.get("version_status") == "latest"
          and a.get("refseq_category") in ("reference genome", "representative genome") and a.get("group") == "bacteria"]            # 6,812 in the summaries of November 2026

Genome-set selection and the historical summaries are not part of omnitax yet.

10. GTDB is another taxonomy, not another version

GTDB re-classifies the same genomes on a genome tree: different species (average nucleotide identity), ranks normalised by relative evolutionary divergence, names with letter suffixes (Bacillota_A), Shigella inside Escherichia, no kingdom, no placeholders (an unnamed species is s__Genus spNNNNNN). The two are not one to one: translate through the genomes they share, with a vote (translation); the defaults were measured on GTDB 232 to NCBI 2026-11, and on nothing else.

gtdb = omnitax.open("taxonomies.sqlite", "gtdb:232")
gtdb.translate("s__Escherichia coli", ncbi)       # the NCBI taxon that holds its genomes
ncbi.translate("620", gtdb)                       # Shigella has no GTDB genus: its genomes are GTDB's Escherichia coli and ECMA0423 sp047199055, so the vote answers the family

GTDB ids are names, and its releases change them; tools that want numbers use gtdb-taxdump's: the xxHash64 of the rank and the name, which omnitax reproduces (below).

11. Taxdumps for the tools that want them

Kraken2, KMCP, ganon and TaxonKit read NCBI-style taxdumps. Any taxonomy of omnitax can be written as one, and a dump made by TaxonKit's create-taxdump (gtdb-taxdump, ictv-taxdump) can be read:

omnitax export-taxdump gtdb-r232/ -t gtdb:232            # nodes.dmp names.dmp merged.dmp delnodes.dmp taxid.map: the ids of gtdb-taxdump
omnitax export-taxdump ncbi-linked/ -t ncbi --source gtdb:232   # NCBI's own ids; taxid.map from the GTDB genome links
gtdb = omnitax.load("taxdump", "R232", files=["gtdb-taxdump-R232.tar.gz"])    # a taxdump as a taxonomy; taxid.map as genome links
gtdb.link("GCF_013185635.1").taxon                                            # the genome's own node (gtdb-taxdump has one per assembly)

See taxdump for the ids, what is reproduced exactly and what is not.

References