mass.core.mass_reaction
MassReaction is a class for holding information regarding reactions.
The MassReaction class inherits and extends the
Reaction class in cobra. It contains
additional information required for simulations and other mass
functions and workflows.
Some key differences between the
cobra.Reaction and the
mass.MassReaction are
listed below:
When instantiating a
MassReactionfrom acobra.Reaction, any associatedcobra.Metabolitewill also be converted into aMassMetabolite.Unlike the
cobra.Reactionwhich initializes thelower_boundat a default value of0.0, theMassReactioninitializes thelower_boundasNoneto utilize the default value set in theMassConfiguration.The
MassReactioncontains both thesteady_state_fluxand the inheritedcobra.Reaction.fluxattributes. Note that these attributes DO NOT refer to the same flux value unless specifically set as such. Thefluxrefers to the flux value in the most recent optimization solution, while thesteady_state_fluxrefers to the net steady state flux through the reaction.The
MassReactioncontains both thereversibleandreversibilityattributes.Note that these attributes are NOT the same. While the
reversiblerefers the the kinetic reversibility of the reaction and thus determines how therateis set, while the inhertiedcobra.Reaction.reversibilityrefers to the computed reversibility based on the current lower and upper bounds.The arrow in the string representation of the reaction is dependent on the
MassReaction.reversiblerather than the inhertiedcobra.Reaction.reversibilityattribute.
Module Contents
Classes
Class for holding kinetic information regarding a biochemical reaction. |
- class mass.core.mass_reaction.MassReaction(id_or_reaction=None, name='', subsystem='', reversible=True, steady_state_flux=None, **kwargs)[source]
Bases:
cobra.core.reaction.ReactionClass for holding kinetic information regarding a biochemical reaction.
Accepted
kwargsare passed onto the initialization method for the base classReaction.- Parameters
id_or_reaction (str, Reaction, MassReaction) – A string identifier to associate with the reaction, or an existing reaction. If an existing reaction object is provided, a new
MassReactionobject is instantiated with the same properties as the original reaction.name (str) – A human readable name for the reaction.
subsystem (str) – The subsystem where the reaction is meant to occur.
reversible (bool) – The kinetic reversibility of the reaction. Irreversible reactions have an equilibrium constant and a reverse rate constant as set in the
irreversible_Keqandirreversible_krattributes of theMassConfiguration. Default isTrue.**kwargs –
- lower_boundfloat or None
The lower flux bound for optimization. If
Nonethen the default bound from theMassConfigurationis used.Default is
None.- upper_boundfloat or None
The upper flux bound for optimization. If
Nonethen the default bound from theMassConfigurationis used.Default is
None.
- property reversible[source]
Get or set the kinetic reversibility of the reaction.
When using a HistoryManager context, this attribute can be set temporarily, reversed when the exiting the context.
- Parameters
reversible (bool) – The kinetic reversibility of the reaction.
Warning
Changing the
reversibleattribute will reset theequilibrium_constantand thereverse_rate_constantto the initialization defaults.
- property steady_state_flux[source]
Get or set the steady state flux of the reaction.
When using a HistoryManager context, this attribute can be set temporarily, reversed when the exiting the context.
- Parameters
flux_value (bool) – The steady state flux value of the reaction.
- property forward_rate_constant[source]
Get or set the forward rate constant (kf) of the reaction.
When using a HistoryManager context, this attribute can be set temporarily, reversed when the exiting the context.
Notes
Forward rate constants cannot be negative.
- Parameters
value (float) – A non-negative number for the forward rate constant (kf) of the reaction.
- Raises
ValueError – Occurs when trying to set a negative value.
- property reverse_rate_constant[source]
Get or set the reverse rate constant (kr) of the reaction.
When using a HistoryManager context, this attribute can be set temporarily, reversed when the exiting the context.
Notes
Reverse rate constants cannot be negative.
If reaction is not reversible, will warn the user instead of setting the parameter value.
- Parameters
value (float) – A non-negative number for the reverse rate constant (kr) of the reaction.
- Raises
ValueError – Occurs when trying to set a negative value.
- property equilibrium_constant[source]
Get or set the equilibrium constant (Keq) of the reaction.
When using a HistoryManager context, this attribute can be set temporarily, reversed when the exiting the context.
Notes
Equilibrium constants cannot be negative.
If reaction is not reversible, will warn the user instead of setting the parameter value.
- Parameters
value (float) – A non-negative number for the equilibrium constant (Keq) of the reaction.
- Raises
ValueError – Occurs when trying to set a negative value.
- property parameters[source]
Return a
dictof rate and equilibrium constants.Notes
The
reverse_rate_constantis only included for reversible reactions. Additionally, only rate and equilibrium constants are accessed here. Steady state fluxes can be accessed through thesteady_state_fluxattribute, and custom parameters can only be accessed through the model.
- property rate[source]
Return the current rate as a
sympyexpression.If reaction has a custom rate in its associated
MassModel, the custom rate will be returned instead.
- property reaction[source]
Get or set the reaction as a human readable string.
- Parameters
reaction_str (str) – String representation of the reaction.
Warning
Care must be taken when setting a reaction using this method. See documentation for
build_reaction_from_string()for more information.See also
build_reaction_stringBase function for getter method.
- property boundary[source]
Determine whether or not the reaction is a boundary reaction.
Will return
Trueif the reaction has no products or no reactants and only one metabolite.Notes
These are reactions with a sink or a source term (e.g. ‘A –> ‘)
- property boundary_metabolite[source]
Return an ‘boundary’ metabolite for bounary reactions.
Notes
The ‘boundary_metabolite’ represents the metabolite that corresponds to the empty part of a boundary reaction through a string. It’s primary use is for setting of the
boundary_conditionswithout creating aMassMetaboliteobject. Therefore it is not counted as a metabolite but instead as a parameter.- Returns
boundary_metabolite – String representation of the boundary metabolite of the reaction, or
Noneif the reaction is not considered a boundary reaction.- Return type
See also
boundaryMethod must return
Trueto get the boundary_metabolite.
- property gene_reaction_rule[source]
Get or set the gene reaction rule for the reaction.
- Parameters
new_rule (str) – String representation of the new reaction rule.
Notes
New genes will be associated with the reaction and old genes will be dissociated from the reaction.
- property gene_name_reaction_rule[source]
Display gene_reaction_rule with names.
Warning
Do NOT use this string for computation. It is intended to give a representation of the rule using more familiar gene names instead of the often cryptic ids.
- property kf[source]
Alias for the
forward_rate_constant.
- property kr[source]
Alias for the
reverse_rate_constant.
- property Keq[source]
Alias for the
equilibrium_constant.
- property S[source]
Alias for the
stoichiometry.
- property v[source]
Alias for the
steady_state_flux.
- reverse_stoichiometry(inplace=False, reverse_parameters=False, reverse_bounds=True, reverse_flux=True)[source]
Reverse the stoichiometry of the reaction.
Reversing the stoichiometry will turn the products into the reactants and the reactants into the products.
Notes
To avoid errors when reversing the reaction equilibrium constant:
If
self.equilibrium_constant=0.thennew_reaction.equilibrium_constant=float("inf")If
self.equilibrium_constant=float("inf")thennew_reaction.equilibrium_constant=0.
- Parameters
inplace (bool) – If
True, modify the reaction directly. Otherwise a new reaction is created, modified, and returned.reverse_parameters (bool) –
If
Truethen also switch the reaction rate constants and inverse the equilibrium constants such that:new_reaction.forward_rate_constant = self.reverse_rate_constant new_reaction.reverse_rate_constant = self.forward_rate_constant new_reaction.equilibrium_constant = 1/self.equilibrium_constant
Default is
False.reverse_bounds (bool) –
If
Truethen also switch the lower and upper bounds with one another such that:new_reaction.bounds = (-self.upper_bound, -self.lower_bound)
Default is
True.reverse_flux (bool) –
If
Truethen also switch the direction of the flux such that:new_reaction.steady_state_flux = -self.steady_state_flux
Default is
True.
- Returns
new_reaction – Returns the original
MassReactionifinplace=True. Otherwise return a modified copy of the original reaction.- Return type
- get_mass_action_rate(rate_type=1, update_reaction=False, destructive=False)[source]
Get the mass action rate law for the reaction.
- Parameters
rate_type (int) –
The type of rate law to return. Must be 1, 2, or 3.
Type 1 will utilize the
forward_rate_constantand theequilibrium_constant.Type 2 will utilize the
forward_rate_constantand thereverse_rate_constant.Type 3 will utilize the
equilibrium_constantand thereverse_rate_constant.
Default is
1.update_reaction (bool) – Whether to update the
MassReaction.rateattribute in addition to returning the rate law. Default isFalse.destructive (bool) – If
Trueand the reaction has a custom rate law in its associated model, then settingupdate_reaction=Truewill replace the rate law and remove the custom rate law and orphaned parameters from the model. Default isFalse.
- Returns
rate_expression – The rate law as a
sympyexpression. If the reaction has no metabolites associated,Nonewill be returned.- Return type
sympy.core.basic.BasicorNone
Warning
Setting
update_reaction=Truewill not remove any associated custom rate laws from the model unlessdestructive=Trueas well.
- get_forward_mass_action_rate_expression(rate_type=None)[source]
Get the forward mass action rate expression for the reaction.
- Parameters
rate_type (int, None) –
The type of rate law to return. Must be 1, 2, or 3.
Type 1 and 2 will utilize the
forward_rate_constant.Type 3 will utilize the
equilibrium_constantand thereverse_rate_constant.
If
None, the current rate type will be used. Default isNone.- Returns
fwd_rate – The forward rate as a
sympyexpression. If the reaction has no metabolites associated,Nonewill be returned.- Return type
sympy.core.basic.BasicorNone
- get_reverse_mass_action_rate_expression(rate_type=1)[source]
Get the reverse mass action rate expression for the reaction.
- Parameters
rate_type (int, None) –
The type of rate law to return. Must be 1, 2, or 3.
Type 1 will utilize the
forward_rate_constantand theequilibrium_constant.Type 2 and 3 will utilize the
reverse_rate_constant.
If
None, the current rate type will be used. Default isNone.- Returns
rev_rate – The reverse rate as a
sympyexpression. If the reaction has no metabolites associated,Nonewill be returned.- Return type
sympy.core.basic.BasicorNone
- get_mass_action_ratio()[source]
Get the mass action ratio as a
sympyexpression.- Returns
The mass action ratio as a sympy expression.
- Return type
- get_disequilibrium_ratio()[source]
Get the disequilibrium ratio as a
sympyexpression.- Returns
The disequilibrium ratio as a sympy expression.
- Return type
- copy()[source]
Copy a reaction.
The reaction parameters, referenced metabolites, and genes are also copied.
- get_coefficient(metabolite_id)[source]
Return the coefficient of a metabolite in the reaction.
- Parameters
metabolite_id (str or MassMetabolite) – The
MassMetaboliteor the string identifier of the metabolite whose coefficient is desired.
- get_coefficients(metabolite_ids)[source]
Return coefficients for a
listof metabolites in the reaction.- Parameters
metabolite_ids (iterable) – Iterable containing the
MassMetabolites or their string identifiers.
- add_metabolites(metabolites_to_add, combine=True, reversibly=True)[source]
Add metabolites and their coefficients to the reaction.
If the final coefficient for a metabolite is 0 then it is removed from the reaction.
The change is reverted upon exit when using the
MassModelas a context.Notes
A final coefficient of < 0 implies a reactant and a final coefficient of > 0 implies a product.
Extends
add_metabolites()of thecobra.Reactionby first ensuring that the metabolites to be added areMassMetabolites and notcobra.Metabolites. and error message raised reflects themassobject.If a
cobra.Metaboliteis provided. a warning is raised and aMassMetabolitewill be instantiated using thecobra.Metabolite.
- Parameters
metabolites_to_add (dict) – A
dictwithMassMetabolites or metabolite identifiers as keys and stoichiometric coefficients as values. If keys are strings (id of a metabolite), the reaction must already be part of aMassModeland a metabolite with the given id must already exist in theMassModel.combine (bool) – Describes the behavior of existing metabolites. If
True, the metabolite coefficients are combined together. IfFalsethe coefficients are replaced.reversibly (bool) – Whether to add the change to the context to make the change reversible (primarily intended for internal use).
See also
- subtract_metabolites(metabolites, combine=True, reversibly=True)[source]
Subtract metabolites and their coefficients from the reaction.
This function will ‘subtract’ metabolites from a reaction by adding the given metabolites with
-1 * coeffcient. If the final coefficient for a metabolite is 0, the metabolite is removed from the reaction.The change is reverted upon exit when using the
MassModelas a context.Notes
A final coefficient of < 0 implies a reactant and a final coefficient of > 0 implies a product.
Extends
cobra.core.reaction.Reaction.subtract_metabolites()of thecobra.Reactionby first ensuring that the metabolites to be added areMassMetabolites and notcobra.Metabolites. and error message raised reflects themassobject.If a
cobra.Metaboliteis provided. a warning is raised and aMassMetabolitewill be instantiated using thecobra.Metabolite.
- Parameters
metabolites (dict) – A
dictwithMassMetabolites or their identifiers as keys and stoichiometric coefficients as values. If keys are strings (id of a metabolite), the reaction must already be part of aMassModeland a metabolite with the given id must already exist in theMassModel.combine (bool) – Describes the behavior of existing metabolites. If
True, the metabolite coefficients are combined together. IfFalsethe coefficients are replaced.reversibly (bool) – Whether to add the change to the context to make the change reversible (primarily intended for internal use).
See also
- build_reaction_string(use_metabolite_names=False)[source]
Generate a human readable string to represent the reaction.
Notes
Overrides
build_reaction_string()of thecobra.Reactionso that the reaction arrow depends onMassReaction.reversiblerather than the inheritedcobra.Reaction.reversibilityattribute.
- check_mass_balance()[source]
Compute the mass and charge balances for the reaction.
- Returns
Returns a
dictof{element: amount}for unbalanced elements, with the “charge” treated as an element in thedict. For a balanced reaction, an emptydictis returned.- Return type
- build_reaction_from_string(reaction_str, verbose=True, fwd_arrow=None, rev_arrow=None, reversible_arrow=None, term_split='+')[source]
Build reaction from reaction equation
reaction_strusing parser.Takes a string representation of the reaction and uses the specifications supplied in the optional arguments to infer a set of metabolites, metabolite compartments, and stoichiometries for the reaction. It also infers the refversibility of the reaction from the reaction arrow.
For example:
'A + B <=> C'for reversible reactions, A & B are reactants.'A + B --> C'for irreversible reactions, A & B are reactants.'A + B <-- C'for irreversible reactions, A & B are products.
The change is reverted upon exit when using the
MassModelas a context.Notes
Extends
build_reaction_from_string()of thecobra.Reactionin order to change how the irreversible backwards arrow is interpreted, affecting the assignment of reactants and products rather than how the bounds are set.- Parameters
reaction_str (str) – A string containing the reaction formula (equation).
verbose (bool) – Setting the verbosity of the function. Default is
True.fwd_arrow (re.compile, None) – For forward irreversible reaction arrows. If
None, the arrow is expected to be'-->'or'==>'.rev_arrow (re.compile, None) – For backward irreversible reaction arrows. If
None, the arrow is expected to be'<--'or'<=='.reversible_arrow (re.compile, None) – For reversible reaction arrows. If
None, the arrow is expected to be'<=>'or'<->'.term_split (str) – Dividing individual metabolite entries. Default is
"+".
- _cobra_to_mass_repair()[source]
Convert associated cobra.Metabolites to MassMetabolites for self.
Warning
This method is intended for internal use only.
- _associate_gene(cobra_gene)[source]
Associates a
Genewith the reaction.- Parameters
cobra_gene (Gene) –
Geneto be assoicated with the reaction.
Warning
This method is intended for internal use only.
- _dissociate_gene(cobra_gene)[source]
Dissociates a
Genewith the reaction.- Parameters
cobra_gene (Gene) –
Geneto be disassociated with the reaction.
Warning
This method is intended for internal use only.
- _make_boundary_metabolites()[source]
Make the boundary metabolite.
Warning
This method is intended for internal use only.
- _repr_html_()[source]
HTML representation of the overview for the MassReaction.
Warning
This method is intended for internal use only.
- __copy__()[source]
Create a copy of the MassReaction.
Warning
This method is intended for internal use only.
- __deepcopy__(memo)[source]
Create a deepcopy of the MassReaction.
Warning
This method is intended for internal use only.