Skip to content

Commit

Permalink
enabled changing the enzyme identification to a manual input via Conf…
Browse files Browse the repository at this point in the history
…ig() object
  • Loading branch information
SamiralVdB committed Aug 28, 2024
1 parent 9a4d103 commit bf9ec9b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
2 changes: 0 additions & 2 deletions Scripts/pam_generation_uniprot_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,6 @@ def filter_sublists(nested_list, target_string):
# ecoli_pam.objective = ecoli_pam.BIOMASS_REACTION
ecoli_pam.change_reaction_bounds('EX_glc__D_e', -10, 0)
ecoli_pam.optimize()
print(ecoli_pam.objective.value)
print(ecoli_pam.reactions.query('ACONT'))
# import pickle
#
# with open('path_to_your_pickle_file.pkl', 'wb') as file:
Expand Down
9 changes: 5 additions & 4 deletions src/PAModelpy/CatalyticEvent.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ def add_catalytic_reaction_to_enzyme_constraint(self, catalytic_reaction:Reactio
if self.rxn_id in enzyme.rxn2kcat.keys():
del enzyme.rxn2kcat[self.rxn_id]
enzyme.rxn2kcat[catalytic_reaction.id] = kcat_dict
#also add catalytic reaction to the ActiveEnzymeSector
self._model.sectors.ActiveEnzymeSector.rxn2protein[catalytic_reaction.id] = {enzyme.id: kcat_dict}


def remove_enzymes(self, enzyme_list: list):
Expand Down Expand Up @@ -395,10 +397,9 @@ def change_kcat_values(self, enzyme_kcat_dict : dict):
self._model._change_kcat_in_enzyme_constraint(ce_reaction, enzyme, direction, kcat)

@staticmethod
def _extract_reaction_id_from_catalytic_reaction_id(input_str: str) -> str:
# Define the regex pattern for protein IDs, obtained from UniProtKB, 2024-08-07
# https://www.uniprot.org/help/accession_numbers
protein_id_pattern = r'(?:[OPQ][0-9][A-Z0-9]{3}[0-9]|[A-NR-Z][0-9]([A-Z][A-Z0-9]{2}[0-9]){1,2})'
def _extract_reaction_id_from_catalytic_reaction_id(input_str: str,
protein_id_pattern:str = r'(?:[OPQ][0-9][A-Z0-9]{3}[0-9]|[A-NR-Z][0-9]([A-Z][A-Z0-9]{2}[0-9]){1,2})'
) -> str:

# Remove the 'CE_' prefix if it exists
if input_str.startswith('CE_'):
Expand Down
4 changes: 3 additions & 1 deletion src/PAModelpy/Enzyme.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __init__(
self.enzyme_variable = None
self.create_enzyme_variable()

self.enzyme_id_regex = r'(?:[OPQ][0-9][A-Z0-9]{3}[0-9]|[A-NR-Z][0-9]([A-Z][A-Z0-9]{2}[0-9]){1,2})'
self.catalytic_event_id = (
"CE_" + "{0}"
) # generic template for the catalytic events IDs
Expand Down Expand Up @@ -132,6 +133,7 @@ def model(self):
@model.setter
def model(self, model):
self._model = model
self.enzyme_id_regex = model.ENZYME_ID_REGEX

def set_forward_concentration(self, conc):
self.enzyme_variable.set_forward_concentration(conc)
Expand Down Expand Up @@ -249,7 +251,7 @@ def change_kcat_values(self, rxn2kcat: Dict):
if 'CE_' not in rxn_id:
catalytic_event_id = self.catalytic_event_id.format(rxn_id)
else:
catalytic_event_id = f"CE_{CatalyticEvent._extract_reaction_id_from_catalytic_reaction_id(rxn_id)}"
catalytic_event_id = f"CE_{CatalyticEvent._extract_reaction_id_from_catalytic_reaction_id(rxn_id, self.enzyme_id_regex)}"

# change rxn2kcat dictionary
self.rxn2kcat[rxn_id] = kcats
Expand Down
4 changes: 4 additions & 0 deletions src/PAModelpy/EnzymeSectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ def add(self, model):
)

model.add_enzymes([enzyme])
#add relation to rxn2protein dictionary

self.rxn2protein[rxn_id] = {**self.rxn2protein[rxn_id],
**{enzyme_complex_id:kcat}}
self.constraints += [enzyme]
self.variables.append(enzyme.enzyme_variable)
else:
Expand Down
7 changes: 5 additions & 2 deletions src/PAModelpy/PAModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class PAModel(Model):
CO2_EXHANGE_RXNID = Config.CO2_EXHANGE_RXNID
GLUCOSE_EXCHANGE_RXNID = Config.GLUCOSE_EXCHANGE_RXNID
BIOMASS_REACTION = Config.BIOMASS_REACTION
ENZYME_ID_REGEX = Config.ENZYME_ID_REGEX

def __init__(self, id_or_model: Union[str, "Model", None] = None,
name: Optional[str] = None,
Expand All @@ -78,13 +79,14 @@ def __init__(self, id_or_model: Union[str, "Model", None] = None,
translational_sector: Optional[TransEnzymeSector]=None,
unused_sector: Optional[UnusedEnzymeSector]=None,
custom_sectors: Optional[CustomSector] =[None],
configuration = Config):
configuration = Config()):
"""Constants"""
self.TOTAL_PROTEIN_CONSTRAINT_ID = configuration.TOTAL_PROTEIN_CONSTRAINT_ID
self.P_TOT_DEFAULT = configuration.P_TOT_DEFAULT # g_protein/g_cdw
self.CO2_EXHANGE_RXNID = configuration.CO2_EXHANGE_RXNID
self.GLUCOSE_EXCHANGE_RXNID = configuration.GLUCOSE_EXCHANGE_RXNID
self.BIOMASS_REACTION = configuration.BIOMASS_REACTION
self.ENZYME_ID_REGEX = configuration.ENZYME_ID_REGEX

self.configuration = configuration
"""Initialize the Model."""
Expand Down Expand Up @@ -1377,7 +1379,8 @@ def change_kcat_value(self, enzyme_id:str, kcats:dict):
for rxn, kcat_f_b in kcats.items():
# if a catalytic reaction is given, then extract the actual reaction id from it using the protein id convention from uniprot
if 'CE' in rxn:
rxn = CatalyticEvent._extract_reaction_id_from_catalytic_reaction_id(rxn)
rxn = CatalyticEvent._extract_reaction_id_from_catalytic_reaction_id(rxn,
self.ENZYME_ID_REGEX)
active_enzyme.rxn2protein[rxn][enzyme_id] = kcat_f_b
else:
warnings.warn(f'The enzyme {enzyme_id} does not exist in the model. The kcat can thus not be changed.')
Expand Down
6 changes: 6 additions & 0 deletions src/PAModelpy/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Config:
- ACETATE_EXCRETION_RXNID: str, `EX_ac_e`
- PHYS_RXN_IDS: List of str, `[BIOMASS_REACTION, GLUCOSE_EXCHANGE_RXNID, ACETATE_EXCRETION_RXNID, CO2_EXHANGE_RXNID, OXYGEN_UPTAKE_RXNID,
'PGI', 'G6PDH2r', 'EDA', 'CS', 'ICL', 'PPC', 'ME1', 'ME2']`
- ENZYME_ID_REGEX: r-str: r'(?:[OPQ][0-9][A-Z0-9]{3}[0-9]|[A-NR-Z][0-9]([A-Z][A-Z0-9]{2}[0-9]){1,2})'
Defaults are configured for the iML1515 E.coli model
"""
Expand Down Expand Up @@ -37,6 +38,10 @@ class Config:
"ME2",
]

# Define the regex pattern for protein IDs, obtained from UniProtKB, 2024-08-07
# https://www.uniprot.org/help/accession_numbers
ENZYME_ID_REGEX = r'(?:[OPQ][0-9][A-Z0-9]{3}[0-9]|[A-NR-Z][0-9]([A-Z][A-Z0-9]{2}[0-9]){1,2})'

def reset(self):
"""
Reset the config object to the standard settings for E.coli iML1515.
Expand Down Expand Up @@ -64,3 +69,4 @@ def reset(self):
"ME1",
"ME2",
]
self.ENZYME_ID_REGEX = r'(?:[OPQ][0-9][A-Z0-9]{3}[0-9]|[A-NR-Z][0-9]([A-Z][A-Z0-9]{2}[0-9]){1,2})'

0 comments on commit bf9ec9b

Please sign in to comment.