Skip to main content

Python library for parsing and querying the UNIMOD mass spectrometry modifications database.

Project description

unimodpy

CI PyPI version Python License: MIT

Python library for parsing and querying the UNIMOD mass spectrometry modifications database.

  • Zero dependencies
  • Bundled UNIMOD data (1,552 entries) — works offline out of the box
  • Typed, immutable data models (py.typed / PEP 561)

Installation

pip install unimodpy

Or with uv:

uv add unimodpy

Requires Python 3.12+. No third-party dependencies.

Quick Start

import unimodpy

# Load the bundled UNIMOD database (no file path needed)
db = unimodpy.load()

# Look up by ID
acetyl = db.get_by_id(1)          # integer
acetyl = db.get_by_id("UNIMOD:1") # UNIMOD accession string
acetyl = db["UNIMOD:1"]           # subscript notation

# Look up by name (case-insensitive)
phospho = db.get_by_name("Phospho")

# Full-text search across name, definition, and synonyms
hits = db.search("glycosyl")

print(acetyl)
# UNIMOD:1  Acetyl
#   Acetylation.
#   Formula  : C2H2O
#   Mass     : +42.010565 Da (mono)  +42.0373 Da (avg)
#   Sites (9):
#     1: K @ Anywhere [Post-translational]
#     ...

Refreshing from unimod.org

# Download the latest OBO and use it immediately
db = unimodpy.load(refresh=True)

# Or just download the file
path = unimodpy.download()                        # ~/.cache/unimodpy/UNIMOD.obo
path = unimodpy.download("/my/dir/UNIMOD.obo")    # custom destination

Loading a Custom File

db = unimodpy.load("/path/to/UNIMOD.obo")
# or low-level:
db = unimodpy.parse_obo("/path/to/UNIMOD.obo")

Working with Entries

Each UnimodEntry is a frozen dataclass:

entry = db.get_by_name("Carbamidomethyl")

entry.id                  # int — UNIMOD accession number
entry.name                # str
entry.delta_mono_mass     # float — monoisotopic mass shift in Da
entry.delta_avge_mass     # float — average mass shift in Da
entry.proforma_formula    # str — Hill-notation formula, e.g. "C3H5NO"
entry.dict_composition    # dict[str, int] — {"C": 3, "H": 5, "N": 1, "O": 1}
entry.synonyms            # tuple[str, ...] — alternative names
entry.specificities       # tuple[Specificity, ...] — site/position rules

for spec in entry.specificities:
    print(spec.site)            # Site enum, e.g. Site.C ("C")
    print(spec.position)        # Position enum, e.g. Position.ANYWHERE
    print(spec.classification)  # Classification enum
    for nl in spec.neutral_losses:
        print(nl.mono_mass, nl.proforma_formula)

Enums

Site, position, and classification values are typed StrEnum members:

from unimodpy import Site, Position, Classification

ptm_sites = [
    spec for spec in entry.specificities
    if spec.classification == Classification.POST_TRANSLATIONAL
    and spec.position == Position.ANYWHERE
]

API Overview

Symbol Description
load(source=None, *, refresh=False) Load the database. No args -> bundled file. refresh=True -> download first.
download(dest=None) Download latest OBO from unimod.org; returns Path.
parse_obo(path) Low-level: parse any OBO file at path.
UnimodDatabase Iterable collection with get_by_id, get_by_name, search, __getitem__.
UnimodEntry Frozen dataclass for one modification term.
Specificity Frozen dataclass for one site/position rule.
NeutralLoss Frozen dataclass for one neutral loss.
Site StrEnum of amino acid residues and termini.
Position StrEnum of sequence position constraints.
Classification StrEnum of modification classes.

Development

just install   # install dependencies with uv
just lint      # ruff check
just format    # ruff format
just ty        # ty type check
just test      # pytest
just check     # lint + type check + test

Related Projects

Package Description
uniprotptmpy Parse and query the UniProt PTM controlled vocabulary
psimodpy Parse and query the PSI-MOD protein modification ontology

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unimodpy-0.1.1.tar.gz (163.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unimodpy-0.1.1-py3-none-any.whl (165.1 kB view details)

Uploaded Python 3

File details

Details for the file unimodpy-0.1.1.tar.gz.

File metadata

  • Download URL: unimodpy-0.1.1.tar.gz
  • Upload date:
  • Size: 163.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for unimodpy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 47ff6d27920efb6ec71494d13d55dbf5c946c209cb4e89ba90679153de702b5e
MD5 dded512bdd2f7f215697d3118fefbcb6
BLAKE2b-256 0af129298d749117c76e6a56d7308b02e49eebc23058616beac477a50594c302

See more details on using hashes here.

Provenance

The following attestation bundles were made for unimodpy-0.1.1.tar.gz:

Publisher: release.yml on tacular-omics/unimodpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file unimodpy-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: unimodpy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 165.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for unimodpy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7f9b22982ba8a67cc1411d246baddba250cdb901335465489e5736fc174d0e6d
MD5 2aecaf0ab810ef79fb687bbfc93c2338
BLAKE2b-256 6f26bfc3a2da4dc695464c50b020b9dc3ba38df7fbe6d1edc6763b306cbb960a

See more details on using hashes here.

Provenance

The following attestation bundles were made for unimodpy-0.1.1-py3-none-any.whl:

Publisher: release.yml on tacular-omics/unimodpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page