Skip to content

Commit 0636ac8

Browse files
authored
Merge pull request #242 from daichengxin/master
Fixed Unimod match bugs
2 parents 93bb632 + 7c3c3ec commit 0636ac8

File tree

5 files changed

+2594
-616
lines changed

5 files changed

+2594
-616
lines changed

sdrf_pipelines/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.0.32"
1+
__version__ = "0.0.33"

sdrf_pipelines/maxquant/maxquant.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,8 +700,9 @@ def maxquant_ify_mods(self, sdrf_mods, mqconfdir):
700700
else:
701701
warning_message = "modification is not supported in MaxQuant. skip " + m
702702
self.warnings[warning_message] = self.warnings.get(warning_message, 0) + 1
703+
oms_mods = ",".join(oms_mods)
703704

704-
return ",".join(oms_mods)
705+
return oms_mods
705706

706707
def maxquant_convert(
707708
self,

sdrf_pipelines/openms/openms.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -206,21 +206,32 @@ def __init__(self) -> None:
206206
self.silac3 = {"silac light": 1, "silac medium": 2, "silac heavy": 3}
207207
self.silac2 = {"silac light": 1, "silac heavy": 2}
208208

209+
def _extract_modification_name(self, mod_string):
210+
name_match = re.search("NT=(.+?)(;|$)", mod_string)
211+
if name_match:
212+
name = name_match.group(1)
213+
else:
214+
raise ValueError(f"Invalid modification string format (missing NT=): {mod_string}")
215+
accession = re.search("AC=(.+?)(;|$)", mod_string)
216+
if accession:
217+
ptm = self._unimod_database.get_by_accession(accession.group(1))
218+
else:
219+
ptm = None
220+
221+
if ptm is None:
222+
ptm = self._unimod_database.get_by_name(name)
223+
224+
if ptm is None:
225+
raise ValueError("only UNIMOD modifications supported. " + mod_string)
226+
else:
227+
return ptm.get_name()
228+
209229
# convert modifications in sdrf file to OpenMS notation
210230
def openms_ify_mods(self, sdrf_mods):
211231
oms_mods = []
212232

213233
for m in sdrf_mods:
214-
if "AC=UNIMOD" not in m and "AC=Unimod" not in m:
215-
raise Exception("only UNIMOD modifications supported. " + m)
216-
217-
name = re.search("NT=(.+?)(;|$)", m).group(1)
218-
name = name.capitalize()
219-
220-
accession = re.search("AC=(.+?)(;|$)", m).group(1)
221-
ptm = self._unimod_database.get_by_accession(accession)
222-
if ptm is not None:
223-
name = ptm.get_name()
234+
name = self._extract_modification_name(m)
224235

225236
# workaround for missing PP in some sdrf TODO: fix in sdrf spec?
226237
if re.search("PP=(.+?)(;|$)", m) is None:
@@ -1130,8 +1141,9 @@ def save_search_settings_to_file(self, output_filename, sdrf, f2c):
11301141
label = "itraq8plex"
11311142
else:
11321143
label = "itraq4plex"
1144+
11331145
# add default ITRAQ modification when sdrf with label not contains ITRAQ modification
1134-
if "ITRAQ" not in f2c.file2mods[raw][0] and "ITRAQ" not in f2c.file2mods[raw][1]:
1146+
if "itraq" not in f2c.file2mods[raw][0].lower() and "itraq" not in f2c.file2mods[raw][1].lower():
11351147
warning_message = (
11361148
"The sdrf with ITRAQ label doesn't contain label modification. Adding default "
11371149
"variable modifications."

sdrf_pipelines/openms/unimod.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,9 @@ def get_by_accession(self, accession):
128128
if mod.get_accession() == accession:
129129
return mod
130130
return None
131+
132+
def get_by_name(self, name):
133+
for mod in self.modifications:
134+
if mod.get_name().lower() == name.lower():
135+
return mod
136+
return None

0 commit comments

Comments
 (0)