Skip to content

Commit

Permalink
added a few lines for sage
Browse files Browse the repository at this point in the history
  • Loading branch information
“Karim committed Oct 27, 2023
1 parent c8ce0d1 commit df44fb1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 30 deletions.
20 changes: 10 additions & 10 deletions spectrum_fundamentals/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,17 @@
"[UNIMOD:35]": 15.9949146, # Oxidation
"[UNIMOD:1]": 42.010565, # Acetylation
}
MOD_MASSES_SAGE = {+229.1629: '[UNIMOD:737]',
+304.2071: '[UNIMOD:2016]',
+144.1020: '[UNIMOD:214]',
+304.2053: '[UNIMOD:730]',
+8.0141: '[UNIMOD:259]',
+10.0082: '[UNIMOD:267]',
+79.9663: '[UNIMOD:21]',
MOD_MASSES_SAGE = {229.1629: '[UNIMOD:737]',
304.2071: '[UNIMOD:2016]',
144.1020: '[UNIMOD:214]',
304.2053: '[UNIMOD:730]',
8.0141: '[UNIMOD:259]',
10.0082: '[UNIMOD:267]',
79.9663: '[UNIMOD:21]',
-18.0105: '[UNIMOD:23]',
+57.0214: '[UNIMOD:4]',
+15.9949: '[UNIMOD:35]',
+42.0105: '[UNIMOD:1]'}
57.0214: '[UNIMOD:4]',
15.9949: '[UNIMOD:35]',
42.0105: '[UNIMOD:1]'}
# these are only used for prosit_grpc, oktoberfest uses the masses from MOD_MASSES
AA_MOD_MASSES = {
"K[UNIMOD:737]": AA_MASSES["K"] + MOD_MASSES["[UNIMOD:737]"],
Expand Down
50 changes: 30 additions & 20 deletions spectrum_fundamentals/mod_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,36 @@

from .constants import MAXQUANT_VAR_MODS, MOD_MASSES, MOD_NAMES, SPECTRONAUT_MODS , MOD_MASSES_SAGE

def sage_to_internal(sequences: List[str])->List[str]:
# Find the number within square brackets (as a float)
start_idx = sequences.find('[') + 1
end_idx = sequences.find(']')

# Extract the number string
number_str = sequences[start_idx:end_idx]

try:
# Attempt to convert the number to a float
number = float(number_str)
except ValueError:
# If conversion fails, keep the original text
return sequences

# Replace with the corresponding value from the dictionary
if number in MOD_MASSES_SAGE:
return sequences.replace(f'[{number_str}]', MOD_MASSES_SAGE[number])
else:
return sequences
def sage_to_internal(strings: List[str]) -> List[str]:
modified_strings = []

for string in strings:
# Find the number within square brackets (as a float)
start_idx = string.find('[') + 1
end_idx = string.find(']')

if start_idx > 0 and end_idx > start_idx:
# Extract the number string
number_str = string[start_idx:end_idx]

try:
# Attempt to convert the number to a float
number = float(number_str)
except ValueError:
# If conversion fails, keep the original text
modified_strings.append(string)
continue

# Replace with the corresponding value from the dictionary
if number in MOD_MASSES_SAGE:
modified_value = string.replace(f'[{number_str}]', MOD_MASSES_SAGE[number])
modified_strings.append(modified_value)
else:
modified_strings.append(string)
else:
modified_strings.append(string)

return modified_strings


def internal_to_spectronaut(sequences: List[str]) -> List[str]:
Expand Down

0 comments on commit df44fb1

Please sign in to comment.