何时使用
需要用 PyOpenMS(OpenMS C++ 库的 Python 绑定)处理计算质谱数据时使用,覆盖蛋白质组学与代谢组学:
- 读写 10+ 种质谱格式(mzML/mzXML/featureXML/idXML 等),含大文件的索引按需加载。
- 信号处理:高斯/SG 平滑、质心化(峰检测)、归一化、去噪、基线扣除。
- 特征检测(
FeatureFinder)与跨样本的 RT 对齐 + 特征连接(共识图)。 - 肽段/蛋白鉴定:解析搜索引擎结果,做 target-decoy FDR 控制与蛋白推断。
- 非靶向代谢组学全流程:质心化 → 特征检测 → 加合物去电荷 → 对齐 → 连接 → 导出特征表。
触发词:PyOpenMS、OpenMS、质谱、mass spectrometry、mzML、LC-MS/MS、蛋白质组学、proteomics、代谢组学、metabolomics、峰检测、peak picking、特征检测、FDR、质心化、centroiding。
不该用(边界):
- 简单谱库匹配 / 代谢物谱图比对 → 用 matchms,更轻。
- 纯蛋白序列分析(FASTA 解析、BLAST,不涉质谱)→ 用 biopython。
- 不读质谱原始数据、只做统计/可视化的任务 → 直接用 pandas/numpy 即可。
步骤 / 指令
通用:所有算法都是 4 步范式 —— 实例化 → getParameters() → setValue(...) → setParameters(),再执行。发现参数:for k in params.keys(): print(k, params.getValue(k))。
- 装环境:
uv pip install pyopenms numpy pandas matplotlib(Python 3.8+)。 - 读数据:
MzMLFile().load(path, exp);大文件(>1 GB)用OnDiscMSExperiment按需取谱避免爆内存。 - 预处理:平滑(
GaussFilter或SavitzkyGolayFilter,二选一)→ 质心化PeakPickerHiRes(特征检测前必做) → 按需归一化/去噪/扣基线。 - 特征检测:
FeatureFinder.run("centroided", exp, features, params, seeds);代谢组学设isotopic_pattern:charge_low/high。 - 跨样本:
MapAlignmentAlgorithmPoseClustering对齐 RT →FeatureGroupingAlgorithmQT连接成ConsensusMap。 - 鉴定:
IdXMLFile().load(...)→FalseDiscoveryRate().apply(peptide_ids)→ 过滤 ≤1% FDR →BasicProteinInferenceAlgorithm蛋白推断。 - 导出:
features.get_df()/consensus.get_df()转 pandas 早做统计;to_csv落盘。
示例
快速加载 + 平滑 + 质心化:
import pyopenms as ms
exp = ms.MSExperiment()
ms.MzMLFile().load("sample.mzML", exp)
print(f"谱图: {exp.getNrSpectra()}, 色谱: {exp.getNrChromatograms()}")
gauss = ms.GaussFilter()
p = gauss.getParameters(); p.setValue("gaussian_width", 0.1); gauss.setParameters(p)
gauss.filterExperiment(exp)
picker = ms.PeakPickerHiRes()
centroided = ms.MSExperiment()
picker.pickExperiment(exp, centroided)
蛋白质组学:检测特征并导出:
ff = ms.FeatureFinder()
features = ms.FeatureMap()
params = ff.getParameters("centroided")
ff.run("centroided", centroided, features, params, ms.FeatureMap())
features.get_df().to_csv("proteomics_features.csv", index=False)
鉴定结果 1% FDR 过滤:
prot_ids, pep_ids = [], []
ms.IdXMLFile().load("search.idXML", prot_ids, pep_ids)
ms.FalseDiscoveryRate().apply(pep_ids)
for pid in pep_ids:
pid.setHits([h for h in pid.getHits() if h.getScore() <= 0.01])
肽段质量 / 酶切:
seq = ms.AASequence.fromString("PEPTIDER")
print(seq.getMonoWeight(), seq.getFormula())
dig = ms.ProteaseDigestion(); dig.setEnzyme("Trypsin")
peps = []
dig.digest(ms.AASequence.fromString("MKWVTFISLLLLFSSAYSRGVFRR"), peps)
注意事项
- 质心化是硬前置:
FeatureFinder只吃质心化数据;若特征图为空,多半是把 profile 数据直接喂了进去 —— 先跑PeakPickerHiRes。 - 处理是破坏性的:改动前先存原始
orig = ms.MSExperiment(exp)。 - profile vs centroid:
spec.getType()返回 1(profile)/ 2(centroid),部分算法挑类型。 - 大文件用
OnDiscMSExperiment索引按需加载,否则易 OOM。 - FDR 全为 1.0:搜索库没有 decoy 命中 —— 确认用了 target-decoy 库并核对打分方向。
- 特征数过少:调低
signal_to_noise(0.5–1.0),并放宽isotopic_pattern电荷范围。 - 连接过激:调小
distance_RT:max_difference(秒)与distance_MZ:max_difference(ppm)。 setValue类型错:数值用 float、枚举用 string,查params.getDescription(key)。- 提速:先按 MS level 过滤再处理,如
[s for s in exp if s.getMSLevel() == 1]。
互见
- related:
cheminformatics-toolkit—— 代谢组学小分子的结构/性质处理与注释配套 - related:
genomic-file-toolkit—— 同属生信文件 I/O 与组学数据处理思路 - related:
single-cell-rnaseq-analysis—— 另一类高维组学定量分析参照 - combines_with:
scientific-database-lookup—— 对检出的代谢物/蛋白做数据库注释 - combines_with:
gene-set-enrichment-analysis—— 蛋白鉴定结果接功能富集下游分析
本条采编自 jaechang-hits/SciAgent-Skills(CC-BY-4.0)。