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
MassReaction
from acobra.Reaction
, any associatedcobra.Metabolite
will also be converted into aMassMetabolite
.Unlike the
cobra.Reaction
which initializes thelower_bound
at a default value of0.0
, theMassReaction
initializes thelower_bound
asNone
to utilize the default value set in theMassConfiguration
.The
MassReaction
contains both thesteady_state_flux
and the inheritedcobra.Reaction.flux
attributes. Note that these attributes DO NOT refer to the same flux value unless specifically set as such. Theflux
refers to the flux value in the most recent optimization solution, while thesteady_state_flux
refers to the net steady state flux through the reaction.The
MassReaction
contains both thereversible
andreversibility
attributes.Note that these attributes are NOT the same. While the
reversible
refers the the kinetic reversibility of the reaction and thus determines how therate
is set, while the inhertiedcobra.Reaction.reversibility
refers 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.reversible
rather than the inhertiedcobra.Reaction.reversibility
attribute.
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.Reaction
Class for holding kinetic information regarding a biochemical reaction.
Accepted
kwargs
are 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
MassReaction
object 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_Keq
andirreversible_kr
attributes of theMassConfiguration
. Default isTrue
.**kwargs –
- lower_boundfloat or None
The lower flux bound for optimization. If
None
then the default bound from theMassConfiguration
is used.Default is
None
.- upper_boundfloat or None
The upper flux bound for optimization. If
None
then the default bound from theMassConfiguration
is 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
reversible
attribute will reset theequilibrium_constant
and thereverse_rate_constant
to 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
dict
of rate and equilibrium constants.Notes
The
reverse_rate_constant
is only included for reversible reactions. Additionally, only rate and equilibrium constants are accessed here. Steady state fluxes can be accessed through thesteady_state_flux
attribute, and custom parameters can only be accessed through the model.
- property rate[source]
Return the current rate as a
sympy
expression.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_string
Base function for getter method.
- property boundary[source]
Determine whether or not the reaction is a boundary reaction.
Will return
True
if 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_conditions
without creating aMassMetabolite
object. 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
None
if the reaction is not considered a boundary reaction.- Return type
See also
boundary
Method must return
True
to 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
True
then 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
True
then 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
True
then 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
MassReaction
ifinplace=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_constant
and theequilibrium_constant
.Type 2 will utilize the
forward_rate_constant
and thereverse_rate_constant
.Type 3 will utilize the
equilibrium_constant
and thereverse_rate_constant
.
Default is
1
.update_reaction (bool) – Whether to update the
MassReaction.rate
attribute in addition to returning the rate law. Default isFalse
.destructive (bool) – If
True
and the reaction has a custom rate law in its associated model, then settingupdate_reaction=True
will 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
sympy
expression. If the reaction has no metabolites associated,None
will be returned.- Return type
sympy.core.basic.Basic
orNone
Warning
Setting
update_reaction=True
will not remove any associated custom rate laws from the model unlessdestructive=True
as 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_constant
and thereverse_rate_constant
.
If
None
, the current rate type will be used. Default isNone
.- Returns
fwd_rate – The forward rate as a
sympy
expression. If the reaction has no metabolites associated,None
will be returned.- Return type
sympy.core.basic.Basic
orNone
- 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_constant
and 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
sympy
expression. If the reaction has no metabolites associated,None
will be returned.- Return type
sympy.core.basic.Basic
orNone
- get_mass_action_ratio()[source]
Get the mass action ratio as a
sympy
expression.- Returns
The mass action ratio as a sympy expression.
- Return type
- get_disequilibrium_ratio()[source]
Get the disequilibrium ratio as a
sympy
expression.- 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
MassMetabolite
or the string identifier of the metabolite whose coefficient is desired.
- get_coefficients(metabolite_ids)[source]
Return coefficients for a
list
of metabolites in the reaction.- Parameters
metabolite_ids (iterable) – Iterable containing the
MassMetabolite
s 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
MassModel
as 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.Reaction
by first ensuring that the metabolites to be added areMassMetabolite
s and notcobra.Metabolites
. and error message raised reflects themass
object.If a
cobra.Metabolite
is provided. a warning is raised and aMassMetabolite
will be instantiated using thecobra.Metabolite
.
- Parameters
metabolites_to_add (dict) – A
dict
withMassMetabolite
s 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 aMassModel
and 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. IfFalse
the 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
MassModel
as 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.Reaction
by first ensuring that the metabolites to be added areMassMetabolite
s and notcobra.Metabolites
. and error message raised reflects themass
object.If a
cobra.Metabolite
is provided. a warning is raised and aMassMetabolite
will be instantiated using thecobra.Metabolite
.
- Parameters
metabolites (dict) – A
dict
withMassMetabolite
s 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 aMassModel
and 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. IfFalse
the 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.Reaction
so that the reaction arrow depends onMassReaction.reversible
rather than the inheritedcobra.Reaction.reversibility
attribute.
- check_mass_balance()[source]
Compute the mass and charge balances for the reaction.
- Returns
Returns a
dict
of{element: amount}
for unbalanced elements, with the “charge” treated as an element in thedict
. For a balanced reaction, an emptydict
is 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_str
using 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
MassModel
as a context.Notes
Extends
build_reaction_from_string()
of thecobra.Reaction
in 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
Gene
with the reaction.- Parameters
cobra_gene (Gene) –
Gene
to be assoicated with the reaction.
Warning
This method is intended for internal use only.
- _dissociate_gene(cobra_gene)[source]
Dissociates a
Gene
with the reaction.- Parameters
cobra_gene (Gene) –
Gene
to 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.