Skip to content

JSON Output Contract

All gside output is unified JSON printed to stdout.

Single-Method Output (-m marker/ani/mash/sourmash)

Example with -m marker (marker results are flat; no result wrapper):

{
  "analysis_type": "species_identification",
  "tool": "gside",
  "version": "0.2.5",
  "contigs": "/path/to/contigs.fasta",
  "methods": {
    "marker": {
      "species": "Campylobacter_jejuni",
      "confidence": "high",
      "method": "marker",
      "database": {
        "name": "species_markers_v2",
        "version": "a1b2c3d4"
      },
      "detected_markers": [
        {
          "gene": "hipo",
          "identity": 100.0,
          "coverage": 100.0
        }
      ],
      "matched_rule": "hipo+cadf+mapa (3/2 required)",
      "notes": [],
      "interpretation": "Identified as Campylobacter jejuni (confidence: high)."
    }
  },
  "verdict": {
    "species": "Campylobacter_jejuni",
    "display_name": "Campylobacter jejuni",
    "strain": null,
    "confidence": "high",
    "basis": ["marker"],
    "supporting": [],
    "agreement": "1/1",
    "scope": "species",
    "alternatives": [],
    "ambiguity_reason": null
  }
}

The ANI modes (panel, mash_refseq) and sourmash instead nest their findings under a result object, as the all example below shows.

Marker results additionally carry the reads-mode depth gate fields (control_gene, control_depth, control_source, depth_gate); on FASTQ input each detected_markers row also reports mean_depth, reads and relative_depth_pct, and genes removed by the depth gate are summarized in notes (see Marker Rules Format). Assembly input leaves the gate fields empty.

When a method runs several selected databases (-d), its database field reports the joined provenance ({"name": "food+lab2026", ...}) and a databases array lists each contributing database:

"databases": [
  {"name": "food", "version": "9c1f2ab3", "path": "/data/db/marker/food"},
  {"name": "lab2026", "version": "2026.1", "path": "/data/db/marker/lab2026"}
]

A single-database selection (the default) omits databases entirely.

Multi-Method Arbitration Output (-m all)

{
  "analysis_type": "species_identification",
  "tool": "gside",
  "version": "0.2.5",
  "contigs": "/path/to/contigs.fasta",
  "methods": {
    "marker": {},
    "panel": {
      "method": "panel",
      "database": {
        "name": "D2_ani",
        "version": "e5f6g7h8"
      },
      "result": {
        "species": "Campylobacter_jejuni",
        "species_raw": "Campylobacter jejuni subsp. jejuni NCTC 11168",
        "strain": "subsp. jejuni NCTC 11168",
        "confidence": "high",
        "ani": 100.0,
        "aligned_fraction": 95.2,
        "top_hits": [
          {
            "genome": "GCF_000009085.1_ASM908v1_genomic.fna",
            "species": "Campylobacter jejuni",
            "ani": 100.0,
            "af": 95.2
          }
        ]
      }
    },
    "mash_refseq": {}
  },
  "verdict": {
    "species": "Campylobacter_jejuni",
    "display_name": "Campylobacter jejuni",
    "strain": "subsp. jejuni NCTC 11168",
    "confidence": "high",
    "basis": ["panel"],
    "supporting": ["mash_refseq"],
    "agreement": "2/2",
    "scope": "species",
    "alternatives": [],
    "ambiguity_reason": null
  }
}

Verdict scope, alternatives, and ambiguity

verdict states the evidence granularity, not only a label:

scope Meaning
species The winning evidence supports a binomial call
genus gside deliberately stops at genus (Salmonella fallback, Shigella); serovar/pathotype typing belongs to gspec
complex Successful methods disagree inside a known close-relative group; the winner stays in species, competing labels move to alternatives
unknown No method produced a call

When methods disagree inside a close-relative group, the label selected by the layer arbitration remains backward-compatible in species, while the competing labels are reported explicitly:

"verdict": {
  "species": "Escherichia_coli",
  "scope": "complex",
  "confidence": "high",
  "basis": ["ani"],
  "supporting": [],
  "agreement": "1/2",
  "alternatives": [
    {
      "species": "Shigella",
      "methods": ["mash"],
      "confidence": "high",
      "evidence": {"mash": {"identity": 0.981}}
    }
  ],
  "ambiguity_reason": "same_genomic_species_complex"
}

ambiguity_reason is a stable machine value (same_genomic_species_complex, clostridium_botulinum_complex, close_species_complex) and is null when the successful methods agree. alternatives is empty unless scope is complex.

Multiple Inputs (Samples)

gside scan accepts several inputs in one run. FASTQ mates (_R1/_R2, _1/_2, .1/.2) are grouped into one sample; unmatched files are separate samples. The top-level JSON shape depends on the sample count:

  • 1 sample: a single JSON object, as in the examples above
  • 2+ samples: a JSON array of those objects, one per sample, in input order

For a paired sample, contigs is the first mate (both were analyzed).

Every output format — json, tsv, csv and md — is streamed: each sample is written (to stdout or -o) as soon as it finishes, and a JSON array is closed only after the last sample. --format tsv/md/csv render one row per sample instead of nested objects.

Field Reference

Field Type Description
analysis_type str Always species_identification
tool str Always gside
version str gside version
contigs str Input path; for paired FASTQ, the first mate
methods dict Results per method (key = mode name)
methods.<mode>.species str Canonical Genus_species call for this method
methods.<mode>.species_raw str Original tool label, present only when it differs from species
methods.<mode>.strain str Strain / accession detail, when the method resolved one
methods.<mode>.confidence str high / medium / low
methods.<mode>.error str Method execution error (only on failure)
methods.<mode>.suggested_command str Fix-up command when the error is a missing database
methods.<mode>.missing_tier str Tier to provision (panel, mash, sourmash)
methods.<mode>.estimated_size str Approximate download size for that tier
verdict.species str Final arbitrated call (canonical Genus_species)
verdict.display_name str Same call with spaces (Escherichia coli)
verdict.strain str | null Strain of the winning method, if any
verdict.confidence str Final confidence
verdict.basis list[str] The single method that produced the verdict
verdict.supporting list[str] Other successful methods that agree on verdict.species
verdict.agreement str agreeing/successful, e.g. 2/3 (exact label match)
verdict.scope str Evidence granularity: species / genus / complex / unknown
verdict.alternatives list[dict] Competing labels when methods disagree in a close-relative group
verdict.alternatives[].species str Canonical competing label
verdict.alternatives[].methods list[str] Modes that produced the alternative
verdict.alternatives[].confidence str Highest confidence among those modes
verdict.alternatives[].evidence dict Numeric method evidence (ani, identity, aligned_fraction, f_unique_weighted)
verdict.ambiguity_reason str | null Stable machine reason; null when methods agree

agreement compares canonical labels exactly. Marker rules now emit species-level labels — Salmonella_enterica and Salmonella_bongori have their own rules, and the bare Salmonella survives only as the genus-level fallback for edge cases (bongori markers in the 85–90 detection band). Shigella stays a deliberate genus label. Serovar/pathotype typing belongs to gspec; verdict.scope says explicitly whether the evidence supports a species, a genus, or a close-relative complex.

Species name contract

species is always Genus_species with underscores, matching the labels in data/db/D1_marker/marker_rules.yaml and the downstream bacmap registry:

Tier Raw tool label species
marker Streptococcus_agalactiae Streptococcus_agalactiae (unchanged)
panel Streptococcus agalactiae 2603V/R Streptococcus_agalactiae
mash_refseq Streptococcus_agalactiae_GCF_949788565.1 Streptococcus_agalactiae
sourmash ...;s__Vibrio parahaemolyticus Vibrio_parahaemolyticus
gtdbtk Vibrio cholerae Vibrio_cholerae

Marker registry labels are already in contract form: Salmonella_enterica, Salmonella_bongori, Salmonella (genus fallback), Vibrio_parahaemolyticus, Escherichia_coli, Shigella. Shigella is deliberately genus-level only — species/serotype discrimination belongs to gspec and is called out in methods.marker.notes. Strain/accession text is never glued into species (a dot would break the downstream matcher); it goes to strain. Species-group placeholders (Campylobacter sp.) and Unknown are emitted as Unknown.

ANI-Specific Fields (panel / mash_refseq)

Field Type Description
result.ani float Highest ANI value (0-100)
result.aligned_fraction float Alignment coverage fraction
result.top_hits list Top N hits (genome/species/ani/af)

sourmash-Specific Fields

Field Type Description
result.ani float | null Containment ANI of the best match (0-100)
result.f_unique_weighted float Fraction of query hashes in the best match
result.gather_partition list Per-match species / f_unique_weighted / ani
result.flags list[str] possible_mixture when >=2 distinct species each reach 10% with ANI >= 93

Confidence follows the containment ANI (95/93 bands, same as panel). If the gather CSV has no ANI column, the hash-fraction fallback (0.90/0.70) applies.

Genome Quality Output (gside validate)

{
  "schema": "gside.validate/1",
  "genome": {"name": "GCF_000006945.2_ASM694v2_genomic", "path": "/abs/contigs.fna"},
  "parameters": {"threads": 4, "checkm2_db": "/db/checkm2", "gtdbtk_db": "/db/gtdb"},
  "software": {"gside": "0.2.5", "checkm2": "1.0.2", "gtdbtk": "2.4.0"},
  "tools": {"checkm2": "ok", "gtdbtk": "ok"},
  "quality": {"completeness": 99.1, "contamination": 0.5, "verdict": "PASS"},
  "taxonomy": {"classification": "d__Bacteria;p__...;s__Salmonella enterica", "note": ""},
  "status": "ok",
  "errors": [],
  "interpretation": "Genome quality: PASS (...); GTDB-Tk: ...",
  "created_at": "2026-10-21T14:30:00+00:00"
}
Field Type Description
schema str gside.validate/1
genome dict name (file stem) and absolute path
parameters dict threads, checkm2_db, gtdbtk_db used for this run
software dict gside, checkm2, gtdbtk versions ("" when unavailable)
tools dict Per-tool status: ok / missing / failed
quality dict CheckM2 completeness, contamination, verdict (PASS/CHECK/WARNING/UNKNOWN)
taxonomy dict GTDB-Tk classification (full lineage) and note
status str ok (both tools) / partial (one) / error (none)
errors list[str] Missing/failed tool messages
created_at str UTC ISO-8601 timestamp

The same document is written to <output-dir>/validation.json. Exit code is 0 only when status == "ok"; a low-quality verdict is still exit 0.

Consuming the output

The JSON is self-describing, so consuming it from Python needs nothing beyond the standard library:

import json
import subprocess

result = subprocess.run(
    ["gside", "scan", "contigs.fna", "-m", "all"],
    capture_output=True,
    text=True,
)
payload = json.loads(result.stdout)

verdict = payload["verdict"]
print(verdict["species"], verdict["confidence"])

for mode, entry in payload["methods"].items():
    if "error" in entry:
        print(f"{mode}: failed — {entry['error']}")

A method that failed carries an error key instead of a species call, plus the structured fix-up fields above when the cause is a missing database, and in all mode the remaining methods still contribute to the verdict.

Exit Codes

gside scan always exits 0, even when one or more methods fail. Judge success by the JSON content (methods.<mode>.error and verdict), not by the exit code.

Command Exit code Behavior
gside scan always 0 Per-method failures go to methods.<mode>.error, never the exit code
gside db setup 0 / 1 1 iff any setup result message contains ERROR, else 0
gside db (unknown subcommand) 1 Prints unknown subcommand: ...
gside validate 0 / 1 0 only when CheckM2 and GTDB-Tk both ran; partial/error exit 1 (quality verdict does not affect the code)