Skip to content

Commit

Permalink
changes in unimod parser
Browse files Browse the repository at this point in the history
  • Loading branch information
ypriverol committed Sep 4, 2023
1 parent 47d1af6 commit f5c91d6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 40 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pytest
requests
pyyaml
numpy
defusedxml
43 changes: 4 additions & 39 deletions sdrf_pipelines/openms/unimod.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
import xml.etree.ElementTree as et
import defusedxml.ElementTree as et

import pkg_resources

Expand Down Expand Up @@ -47,6 +47,9 @@ def get_delta_mono_mass(self):
def get_delta_composition(self):
return self._delta_composition

def to_str(self):
return f"{self.get_accession()} {self.get_name()} {self.get_delta_mono_mass()} {self.get_delta_composition()}"


class UnimodDatabase:
"""Wrapper for the Unimod database"""
Expand Down Expand Up @@ -120,44 +123,6 @@ def _get_modifications(self, node):
mod = PostTranslationalModification(ontology_term, ma["delta_composition"], sites, ma["delta_mono_mass"])
self.modifications.append(mod)

def get_label(self, label):
mod = self.modifications.get(label, None)
return mod

def get_element(self, name):
el = self.elements.get(name, None)
return el

def list_labels(self, search):
labels = []
lre = re.compile(search)
for k in self.modifications.keys():
l = lre.search(k)
if l is not None:
labels.append(k)
return labels

def get_neutral_loss(self, label, site):
mod = self.modifications.get(label, None)
if mod is not None:
try:
nl = []
for n in mod["sites"][site]["NeutralLoss"]:
if n["composition"] != "0":
nl.append(n)
return nl
except:
return []
return []

def get_delta_mono(self, label):
mod = self.modifications.get(label, None)
if mod is not None:
try:
val = float(mod["delta_mono_mass"])
return val
except:
pass

def get_by_accession(self, accession):
for mod in self.modifications:
Expand Down
19 changes: 19 additions & 0 deletions sdrf_pipelines/tests/test_unimod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from sdrf_pipelines.openms.unimod import UnimodDatabase


def test_search_mods_by_keyword():
unimod = UnimodDatabase()
ptm = unimod.get_by_accession("UNIMOD:21")
print(ptm.get_name())

def test_search_mods_by_keyword():
unimod = UnimodDatabase()
ptms = unimod.search_mods_by_keyword("Phospho")
for ptm in ptms:
print(ptm.to_str())

if __name__ == "__main__":
test_search_mods_by_keyword()



2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_version(rel_path):
},
url="https://github.com/bigbio/sdrf-pipelines",
packages=find_packages(),
install_requires=["click", "pandas", "pandas_schema", "requests", "pytest", "pyyaml"],
install_requires=["click", "pandas", "pandas_schema", "requests", "pytest", "pyyaml", "defusedxml"],
entry_points={"console_scripts": ["parse_sdrf = sdrf_pipelines.parse_sdrf:main"]},
platforms=["any"],
classifiers=[
Expand Down

0 comments on commit f5c91d6

Please sign in to comment.