gmeta 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. gmeta-0.1.0/.gitignore +20 -0
  2. gmeta-0.1.0/CHANGELOG.md +38 -0
  3. gmeta-0.1.0/LICENSE +21 -0
  4. gmeta-0.1.0/PKG-INFO +170 -0
  5. gmeta-0.1.0/README.md +135 -0
  6. gmeta-0.1.0/pyproject.toml +93 -0
  7. gmeta-0.1.0/src/gmeta/__init__.py +15 -0
  8. gmeta-0.1.0/src/gmeta/__main__.py +6 -0
  9. gmeta-0.1.0/src/gmeta/analysis/__init__.py +125 -0
  10. gmeta-0.1.0/src/gmeta/analysis/_envelope.py +26 -0
  11. gmeta-0.1.0/src/gmeta/analysis/centrifuge.py +131 -0
  12. gmeta-0.1.0/src/gmeta/analysis/coverage.py +359 -0
  13. gmeta-0.1.0/src/gmeta/analysis/host.py +113 -0
  14. gmeta-0.1.0/src/gmeta/analysis/kaiju.py +139 -0
  15. gmeta-0.1.0/src/gmeta/analysis/kmcp.py +161 -0
  16. gmeta-0.1.0/src/gmeta/analysis/kraken2.py +329 -0
  17. gmeta-0.1.0/src/gmeta/analysis/metaphlan.py +106 -0
  18. gmeta-0.1.0/src/gmeta/analysis/profilers.py +410 -0
  19. gmeta-0.1.0/src/gmeta/analysis/qc.py +139 -0
  20. gmeta-0.1.0/src/gmeta/analysis/sylph.py +200 -0
  21. gmeta-0.1.0/src/gmeta/cli.py +769 -0
  22. gmeta-0.1.0/src/gmeta/config.py +60 -0
  23. gmeta-0.1.0/src/gmeta/data/genus_chinese_names.tsv +52 -0
  24. gmeta-0.1.0/src/gmeta/data/priority_pathogens.json +188 -0
  25. gmeta-0.1.0/src/gmeta/data/species_chinese_names.tsv +96 -0
  26. gmeta-0.1.0/src/gmeta/data/taxid_chinese_mapping.csv +94 -0
  27. gmeta-0.1.0/src/gmeta/dbfetch.py +307 -0
  28. gmeta-0.1.0/src/gmeta/dbstate.py +92 -0
  29. gmeta-0.1.0/src/gmeta/engine/__init__.py +1 -0
  30. gmeta-0.1.0/src/gmeta/engine/_env.py +72 -0
  31. gmeta-0.1.0/src/gmeta/report/__init__.py +50 -0
  32. gmeta-0.1.0/src/gmeta/report/excel.py +88 -0
  33. gmeta-0.1.0/src/gmeta/report/models.py +231 -0
  34. gmeta-0.1.0/src/gmeta/report/network.py +518 -0
  35. gmeta-0.1.0/src/gmeta/report/pdf.py +18 -0
  36. gmeta-0.1.0/src/gmeta/report/priority.py +37 -0
  37. gmeta-0.1.0/src/gmeta/report/render.py +60 -0
  38. gmeta-0.1.0/src/gmeta/samples.py +168 -0
  39. gmeta-0.1.0/src/gmeta/templates/report.html.j2 +112 -0
  40. gmeta-0.1.0/tests/conftest.py +66 -0
  41. gmeta-0.1.0/tests/integration/test_coverage_integration.py +82 -0
  42. gmeta-0.1.0/tests/unit/test_cli.py +97 -0
  43. gmeta-0.1.0/tests/unit/test_cli_net.py +60 -0
  44. gmeta-0.1.0/tests/unit/test_config.py +36 -0
  45. gmeta-0.1.0/tests/unit/test_coverage_parse.py +124 -0
  46. gmeta-0.1.0/tests/unit/test_dbfetch.py +74 -0
  47. gmeta-0.1.0/tests/unit/test_dbstate.py +115 -0
  48. gmeta-0.1.0/tests/unit/test_executors.py +288 -0
  49. gmeta-0.1.0/tests/unit/test_kraken2_parse.py +69 -0
  50. gmeta-0.1.0/tests/unit/test_network.py +126 -0
  51. gmeta-0.1.0/tests/unit/test_network_profilers.py +145 -0
  52. gmeta-0.1.0/tests/unit/test_profilers.py +160 -0
  53. gmeta-0.1.0/tests/unit/test_qc_host_parse.py +55 -0
  54. gmeta-0.1.0/tests/unit/test_report_models.py +71 -0
  55. gmeta-0.1.0/tests/unit/test_report_render.py +72 -0
  56. gmeta-0.1.0/tests/unit/test_samples.py +93 -0
gmeta-0.1.0/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ # pixi environments
2
+ .pixi/*
3
+ !.pixi/config.toml
4
+
5
+ # python
6
+ __pycache__/
7
+ *.py[cod]
8
+ *.egg-info/
9
+ dist/
10
+ build/
11
+ .pytest_cache/
12
+ .ruff_cache/
13
+ .coverage
14
+ htmlcov/
15
+
16
+ # gmeta outputs (anchored: never match src/gmeta/data, the bundled tables)
17
+ /gmeta-out/
18
+ /site/
19
+ /db-fetch/
20
+ /data/
@@ -0,0 +1,38 @@
1
+ # Changelog
2
+
3
+ 本项目所有显著变更记录于此。
4
+ 格式基于 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),
5
+ 版本遵循 [Semantic Versioning](https://semver.org/lang/zh-CN/)。
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.0] - 2026-11-07
10
+
11
+ 首个发行版:宏基因组(mNGS)分析与监测报告工具,自 gside 的 meta 层整体迁移并扩展。
12
+
13
+ ### Changed
14
+
15
+ - 数据库默认根目录不再指向包内路径:仓库检出用 `<repo>/data/db`(已 gitignore),pip 安装用 XDG 数据目录(`~/.local/share/gmeta/db`)——gmeta 的数据库全部是外部下载的大文件,`site-packages` 不可写也不该存放。`$GMETA_DB_DIR` 仍最优先。移除了从未实际生效的 `GMETA_DATA_DIR`(中文名表本就随包分发)。
16
+ - `gmeta db list` 重写:覆盖全部 8 个数据库目标(kraken2/centrifuge/kaiju/metaphlan/kmcp/sylph/taxdump/host),每个探针直接复用执行器的 resolver(就绪 = 分析软件会真正接受该路径,含 bracken kmer_distrib、kaiju names.dmp、kmcp taxdump 等伴生文件校验);默认 Rich 表格输出,`-f json` 提供稳定机器契约。新增 `gmeta/dbstate.py`。
17
+ - `resolve_sylph_db` 从 `profile_sylph` 中抽出复用;kmcp 的 taxdump 查找支持兄弟目录布局(`$DB_ROOT/kmcp` + `$DB_ROOT/taxdump`);kraken2 缺库错误提示统一指向 `gmeta db fetch`。
18
+ - `gmeta run` 批量模式(自 gside `scan --meta` 体系移植):`-S/--samples` 清单(`sample_id<TAB>reads [<TAB>reads2]`,表头可选、# 注释、重复 id 拒绝)、位置参数多样本按 mate 标记分组(`A_R1 A_R2 B_R1 B_R2` → 两样本)、`-J/--jobs` 线程池并行(输出保持清单顺序);批量每样本一个输出目录,stdout 每样本一行 JSON,单样本失败不中断整批。`-s/--sample-id` 变为可选(单样本可从文件名推导)。新增 `gmeta/samples.py`。
19
+ - `gmeta run` 执行器扩展:centrifuge(比对 + `centrifuge-kreport` 转 kreport,复用树形精确路径)、kaiju(比对 + 种/属双 rank kaiju2table)、MetaPhlAn(`-t rel_ab_w_read_stats`,种序列数可用)、KMCP(官方推荐的 search 单端模式 + profile --level species)。`-m/--method` 现支持 kraken2/sylph/centrifuge/kaiju/metaphlan/kmcp。
20
+ - `gmeta db fetch`:生成数据库下载 shell 脚本(不代执行),目标 kraken2/centrifuge/kaiju/metaphlan/kmcp/sylph/taxdump/host,含可续传下载函数、目录校验、run_all.sh;kmcp 预建库为 OneDrive/网盘发布,脚本自动下载 taxdump 并指引手动步骤。
21
+ - `engine/_env.run_to_file`:stdout 流式落盘执行(centrifuge 系工具用)。
22
+ - sylph 下 fetch 脚本地址更新为官方预建库(gside 同源验证过的 googleapis 地址)。
23
+ - MetaPhlAn 解析器按表头名识别 `estimated_number_of_reads_from_the_clade` 列(rel_ab_w_read_stats),种序列数不再恒为 0。
24
+ - 第三方 mNGS 分析软件导入支持(解析+导出,不含执行):Centrifuge(原生 report,属级行直接采信)、Kaiju(kaiju2table,可附属级表)、MetaPhlAn(v3/v4 profile)、KMCP(compute profile,按 taxid 聚合参考行)。
25
+ - `analysis/profilers.py`:统一 `AbundanceProfile` 规范化模型(物种/属丰度行)、四工具解析器、格式自动嗅探 `detect_profiler`(含 kraken2/bracken/sylph 共 7 种)。相对丰度优先采信软件自带数值(百分比/比例量纲按列总和自动判定),缺失时由读数重算。
26
+ - `report/network.py`:`build_rows_from_profile` 通用识别网适配层——表格式软件的属序列数优先用真实属级行,否则由种读数聚合;`profile_to_network_rows` 统一入口(kraken2 走树形精确路径,其余走适配层)。
27
+ - `gmeta net build` 输入扩展为任意支持格式(自动嗅探 / `--profiler` 强制指定 / `--kaiju-genus` 补属级数据);`gmeta report` 新增 `--centrifuge/--kaiju/--metaphlan/--kmcp` 输入。
28
+ - 交叉验证:同一数据经 centrifuge 格式路径与 kraken2 kreport 树形路径生成识别网表,10/10 行一致。
29
+ - mkdocs 文档站(material + 中英双语):安装/使用/识别网导出/分析软件/覆盖度/架构/格式规范/JSON 契约/开发指南。
30
+ - `gmeta net build`:国家致病菌识别网"混合样本"上报格式。整合原有 kraken2 结果转换脚本:kreport 属/种配对(缩进树解析)、属/种中文名映射(taxid 表 + 拉丁名表)、参考基因组 manifest 解析、minimap2+samtools 种基因组覆盖度计算(合并参考/逐参考两种模式,纯 Python 流式统计,无 numpy/pandas 依赖)、批量多样本工作簿 + 按样本拆分 + 审核明细 sheet。实测与旧流程输出逐行一致。
31
+ - 修正 kreport 解析的列序(col2=clade 读段数、col3=直接读段数),kreport 行新增缩进深度 `depth` 用于属种树配对。
32
+ - samtools/centrifuge/kaiju/metaphlan/kmcp 加入 pixi 依赖。
33
+ - 项目骨架:pixi + src 布局 + hatchling,与 gside/gspec/gmlst 工具家族风格统一。
34
+ - `analysis/`:kraken2+bracken 解析与执行、sylph 解析与执行(自 gside meta 层移植,kreport 解析扩展至全分类层级)、fastp 质控、bowtie2 去宿主。
35
+ - `report/`:pydantic 报告数据模型、重点病原标注(内置监测列表)、JSON/HTML/Excel/PDF 四种渲染(HTML 与 PDF 共用 Jinja2 模板)。
36
+ - `gmeta run`:FASTQ → fastp → 去宿主 → kraken2/bracken 或 sylph → 多格式报告。
37
+ - `gmeta report`:从已有 kreport/bracken/fastp/sylph 结果直接生成报告。
38
+ - `gmeta db list`:数据库位置与状态检查。
gmeta-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 indexofire
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
gmeta-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,170 @@
1
+ Metadata-Version: 2.5
2
+ Name: gmeta
3
+ Version: 0.1.0
4
+ Summary: Metagenomic (mNGS) profiling and surveillance reporting — kraken2/bracken/sylph analysis to China CDC pathogen-network reports
5
+ Project-URL: Homepage, https://github.com/indexofire/gmeta
6
+ Project-URL: Documentation, https://indexofire.github.io/gmeta/
7
+ Project-URL: Repository, https://github.com/indexofire/gmeta
8
+ Project-URL: Issues, https://github.com/indexofire/gmeta/issues
9
+ Project-URL: Changelog, https://github.com/indexofire/gmeta/blob/main/CHANGELOG.md
10
+ Author-email: indexofire <indexofire@gmail.com>
11
+ License: MIT
12
+ License-File: LICENSE
13
+ Keywords: bioinformatics,bracken,kraken2,mNGS,metagenomics,surveillance,sylph
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: POSIX :: Linux
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
21
+ Requires-Python: <3.13,>=3.12
22
+ Requires-Dist: click>=8.1
23
+ Requires-Dist: jinja2>=3.1
24
+ Requires-Dist: openpyxl>=3.1
25
+ Requires-Dist: pydantic>=2.7
26
+ Requires-Dist: pyyaml>=6.0
27
+ Requires-Dist: rich>=13
28
+ Requires-Dist: weasyprint>=62
29
+ Provides-Extra: dev
30
+ Requires-Dist: pyright>=1.1; extra == 'dev'
31
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
32
+ Requires-Dist: pytest>=8.0; extra == 'dev'
33
+ Requires-Dist: ruff>=0.5; extra == 'dev'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # gmeta
37
+
38
+ 宏基因组(mNGS)分析与监测报告工具 — 从测序数据到国家致病菌识别网监测报告、突发疫情宏基因组测序报告。
39
+
40
+ `gmeta` 与 [gside](../gside)(单菌物种鉴定)、[gmlst](../gmlst)(基因组分型)同一工具家族:纯 Python CLI(Python 3.12),外部生信工具经 pixi(bioconda)管理,风格与输出结构保持一致。
41
+
42
+ ## 功能
43
+
44
+ - **mNGS 全流程** `gmeta run`:fastp 质控 → bowtie2 去宿主 → 物种丰度分析,支持 **6 种分析软件**:kraken2+bracken、sylph、centrifuge、kaiju、MetaPhlAn、KMCP
45
+ - **结果解析出报告** `gmeta report`:直接导入已有分析结果(同样 6 种软件的 8 种格式),无需重跑
46
+ - **识别网上报** `gmeta net build`:分析结果 → 国家致病菌识别网"混合样本"模板格式(属/种中文名、序列数、相对丰度、种基因组覆盖度),支持批量样本、按样本拆分、覆盖度自动计算、**格式自动嗅探**
47
+ - **数据库管理** `gmeta db fetch`:生成各数据库的可续传下载脚本(不代跑,URL 可审查),`gmeta db list` 检查数据库状态
48
+ - **报告输出**:JSON(结构化)、HTML(网页)、Excel(上报数据交换)、PDF(正式文档),同一数据模型四种渲染
49
+ - **重点病原标注**:内置监测重点病原列表(甲类/乙类传染病、监测重点、突发疫情防控、呼吸道病原),检出自动标注中文名与类别
50
+ - **MAGs 分析**(规划中):bin 质量评估、物种归属、基因组汇总
51
+
52
+ ### 支持的 mNGS 分析软件
53
+
54
+ | 软件 | 执行(`run -m`) | 导入格式 | 识别网属计数来源 |
55
+ |---|:---:|---|---|
56
+ | kraken2 (+bracken) | ✅ | kreport / bracken 表 | 树形解析,真实 clade 计数 |
57
+ | sylph | ✅ | profile TSV | 种读数聚合 |
58
+ | centrifuge | ✅ | 原生 report 或 kreport | 原生属级行 |
59
+ | kaiju | ✅ | kaiju2table(种级+属级) | 属级表 |
60
+ | MetaPhlAn | ✅ | profile(v3/v4) | `g__` 属级行 |
61
+ | KMCP | ✅ | compute profile TSV | 种读数聚合 |
62
+
63
+ ## 安装
64
+
65
+ ```bash
66
+ pixi install # 解析 conda + pypi 依赖(kraken2/bracken/fastp/bowtie2/sylph/minimap2)
67
+ pixi run test # dev 环境跑测试
68
+ ```
69
+
70
+ ## 快速上手
71
+
72
+ ### 全流程(从 FASTQ 开始)
73
+
74
+ ```bash
75
+ gmeta run sample_R1.fq.gz sample_R2.fq.gz \
76
+ -s SAMPLE-001 \ # 样本编号
77
+ -D /data/db/kraken2 \ # kraken2+bracken 数据库
78
+ --host-index /data/db/hg19 \ # 宿主 bowtie2 索引(可省略,跳过去宿主)
79
+ -f json -f html -f xlsx -f pdf \
80
+ -O gmeta-out/SAMPLE-001
81
+ ```
82
+
83
+ ### 从已有结果出报告
84
+
85
+ ```bash
86
+ # JSON 到 stdout
87
+ gmeta report -s SAMPLE-001 --bracken bracken.txt --kreport kreport.txt --fastp-json fastp.json
88
+
89
+ # 四种格式,按扩展名分发
90
+ gmeta report -s SAMPLE-001 --bracken bracken.txt -o SAMPLE-001.report.html
91
+ gmeta report -s SAMPLE-001 --bracken bracken.txt -o SAMPLE-001.report.xlsx
92
+ gmeta report -s SAMPLE-001 --bracken bracken.txt -o SAMPLE-001.report.pdf
93
+ ```
94
+
95
+ ### 识别网上报(国家致病菌识别网"混合样本"模板)
96
+
97
+ ```bash
98
+ # 自动嗅探输入格式(kraken2/bracken/centrifuge/kaiju/metaphlan/kmcp/sylph 可混用)
99
+ gmeta net build results/*.{report,tsv,txt} -o 识别网上报.xlsx --split-dir result/ --top 10
100
+
101
+ # 指定软件类型 / kaiju 补充属级表
102
+ gmeta net build sample.kmcp.tsv --profiler kmcp -o 识别网上报.xlsx
103
+ gmeta net build sample.species.tsv --kaiju-genus sample.genus.tsv -o 识别网上报.xlsx
104
+
105
+ # 含种基因组覆盖度:提供原始 reads + 参考基因组 manifest(CSV:
106
+ # accession,species_taxid,organism_taxid,scientific_name,file_path)
107
+ gmeta net build kraken/*.report \
108
+ --reads-dir raw_reads --reads-pattern "{sample}_R{pair}.fastq.gz" \
109
+ --manifest ref_genome_manifest.csv \
110
+ -o 识别网上报.xlsx --split-dir result/ --details coverage_details.tsv
111
+ ```
112
+
113
+ - 输出工作簿含两个 sheet:**混合样本**(模板 8 列:样本名称/属中文名/属序列数/属相对丰度/种中文名/种序列数/种基因组覆盖度/种相对丰度)+ **审核明细**(拉丁名、TaxID、accession、参考基因组、平均深度等)
114
+ - `--split-dir` 按样本另存单样本工作簿(每行填样本名,与上报要求一致)
115
+ - 覆盖度默认合并参考一次比对(快);`--per-species` 逐参考独立比对(精确、慢)
116
+ - 长读段用 `--preset map-ont` / `--preset map-pb`
117
+ - 属/种中文名取自内置映射表(`src/gmeta/data/*.tsv|csv`),未收录回退拉丁名
118
+ - 表格式软件(centrifuge/kaiju/metaphlan/kmcp)的属序列数:有属级行时直接采信,否则由种读数聚合;相对丰度优先采信软件自带数值
119
+
120
+ ### 数据库准备
121
+
122
+ ```bash
123
+ gmeta db list # 查看数据库位置与状态
124
+ gmeta db fetch # 生成全部数据库下载脚本 → ./db-fetch/
125
+ gmeta db fetch kraken2 kmcp -O scripts/ --db-root /data/db # 数据库默认: <repo>/data/db(仓库)或 ~/.local/share/gmeta/db(pip 安装),GMETA_DB_DIR 可覆盖
126
+ bash scripts/fetch-kraken2.sh # 审查 URL 后自行运行(可断点续传)
127
+ bash scripts/run_all.sh # 或按顺序全部执行
128
+ ```
129
+
130
+ kmcp 预建库在 OneDrive/网盘(无稳定 wget 地址),其脚本会自动下载 NCBI
131
+ taxdump 并给出手动下载指引;其余数据库(minikraken2、centrifuge 索引、kaiju
132
+ nr_ezh、metaphlan 标记库、sylph sketch、GRCh38 宿主索引)脚本直接下载。
133
+
134
+ ## 文档
135
+
136
+ 完整文档(中英双语):`pixi run -e dev docs` 本地预览,或
137
+ https://indexofire.github.io/gmeta/
138
+
139
+ ## 报告判读
140
+
141
+ - 丰度:物种读段占比(bracken 估计读数 / sylph 分类丰度)
142
+ - 置信度:high ≥10%、medium ≥1%、low <1%(sylph:ANI ≥95% 为 high、≥90% 为 medium)
143
+ - 重点病原:命中内置监测列表时在报告中单独提示(含中文名与监测类别)
144
+ - 结果需结合临床与流行病学信息判读,不作为唯一诊断依据
145
+
146
+ ## 项目结构
147
+
148
+ ```
149
+ src/gmeta/
150
+ ├── cli.py # click CLI:run / report / db
151
+ ├── config.py # GMETA_* 环境变量、pixi-aware 二进制定位
152
+ ├── engine/_env.py # require_bin + run_checked(与 gside 同源)
153
+ ├── analysis/ # kraken2/bracken、sylph(移植自 gside meta 层)+ fastp、bowtie2
154
+ ├── report/ # pydantic 数据模型、优先病原标注、JSON/HTML/Excel/PDF 渲染
155
+ └── templates/ # Jinja2 报告模板(HTML 与 PDF 共用)
156
+ ```
157
+
158
+ ## 开发
159
+
160
+ ```bash
161
+ pixi run -e dev check # ruff lint + format 检查
162
+ pixi run -e dev fix # 自动修复
163
+ pixi run -e dev typecheck # pyright
164
+ pixi run -e dev test # pytest
165
+ pixi run -e dev cov # pytest + coverage
166
+ ```
167
+
168
+ ## License
169
+
170
+ MIT
gmeta-0.1.0/README.md ADDED
@@ -0,0 +1,135 @@
1
+ # gmeta
2
+
3
+ 宏基因组(mNGS)分析与监测报告工具 — 从测序数据到国家致病菌识别网监测报告、突发疫情宏基因组测序报告。
4
+
5
+ `gmeta` 与 [gside](../gside)(单菌物种鉴定)、[gmlst](../gmlst)(基因组分型)同一工具家族:纯 Python CLI(Python 3.12),外部生信工具经 pixi(bioconda)管理,风格与输出结构保持一致。
6
+
7
+ ## 功能
8
+
9
+ - **mNGS 全流程** `gmeta run`:fastp 质控 → bowtie2 去宿主 → 物种丰度分析,支持 **6 种分析软件**:kraken2+bracken、sylph、centrifuge、kaiju、MetaPhlAn、KMCP
10
+ - **结果解析出报告** `gmeta report`:直接导入已有分析结果(同样 6 种软件的 8 种格式),无需重跑
11
+ - **识别网上报** `gmeta net build`:分析结果 → 国家致病菌识别网"混合样本"模板格式(属/种中文名、序列数、相对丰度、种基因组覆盖度),支持批量样本、按样本拆分、覆盖度自动计算、**格式自动嗅探**
12
+ - **数据库管理** `gmeta db fetch`:生成各数据库的可续传下载脚本(不代跑,URL 可审查),`gmeta db list` 检查数据库状态
13
+ - **报告输出**:JSON(结构化)、HTML(网页)、Excel(上报数据交换)、PDF(正式文档),同一数据模型四种渲染
14
+ - **重点病原标注**:内置监测重点病原列表(甲类/乙类传染病、监测重点、突发疫情防控、呼吸道病原),检出自动标注中文名与类别
15
+ - **MAGs 分析**(规划中):bin 质量评估、物种归属、基因组汇总
16
+
17
+ ### 支持的 mNGS 分析软件
18
+
19
+ | 软件 | 执行(`run -m`) | 导入格式 | 识别网属计数来源 |
20
+ |---|:---:|---|---|
21
+ | kraken2 (+bracken) | ✅ | kreport / bracken 表 | 树形解析,真实 clade 计数 |
22
+ | sylph | ✅ | profile TSV | 种读数聚合 |
23
+ | centrifuge | ✅ | 原生 report 或 kreport | 原生属级行 |
24
+ | kaiju | ✅ | kaiju2table(种级+属级) | 属级表 |
25
+ | MetaPhlAn | ✅ | profile(v3/v4) | `g__` 属级行 |
26
+ | KMCP | ✅ | compute profile TSV | 种读数聚合 |
27
+
28
+ ## 安装
29
+
30
+ ```bash
31
+ pixi install # 解析 conda + pypi 依赖(kraken2/bracken/fastp/bowtie2/sylph/minimap2)
32
+ pixi run test # dev 环境跑测试
33
+ ```
34
+
35
+ ## 快速上手
36
+
37
+ ### 全流程(从 FASTQ 开始)
38
+
39
+ ```bash
40
+ gmeta run sample_R1.fq.gz sample_R2.fq.gz \
41
+ -s SAMPLE-001 \ # 样本编号
42
+ -D /data/db/kraken2 \ # kraken2+bracken 数据库
43
+ --host-index /data/db/hg19 \ # 宿主 bowtie2 索引(可省略,跳过去宿主)
44
+ -f json -f html -f xlsx -f pdf \
45
+ -O gmeta-out/SAMPLE-001
46
+ ```
47
+
48
+ ### 从已有结果出报告
49
+
50
+ ```bash
51
+ # JSON 到 stdout
52
+ gmeta report -s SAMPLE-001 --bracken bracken.txt --kreport kreport.txt --fastp-json fastp.json
53
+
54
+ # 四种格式,按扩展名分发
55
+ gmeta report -s SAMPLE-001 --bracken bracken.txt -o SAMPLE-001.report.html
56
+ gmeta report -s SAMPLE-001 --bracken bracken.txt -o SAMPLE-001.report.xlsx
57
+ gmeta report -s SAMPLE-001 --bracken bracken.txt -o SAMPLE-001.report.pdf
58
+ ```
59
+
60
+ ### 识别网上报(国家致病菌识别网"混合样本"模板)
61
+
62
+ ```bash
63
+ # 自动嗅探输入格式(kraken2/bracken/centrifuge/kaiju/metaphlan/kmcp/sylph 可混用)
64
+ gmeta net build results/*.{report,tsv,txt} -o 识别网上报.xlsx --split-dir result/ --top 10
65
+
66
+ # 指定软件类型 / kaiju 补充属级表
67
+ gmeta net build sample.kmcp.tsv --profiler kmcp -o 识别网上报.xlsx
68
+ gmeta net build sample.species.tsv --kaiju-genus sample.genus.tsv -o 识别网上报.xlsx
69
+
70
+ # 含种基因组覆盖度:提供原始 reads + 参考基因组 manifest(CSV:
71
+ # accession,species_taxid,organism_taxid,scientific_name,file_path)
72
+ gmeta net build kraken/*.report \
73
+ --reads-dir raw_reads --reads-pattern "{sample}_R{pair}.fastq.gz" \
74
+ --manifest ref_genome_manifest.csv \
75
+ -o 识别网上报.xlsx --split-dir result/ --details coverage_details.tsv
76
+ ```
77
+
78
+ - 输出工作簿含两个 sheet:**混合样本**(模板 8 列:样本名称/属中文名/属序列数/属相对丰度/种中文名/种序列数/种基因组覆盖度/种相对丰度)+ **审核明细**(拉丁名、TaxID、accession、参考基因组、平均深度等)
79
+ - `--split-dir` 按样本另存单样本工作簿(每行填样本名,与上报要求一致)
80
+ - 覆盖度默认合并参考一次比对(快);`--per-species` 逐参考独立比对(精确、慢)
81
+ - 长读段用 `--preset map-ont` / `--preset map-pb`
82
+ - 属/种中文名取自内置映射表(`src/gmeta/data/*.tsv|csv`),未收录回退拉丁名
83
+ - 表格式软件(centrifuge/kaiju/metaphlan/kmcp)的属序列数:有属级行时直接采信,否则由种读数聚合;相对丰度优先采信软件自带数值
84
+
85
+ ### 数据库准备
86
+
87
+ ```bash
88
+ gmeta db list # 查看数据库位置与状态
89
+ gmeta db fetch # 生成全部数据库下载脚本 → ./db-fetch/
90
+ gmeta db fetch kraken2 kmcp -O scripts/ --db-root /data/db # 数据库默认: <repo>/data/db(仓库)或 ~/.local/share/gmeta/db(pip 安装),GMETA_DB_DIR 可覆盖
91
+ bash scripts/fetch-kraken2.sh # 审查 URL 后自行运行(可断点续传)
92
+ bash scripts/run_all.sh # 或按顺序全部执行
93
+ ```
94
+
95
+ kmcp 预建库在 OneDrive/网盘(无稳定 wget 地址),其脚本会自动下载 NCBI
96
+ taxdump 并给出手动下载指引;其余数据库(minikraken2、centrifuge 索引、kaiju
97
+ nr_ezh、metaphlan 标记库、sylph sketch、GRCh38 宿主索引)脚本直接下载。
98
+
99
+ ## 文档
100
+
101
+ 完整文档(中英双语):`pixi run -e dev docs` 本地预览,或
102
+ https://indexofire.github.io/gmeta/
103
+
104
+ ## 报告判读
105
+
106
+ - 丰度:物种读段占比(bracken 估计读数 / sylph 分类丰度)
107
+ - 置信度:high ≥10%、medium ≥1%、low <1%(sylph:ANI ≥95% 为 high、≥90% 为 medium)
108
+ - 重点病原:命中内置监测列表时在报告中单独提示(含中文名与监测类别)
109
+ - 结果需结合临床与流行病学信息判读,不作为唯一诊断依据
110
+
111
+ ## 项目结构
112
+
113
+ ```
114
+ src/gmeta/
115
+ ├── cli.py # click CLI:run / report / db
116
+ ├── config.py # GMETA_* 环境变量、pixi-aware 二进制定位
117
+ ├── engine/_env.py # require_bin + run_checked(与 gside 同源)
118
+ ├── analysis/ # kraken2/bracken、sylph(移植自 gside meta 层)+ fastp、bowtie2
119
+ ├── report/ # pydantic 数据模型、优先病原标注、JSON/HTML/Excel/PDF 渲染
120
+ └── templates/ # Jinja2 报告模板(HTML 与 PDF 共用)
121
+ ```
122
+
123
+ ## 开发
124
+
125
+ ```bash
126
+ pixi run -e dev check # ruff lint + format 检查
127
+ pixi run -e dev fix # 自动修复
128
+ pixi run -e dev typecheck # pyright
129
+ pixi run -e dev test # pytest
130
+ pixi run -e dev cov # pytest + coverage
131
+ ```
132
+
133
+ ## License
134
+
135
+ MIT
@@ -0,0 +1,93 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "gmeta"
7
+ version = "0.1.0"
8
+ description = "Metagenomic (mNGS) profiling and surveillance reporting — kraken2/bracken/sylph analysis to China CDC pathogen-network reports"
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ requires-python = ">=3.12,<3.13"
12
+ authors = [
13
+ { name = "indexofire", email = "indexofire@gmail.com" },
14
+ ]
15
+ keywords = [
16
+ "metagenomics",
17
+ "mNGS",
18
+ "kraken2",
19
+ "bracken",
20
+ "sylph",
21
+ "surveillance",
22
+ "bioinformatics",
23
+ ]
24
+ classifiers = [
25
+ "Development Status :: 3 - Alpha",
26
+ "Intended Audience :: Science/Research",
27
+ "Topic :: Scientific/Engineering :: Bio-Informatics",
28
+ "License :: OSI Approved :: MIT License",
29
+ "Programming Language :: Python :: 3",
30
+ "Programming Language :: Python :: 3.12",
31
+ "Operating System :: POSIX :: Linux",
32
+ ]
33
+ dependencies = [
34
+ "click>=8.1",
35
+ "jinja2>=3.1",
36
+ "openpyxl>=3.1",
37
+ "pydantic>=2.7",
38
+ "pyyaml>=6.0",
39
+ "rich>=13",
40
+ "weasyprint>=62",
41
+ ]
42
+
43
+ [project.optional-dependencies]
44
+ dev = [
45
+ "pytest>=8.0",
46
+ "pytest-cov>=5.0",
47
+ "ruff>=0.5",
48
+ "pyright>=1.1",
49
+ ]
50
+
51
+ [project.scripts]
52
+ gmeta = "gmeta.cli:main"
53
+
54
+ [project.urls]
55
+ Homepage = "https://github.com/indexofire/gmeta"
56
+ Documentation = "https://indexofire.github.io/gmeta/"
57
+ Repository = "https://github.com/indexofire/gmeta"
58
+ Issues = "https://github.com/indexofire/gmeta/issues"
59
+ Changelog = "https://github.com/indexofire/gmeta/blob/main/CHANGELOG.md"
60
+
61
+ [tool.hatch.build.targets.wheel]
62
+ packages = ["src/gmeta"]
63
+
64
+ [tool.hatch.build.targets.sdist]
65
+ include = ["/src", "/README.md", "/LICENSE", "/CHANGELOG.md", "/tests"]
66
+
67
+ [tool.ruff]
68
+ target-version = "py312"
69
+ line-length = 100
70
+
71
+ [tool.ruff.lint]
72
+ select = ["E", "F", "I", "UP", "B", "SIM"]
73
+ ignore = []
74
+
75
+ [tool.ruff.lint.per-file-ignores]
76
+ # kreport/bracken fixtures embed the raw column layout verbatim
77
+ "tests/conftest.py" = ["E501"]
78
+ # kmcp 17-column literal TSV rows cannot be wrapped
79
+ "tests/unit/test_executors.py" = ["E501"]
80
+
81
+ [tool.ruff.format]
82
+ quote-style = "double"
83
+ indent-style = "space"
84
+
85
+ [tool.pytest.ini_options]
86
+ testpaths = ["tests"]
87
+ addopts = "-q"
88
+
89
+ [tool.coverage.run]
90
+ source = ["gmeta"]
91
+
92
+ [tool.coverage.report]
93
+ skip_covered = true
@@ -0,0 +1,15 @@
1
+ """gmeta — metagenomic (mNGS) profiling and surveillance reporting."""
2
+
3
+ from __future__ import annotations
4
+
5
+ try:
6
+ from importlib.metadata import PackageNotFoundError, version
7
+
8
+ try:
9
+ __version__ = version("gmeta")
10
+ except PackageNotFoundError:
11
+ __version__ = "0.1.0.dev"
12
+ except Exception: # pragma: no cover — extremely defensive fallback
13
+ __version__ = "0.1.0.dev"
14
+
15
+ __all__ = ["__version__"]
@@ -0,0 +1,6 @@
1
+ """Entry point for ``python -m gmeta``."""
2
+
3
+ from gmeta.cli import main
4
+
5
+ if __name__ == "__main__":
6
+ main()
@@ -0,0 +1,125 @@
1
+ """Metagenomic profilers: kraken2/bracken, sylph (ported from gside) plus
2
+ centrifuge, kaiju, metaphlan, kmcp executors, third-party profile parsers,
3
+ and the mNGS pre-processing steps (fastp QC, bowtie2 host removal).
4
+ """
5
+
6
+ from gmeta.analysis._envelope import METAGENOMIC, MethodEnvelope
7
+ from gmeta.analysis.centrifuge import (
8
+ CentrifugeResult,
9
+ profile_centrifuge,
10
+ resolve_centrifuge_db,
11
+ run_centrifuge,
12
+ run_centrifuge_kreport,
13
+ )
14
+ from gmeta.analysis.coverage import (
15
+ CoverageStats,
16
+ ManifestEntry,
17
+ coverage_for_species,
18
+ coverage_per_species,
19
+ discover_reads,
20
+ fasta_sequence_lengths,
21
+ load_manifest,
22
+ resolve_reference,
23
+ )
24
+ from gmeta.analysis.host import HostRemovalStats, run_host_removal
25
+ from gmeta.analysis.kaiju import (
26
+ KaijuResult,
27
+ profile_kaiju,
28
+ resolve_kaiju_db,
29
+ run_kaiju,
30
+ run_kaiju2table,
31
+ )
32
+ from gmeta.analysis.kmcp import (
33
+ KmcpResult,
34
+ profile_kmcp,
35
+ resolve_kmcp_db,
36
+ run_kmcp_profile,
37
+ run_kmcp_search,
38
+ )
39
+ from gmeta.analysis.kraken2 import (
40
+ Kraken2Result,
41
+ KreportRow,
42
+ KreportSummary,
43
+ parse_bracken,
44
+ parse_kreport,
45
+ profile_kraken2,
46
+ resolve_kraken2_db,
47
+ run_bracken,
48
+ run_kraken2,
49
+ )
50
+ from gmeta.analysis.metaphlan import (
51
+ MetaphlanResult,
52
+ profile_metaphlan,
53
+ resolve_metaphlan_db,
54
+ run_metaphlan,
55
+ )
56
+ from gmeta.analysis.profilers import (
57
+ AbundanceProfile,
58
+ TaxonAbundance,
59
+ attach_kaiju_genus,
60
+ detect_profiler,
61
+ parse_centrifuge_report,
62
+ parse_kaiju_table,
63
+ parse_kmcp_profile,
64
+ parse_metaphlan_profile,
65
+ )
66
+ from gmeta.analysis.qc import QcMetrics, parse_fastp_json, run_fastp
67
+ from gmeta.analysis.sylph import SylphResult, ani_confidence, parse_profile, profile_sylph
68
+
69
+ __all__ = [
70
+ "AbundanceProfile",
71
+ "CentrifugeResult",
72
+ "CoverageStats",
73
+ "HostRemovalStats",
74
+ "KaijuResult",
75
+ "KmcpResult",
76
+ "KreportRow",
77
+ "KreportSummary",
78
+ "Kraken2Result",
79
+ "ManifestEntry",
80
+ "METAGENOMIC",
81
+ "MetaphlanResult",
82
+ "MethodEnvelope",
83
+ "QcMetrics",
84
+ "SylphResult",
85
+ "TaxonAbundance",
86
+ "ani_confidence",
87
+ "attach_kaiju_genus",
88
+ "coverage_for_species",
89
+ "coverage_per_species",
90
+ "detect_profiler",
91
+ "discover_reads",
92
+ "fasta_sequence_lengths",
93
+ "load_manifest",
94
+ "parse_bracken",
95
+ "parse_centrifuge_report",
96
+ "parse_fastp_json",
97
+ "parse_kaiju_table",
98
+ "parse_kmcp_profile",
99
+ "parse_kreport",
100
+ "parse_metaphlan_profile",
101
+ "parse_profile",
102
+ "profile_centrifuge",
103
+ "profile_kaiju",
104
+ "profile_kmcp",
105
+ "profile_kraken2",
106
+ "profile_metaphlan",
107
+ "profile_sylph",
108
+ "resolve_centrifuge_db",
109
+ "resolve_kaiju_db",
110
+ "resolve_kmcp_db",
111
+ "resolve_kraken2_db",
112
+ "resolve_metaphlan_db",
113
+ "resolve_reference",
114
+ "run_bracken",
115
+ "run_centrifuge",
116
+ "run_centrifuge_kreport",
117
+ "run_fastp",
118
+ "run_host_removal",
119
+ "run_kaiju",
120
+ "run_kaiju2table",
121
+ "run_kraken2",
122
+ "run_kmcp_profile",
123
+ "run_kmcp_search",
124
+ "run_metaphlan",
125
+ ]
@@ -0,0 +1,26 @@
1
+ """Shared JSON envelope for per-method results (aligned with gside)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, field
6
+ from typing import Any, ClassVar
7
+
8
+ METAGENOMIC = "metagenomic_profiling"
9
+
10
+
11
+ @dataclass
12
+ class MethodEnvelope:
13
+ """Every profiler returns ``{analysis_type, method, database, result}``."""
14
+
15
+ analysis_type: ClassVar[str] = METAGENOMIC
16
+ method: str = ""
17
+ database: dict[str, str] = field(default_factory=dict)
18
+ result: dict[str, Any] = field(default_factory=dict)
19
+
20
+ def to_dict(self) -> dict[str, Any]:
21
+ return {
22
+ "analysis_type": self.analysis_type,
23
+ "method": self.method,
24
+ "database": self.database,
25
+ "result": self.result,
26
+ }