Adding your own taxa¶
An overlay is a set of changes to a taxonomy that you keep as data: new taxa (your genus, your species, the MAGs of your lab), genomes linked to them, a rank or parent corrected, a node removed. It is applied to a taxonomy when you build it, and again to every newer version of the taxonomy, so a new NCBI dump never loses your work, and a change that no longer fits (the parent was deleted, a taxid was reused) is an error, not a silent wrong tree.
An overlay says how the nodes should be, not what to do: a new id adds a node, an existing id changes it. So applying it twice, or with its rows in another order (children before their parents), gives the same taxonomy.
The format¶
The format is the one of the custom loader: tab-separated files with a header line, in a directory (or given one by one). Blank lines and lines starting with # are ignored.
nodes.tsvidandparentare required. Optional:rank,name,parent_nameand any other column, which becomes an attribute of the node. A blank cell of an existing node leaves it as it is; a new node withoutrankisno rank, withoutnameit is named by its id. Attribute values that are JSON scalars (7,true,2.5) are numbers or booleans, else text (NaNandInfinityare text). The files are UTF-8, a byte order mark is ignored.links.tsv(optional)keyandnodeare required. Optional:kind(defaultgenome;seq, or a cross-reference kind),name(the organism),source(defaultoverlay,overlay/<kind>for another kind), other columns are attributes of the link. A link of the same key and source in the taxonomy is replaced.remove.tsv(optional)- one node id per line (an optional header
id). uninformative.tsv(optional)- one node id per line: nodes whose members say nothing (NCBI's unclassified and environmental samples): they are added to the taxonomy's
uninformativelist (tax.uninformative, theexclude=ofconsensusandtranslate; NCBI's loader writes its three). A taxonomy that has none gets yours; a removed node leaves the list.
parent_name is a guard: the name the parent had when you wrote the row. If it is not the parent's name any more (NCBI reuses taxids: see
NCBI taxonomy without pitfalls), the overlay is rejected.
Your ids¶
A new id must not be a number in a taxonomy whose ids are numbers (NCBI, taxdumps): those are NCBI's, and a number you chose today may be NCBI's tomorrow. Use a slug of your own, <slug>:<id>:
abrinca:mag7. One slug per strain collection, user or project, the style of the cross-reference keys (ncbi:9606). Taxdump export (below) gives them integer taxids.
A worked example¶
Add a genus, a species and two MAGs to NCBI, with their genomes, and make a Kraken2 database taxonomy.
abrinca/nodes.tsv:
id parent rank name parent_name isolation
# a new genus in the Enterobacteriaceae (NCBI 543)
abrinca:genus 543 genus Abrincaea Enterobacteriaceae
abrinca:sp abrinca:genus species Abrincaea mira
abrinca:mag7 abrinca:sp strain Abrincaea mira MAG 7 river
abrinca:mag9 abrinca:sp strain Abrincaea mira MAG 9 soil
abrinca/links.tsv:
key node name
GCA_900000001.1 abrinca:mag7 Abrincaea mira MAG 7
GCA_900000002.1 abrinca:mag9 Abrincaea mira MAG 9
Build, from the command line (--overlay is repeatable: overlays apply in the order given, to each SPEC):
or in Python, on any taxonomy, the result being a new taxonomy (in a temporary file; one rebuild):
ncbi = omnitax.open("taxonomies.sqlite", "ncbi")
mine = ncbi.apply("abrinca/") # a directory, or a list of directories and files
mine.save("taxonomies.sqlite") # replaces ncbi:DATE in the file with the changed one
[t.name for t in mine["abrinca:mag7"].lineage()] # [..., 'Enterobacteriaceae', 'Abrincaea', 'Abrincaea mira', 'Abrincaea mira MAG 7']
mine.link("GCA_900000001.1").taxon # the MAG
A month later, rebuild on the new dump with the same command: omnitax build -o taxonomies.sqlite ncbi --overlay abrinca/ (or ncbi:2026-12-01). The overlay is checked again against the new nodes.
Export it for Kraken2, KMCP or ganon:
NCBI's taxids stay; your new nodes get taxids made as gtdb-taxdump makes them (species + abrincaea mira hashed to 31 bits, the next number when it is taken by
any id of the export, including NCBI's), so they are the same on every export of the same names. taxid.map has your genomes: GCA_900000001.1 <taxid of the MAG>.
What is checked¶
Everything is checked before anything is written; all the problems are reported at once, with the file and line of each. A failing overlay leaves an existing file untouched (the build is one transaction).
| rule | result |
|---|---|
| the parent is a node of the taxonomy, or of the overlay | else an error: deleted (NCBI deleted it) or unknown |
| the parent was merged into another taxid | the new one is used, logged at info |
parent_name is not the name of the parent |
error (was the id reused?) |
| a new id is a number, in a taxonomy of numbers | error |
| a new id is a merged or deleted id of the taxonomy | error |
| a node is its own ancestor after the overlay | error |
| a new node has no parent | error |
| a node is removed that has children | error, unless the overlay removes them too or gives them another parent in nodes.tsv (nothing moves silently) |
| the same id (or link, or removal) twice in the overlay | error |
an id in nodes.tsv and in remove.tsv |
error |
a row of nodes.tsv with a blank id |
error, with the line |
| a file that is not UTF-8 text | error, naming the file |
| a link to a removed, deleted or unknown node (a merged one is followed) | error |
| the links of one source are of two kinds | error |
| the overlay changes nodes of the taxonomy itself (parent, rank, name, attributes) | allowed, one warning for all of them (how many, and three examples); every node at DEBUG |
an uninformative.tsv id that is no node (merged ids are followed) |
error |
| removing an id that is no node (removed already) | warning |
The overlay's files are recorded in the provenance of the taxonomy (tax.provenance["files"]) with their sha256 and "role": "overlay", next to the files of the source (the entries of the source have no role).
The same from Python data¶
A script that makes its edits as it goes does not need files: apply takes the rows as Python data, with the columns of the files as keys (the other keys are attributes, and keep their
types), and applies them after any files, in one rebuild (a copy of NCBI is about 90 s, so never one apply per row):
mine = ncbi.apply(
"abrinca/", # files, if you have them too
nodes=[{"id": "abrinca:mag9", "parent": "abrinca:sp", "name": "MAG 9", "completeness": 98.1},
{"id": "564", "name": "Escherichia fergusonii"}], # an existing node: only what is given changes
links=[{"key": "GCA_900000002.1", "node": "abrinca:mag9"}],
remove=["999"],
)
Errors name the row (nodes[1]: the parent nope is unknown). In data, "parent": None makes a root (a blank cell of a file leaves the parent as it is). apply is the only way to edit a taxonomy: to add a node, give a new id; to change one, give its id with the new values; to remove one, list it in remove. A node with children needs them removed too, or given another parent in the same call ({"id": child, "parent": up}; None makes a root). The links of a removed node are dropped unless the same call links their keys to another node. Removing an id that is no node logs a warning. Applying the same rows twice gives the same taxonomy.
Limits¶
- A different
namereplaces the scientific name of a node (the old one is not kept as a synonym); its synonyms and common names stay. - Merging and splitting taxa are not operations of an overlay: give the children another parent and remove the node.
- The ids of an overlaid taxonomy that is exported with
ids="hash"are hashed as everything else; withids="auto"on NCBI only yours are made.