Python library for parsing and querying the UNIMOD mass spectrometry modifications database.
Project description
unimodpy
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47ff6d27920efb6ec71494d13d55dbf5c946c209cb4e89ba90679153de702b5e
|
|
| MD5 |
dded512bdd2f7f215697d3118fefbcb6
|
|
| BLAKE2b-256 |
0af129298d749117c76e6a56d7308b02e49eebc23058616beac477a50594c302
|
Provenance
The following attestation bundles were made for unimodpy-0.1.1.tar.gz:
Publisher:
release.yml on tacular-omics/unimodpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unimodpy-0.1.1.tar.gz -
Subject digest:
47ff6d27920efb6ec71494d13d55dbf5c946c209cb4e89ba90679153de702b5e - Sigstore transparency entry: 1189552306
- Sigstore integration time:
-
Permalink:
tacular-omics/unimodpy@82e6e09100d285db341cbfbb2d2d505701f4019c -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/tacular-omics
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@82e6e09100d285db341cbfbb2d2d505701f4019c -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f9b22982ba8a67cc1411d246baddba250cdb901335465489e5736fc174d0e6d
|
|
| MD5 |
2aecaf0ab810ef79fb687bbfc93c2338
|
|
| BLAKE2b-256 |
6f26bfc3a2da4dc695464c50b020b9dc3ba38df7fbe6d1edc6763b306cbb960a
|
Provenance
The following attestation bundles were made for unimodpy-0.1.1-py3-none-any.whl:
Publisher:
release.yml on tacular-omics/unimodpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unimodpy-0.1.1-py3-none-any.whl -
Subject digest:
7f9b22982ba8a67cc1411d246baddba250cdb901335465489e5736fc174d0e6d - Sigstore transparency entry: 1189552313
- Sigstore integration time:
-
Permalink:
tacular-omics/unimodpy@82e6e09100d285db341cbfbb2d2d505701f4019c -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/tacular-omics
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@82e6e09100d285db341cbfbb2d2d505701f4019c -
Trigger Event:
release
-
Statement type: