Skip to content

Commit

Permalink
Merge pull request #129 from mobiusklein/feature/use_psims_unimod_if_…
Browse files Browse the repository at this point in the history
…available

If psims is available, use its Unimod because it caches and vendors
  • Loading branch information
levitsky committed Oct 17, 2023
2 parents e2d4a8a + d44e77e commit 07ae745
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pyteomics/proforma.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@
np = None

try:
from psims.controlled_vocabulary.controlled_vocabulary import (load_psimod, load_xlmod, load_gno, obo_cache)
from psims.controlled_vocabulary.controlled_vocabulary import (load_psimod, load_xlmod, load_gno, obo_cache, load_unimod)
_has_psims = True
except ImportError:
def _needs_psims(name):
raise ImportError("Loading %s requires the `psims` library. To access it, please install `psims`" % name)

load_psimod = partial(_needs_psims, 'PSIMOD')
load_xlmod = partial(_needs_psims, 'XLMOD')
load_gno = partial(_needs_psims, 'GNO')
load_unimod = partial(_needs_psims, 'UNIMOD')
obo_cache = None
_has_psims = False

_water_mass = calculate_mass("H2O")

Expand Down Expand Up @@ -357,6 +360,8 @@ def __init__(self, **kwargs):
self.strict = kwargs.get("strict", True)

def load_database(self):
if _has_psims:
return obo_cache.resolve("http://www.unimod.org/obo/unimod.obo")
return Unimod()

def resolve(self, name=None, id=None, **kwargs):
Expand Down Expand Up @@ -392,9 +397,12 @@ def resolve(self, name=None, id=None, **kwargs):
'provider': self.name
}
else:
name = defn.ex_code_name
if not name:
name = defn.code_name
return {
"composition": defn.composition,
"name": defn.ex_code_name,
"name": name,
"id": defn.id,
"mass": defn.monoisotopic_mass,
"provider": self.name
Expand Down

0 comments on commit 07ae745

Please sign in to comment.