Skip to content

Custom databases

English | 简体中文

gside modes draw on databases. Besides the bundled/setup tiers (D1_marker, D2_ani, D3_mash, D4_sourmash), every database-capable mode — marker, ani, mash, sourmash — accepts additional named databases, and one identification run can select several of them.

Selecting databases

scan takes repeatable -d/--db [MODE:]NAME values. A value resolves as:

  1. an existing directory path → used directly;
  2. a name under data/db/<family>/<name>/ (see below);
  3. the reserved name default → the mode's bundled tier.
# one named marker database (single mode: the MODE: prefix is optional)
gside scan sample.fna -m marker -d food

# two marker databases in one run: rules and hits are pooled and arbitrated
gside scan sample.fna -m marker -d food -d lab2026

# combined modes need qualified names
gside scan sample.fna -m marker+panel -d marker:food -d panel:lab2026

# a directory path also works (validated per family layout)
gside scan sample.fna -m panel -d /opt/dbs/my-panel

--marker-db PATH remains as a compatibility alias for -d marker:PATH.

Family directories

Named databases live under the mode's family directory inside the database root (data/db/ unless --db-dir moves it):

data/db/
├── D1_marker/               # marker tier: one subdirectory per database
│   ├── default/             # bundled default (markers.fasta + rules + blastdb)
│   └── cpin/                # bundled CPIN extension (ships with gside)
├── D2_ani/                  # panel tier (default/ holds panel.sketch; genomes/ is build input)
│   └── <name>/              # your named panel databases
├── D3_mash/                 # mash tier (default/mash.msh; <name>/ for more)
└── D4_sourmash/             # sourmash tier (default/; <name>/ for more)

Every mode owns exactly one tier directory, and databases live inside it — one subdirectory per database, default plus any named ones. The (mode, name) pair is unique because names cannot repeat inside a single directory. The -d MODE: prefix takes the mode name (panel:lab) or its alias (ani:lab) — they resolve identically.

Multiple bundled databases per mode ship exactly like user databases, as sibling subdirectories of default/ — D1_marker/cpin is the shipped example (git-tracked, validated by the same layout rules). Add yours next to it (D1_marker/my-panel/) or point -d at any directory path.

Database composition via extends: a marker database can declare extends: <name> in its metadata.yaml to pool a sibling database in automatically at runtime. The bundled cpin extends default, so these two invocations are identical:

gside scan -m marker -d cpin sample.fna              # auto: cpin + default
gside scan -m marker -d default -d cpin sample.fna   # explicit merge

Without extends, an explicit -d selection replaces the default tier — -d cpin alone would run ONLY the cpin rules (34 rules), so default species such as Shigella, Citrobacter, M. tuberculosis and C. pneumoniae would slip through. extends makes the extension database safe by construction: default updates propagate automatically (no copy to keep in sync), the databases array reports every database that ran, and cycle/missing targets degrade with a note. To test an extension in strict isolation, point --marker-db at a copy without the extends key.

gside db list / gside db status enumerate them: every database -d can select appears as a MODE / DATABASE row (JSON: modes, plus installable tiers). Modes without local databases (gtdbtk) reject -d with an actionable error.

Merge semantics

Selecting several databases of one mode runs all of them and merges:

  • marker: rules from every database compete over pooled hits — equivalent to one merged database. Control genes and reads defaults merge first-wins (selection order).
  • panel / mash_refseq / sourmash: each database is searched; hits are pooled and re-ranked, and the verdict is derived once from the global best hit. Taxa maps merge first-wins.

The method's database field reports the joined provenance ({"name": "food+lab2026", ...}) and a databases array lists each contributing database (name, version, path). A single selection keeps the exact single-database output shape.

Marker database layout

my-markers/
├── markers.fasta          # required
├── marker_rules.yaml      # required
├── metadata.yaml          # optional
└── markers_blastdb.*       # optional; built on first use

markers.fasta

Headers follow the gspec-style pipe contract:

>gside|db=<database>|gene=<gene>|acc=<accession>|func=<role>|note=<text>

Example:

>markers~~~tlh~~~MY001 thermolabile hemolysin
ATGCGT...
>markers~~~tdh~~~MY002 thermostable direct hemolysin
ATGCGT...

Requirements:

  • IDs are unique.
  • The gene token is non-empty and is matched case-insensitively against rules.
  • db validate rejects malformed headers and rules referencing unknown genes.

marker_rules.yaml

Same schema as the bundled database:

rules:
  - species: Vibrio_parahaemolyticus
    genes: [tlh, tdh]
    min_hits: 2
    min_identity: 90
    min_coverage: 60
    exclude_genes: [some_confounder]
    note: custom scheme note

Rules with more matched genes win; priority_over can make a species dominate non-priority candidates. See Marker rules for the full semantics.

metadata.yaml (optional)

schema: gside.marker-db/1
name: my_vibrio_panel
description: In-house Vibrio marker panel
version: 2026.1
# Optional relative/absolute BLAST prefix:
# blast_db: markers_blastdb

Without metadata.yaml, the database name is the directory name and the version is the first 8 hex characters of a SHA-256 over FASTA + rules.

Validation

gside db validate my-markers
gside db validate my-markers -f json

db validate checks:

  • required files;
  • FASTA header shape and duplicate IDs;
  • YAML syntax;
  • rules shape;
  • unknown gene references;
  • empty FASTA/rules.

Exit code is 0 for a valid DB and 1 when errors are reported.

BLAST database

The default gseek marker path aligns against markers.fasta directly. The legacy BLAST path uses markers_blastdb; if markers_blastdb.nhr / .nin is missing, gside builds it in the database directory on first use:

makeblastdb -in my-markers/markers.fasta -dbtype nucl -out my-markers/markers_blastdb

You can prebuild it (recommended for read-only databases):

makeblastdb \
  -in my-markers/markers.fasta \
  -dbtype nucl \
  -out my-markers/markers_blastdb

If the directory is read-only and the database is missing, gside raises an actionable error instead of writing outside it.

CLI usage

# explicit path
gside scan sample.fna -m marker --marker-db ./my-markers

# environment variable
GSIDE_MARKER_DB=./my-markers gside scan sample.fna -m marker

# a database root containing D1_marker
gside scan sample.fna -m marker --db-dir ./my-db-root

# named / multi-database selection (see "Selecting databases" above)
gside scan sample.fna -m marker -d food -d lab2026

--marker-db affects only the marker method when used with a combined mode such as -m marker+sourmash; the other methods keep using their tiers. The same holds for --db marker:food.

--auto-setup never installs custom databases. The custom DB is user-managed; db validate is the supported check.

Python usage

from gside.api import identify_multigene
from gside.marker_db import MarkerDatabase

db = MarkerDatabase.from_path("my-markers")
errors = db.validate()
if errors:
    raise SystemExit("\n".join(errors))

result = identify_multigene("sample.fna", marker_db=db)
print(result.database_name, result.database_version)
print(result.to_dict())

You can also pass a path directly, or a list to run and merge several databases:

result = identify_multigene("sample.fna", marker_db="my-markers")
merged = identify_multigene("sample.fna", marker_db=["my-markers", "other"])

The result's database object reports the custom name and version (joined with + when several databases ran), so downstream JSON remains traceable.

Limits

  • Named databases are supported for marker, panel, mash_refseq, and sourmash; gtdbtk (external GTDB-Tk database) does not accept -d.
  • db setup -d marker|ani|mash|sourmash installs a mode's default (its tier); -t/--tier remains as the legacy spelling.
  • Custom databases do not participate in db setup / db status; db list shows named databases, db validate checks marker layouts.
  • The default gseek path and the shadow comparison use the same custom FASTA; the legacy BLAST path uses the custom BLAST index.
  • Marker rules cannot create new algorithm behavior; they only select species from gene hits.