JSON 输出契约
所有 gside 输出为统一 JSON(stdout)。
marker 方法的结果为扁平结构(无 result 包装);ani、mash、
sourmash 的结果嵌套在 result 字段内。
marker 结果额外携带 reads 模式深度门控字段(control_gene、control_depth、
control_source、depth_gate);FASTQ 输入时 detected_markers 每行还会给出
mean_depth、reads 与 relative_depth_pct,被深度门控剔除的基因汇总在
notes 中(见标记规则格式的「Reads 模式深度门控」一节)。
组装输入的这些门控字段为空。
当一个方法通过 -d 运行多个选中数据库时,其 database 字段报告合并溯源
({"name": "food+lab2026", ...}),并用 databases 数组列出每个参与的库:
"databases": [
{"name": "food", "version": "9c1f2ab3", "path": "/data/db/marker/food"},
{"name": "lab2026", "version": "2026.1", "path": "/data/db/marker/lab2026"}
]
单库选择(默认)完全不输出 databases 字段。
单方法输出(-m marker)
{
"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
}
}
多方法仲裁输出(-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": { ... },
"sourmash": { ... }
},
"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 的范围、候选与歧义
verdict 不仅给出标签,还声明证据粒度:
scope |
含义 |
|---|---|
species |
证据支持二名法种级判定 |
genus |
gside 有意只判到属(Salmonella 属级回退、Shigella);血清型/致病型分型属于 gspec |
complex |
多个成功方法在已知近缘群内不一致;胜者仍写入 species,其余标签进入 alternatives |
unknown |
没有任何方法给出判定 |
当方法在近缘群内不一致时,为了兼容既有消费者,species 仍保留分层仲裁
选出的标签,同时显式列出竞争标签:
"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 是稳定的机器值(same_genomic_species_complex、
clostridium_botulinum_complex、close_species_complex);方法一致时为
null。只有 scope == "complex" 时 alternatives 非空。
多输入(样本)
gside scan 一次可接受多个 contigs 文件,顶层 JSON 结构随文件数量变化:
- 1 个文件:单个 JSON 对象,即上文示例的结构
- 多个文件:JSON 数组,每个输入文件对应一个对象,按输入顺序排列
所有输出格式——json、tsv、csv、md——都是流式的:每个样本一完成
就写入(stdout 或 -o),JSON 数组在最后一个样本后才闭合。--format
tsv/md/csv 每个样本渲染一行,而非嵌套对象。
字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
analysis_type |
str | 固定为 species_identification |
tool |
str | 固定为 gside |
version |
str | gside 版本号 |
contigs |
str | 输入 contigs 文件路径 |
methods |
dict | 每个运行的方法的结果(key = mode 名) |
methods.<mode>.species |
str | 该方法判定的规范名 Genus_species(Unknown 表示无法判定) |
methods.<mode>.species_raw |
str | 工具原始标签,仅当与 species 不同时出现 |
methods.<mode>.strain |
str | 该方法解析出的菌株/登录号细节 |
methods.<mode>.confidence |
str | high / medium / low |
methods.<mode>.result |
dict | ANI/sourmash 方法的嵌套结果(marker 无此层) |
methods.<mode>.error |
str | 方法执行错误(仅失败时出现) |
methods.<mode>.suggested_command |
str | 缺库时的修复命令 |
methods.<mode>.missing_tier |
str | 需要安装的档位(panel / mash / sourmash) |
methods.<mode>.estimated_size |
str | 该档位的近似下载体积 |
verdict.species |
str | 最终仲裁判定(规范名 Genus_species) |
verdict.display_name |
str | 同一判定的可读形式(空格分隔,如 Escherichia coli) |
verdict.strain |
str | null | 胜出方法给出的菌株信息 |
verdict.confidence |
str | 最终置信度 |
verdict.basis |
list[str] | 产生该判定的方法(单个) |
verdict.supporting |
list[str] | 其他成功且与 verdict.species 一致的方法 |
verdict.agreement |
str | 一致数/成功数,如 2/3(按标签精确匹配) |
verdict.scope |
str | 证据粒度:species / genus / complex / unknown |
verdict.alternatives |
list[dict] | 近缘群内方法不一致时的竞争标签 |
verdict.alternatives[].species |
str | 规范竞争标签 |
verdict.alternatives[].methods |
list[str] | 给出该候选的方法 |
verdict.alternatives[].confidence |
str | 这些方法中的最高置信度 |
verdict.alternatives[].evidence |
dict | 数值证据(ani、identity、aligned_fraction、f_unique_weighted) |
verdict.ambiguity_reason |
str | null | 稳定机器原因;方法一致时为 null |
agreement 按规范标签精确比对。marker 规则现在输出种级标签(仅在无种特异
标记时回退到属级 Shigella),因此 marker 与 ANI/sketch 层使用同一字符串。
DEC/EIEC、志贺菌血清型等致病型/血清型分型属于 gspec,不在 gside 中做。
物种名契约
species 一律为下划线分隔的 Genus_species,与
data/db/D1_marker/marker_rules.yaml 及下游 bacmap 注册表一致:
| 档位 | 工具原始标签 | species |
|---|---|---|
| marker | Streptococcus_agalactiae |
Streptococcus_agalactiae(原样) |
| 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 注册标签本身即契约形式:Salmonella_enterica、
Salmonella_bongori、Salmonella(属级回退)、
Vibrio_parahaemolyticus、Escherichia_coli、Shigella。沙门菌两个种
各有专属规则(见 marker-rules),裸 Salmonella 只作为边缘情形的属级回退
(bongori 标记落在 85–90 检出带时两个种级规则都被压制)。Shigella
是有意的属级标签——血清型/致病型分型属于 gspec;
verdict.scope 明确说明证据支持种、属还是近缘 complex。菌株/登录号
文本绝不拼进 species(点号会破坏下游匹配),统一放入 strain。
种组占位(Campylobacter sp.)与 Unknown 一律输出 Unknown。
ANI 方法特有字段(panel / mash_refseq)
| 字段 | 类型 | 说明 |
|---|---|---|
result.ani |
float | 最高 ANI 值(0-100) |
result.aligned_fraction |
float | 比对覆盖比例 |
result.top_hits |
list | 前 N 个命中(genome/species/ani/af) |
sourmash 特有字段
| 字段 | 类型 | 说明 |
|---|---|---|
result.ani |
float | null | 最佳匹配的 containment ANI(0-100) |
result.f_unique_weighted |
float | 最佳匹配占查询哈希的比例 |
result.gather_partition |
list | 逐匹配的 species / f_unique_weighted / ani |
result.flags |
list[str] | 两个及以上不同物种各自 ≥10% 且 ANI ≥93 时为 possible_mixture |
置信度按 containment ANI 的 95/93 分界(与 panel 一致);若 gather CSV 无 ANI 列,则回退到哈希比例 0.90/0.70。
基因组质量输出(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"
}
| 字段 | 类型 | 说明 |
|---|---|---|
schema |
str | gside.validate/1 |
genome |
dict | name(文件名主干)与绝对 path |
parameters |
dict | 本次运行的 threads、checkm2_db、gtdbtk_db |
software |
dict | gside、checkm2、gtdbtk 版本(不可用时为 "") |
tools |
dict | 逐工具状态:ok / missing / failed |
quality |
dict | CheckM2 的 completeness、contamination、verdict(PASS/CHECK/WARNING/UNKNOWN) |
taxonomy |
dict | GTDB-Tk 的 classification(完整 lineage)与 note |
status |
str | ok(两工具)/ partial(其一)/ error(都无) |
errors |
list[str] | 缺失/失败的工具信息 |
created_at |
str | UTC ISO-8601 时间戳 |
同一份文档会写入 <output-dir>/validation.json。仅当 status == "ok" 时退出
0;质量结论为低质量仍退出 0。
消费输出
用 subprocess 调用 gside,再用标准库 json 解析 stdout:
import json, subprocess
result = subprocess.run(
["gside", "scan", "contigs.fna", "-m", "all"],
capture_output=True, text=True,
)
payload = json.loads(result.stdout)
print(payload["verdict"]["species"]) # 最终判定
print(payload["verdict"]["confidence"]) # 最终置信度
for name, method in payload["methods"].items():
if "error" in method:
print(f"{name} failed: {method['error']}")
退出码
gside scan 恒以退出码 0 结束,即使一个或多个方法失败。判断鉴定成败
应读取 JSON 内容(methods.<mode>.error 与 verdict),而不是依赖退出码。
| 命令 | 退出码 | 行为 |
|---|---|---|
gside scan |
恒为 0 | 单法失败写入 methods.<mode>.error,不影响退出码 |
gside db setup |
0 / 1 | 任一安装结果消息含 ERROR 时为 1,否则为 0 |
gside db(未知子命令) |
1 | 输出 unknown subcommand: ... |
gside validate |
0 / 非零 | 无单法错误保护,失败直接抛出并以非零退出 |