From c8ce0d11ffbcbaf638ae4418a23167a3bac9236f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CKarim?= <“karimwael48@gmail.com”> Date: Thu, 26 Oct 2023 11:36:07 +0200 Subject: [PATCH] added final funcion for sage. --- spectrum_fundamentals/mod_string.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/spectrum_fundamentals/mod_string.py b/spectrum_fundamentals/mod_string.py index 9118438..6e57257 100644 --- a/spectrum_fundamentals/mod_string.py +++ b/spectrum_fundamentals/mod_string.py @@ -3,9 +3,29 @@ from itertools import repeat from typing import Dict, List, Optional, Tuple -from .constants import MAXQUANT_VAR_MODS, MOD_MASSES, MOD_NAMES, SPECTRONAUT_MODS +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(): def internal_to_spectronaut(sequences: List[str]) -> List[str]: """