diff --git a/src/PAModelpy/Enzyme.py b/src/PAModelpy/Enzyme.py index 860be25..c96facb 100644 --- a/src/PAModelpy/Enzyme.py +++ b/src/PAModelpy/Enzyme.py @@ -13,7 +13,7 @@ from optlang.symbolics import Zero from .CatalyticEvent import CatalyticEvent -from typing import Dict, Union, Optional +from typing import Dict, Union, Optional, Literal from warnings import warn def _change_catalytic_event_list_to_dictlist_after_unpickling(self): @@ -97,7 +97,7 @@ def kcat_values(self): @property def concentration( - self, units: str = "mmol/gDW", return_units: bool = False + self, units: Literal['mmol/gDW', 'g/gDW'] = "mmol/gDW", return_units: bool = False ) -> float: """Returns the enzyme's total concentration considering any associated reactions. @@ -113,11 +113,11 @@ def concentration( concentration = self.enzyme_variable.concentration if units == 'g/gDW': #converting mmol to grams of protein: - # [g] = [mmol]* 1e-3 [mol/mmol] * MW[g/mol] *1e-6 [solver tolerance conversion factor] - concentration = concentration * 1e-3 * self.molmass*1e-6 + # [g] = [mmol]* 1e-3 [mol/mmol] * MW[g/mol] + concentration = concentration * 1e-3 * self.molmass if return_units: - return concentration*1e-6, units - return concentration*1e-6 + return concentration, units + return concentration @concentration.setter def concentration(self, conc): diff --git a/src/PAModelpy/EnzymeSectors.py b/src/PAModelpy/EnzymeSectors.py index 12387b3..0090873 100644 --- a/src/PAModelpy/EnzymeSectors.py +++ b/src/PAModelpy/EnzymeSectors.py @@ -160,7 +160,6 @@ def add(self, model): if rxn_id in rxn2protein.keys(): del rxn2protein[rxn_id] except: - print(model.reactions.query(rxn_id)) warn( f"Reaction {rxn_id} is not in the model, this reaction will be skipped" ) @@ -194,6 +193,11 @@ def add(self, model): if enzyme_id in model.enzyme_variables and not self._enzyme_is_enzyme_complex(protein_reaction, enzyme_id): enzyme = model.enzymes.get_by_id(enzyme_id) self._add_reaction_to_enzyme(model, enzyme, rxn_id, kcat) + self.rxn2protein[rxn_id] = {**self.rxn2protein[rxn_id], + **{enzyme_id: { + **kcat, + 'genes': enzyme.genes, + 'protein_reaction_association': protein_reaction}}} else: if self.protein2gene != {}: @@ -208,7 +212,6 @@ def add(self, model): molmass=molmass, genes=gene_list ) - if self._enzyme_is_enzyme_complex(protein_reaction, enzyme_id): for pr in protein_reaction: if len(pr) > 1: @@ -252,7 +255,6 @@ def add(self, model): # adding to the enzyme sector object for easy removal model.tpc += 1 - return model def check_kcat_values(self, model, reaction, enzyme_dict): diff --git a/src/PAModelpy/PAModel.py b/src/PAModelpy/PAModel.py index c24c941..0b0df86 100644 --- a/src/PAModelpy/PAModel.py +++ b/src/PAModelpy/PAModel.py @@ -264,8 +264,8 @@ def parameter_filter(enz: Enzyme) -> bool: # check kcat values for kcatdict in kcats.values(): - for kcat in kcatdict.values(): - if kcat < 0: + for kcat_dict in kcatdict.values(): + if kcat_dict < 0: # invalid kcat value warnings.warn( 'Turnover number for reaction "' @@ -276,7 +276,8 @@ def parameter_filter(enz: Enzyme) -> bool: # extract reaction from model reaction = self.reactions.get_by_id(rxn_id) - for kcats in kcats.values(): + + for kcat_dict in kcats.values(): # check consistency between provided kcat values and reaction direction if self._sensitivity: lower_bound = -self.constraints[f"{rxn_id}_lb"].ub @@ -286,7 +287,7 @@ def parameter_filter(enz: Enzyme) -> bool: upper_bound = reaction.upper_bound if lower_bound >= 0 and upper_bound > 0: # reaction is irreversible in the forward direction - if "f" not in kcats: # or 'b' in kcats: + if "f" not in kcat_dict: # or 'b' in kcats: warnings.warn( rxn_id + ": Inconsistencies between the reaction reversibility and the provided kcat values" @@ -294,7 +295,7 @@ def parameter_filter(enz: Enzyme) -> bool: return False elif lower_bound < 0 and upper_bound <= 0: # reaction is irreversible in the backward direction - if "b" not in kcats or "f" in kcats: + if "b" not in kcats or "f" in kcat_dict: warnings.warn( rxn_id + ": Inconsistencies between the reaction reversibility and the provided kcat values" @@ -302,7 +303,7 @@ def parameter_filter(enz: Enzyme) -> bool: return False else: # reaction is reversible - if "f" not in kcats: # or 'b' not in kcats: + if "f" not in kcat_dict: # or 'b' not in kcats: warnings.warn( rxn_id + ": Inconsistencies between the reaction reversibility and the provided kcat values" @@ -1338,12 +1339,14 @@ def change_reaction_bounds( def change_reaction_ub(self, rxn_id: str, upper_bound: float = None): if self._sensitivity: self.constraints[rxn_id + "_ub"].ub = upper_bound + self.reactions.get_by_id(rxn_id).upper_bound = upper_bound*0.01 else: self.reactions.get_by_id(rxn_id).upper_bound = upper_bound def change_reaction_lb(self, rxn_id: str, lower_bound: float = None): if self._sensitivity: self.constraints[rxn_id + "_lb"].ub = -lower_bound + self.reactions.get_by_id(rxn_id).lower_bound = lower_bound*0.01 else: self.reactions.get_by_id(rxn_id).lower_bound = lower_bound