PAModel Objects
class PAModel(Model)
Class representation for a cobra model extended with enzyme kinetics as published in Alter et al. (2021).
Arguments:
id_or_modelstr or Model - String to use as model id, or actual model to base new model on. If a string, it is used as input to load a model from. If a model, a new model object is instantiated with the same properties as the original model (default None).namestr, optional - Human-readable string to be model description (default None).p_totfloat, optional - Total protein concentration (condition-dependent) (unit g_prot/g_cdw) (default 0.285).senstitivitybool - Boolean value whether or not a sensitivity analysis should be performed during each simulation. This sensitivity analysis will indicate to which extent individual constraints contribute to the objective value. Enzyme sectors (EnzymeSector objects, optional): Information about the different enzyme sectors, including:Active_enzyme: Metabolic active proteins.
Transl_enzyme: Enzymes related to translation.
Unused_enzymes: Excess enzymes.
Custom_enzymes (list): Custom enzyme sectors.
configurationConfig object, optional - Information about the general configuration of the model, including identifier conventions. Default as defined in thePAModelpy.configurationscript for the E.coli iML1515 model.
Attributes:
p_totfloat - The fraction of biomass allocated to proteins (units: g_prot/g_cdw).reactionsDictList - A DictList where the key is the reaction identifier and the value is a Reaction.metabolitesDictList - A DictList where the key is the metabolite identifier and the value is a Metabolite.genesDictList - A DictList where the key is the gene identifier and the value is a Gene.name0 DictList - A DictList where the key is the group identifier and the value is a Group.name1 DictList - A DictList where the key is the enzyme identifier and the value is an Enzyme.name2 DictList - A DictList where the key is the enzyme variable identifier and the value is an EnzymeVariable.name3 DictList - A DictList where the key is the catalytic event identifier and the value is a CatalyticEvent.name4 dict - A dictionary containing sector-specific constraints.name5 DictList - A DictList where the key is the sector identifier and the value is an EnzymeSector.
P_TOT_DEFAULT
g_protein/g_cdw
__init__
def __init__(id_or_model: Union[str, "Model", None] = None,
name: Optional[str] = None,
p_tot: Optional[float] = Config.P_TOT_DEFAULT,
sensitivity: bool = True,
active_sector: Optional[ActiveEnzymeSector] = None,
translational_sector: Optional[TransEnzymeSector] = None,
unused_sector: Optional[UnusedEnzymeSector] = None,
custom_sectors: Union[List, CustomSector] = None,
configuration=Config)
Constants
add_enzymes
def add_enzymes(enzyme_list: list) -> None
Add new enzymes to a model. Adapted from Cobra.core.model.add_reactions and Cobra.core.model.add_metabolites.
This function will add a DictList of enzymes to the model object and add new variables accordingly. For each enzyme-associated reaction, a constraint in each direction is added to the model. The change is reverted upon exit when using the model as a context.
Arguments:
enzyme_listlist or Enzyme - A list ofEnzymeobjects. If it isn’t an iterable container, the enzyme will be placed into a list.
add_sectors
def add_sectors(sectors: List = None)
Adds sector variables to the model and adds these to the total protein constraint.
Arguments:
sectorslist - A list of PAModelpy.EnzymeSectors to add to the model.
add_sector
def add_sector(sector)
Adds the sector variable for a specific sector to the model and adds this to the total protein constraint. Also stores the sector variables in the model attributes.
Arguments:
sectorPAModelpy.EnzymeSector - The specific EnzymeSector to add to the model.
add_catalytic_events
def add_catalytic_events(catalytic_events: Optional[Iterable])
Add a new CatalyticEvent to the model. Will add a list of CatalyticEvent variables to the model object using the function defined in the CatalyticEvent object.
Arguments:
catalytic_eventslist or variables.CatalyticEvent - A list ofvariables.CatalyticEventobjects. If it isn’t an iterable container, the catalytic event will be placed into a list.
add_enzyme_constraints
def add_enzyme_constraints(constraint_list: Optional[list])
Add new enzyme constraints to a model. Will add a list of constraints to the model object and add new constraints accordingly. The change is reverted upon exit when using the model as a context.
Arguments:
constraint_listlist, str, or constraints.Constraint - A list ofconstraints.Constraintobjects. If it isn’t an iterable container, the constraint will be placed into a list. Also, a string with the constraint id can be provided. A constraint will be created before adding it to the model.
add_sector_constraints
def add_sector_constraints(constraint_list: Optional[list])
Add a new constraint related to a sector to a model. Will add a list of constraints to the model object and add new constraints accordingly. The change is reverted upon exit when using the model as a context.
Arguments:
constraint_listlist or constraints.Constraint - A list ofconstraints.Constraintobjects. If it isn’t an iterable container, the constraint will be placed into a list.
add_total_protein_constraint
def add_total_protein_constraint(p_tot: Optional[float] = P_TOT_DEFAULT)
Function which adds the total protein constraint to the model. This limits the amount of available enzymes and thus the resulting fluxes.
Notes:
The constraint expression looks like this:
``Etot
- sum(E) + E_translprot + E_unusedprot == p_tot - E_trsn_0 - E_ue_0
Arguments:
p_totfloat, optional - Fraction of biomass which consists of protein (g_protein/g_cdw). Default is 0.258 (E.coli).
add_reactions
def add_reactions(reaction_list: Iterable[Reaction]) -> None
Add reactions to the model. This method is superimposed upon the cobra.Model.add_reactions() function. As a new feature, it will add constraints to determine the lower and upper bound if a sensitivity analysis should be performed (which is determined by the model attribute: PAModel.sensitivity). Reactions with identifiers identical to a reaction already in the model are ignored. The change is reverted upon exit when using the model as a context.
Arguments:
reaction_listlist - A list ofcobra.Reactionobjects.
add_lb_ub_constraints
def add_lb_ub_constraints()
Makes additional constraints for the reaction lower bounds and upperbounds. By adding these constraints the shadow prices of the reaction bounds can be calculated and used in sensitivity analysis
make_lb_ub_constraint
@staticmethod
def make_lb_ub_constraint(m: Optional[Model], rxn: Reaction,
lower_bound: float, upper_bound: float)
Adding variables and constraints for the lower and upper bounds of a reaction to a model. When solving the model, shadow prices for the lower and upper bounds will be calculated. This allows for the calculation of sensitivity coefficients. The constraints are formulated as follows:
Notes:
Constraints are formulated as follows:
R_ub: R_fwd - R_rev <= UBR_lb: -(R_fwd - R_rev) <= -LB
Arguments:
mcobra.Model or PAModelpy.PAModel - The model to which the upper and lower bound constraints and variables should be added.rxncobra.Reaction - The reaction for which upper and lower bound constraints should be generated.lower_boundfloat - The value of the lower bound.upper_boundfloat - The value of the upper bound.
Returns:
mcobra.Model or PAModelpy.PAModel - The model with additional constraints and variables for the reactions.
make_enzyme_min_max_constraint
@staticmethod
def make_enzyme_min_max_constraint(m: Optional[Model], enz: Enzyme,
lower_bound: float, upper_bound: float)
Adding variables and constraints for the lower and upper bounds of an enzyme’s concentration to a model. When solving the model, shadow prices for the lower and upper bounds will be calculated. This allows for the calculation of sensitivity coefficients.
Notes:
The constraints are formulated as follows:
E_ub: E <= EmaxE_lb: -E <= -Emin
Arguments:
mcobra.Model or PAModelpy.PAModel - The model to which the upper and lower bound constraints and variables should be added.rxnPAModelpy.Enzyme - The enzyme for which minimal and maximal concentration constraints should be generated.lower_boundfloat - The value of the lower bound.upper_boundfloat - The value of the upper bound.
Returns:
mcobra.Model or PAModelpy.PAModel - The model with additional constraints and variables for the enzyme’s concentration.
parse_shadow_prices
@staticmethod
def parse_shadow_prices(shadow_prices)
Parse the shadow prices to a DataFrame where each constraint corresponds to a row, and shadow prices and directions are columns.
calculate_csc
def calculate_csc(obj_value, mu, mu_ub, mu_lb, mu_ec_f, mu_ec_b)
Calculate the capacity sensitivity coefficient for all inequality constraints in the model. The sum of all capacity sensitivity coefficients should equal 1 for growth maximization.
Capacity Sensitivity Coefficient Calculation: Capacity Sensitivity Coefficient = constraint_UB * shadowprice / obj_value
Arguments:
obj_valuefloat - The objective value of the model.muDataFrame - Shadow prices for all constraints.mu_ubDataFrame - Shadow prices for the reaction upper bound (UB) constraints.mu_lbDataFrame - Shadow prices for the reaction lower bound (LB) constraints.mu_ec_fDataFrame - Shadow prices for the constraints related to enzymatic catalysis of the forward reaction.mu_ec_bDataFrame - Shadow prices for the constraints related to enzymatic catalysis of the backward reaction.
Returns:
None
Results are saved in the self.capacity_sensitivity_coefficients attribute as a DataFrame.
calculate_esc
def calculate_esc(obj_value, mu_ec_f, mu_ec_b)
Calculate enzyme sensitivity coefficients for the enzyme variables using their primal values, the objective value, and shadow prices according to the following relations:
Enzyme Sensitivity Coefficient Calculation: esc = enzyme_variable.primal * constraint.shadowprice / obj_value
Arguments:
obj_valuefloat - The objective value from the most recent optimal solution.mu_ec_fpd.DataFrame - Shadow prices for maximizing enzyme concentrations (forward variables).mu_ec_bpd.DataFrame - Shadow prices for minimizing enzyme concentrations (reverse variables).
Returns:
None
Fills the PAModel.enzyme_sensitivity_coefficients dataframe with the calculated enzyme sensitivity coefficients.
calculate_sum_of_enzymes
def calculate_sum_of_enzymes()
Calculate the sum of all enzyme variables for a feasible solution.
Returns:
float- The sum of all enzyme variables in milligrams per gram of cell dry weight per hour (mg/gCDW/h).
change_total_protein_constraint
def change_total_protein_constraint(p_tot)
Change the fraction of biomass that is allocated to active proteins.
Arguments:
p_totfloat - The new proteome fraction in grams of protein per gram of cell dry weight (g_protein/g_cdw).
change_reaction_bounds
def change_reaction_bounds(rxn_id: str,
lower_bound: float = None,
upper_bound: float = None)
Change the reaction bounds. If a sensitivity analysis is required, the bounds of the upper and lower bound constraints are adjusted.
Arguments:
rxn_idstr - The string representing the reaction identifier to change.lower_boundfloat, optional - The new value for the lower bound of the reaction (default is None).upper_boundfloat, optional - The new value for the upper bound of the reaction (default is None).
change_enzyme_bounds
def change_enzyme_bounds(enzyme_id: str,
lower_bound: float = None,
upper_bound: float = None)
Change the enzyme bounds. If the model should be primed for performing a sensitivity analysis, the upper bound of the minimum and maximum enzyme concentration constraints are adjusted.
Arguments:
enzyme_idstr - The string representing the enzyme identifier to change.lower_boundfloat, optional - The new value for the minimal enzyme concentration (default is None).upper_boundfloat, optional - The new value for the maximal enzyme concentration (default is None).
get_enzymes_with_reaction_id
def get_enzymes_with_reaction_id(rxn_id: str)
Return Enzyme objects associated with the reaction identifier through CatalyticEvent objects.
Arguments:
rxn_idstr - The reaction identifier.
Returns:
DictList- A DictList of Enzyme objects associated with the reaction.
get_reactions_with_enzyme_id
def get_reactions_with_enzyme_id(enz_id: str)
Return a list of reaction identifiers associated with the enzyme identifier (EC number) through CatalyticEvent objects.
Arguments:
enz_idstr - The enzyme identifier (EC number).
Returns:
List[str]- A list of reaction identifiers associated with the enzyme.
change_kcat_value
def change_kcat_value(enzyme_id: str, kcats: dict)
Change the turnover number (kcat) of the enzyme for a specific reaction.
Arguments:
enzyme_idstr - The enzyme identifier.kcatsdict - A dictionary with reaction identifiers as keys and kcat values as values. Each kcat value should be a nested dictionary withf(forward) andb(backward) as keys, and the corresponding kcat values as values.
Example:
Example dictionary for the kcat parameter
{'R1': {'f': 10.0, 'b': 5.0}, 'R2': {'f': 7.0, 'b': 3.0}}
remove_enzymes
def remove_enzymes(
enzymes: Union[str, Enzyme, List[Union[str, Enzyme]]]) -> None
Remove enzymes from the model.
Arguments:
enzymeslist, reaction, or str - A list with enzymes (Enzyme), or their IDs, to remove. Enzymes will be placed in a list. Strings will be placed in a list and used to find the enzymes in the model.
Notes:
The change is reverted upon exit when using the model as a context.
remove_reactions
def remove_reactions(reactions: Union[str, Reaction, List[Union[str,
Reaction]]],
remove_orphans: bool = False) -> None
Remove reactions from the model. Inherited from the cobrapy.core.remove_reactions() function.
Arguments:
reactionslist, reaction, or str - A list with reactions (cobra.Reaction), or their IDs, to remove. Reactions will be placed in a list. Strings will be placed in a list and used to find the reactions in the model.remove_orphansbool, optional - Remove orphaned genes and metabolites from the model as well (default False).
Notes:
The change is reverted upon exit when using the model as a context. Also removes associated CatalyticEvents if they exist.
remove_catalytic_events
def remove_catalytic_events(catalytic_events: Union[
str, CatalyticEvent, List[Union[str, CatalyticEvent]]],
remove_orphans: bool = False) -> None
Remove catalytic events from the model.
Arguments:
reactionslist, reaction, or str - A list with reactions (cobra.Reaction), or their IDs, to remove. Reactions will be placed in a list. Strings will be placed in a list and used to find the reactions in the model.remove_orphansbool, optional - Remove orphaned genes and metabolites from the model as well (default False).
Notes:
The change is reverted upon exit when using the model as a context.
remove_sectors
def remove_sectors(
sectors: Union[
str,
Sector,
ActiveEnzymeSector,
List[Union[str, Sector, ActiveEnzymeSector]],
]
) -> None
Remove sections from the model.
Also removes associated CatalyticEvents if they exist.
Arguments:
sectorslist, sector, or str - A list with sector (PAModelpy.SectororPAModelpy.ActiveEnzymeSector), or their IDs, to remove. A single sector will be placed in a list. Strings will be placed in a list and used to find the sector in the model.
test
def test(glc_flux: Union[int, float] = 10)
Test the proteome allocation model.
Arguments:
glc_fluxfloat, optional - The glucose flux which limits the growth rate (units: mmol_glc/g_cdw/h, default=10).
pfba
def pfba(fraction_of_optimum: float = 1.0,
proteins: bool = False,
reactions: bool = True,
exclude: List["str"] = [],
objective: Union[Dict, "Objective", None] = None)
Perform pFBA (parsimonious Enzyme Usage Flux Balance Analysis) with a custom objective including:
All reactions
All proteins
All proteins and all reactions.
pFBA [1] adds the minimization of all fluxes to the objective of the model. This approach is motivated by the idea that high fluxes have a higher enzyme turnover, and since producing enzymes is costly, the cell will try to minimize overall flux while still maximizing the original objective function, e.g., the growth rate.
Arguments:
fraction_of_optimumfloat, optional - The fraction of optimum which must be maintained. The original objective reaction is constrained to be greater than the maximal value times thefraction_of_optimum(default 1.0).objectivedict or cobra.Model.objective, optional - A desired objective to use during optimization in addition to the pFBA objective. Dictionaries (reaction as the key, coefficient as the value) can be used for linear objectives (default None).proteinsbool, optional - Determines whether to include enzyme variables in the pFBA objective.reactionsbool, optional - Determines whether to include reaction variables in the pFBA objective.excludelist of reaction ids, optional - Reactions to exclude from the minimization objective.
References:
[1] Lewis, N. E., Hixson, K. K., Conrad, T. M., Lerman, J. A., Charusanti, P., Polpitiya, A. D., Palsson, B. O. (2010). Omic data from evolved E. coli are consistent with computed optimal growth from genome-scale models. Molecular Systems Biology, 6, 390. doi:10.1038/msb.2010.47
reset_objective
def reset_objective()
Reseting the objective to the standard biomass maximization objective after pFBA
optimize
def optimize(objective_sense: Optional[str] = None,
raise_error: bool = False) -> "Solution"
Optimize the model using flux balance analysis. Inherits from the cobra.Model.optimize() function and performs a sensitivity analysis after optimization if this is desired (by setting the PAModel.sensitivity attribute to True).
Arguments:
objective_sense{None, 'maximize', 'minimize'}, optional - Whether fluxes should be maximized or minimized. In case of None, the previous direction is used (default None).raise_errorbool - If true, raise an OptimizationError if solver status is not optimal (default False).
Returns:
Solution
Notes:
Only the most commonly used parameters are presented here. Additional parameters for cobra.solver may be available and specified with the appropriate keyword argument.
copy
def copy() -> "PAModel"
Provide a partial ‘deepcopy’ of the Model.
Adjusted from cobra.Model.copy().
All the Metabolite, Gene, Reaction, Enzyme, EnzymeVariable, Sector, and CatalyticEvent objects are created anew but in a faster fashion than deepcopy.
Returns:
PAModelpy.PAModel- A new model copy.