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.2.tar.gz (163.7 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.2-py3-none-any.whl (165.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: unimodpy-0.1.2.tar.gz
  • Upload date:
  • Size: 163.7 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.2.tar.gz
Algorithm Hash digest
SHA256 287238f84cfe30d0fb67e886be2610bdd9a383688fa37e66d117f2a13578b048
MD5 70bfbe9c1cd1c2212986ef8d14d21da3
BLAKE2b-256 f66f78740cb9ed767a203934f50f13f5a856ba7a0a4dde29532c2fbe445021f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for unimodpy-0.1.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: unimodpy-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2e35de860413106d00f148857dc3d05cd95e0e37194d6aa66f9229645cac6c8e
MD5 2b9deab9d0fa6e803ed7040e4fa675fb
BLAKE2b-256 f1d83783dac34d9c020953da73092101f5fbaa0faa134355f5be31b5b1ff6f4f

See more details on using hashes here.

Provenance

The following attestation bundles were made for unimodpy-0.1.2-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