Metadata database¶
sylphd setup turns GTDB's metadata TSV files into a small SQLite file. The server joins it to
every result by accession (--meta), adds its columns to each row, and uses its taxonomy strings
for taxonomic profiles and species assignment.
Accessions¶
The key is the genome accession. The RS_/GB_ prefix of GTDB accessions is stripped, so
RS_GCF_000005845.2 becomes GCF_000005845.2. A sylph genome name such as
.../GCA_964372435.1_genomic.fna.gz maps to GCA_964372435.1. Names without a recognisable
accession get no metadata, and the lookup returns null for each column.
Some catalogues name genomes without the assembly version: GlobDB r232 has
genomes/GCA_041167105.fa.gz, and its sylph-tax keys are GCA_041167105. Such an unversioned
accession is looked up as the row whose accession base (GCA_041167105) it is, when exactly one
version of that base counts — a GTDB row decides first (GTDB has at most one version of a base),
then an NCBI enrichment row, then any row. GCA_041167105 therefore finds
GCA_041167105.1, while two versions of a base are ambiguous: the lookup finds nothing and the
row keeps null metadata rather than guessing a species. The same rule applies to
contains_accessions (a database is GTDB's) and to the key overlap between a sylph-tax source and
the virtual GTDB source.
Columns¶
| Group | Columns |
|---|---|
| GTDB | gtdb_taxonomy, gtdb_representative, gtdb_genome_representative, gtdb_type_species_of_genus, gtdb_type_designation_ncbi_taxa |
| NCBI | ncbi_taxid, ncbi_species_taxid, ncbi_taxonomy, ncbi_taxonomy_unfiltered, ncbi_organism_name, ncbi_strain_identifiers, ncbi_isolate, ncbi_genome_category, ncbi_assembly_level, ncbi_refseq_category, ncbi_type_material_designation, ncbi_biosample, ncbi_bioproject |
| Quality | checkm2_completeness, checkm2_contamination, genome_size, gc_percentage, contig_count, n50_contigs, mimag_high_quality |
--fields of query and profile selects from these names. Taxonomy strings stay as one column
each (no per-rank split), for example gtdb_taxonomy is d__Bacteria;p__...;s__Escherichia coli.
The NCBI columns of a GTDB genome come from GTDB's metadata. setup --taxonomy-db also fills
ncbi_taxid, ncbi_taxonomy and ncbi_organism_name for the genomes of the sylph-tax sources
that GTDB does not cover (fungi, ...): the assembly accession in the key is looked up in NCBI's
assembly summaries and its taxid in the taxdump's rankedlineage.dmp (see
NCBI lineages). Its ncbi_taxonomy keeps GTDB's seven ranks,
d__…;p__…;c__…;o__…;f__…;g__…;s__…, with the superkingdom (or domain) as d__; NCBI's kingdom is
not one of them, so it is left out. No taxid is stored for the other genomes and no taxdump is
kept in the file.
Value conversions while building:
none,naand empty values becomeNULL;- booleans
t/fbecome integers1/0; - numeric columns are
INTEGERorREAL.
Layout¶
The file contains:
- a view
metadatawithaccessionplus the columns above. It is the only thing readers need to know about; - the base table
metadata_data, keyed byaccessionasWITHOUT ROWID, which stores values and, for repetitive text columns, integer ids; it holds the GTDB genomes and, after--taxonomy-db, one row per enriched accession with the GTDB columnsNULL; dict_<column>tables (id,value) for the repetitive text columns: both taxonomies,gtdb_genome_representative, organism names, genome category, assembly level, RefSeq category, type material designation and BioProject. The view joins them back to the original values;- an
infotable with the source files and row counts, the GTDB release, the build date, thesylphdversion, the format version and whether the file is representatives-only (reps_only).
With --taxonomy-db a file also has the nearest NCBI taxa:
taxonomy_nearest (source_id, key → taxid, its formal_taxid, the GTDB clade and the
member support) and ncbi_nearest_taxon (taxid → rank, name, lineage, for the raw and
the formal taxa). They are optional tables, not a
format change: a file without them (an older file, or one built without the flag) is read exactly
as before, and its rows simply have no ncbi_nearest_* columns.
Dictionary-encoding the repetitive text brings the full release down to about 198 MiB instead of about 630 MiB, while lookups stay in the low milliseconds. The file uses 8 KiB pages.
--reps-only¶
All ~900k GTDB genomes are stored by default. --reps-only stores only rows whose
gtdb_representative is true (~200k, about 78 MiB). The server then finds no metadata for
other accessions, which is fine for a sylph database that contains only species
representatives. When two input files contain the same accession, the later row wins.
Taxonomy sources (format version 3)¶
Format version 3 adds sylph-tax taxonomy files to the file, so hits from non-GTDB databases (UHGV viruses, fungi, MAGs, ...) can be given a lineage.
A taxonomy file is plain text, one row per line, tab-separated, optionally gzip-compressed (detected by magic bytes, not by the name):
Parsing follows sylph-tax (sylph_to_taxprof.py, v1.9.2): line.rstrip().split("\t"), the key
verbatim (case sensitive, never normalised, unlike GTDB accessions), the lineage an opaque ;
string, and an optional third column with the virus host. A header row, as IMG/VR 4.1 has, is
stored like any other row and simply never matches a hit; an empty key is stored too (sylph-tax
accepts it). A blank line or a line without a tab is an error naming the file and the line, as it is
in sylph-tax (which would raise there) — a broken source never half-imports.
A key repeated within one file keeps the last lineage but only takes a new host from a row that
has a third column, so a later row without a host leaves the earlier host in place (this is exactly
sylph-tax's two-dict behaviour). Note that a trailing tab is not an empty host: rstrip() runs
before the split, so it counts as no host column. Across files sylph-tax keeps one host dictionary,
so for a key in several sources its lineage comes from the last file and its host from the last file
that had a host column; the database keeps one row per source, so a future resolution step must
pick the two by ord independently.
The file contains:
taxonomy_source— one row per source:ord(the order given tosetup; a key found in two sources resolves to the largerord, as the later file wins in sylph-tax; the virtual GTDB source hasord0),name,kind,origin,md5,rows(stored keys; duplicate keys within a source collapse),has_hostandbuilt;taxonomy_entry—(source_id, key)→lineage/host, dictionary ids,WITHOUT ROWID, with an index onkeyfor batched lookups;taxonomy_overlap—(source_id, other_id)→keys: how many keys two sources share, written in both directions; see overlapping sources;dict_tax_lineage,dict_tax_host—id,value, like the other dictionary tables;- the
infokeyssylphtax_rules(the sylph-tax version whose file formats and rules were implemented, currently1.9.2) andtaxonomy_sources(a JSON copy oftaxonomy_source, including each source'soverlaps).
Two kinds of source exist:
kind |
Meaning |
|---|---|
metadata |
the virtual GTDB source over metadata_data: its keys are metadata_data.accession and its lineages gtdb_taxonomy, so no lineage is stored twice. It is created from -m and named GTDB_r<release> (GTDB without --release). Importing the sylph-tax catalogue file of the same release (GTDB_r232 with --release 232) and -m would duplicate it, so that source is skipped with a message; a different release or a local file is imported. |
sylphtax |
one imported file; md5 is always computed from the file, origin is the path or the download URL it was imported from |
GET /info reports the sources under metadata.taxonomy_sources (name, kind, origin, md5, keys,
has_host). The file keeps the full origin; /info publishes only the base name of a local file
(or the catalogue URL), never a directory. It also reports the shared keys once per pair under
metadata.taxonomy_overlaps, and
metadata.sylphtax_rules; sylphd info prints one line per source and one per overlapping pair.
Overlapping sources¶
Import one taxonomy per database. Sources that share keys are allowed — key spaces of GTDB
(GCA_/GCF_...), UHGV (UHGV-...), fungi and GlobDB overlap in the wild — but they are never
silent: when a source is imported (a build or --update), setup counts, in SQL, the keys it has
in common with the sources already in the file, including the virtual GTDB source (compared on
metadata_data.accession, the key resolve looks up, so an accession in the file and the same key
in a sylph-tax file count), and warns once per pair:
sylphd: warning: taxonomy sources 'UHGV_default' and 'UHGV_ictv' share 1,234 key(s)
(examples: UHGV-0001, UHGV-0002, ...): the source imported later (UHGV_ictv) wins for
these keys; import only one of them, or rebuild without one
The warning goes to the log and to stderr (it is not progress, so -q does not hide it) and the
import still succeeds. For a shared key the source imported later wins (larger ord); profile
--tax-source NAME restricts a request to one source. The counts are stored in taxonomy_overlap
and reported once per pair, in setup order, as
metadata.taxonomy_overlaps: [{"sources": [a, b], "keys": n, "examples": [...]}] by sylphd info
and GET /info (an empty list when the sources are disjoint), with b the later source that wins
for those keys and up to five shared keys in examples.
A key without an assembly version counts as the GTDB accession of the single version of its base
(the rule of accessions), so GlobDB r232 (GCF_003697165) shares its 199,923
GCA_/GCF_ keys with GTDB_r232 (GCF_003697165.1); a base with two GTDB versions counts for
neither.
Resolving a hit¶
The server gives every hit of query, profile and /assembly four extra columns, and lists
them in metadata.columns:
| Column | Meaning |
|---|---|
tax_source |
the source whose lineage was used, or null |
tax_key |
the key that matched, verbatim, or null |
tax_lineage |
that source's lineage string (opaque), or null |
tax_host |
the host of the key, or null |
Resolution replicates sylph-to-taxprof (sylph-tax 1.9.2) key for key over all sources, using
the hit's Genome_file and Contig_name exactly as sylph reports them:
| pass 0 | pass 1 | |
|---|---|---|
gf |
basename, cut at _ASM when ASM occurs anywhere in the full path, else at _genomic |
basename |
glob |
basename.split(".")[0] |
gf |
contig |
Contig_name.split(" ")[0].split("\|")[0] (space only) |
Contig_name.split()[0] (any whitespace) |
Per pass the probes are gf, gf + ".gz", glob, contig, then gf.split(".fa")[0],
gf.split(".fasta")[0] and gf.split(".fna")[0]; the first key that exists wins, and a pass-1
match overrides a pass-0 match. Keys are compared verbatim: never normalised, never
version-stripped (the GTDB accession column is a different thing, and stays as it was).
When several sources contain the same key, the source imported later wins (the larger ord,
as if its file had been passed later to sylph-tax -t): the lineage comes from the largest
ord and the host from the largest ord whose source has a host column for that key — two
different sources, possibly, exactly like the two dictionaries sylph-tax fills while reading its
files. sylphd profile --tax-source NAME selects the sources per request when both files hold the
same keys (e.g. UHGV_default next to UHGV_ictv). A hit that matches nothing has null in all
four columns; sylphd profile --taxonomy tax then writes sylph-tax's
NO_TAXONOMY;t__<genome file>:<contig>.
Keys are not tied to a database: the probe list is what makes UHGV (UHGV-0320751 in the contig
name) and GlobDB (GCF_003697165 without the version) resolve from the same table. The rules are
in one function, sylphd.metadata.sylphtax_probes, and tests/test_sylphtax_parity.py compares
the whole path with the real sylph-tax.
A file built with --taxonomy-db and a key without an NCBI record also carries the
nearest NCBI taxon in eight more virtual columns, likewise listed in
metadata.columns:
| Column | Meaning |
|---|---|
ncbi_nearest_taxid |
the consensus NCBI taxid of the key's GTDB clade, or null |
ncbi_nearest_rank |
its rank (species, genus, ..., domain) |
ncbi_nearest_name |
its scientific name |
ncbi_nearest_clade |
the GTDB clade it came from (g__Thiobacillus) |
ncbi_nearest_lineage |
its d__…;p__…;…;s__… lineage, for the NCBI profile |
ncbi_nearest_formal_taxid |
the nearest ancestor NCBI names formally, when the raw node is an informally named species, else the raw taxid |
ncbi_nearest_formal_rank |
its rank |
ncbi_nearest_formal_name |
its scientific name |
They are never a substitute for ncbi_taxid: that one stays null unless the key's assembly
has a real NCBI taxid. --fields selects them like any other column (a file without the tables
does not have them; requesting one is an error that lists the columns it does have).
NCBI lineages¶
setup --taxonomy-db fills the NCBI columns of the sylph-tax genomes that GTDB's metadata does
not cover, so the NCBI taxonomy view, the NCBI Taxonomy links and the ncbi_* TSV columns work for
them too (e.g. a FungiRefSeq-latest genome keyed GCF_000002495.2_MG8, or a GlobDB key
GCA_000002495 without a version):
- the assembly accession is extracted from the key (
GC[AF]_\d+(?:\.\d+)?, so the_MG8suffix does not matter and the version may be absent); - a key GTDB's metadata covers (
gtdb_taxonomyset for its accession, exactly or as the single version of its base) needs no lookup: GTDB's own NCBI columns are used, and it is counted asgtdb; - otherwise the accession is looked up in the omnitax file's NCBI genomes (GTDB's own taxids, then NCBI's
assembly summaries), as omnitax finds genomes: the same accession, else its version, else the only
stored version of its number (
GCA_andGCF_are different genomes; two versions are ambiguous and skipped). The row is stored under the accession the file holds the genome by, or under the key's own when that has a version; - the genome's taxon is the taxid (merged taxids are followed by omnitax) and its lineage is that of the taxon, on the seven ranks. Nothing is matched by organism name.
The data is stored as ordinary rows of metadata_data keyed by the accession, with GTDB columns
NULL and ncbi_taxid, ncbi_taxonomy and ncbi_organism_name filled, so the metadata lookup,
/assembly, /profile and the web tables need no special case and GTDB rows keep their own NCBI
data. ncbi_taxonomy uses the seven ranks above; NCBI's kingdom is not one of them and is omitted.
The info key ncbi_taxonomy keeps the per-source counts (gtdb, mapped, no_accession,
not_in_summary, ambiguous), which GET /info reports as each source's ncbi object, and the same counts
are printed by setup and sylphd info. The taxonomy file is only read at setup time (it is built once by omnitax),
so serving and requests do no extra work. GTDB rows are never replaced, and each run rebuilds the enrichment rows.
Nearest NCBI taxa¶
Many sylph-tax keys have no assembly in NCBI at all: a GlobDB MAG (MOTU40_002958) has a GTDB-Tk
lineage but no accession, so no NCBI taxid. --taxonomy-db still places it, at the nearest
NCBI taxon of its GTDB clade, which is kept apart from ncbi_taxid (that column stays null:
only an assembly's real taxid is ever written there).
For every key with a GTDB-style lineage (d__…) and no real NCBI taxid, the lineage is walked from
the deepest rank upwards. Each GTDB clade (g__Thiobacillus, matched by rank__name, so a
renamed parent does not hide it) is translated into NCBI through the genomes that GTDB and NCBI
share in the omnitax file (Taxonomy.translate): every GTDB leaf below the clade votes once, with the
NCBI taxa of its genomes (its vote is split between them, so a species of many genomes does not outvote
one of few; a strain votes as its species); genomes below NCBI's unclassified sequences, other
sequences or environmental samples do not vote. That gives the clade's consensus: the deepest NCBI node
that more than 80 % of the weight has as ancestor-or-self, lifted to a major rank (GTDB's seven and NCBI's kingdom); a vote that only
reaches a higher rank (Xanthomonadaceae bacterium) abstains below it instead of counting against a genus it
does not contradict, as long as at least 30 % of the votes reach that rank (the abstention guard 0.3; below it
plain voting applies). The answer is capped: a clade is never answered by something finer than its own rank,
so a genus clade is placed at a genus at most, never at a species, even when all its genomes are one species (the
ladder is GTDB's seven ranks plus the kingdom, so a domain clade is not answered by a kingdom). Guard and cap are
omnitax 0.2's defaults for GTDB → NCBI, passed explicitly by sylphd (strict precision leaving a species out
82.24 % against 80.01 % without them). A strict LCA would be dragged to the root by one misclassified genome, and a bare
majority (the rule before omnitax) put a genus's MAGs at a species the data barely supports: on omnitax's
benchmark of known genomes the genus is placed with 95.6 % precision and 65.8 % recall, against 86.9 % and
67.8 % for the old rule. When no node exceeds 80 %, the members' shared
ancestors still do, so a split clade yields the nearest node they have in common. The first (deepest)
clade with a consensus wins, so a genus with no informative members falls back to its family. The raw
taxon is reported as it is, even when it is a species NCBI only names informally (Clostridia bacterium,
uncultured Collinsella sp.): that is the nearest taxon the profile and the web view place a hit at.
NCBI says which species have a formal name (specified_species, 1 or 0). Alongside
the raw taxon, the formal taxon is the nearest ancestor-or-self of it that is not such an
informal species — the class Clostridia for Clostridia bacterium, the genus Collinsella for
uncultured Collinsella sp. — computed by lifting the raw taxon, never by a new vote. For a
formally named raw taxon it is the same node. This is a structural flag of the taxonomy, not a
pattern on names, and it is extra information: it never replaces the raw taxon.
The result is ncbi_nearest_taxid, ncbi_nearest_rank, ncbi_nearest_name,
ncbi_nearest_clade and ncbi_nearest_lineage, plus ncbi_nearest_formal_taxid,
ncbi_nearest_formal_rank and ncbi_nearest_formal_name, on the key's rows (see
resolving a hit), the tables taxonomy_nearest and ncbi_nearest_taxon, and
the info key ncbi_nearest: per source, the number of keys without an NCBI record (keys), how
many got a taxon (assigned), how many of those are an informally named species (informal) and
the count per raw rank. GET /info reports it as each source's
ncbi_nearest object, setup and sylphd info print it, and the ncbi profile and the web NCBI
view place such hits at that node (the web labels the group, e.g. Thiobacillus (nearest NCBI
genus), or Clostridia bacterium (nearest NCBI taxon; nearest formally named: class Clostridia),
and the /profile JSON marks the strain row with a nearest object). Profiles of a file
without nearest taxa are byte for byte what they were before.
members of a key is the number of GTDB leaves that voted (a share of them, support, agreed). The nearest
step uses the same omnitax file as the enrichment and runs after the enrichment, so a key whose assembly
NCBI knows has its real taxid and gets no nearest taxon. A rerun rebuilds both tables.
Format version and --update¶
Only format version 3 is read or updated; a file of any other version is refused with a message
to rebuild it with sylphd setup. The nearest NCBI taxa did not bump the
version: they are two optional tables and eight virtual columns, a file without them reads exactly
as before, and nothing about an existing column changed, so every format-3 file stays valid. (A
file built with --taxonomy-db by an older sylphd has no nearest taxa; --update
--taxonomy-db adds them.) --update adds sources to an existing file without the GTDB
TSV files:
sylphd setup --update -m old.sqlite --taxonomy UHGV_default -o new.sqlite # copy
sylphd setup --update --taxonomy UHGV_default -o old.sqlite # in place
The copy is built next to the output, in a uniquely named temporary file (so parallel runs and a
source named *.tmp are safe), and replaces the output only on success, exactly like
setup --force, so a failed update leaves the old file untouched. The copy keeps the permission
bits of the file it replaces; a build to a new path uses the normal umask-derived mode.
A source with an existing name is
replaced (its ord is kept).