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 standard public-library model (ml_v2.0.0.joblib, 21.4 MB) and lossless formula databases (v0.4.0, 18.4 MB) download automatically on first use (~39.8 MB total in version 2.0). Inference runs on CPU via ONNX Runtime and LightGBM; PyTorch and CUDA are not required. Python 3.8 or newer is supported.
What's new in 2.0
- Unified four-stage CPU engine (
format_version=5): Combines an Exact-Mass Spectral Transformer with isobaric-contrastive alignment (ONNX), two-pass compilednogilNumba candidate generation + batchedFormulaEncoderV3shortlisting, 48-d compiled MS/MS physics (with internal MS1–MS2 self-recalibration) + 12-d analytical MS1 isotope scoring, and a FiLM-conditionedPureSetRerankerV3(ONNX) +LightGBMLambdaRank hybrid with calibrated[ABSENT]posteriors. - Fast shared-memory parallelism: Streams
formula_db_v0.4.0.msbdbdirectly into contiguousint16arrays (~520 MB peak RSS) and executesparallel=Trueacross a shared-memory thread pool without duplicating database memory. - Opt-in multi-adduct disambiguation (
adduct="auto"): Default known-adduct behavior ([M+H]+/[M-H]-when omitted) is unchanged. Passingadduct="auto"on singly charged queries ranks across common polarity-specific adducts and dimers with Bayesian prevalence log-priors against one shared[ABSENT]anchor and writes the top-ranked adduct back toMetaFeature.adduct. - Pooled batch FDR & signed delta-formula APIs:
get_summary()andestimate_batch_fdr()reportposterior_error_probabilityand collection-widebatch_q_value, andannotate_delta_mass()/annotate_network_delta()annotate signed elemental differences between molecular-network nodes without downloading a model or database. - Full evidence-mode fallback: MS1-only, mass-only, multiply-charged, and
use_spectral=Falsequeries lazily load the optional compatibility bundle (ml_compatibility_v1.3.0.joblib).
Python quick start
from msbuddy import Msbuddy, MsbuddyConfig
engine = Msbuddy(MsbuddyConfig(ms_instr="orbitrap"))
engine.load_mgf("input_file.mgf")
engine.annotate_formula()
results = engine.get_summary()
Use ms_instr="tof" for both QTOF and timsTOF, or "fticr" as appropriate. The older "qtof" and "timstof" settings remain accepted aliases for "tof". Acquisition metadata are optional. See the quick start and configuration guide for other inputs and settings.
Halogens (F, Cl, Br, and I) are searched by default. Set MsbuddyConfig(halogen=False) only when prior knowledge rules out halogens. Reported confidence values (posterior_error_probability, batch_q_value, and legacy estimated_fdr) are model-based estimates; see model settings and confidence for details.
MS/MS spectra can also be loaded by USI. A demo MGF and API reference are available. The API also supports direct formula mass searches, fragment subformula annotation, and signed molecular-network delta annotation:
from msbuddy import annotate_delta_mass, annotate_network_delta
changes = annotate_delta_mass(21.98194425, tolerance=0.001)
print(changes[0].formula) # -H+Na
edge = annotate_network_delta(
181.0706645565, 203.0526088063, "[M+H]+", "[M+Na]+",
source_formula="C6H12O6", preset="broad",
)
print(edge[0].formula, edge.adduct_delta) # 0 -H+Na
Command line
msbuddy -mgf input_file.mgf -output results -ms orbitrap -details
Run msbuddy --help for options. 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 and candidate-audit 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.0.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.0.0.tar.gz | 232.1 kB | Without provenance | Details for msbuddy-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| msbuddy-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for msbuddy-2.0.0-py3-none-any.whl |
Total release size: 363.7 kB
Release files / msbuddy-2.0.0.tar.gz
| Download URL | msbuddy-2.0.0.tar.gz |
|---|---|
| Size | 232.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5b536db465f3272257ea382bce6641f8956ab3fb006c4f0cc22de97eb13ceccf
|
|
BLAKE2b-256 checksum How to use checksums |
9c66d3591f38ae19ecc57af389bbc70d85252706e49bcf813bbdda98d6ad355c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.18
|
Release files / msbuddy-2.0.0-py3-none-any.whl
| Download URL | msbuddy-2.0.0-py3-none-any.whl |
|---|---|
| Size | 131.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e875fcf5124f722b5c1d8d4f30ebacbc8500f4afa7c2b0f7a91ef5bff1d277d7
|
|
BLAKE2b-256 checksum How to use checksums |
199cb12db2761567c80813b7b45751e69fdbf4717f5d226867b93c21c4ebae36
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.18
|
Security for msbuddy 2.0.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.