msbuddy
msbuddy annotates molecular formulas for small molecules from mass spectrometry data. It accepts precursor m/z alone, MS1 isotope patterns, MS/MS spectra, or combinations of these inputs in positive or negative ionization mode. A precursor m/z and polarity are the minimum input.
Documentation · PyPI · Version updates and validation
Install
pip install msbuddy
The default v1.0 databases and v2.1.0 public model bundle (~50.4 MB total: formula_db_v1.0.msbdb, common_db_v1.0.msbdb, and ml_v2.1.0.joblib) download automatically on first use; the optional ml_compatibility_v2.0.1.joblib bundle (3.2 MB, ~53.6 MB combined) is fetched on demand only for MS1-only, precursor-mass-only, and --no-spectral (use_spectral=False) modes. Multiply-charged MS/MS spectra (|z| >= 2) run natively on the default v2.1.0 engine. Runs on CPU only; PyTorch and GPU/CUDA are not required. Python 3.8 or newer is supported.
Dependencies and tested environment
Runtime dependencies (declared in pyproject.toml): brain-isotopic-distribution, numpy (<2 on Python 3.8), numba, requests, joblib, gdown, chemparse, scipy, tqdm, pandas, lightgbm>=4.0, and onnxruntime (>=1.19.2,<2 on Python >=3.9; >=1.16.3,<1.19 on Python 3.8).
Tested reference environment: Python 3.11.18, brain-isotopic-distribution 1.5.19, numpy 2.4.6, numba 0.68.1, scipy 1.17.1, pandas 3.1.1, lightgbm 4.7.0, onnxruntime 1.32.0, joblib 1.6.0, requests 2.34.2, gdown 6.5.2, chemparse 0.3.2, tqdm 4.70.1.
What's new in 2.1
- Clean
v1.0formula and common fragment/loss databases: Purges DBE/SENIOR-invalid entries (formula_db_v1.0.msbdb), expands default element ceilings toC<=150,H<=300,N<=30,O<=50(withF<=80) and PFAS/glycan coverage, and introduces polarity-independent empiricalcommon_fragmentandcommon_losslog-frequency weights (common_db_v1.0.msbdb). - Strictly prior-free default policy: Uses instrument mass tolerances only (
orbitrap,fticr,tofwithqtof/timstofaliases) with no biological/databaseprior_modeintervention; halogens (F, Cl, Br, I) are enabled by default (halogen=True), and omitted adducts default to[M+H]+/[M-H]-(or[M±|z|H]|z|±for|z| >= 2). - Upgraded
adduct="auto"&|z| >= 2/ multi-spectrum support: Native|z| >= 2MS/MS scoring, multi-spectrum feature-group pooling (MetaFeature(ms2=[spec1, spec2])or same-identifier MGF scans), extendedmz < 5000precursor range, monomer-aware dimer (adduct.m >= 2) scoring, and a Stage-0 adduct head with cross-adduct joint Stage-3 reranking whenadduct="auto". - Physicochemical & isolation-window upgrades: ~1 Da isolation-aware MS2 fragment isotope log-likelihoods (
37Cl/81Br/34S/13C) that never penalize missing fragment isotopes,float64subformula DAG disambiguation (dbe < -0.5), DB-backedO < 2*Prelaxation, exact 12-element DB row matching, and radical DBE% 1.0fixes. - Low-FDR Stage-4 calibration & adduct-aware exports: Public-only distilled Stage 0–3 ONNX + LightGBM models with a 9-dimensional context-conditional
[ABSENT]Stage-4 calibrator forposterior_error_probabilityandbatch_q_value(estimate_batch_fdr()), plus adduct-awaremz_error_ppmin detailed exports.
Inputs and outputs
- Supported inputs: MGF files (
load_mgf/--mgf, grouping repeated scans with the same identifier for multi-spectrum pooling), GNPS USIs (load_usi/--usi), USI CSV files (--csv), and PythonMetaFeature/Spectrum/MsbuddyConfigobjects (|z| >= 1,mz < 5000, single or pooledms2=[spec1, spec2]). - Python outputs:
engine.get_summary()returns a list of dicts containingidentifier,mz,rt,adduct,formula_rank_1..formula_rank_5,estimated_fdr,posterior_error_probability, andbatch_q_value;engine.estimate_batch_fdr()computes dataset-wide top-1q_values. - CLI outputs: Writes
msbuddy_result_summary.tsv(withbatch_q_value); adding-d/--detailswrites per-featureformula_results.tsv(adduct-awaremz_error_ppm, explained peaks, probabilities, subformula assignments) plusms1_preprocessed.tsvandms2_preprocessed.tsv.
Python quick start
1. Annotate an MGF file
from msbuddy import Msbuddy, MsbuddyConfig
engine = Msbuddy(MsbuddyConfig(ms_instr="orbitrap")) # also supports "fticr" and "tof" ("qtof"/"timstof" aliases)
engine.load_mgf("input_file.mgf")
engine.annotate_formula()
results = engine.get_summary()
Halogens (F, Cl, Br, I) are searched by default; set MsbuddyConfig(halogen=False) only when prior knowledge rules out halogens. See the demo MGF, quick start, and configuration guide for more options.
2. Annotate from USIs
from msbuddy import Msbuddy, MsbuddyConfig
engine = Msbuddy(MsbuddyConfig(ms_instr="orbitrap"))
engine.load_usi([
"mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00003740036",
"mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00003740037",
])
engine.annotate_formula()
results = engine.get_summary()
3. Annotate spectra (including pooled MS2 and |z| >= 2) via Python API
from msbuddy import MetaFeature, Msbuddy, MsbuddyConfig, Spectrum
features = [
MetaFeature(
identifier="feature_1",
mz=181.0707,
charge=1,
adduct="[M+H]+", # optional; defaults to [M+H]+ / [M-H]-, or use "auto"
ms1=Spectrum([181.0707, 182.0741], [100.0, 6.7]), # optional MS1 isotope pattern
ms2=[ # single Spectrum or list of Spectra for multi-spectrum pooling
Spectrum([109.0284, 127.0390, 145.0495, 163.0601], [30.0, 60.0, 100.0, 80.0]),
Spectrum([109.0284, 127.0390, 145.0495], [45.0, 80.0, 100.0]),
],
),
MetaFeature(
identifier="feature_2",
mz=179.0561,
charge=-1,
ms2=Spectrum([89.0244, 101.0244, 119.0350, 161.0455], [100.0, 40.0, 70.0, 30.0]),
),
]
engine = Msbuddy(MsbuddyConfig(ms_instr="orbitrap"))
engine.add_data(features)
engine.annotate_formula()
results = engine.get_summary()
See the API reference for direct mass-to-formula search (mass_to_formula, mz_to_formula) and fragment subformula assignment (assign_subformula).
Command line
msbuddy -mgf input_file.mgf -output results -ms orbitrap -details
Run msbuddy --help for options (including --download-data, --download-compatibility, --no-halogen, and element bounds defaulting to C<=150, H<=300, N<=30, O<=50, F<=80). The command-line guide covers USIs, batch input, parallel processing, and exports.
Upgrading and contributing
See the migration guide when upgrading older scripts. Release details are in the version updates and changelog.
The annotation pipeline is in msbuddy/ and tests are in tests/. Run python -m unittest discover -s tests -v after installing development dependencies. See the development guide.
Citation
S. Xing et al. BUDDY: molecular formula discovery via bottom-up MS/MS interrogation. Nature Methods (2023). DOI: 10.1038/s41592-023-01850-x
License and contact
Apache License 2.0. Contact: sxing@fudan.edu.cn.
Metadata
Release files for msbuddy 2.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| msbuddy-2.1.0.tar.gz | 338.6 kB | Without provenance | Details for msbuddy-2.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| msbuddy-2.1.0-py3-none-any.whl | Python 3 | none | any | Details for msbuddy-2.1.0-py3-none-any.whl |
Total release size: 506.1 kB
Release files / msbuddy-2.1.0.tar.gz
| Download URL | msbuddy-2.1.0.tar.gz |
|---|---|
| Size | 338.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a848b3d483518a840eead81ec36fdac6b162bdc6e7cd5e0b19d43fd8aceb1974
|
|
BLAKE2b-256 checksum How to use checksums |
ce1591212af99c17c7725a1c757cf5527df2cd4697b54e41af1b833bf5fe10dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.8.18
|
Release files / msbuddy-2.1.0-py3-none-any.whl
| Download URL | msbuddy-2.1.0-py3-none-any.whl |
|---|---|
| Size | 167.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
710f69d02ce8c794eaa3d7dbca511d619ee4be30ff16c6e6164c366b7bd5d374
|
|
BLAKE2b-256 checksum How to use checksums |
cc242480b54148a1b0ef6cad33dd13f9812e8264c3fe62684856249875415a9b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.8.18
|
Security for msbuddy 2.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.