Skip to main content

msbuddy

Maintainer PyPI PyPI Downloads

msbuddy logo

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 model and formula databases (~40 MB total) download automatically on first use; optional MS1-only, mass-only, multiply-charged, and --no-spectral fallback models add only 3.2 MB (~43 MB for all modes combined). Runs on CPU only; PyTorch and GPU/CUDA are not required. Python 3.8 or newer is supported.

What's new in 2.0

  • Higher annotation accuracy: Improved formula ranking across positive and negative modes, diverse adducts/dimers, and halogenated compounds (F, Cl, Br, and I are searched by default).
  • Fast, lightweight CPU runtime: Scales cleanly across CPU cores with low memory usage—no GPU required.
  • Optional automatic adduct selection (adduct="auto"): Uses your provided adduct by default (or [M+H]+ / [M-H]- when omitted), with opt-in multi-adduct disambiguation when the adduct form is unknown.
  • Batch-level confidence: Reports per-feature posterior error probability (posterior_error_probability) and dataset-wide batch_q_value via estimate_batch_fdr().

Python quick start

1. Annotate an MGF file

from msbuddy import Msbuddy, MsbuddyConfig

engine = Msbuddy(MsbuddyConfig(ms_instr="orbitrap"))  # we also support "tof" and "fticr"
engine.load_mgf("input_file.mgf")
engine.annotate_formula()
results = engine.get_summary()

Halogens (F, Cl, Br, and 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 a list of spectra 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=Spectrum([109.0284, 127.0390, 145.0495, 163.0601], [30.0, 60.0, 100.0, 80.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. 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.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for msbuddy 2.0.1
File Size Uploaded Provenance Actions
msbuddy-2.0.1.tar.gz 240.6 kB Without provenance Details for msbuddy-2.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for msbuddy 2.0.1
File Interpreter ABI Platform Actions
msbuddy-2.0.1-py3-none-any.whl Python 3 none any Details for msbuddy-2.0.1-py3-none-any.whl

Total release size: 378.8 kB

Release files / msbuddy-2.0.1.tar.gz

Download URL msbuddy-2.0.1.tar.gz
Size 240.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1b2d72381e35c6f79bc4f42d65b26f3ccd9a5056b9bcc35c93a1ca9b699e981e
BLAKE2b-256 checksum
How to use checksums
ed52fcd7bdf5052f3688f50562564f6571b1c56daad6c176d00deb43e72411b6
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.1-py3-none-any.whl

Download URL msbuddy-2.0.1-py3-none-any.whl
Size 138.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a08a2a1c6b4076c29d32d638b1c3def8e23b4a4812618c4b421ee98464afdc8b
BLAKE2b-256 checksum
How to use checksums
d176e1ed8bdcc891f58423efdb001928a0130e7b6d1ac183247dbf2a89befce6
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.1

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.

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page