Database Providers¶
The Provider protocol, the runtime registry, and the catalog naming rules that keep scheme names globally unique.
Database provider architecture¶
Provider protocol¶
gmlst/database/providers/base.py defines the Provider Protocol. Like the aligner contract, this is a structural interface.
Each provider must expose:
namelabellist_schemes()download_scheme()update_scheme()
Each listed scheme is represented as SchemeInfo from gmlst/database/providers/base.py, which carries:
scheme_namedisplay_nameorganismscheme_type— display/search category (mlst/cgmlst/wgmlst/rmlst/other)compute_type— typing engine (mlst/cgmlst/wgmlst); empty for non-typeable panelsn_lociproviderextrafor provider-specific fields such as URLs or directory names
Provider registry¶
gmlst/database/providers/__init__.py builds the runtime registry. It always registers:
pubmlstviagmlst/database/providers/bigsdb.pypasteurviagmlst/database/providers/bigsdb.pyenterobaseviagmlst/database/providers/enterobase.pycgmlstviagmlst/database/providers/cgmlst.py
If GMLST_PRIVATE_BIGSDB_URL is set, the registry also creates a private BIGSdb provider entry at runtime.
Catalog management and global uniqueness¶
gmlst/database/cache.py manages cached provider catalogs under _catalog/. It also guarantees that scheme names stay globally unique across providers.
This logic has two layers:
_normalize_scheme_names()normalizes names within one provider catalog.save_catalog()compares those names with all other cached catalogs and bumps numeric suffixes when needed.
That is why names like spneumoniae_1, spneumoniae_2, and later spneumoniae_3 can coexist across providers without collisions.
Minimal provider skeleton¶
from pathlib import Path
from gmlst.database.providers.base import SchemeInfo
class MyProvider:
name = "myprovider"
label = "My Provider"
def list_schemes(self, scheme_type: str = "mlst") -> list[SchemeInfo]:
return [
SchemeInfo(
scheme_name="myorg_1",
display_name="My organism MLST",
organism="My organism",
scheme_type="mlst",
n_loci=7,
provider=self.name,
extra={"locus_url": "https://example.org/loci"},
)
]
def download_scheme(self, scheme_name, dest_dir: Path, **kwargs) -> None:
... # write <locus>.tfa, the profile table, and .meta.json
def update_scheme(self, scheme_name, dest_dir: Path, **kwargs) -> bool:
... # return True when remote content changed
Catalog entry example¶
After save_catalog(), a provider catalog is a JSON array of scheme objects:
[
{
"scheme_name": "saureus_1",
"display_name": "Staphylococcus aureus MLST",
"organism": "Staphylococcus aureus",
"scheme_type": "mlst",
"compute_type": "mlst",
"n_loci": 7,
"provider": "pubmlst",
"extra": {
"scheme_url": "https://rest.pubmlst.org/db/pubmlst_saureus_seqdef/schemes/1"
}
}
]
scheme_type drives scheme list -t and search; compute_type drives
typing. A lineage-scoped MLST-like scheme (e.g. ST3/ST4 or O1/O139) is
scheme_type: other with compute_type: mlst, so it stays out of the default
MLST listing but still types through gmlst typing mlst. Non-typing panels
(virulence, resistance, serogroup PCR) are other with an empty
compute_type.
Naming walkthrough¶
Two providers both publish a 7-locus S. pneumoniae scheme:
pubmlst -> spneumoniae_1
pasteur -> spneumoniae_2 # save_catalog() bumps the suffix
Names are recorded in name_history, so a later catalog refresh reuses the same
name even when upstream listing order changes. New schemes take the next free
number; retired names are never reused.