Skip to content

Taxdumps: writing and reading NCBI-style dumps

Kraken2, Centrifuge, KMCP, ganon and TaxonKit read NCBI taxdump files. omnitax writes any of its taxonomies as one, and reads the dumps that TaxonKit's create-taxdump makes for taxonomies that NCBI does not have: gtdb-taxdump (GTDB, with trackable taxids) and ictv-taxdump (viruses, ICTV).

Writing

omnitax export-taxdump out/ -t gtdb:232                      # the taxdump of GTDB 232, with the taxids of gtdb-taxdump
omnitax export-taxdump out/ -t ncbi --source gtdb:232        # NCBI: its own ids; taxid.map from the links of one source
omnitax export-taxdump out/ -t silva:ssu_138.2                # SILVA's ids are numbers and stay; its synthetic root gets an id made as TaxonKit makes them
summary = gtdb.write_taxdump("out/")      # {"nodes": 1148710, "names": ..., "collisions": 911, "ids": "hash", "merged": 0, "deleted": 0, "map": 901341}

It writes:

file content
nodes.dmp, names.dmp the tree and its names: scientific names, and for NCBI's own ids every other class as stored (synonyms, common names, authorities, unique names)
merged.dmp, delnodes.dmp the aliases of the taxonomy that have numbers as ids (merged and deleted taxids)
taxid.map key<TAB>taxid[,taxid...] of the links of one kind (--kind, default genome) and sources (--source, repeatable), like gtdb-taxdump's: the genome accession and its taxid

Ids. --ids auto (the default) keeps ids that are all numbers (NCBI) and makes the others. NCBI's nodes.dmp is written with the attributes it was read with (division, genetic codes, hidden, specified_species, ...), in the 18-column layout of new_taxdump, and what is unknown is left empty. --ids hash makes ids for any taxonomy, --ids keep insists on the ones it has.

Mixed ids: NCBI plus your own taxa

A taxonomy whose ids are mostly numbers keeps them, and the rest (the abrinca:mag7 of an overlay) get the same recipe's ids: the hash of rank and lower-cased name, the next number when it is taken by any id of the export (NCBI's included, which are never moved). ids="keep" and "auto" do this; ids="hash" rehashes everything.

The root of a taxdump is 1. When the ids are kept, a taxonomy with several top nodes gets a root 1 of its own above them, unless it has a node 1 that is a top node itself. A node 1 that has a parent cannot be kept: ids="auto" then hashes all ids (and warns), ids="keep" is an error.

The ids of the taxonomies that have none

For GTDB, a custom table or an edited taxonomy with string ids, omnitax uses exactly TaxonKit's recipe (taxonkit/cmd/create-taxdump.go), so that the ids are those of the published gtdb-taxdump and ictv-taxdump releases:

  • the taxid of a taxon is the xxHash64 of the rank followed by the lower-cased name, & 0x7FFFFFFF (31 bits): species + escherichia coli is 599451526;
  • the root is 1 (a synthetic root, or NCBI-style root node, of the taxonomy is that node), and a hash of 1 becomes 2;
  • collisions, within one export: a taxid already taken by another rank-and-name moves to the next number, and so does one taken by the same rank and name under a different parent (several taxa of one name, as in ICTV); the records are fed one lineage at a time, lowest rank first, so which of two colliding taxa keeps the hash depends on the order (below);
  • GTDB's ranks are written as TaxonKit writes them: domain is superkingdom (and is hashed as such: superkingdom + bacteria), then phylum, class, order, family, genus, species; --rank FROM=TO renames a rank in the files (and in what is hashed);
  • genomes are no rank nodes under their species (--genome-nodes, the default for a GTDB taxonomy): named by the assembly number without GCA_/GCF_ and without the version (a genome that moves from GenBank to RefSeq keeps its taxid), GCF_013185635.1 is 013185635, with the constants of TaxonKit in the other columns of nodes.dmp. taxid.map then has the genome's taxid; without genome nodes, its species'.

The xxHash64 comes from the xxhash package when it is installed (the taxdump extra, see Install), else from a small pure-Python implementation of omnitax (tested against the package and published digests): the same ids, three times slower (GTDB 232: 34 s against 12 s).

What is reproduced, and what is not

Checked against the release gtdb-taxdump R232 (GTDB 232: 199,923 species, 901,341 genomes) with the taxonomy loaded from GTDB's own files, ar53 first and then bac120, as TaxonKit was run:

file
nodes.dmp byte for byte identical: 1,148,710 nodes
names.dmp identical
taxid.map identical: 901,341 genomes, same taxids, same order
merged.dmp, delnodes.dmp not reproduced: the releases keep the history of every earlier release (taxonkit create-taxdump -x previous-release/), omnitax only has the taxonomy it was given (none, for GTDB: they are empty)

The 911 collisions of that export are resolved as in the release. The order matters: ids that collide go to the taxon seen first, and the records are fed in the order of the genome links. A taxonomy loaded from files has them in the order of the file's lines (omnitax.load("gtdb", "232", files=[...ar53, ...bac120]).write_taxdump(...) is the exact route); a taxonomy saved into a SQLite file keeps its links in that order too (the link.seq column), so exporting from the file gives the same bytes: nodes.dmp, names.dmp and taxid.map of R232 are identical from both routes. (Files built before link.seq existed need a rebuild.)

ictv-taxdump (ICTV MSL40, 20,850 nodes): loaded and written with its own ids, the files read back identical in nodes (id, parent, rank, name); loaded and written with --ids hash, the 20,850 taxids are re-derived from the ranks and names, all of them.

Reading

gtdb = omnitax.load("taxdump", "R232", files=["gtdb-taxdump-R232.tar.gz"])   # a directory, a tarball, or the files
ictv = omnitax.load("taxdump", "40.1", files=["ictv-taxdump.tar.gz"])
omnitax build -o taxonomies.sqlite --file taxdump=gtdb-taxdump-R232.tar.gz taxdump:R232

nodes.dmp and names.dmp are needed; merged.dmp, delnodes.dmp, division.dmp and gencode.dmp are read when there. taxid.map becomes genome links (load(..., links="seq") for another kind), source taxid.map; a key with several taxids has the others in taxid.map/2, taxid.map/3, ... (a source lists a key once). In a gtdb-taxdump the genomes are nodes (no rank, named by their assembly number) and the links point to them: gtdb.link("GCF_013185635.1").taxon is the node 169219442, a child of the species. The kind of the dump is its own (taxdump): a taxonomy read from a dump translates to others through the genome links, as a GTDB loaded from its files does.

Not written: TaxonKit's ranks.txt (the order of the ranks for taxonkit lineage -r/reformat), and TaxonKit's taxid-changelog, which compares releases.