memote.support.helpers

Helper functions that are used all over the memote package.

Module Contents

Functions

find_transported_elements(rxn) Return a dictionary showing the amount of transported elements of a rxn.
find_transport_reactions(model) Return a list of all transport reactions.
is_transport_reaction_formulae(rxn) Return boolean if a reaction is a transport reaction (from formulae).
is_transport_reaction_annotations(rxn) Return boolean if a reaction is a transport reaction (from annotations).
find_converting_reactions(model, pair) Find all reactions which convert a given metabolite pair.
filter_sbo_term(component, sbo_term) Return true if the component is annotated with the given SBO term.
filter_match_name(component, buzzwords) Return whether the component’s name matches a biomass description.
filter_identifier(component, buzzwords) Return whether the component’s identifier contains a biomass description.
find_biomass_reaction(model) Return a list of the biomass reaction(s) of the model.
find_demand_reactions(model) Return a list of demand reactions.
find_sink_reactions(model) Return a list of sink reactions.
find_exchange_rxns(model) Return a list of exchange reactions.
find_interchange_biomass_reactions(model, biomass=None) Return the set of all transport, boundary, and biomass reactions.
run_fba(model, rxn_id, direction=’max’, single_value=True) Return the solution of an FBA to a set objective function.
get_biomass_flux(model: cobra.Model, rxn_id: str) → float Compute the maximal objective value.
close_boundaries_sensibly(model) Return a cobra model with all boundaries closed and changed constraints.
open_exchanges(model) Open all exchange reactions.
open_boundaries(model) Open all boundary reactions.
metabolites_per_compartment(model, compartment_id) Identify all metabolites that belong to a given compartment.
largest_compartment_id_met(model) Return the ID of the compartment with the most metabolites.
find_compartment_id_in_model(model, compartment_id) Identify a model compartment by looking up names in COMPARTMENT_SHORTLIST.
find_met_in_model(model, mnx_id, compartment_id=None) Return specific metabolites by looking up IDs in METANETX_SHORTLIST.
find_objective_function(model) Return reactions that are part of the objective function.
find_bounds(model) Return the median upper and lower bound of the metabolic model.
memote.support.helpers.LOGGER[source]
memote.support.helpers.TRANSPORT_RXN_SBO_TERMS = ['SBO:0000185', 'SBO:0000588', 'SBO:0000587', 'SBO:0000655', 'SBO:0000654', 'SBO:0000660', 'SBO:0000659', 'SBO:0000657', 'SBO:0000658'][source]
memote.support.helpers.METANETX_SHORTLIST[source]
memote.support.helpers.COMPARTMENT_SHORTLIST[source]
memote.support.helpers.find_transported_elements(rxn)[source]

Return a dictionary showing the amount of transported elements of a rxn.

Collects the elements for each metabolite participating in a reaction, multiplies the amount by the metabolite’s stoichiometry in the reaction and bins the result according to the compartment that metabolite is in. This produces a dictionary of dictionaries such as this {'p': {'C': -1, 'H': -4}, c: {'C': 1, 'H': 4}} which shows the transported entities. This dictionary is then simplified to only include the non-zero elements of one single compartment i.e. showing the precise elements that are transported.

Parameters:
rxn : cobra.Reaction

Any cobra.Reaction containing metabolites.

memote.support.helpers.find_transport_reactions(model)[source]

Return a list of all transport reactions.

Parameters:
model : cobra.Model

The metabolic model under investigation.

Notes

A transport reaction is defined as follows: 1. It contains metabolites from at least 2 compartments and 2. at least 1 metabolite undergoes no chemical reaction, i.e., the formula and/or annotation stays the same on both sides of the equation.

A notable exception is transport via PTS, which also contains the following restriction: 3. The transported metabolite(s) are transported into a compartment through the exchange of a phosphate group.

An example of transport via PTS would be pep(c) + glucose(e) -> glucose-6-phosphate(c) + pyr(c)

Reactions similar to transport via PTS (referred to as “modified transport reactions”) follow a similar pattern: A(x) + B-R(y) -> A-R(y) + B(y)

Such modified transport reactions can be detected, but only when a formula field exists for all metabolites in a particular reaction. If this is not the case, transport reactions are identified through annotations, which cannot detect modified transport reactions.

memote.support.helpers.is_transport_reaction_formulae(rxn)[source]

Return boolean if a reaction is a transport reaction (from formulae).

Parameters:
rxn: cobra.Reaction

The metabolic reaction under investigation.

memote.support.helpers.is_transport_reaction_annotations(rxn)[source]

Return boolean if a reaction is a transport reaction (from annotations).

Parameters:
rxn: cobra.Reaction

The metabolic reaction under investigation.

memote.support.helpers.find_converting_reactions(model, pair)[source]

Find all reactions which convert a given metabolite pair.

Parameters:
model : cobra.Model

The metabolic model under investigation.

pair: tuple or list

A pair of metabolite identifiers without compartment suffix.

Returns:
frozenset

The set of reactions that have one of the pair on their left-hand side and the other on the right-hand side.

memote.support.helpers.filter_sbo_term(component, sbo_term)[source]

Return true if the component is annotated with the given SBO term.

Parameters:
component : cobra.Reaction or cobra.Metabolite

Either a reaction or a metabolite instance.

sbo_term : str

The term for either biomass production or biomass.

memote.support.helpers.filter_match_name(component, buzzwords)[source]

Return whether the component’s name matches a biomass description.

Parameters:
component : cobra.Reaction or cobra.Metabolite

Either a reaction or a metabolite instance.

buzzwords : collection of regex patterns

One or more regular expression patterns to match against the name of the component.

Returns:
bool

True if there was any match at all.

Notes

Regex patterns are necessary here to prevent, for example, ‘non-growth’ from matching.

memote.support.helpers.filter_identifier(component, buzzwords)[source]

Return whether the component’s identifier contains a biomass description.

Parameters:
component : cobra.Reaction or cobra.Metabolite

Either a reaction or a metabolite instance.

buzzwords : iterable of str

One or more buzzwords that the identifier should contain.

Returns:
bool

True if there was any match at all.

Notes

We check substring presence here because identifiers are often prefixed with M_ or R_.

memote.support.helpers.find_biomass_reaction(model)[source]

Return a list of the biomass reaction(s) of the model.

Identifiy possible biomass reactions using multiple steps: 1. Look for candidate reactions that include the SBO term SBO:0000629 for biomass production, 2. the ‘buzzwords’ biomass, growth, and bof in reaction names and identifiers, 3. reactions that involve a metabolite with the SBO term SBO:0000649 for biomass, 4. or reactions that involve a metabolite whose name or identifier contains the ‘buzzword’ biomass. Return identified reactions excluding any boundary reactions.

Parameters:
model : cobra.Model

The metabolic model under investigation.

Returns:
list

Identified biomass reactions (if any).

memote.support.helpers.find_demand_reactions(model)[source]

Return a list of demand reactions.

Parameters:
model : cobra.Model

The metabolic model under investigation.

Notes

[1] defines demand reactions as: – ‘unbalanced network reactions that allow the accumulation of a compound’ – reactions that are chiefly added during the gap-filling process – as a means of dealing with ‘compounds that are known to be produced by the organism [..] (i) for which no information is available about their fractional distribution to the biomass or (ii) which may only be produced in some environmental conditions – reactions with a formula such as: ‘met_c -> ‘

Demand reactions differ from exchange reactions in that the metabolites are not removed from the extracellular environment, but from any of the organism’s compartments.

References

[1]Thiele, I., & Palsson, B. Ø. (2010, January). A protocol for generating a high-quality genome-scale metabolic reconstruction. Nature protocols. Nature Publishing Group. http://doi.org/10.1038/nprot.2009.203
memote.support.helpers.find_sink_reactions(model)[source]

Return a list of sink reactions.

Parameters:
model : cobra.Model

The metabolic model under investigation.

Notes

[1] defines sink reactions as: – ‘similar to demand reactions’ but reversible, thus able to supply the model with metabolites – reactions that are chiefly added during the gap-filling process – as a means of dealing with ‘compounds that are produced by nonmetabolic cellular processes but that need to be metabolized’ – reactions with a formula such as: ‘met_c <-> ‘

Sink reactions differ from exchange reactions in that the metabolites are not removed from the extracellular environment, but from any of the organism’s compartments.

References

[1]Thiele, I., & Palsson, B. Ø. (2010, January). A protocol for generating a high-quality genome-scale metabolic reconstruction. Nature protocols. Nature Publishing Group. http://doi.org/10.1038/nprot.2009.203
memote.support.helpers.find_exchange_rxns(model)[source]

Return a list of exchange reactions.

Parameters:
model : cobra.Model

The metabolic model under investigation.

Notes

[1] defines exchange reactions as: – reactions that ‘define the extracellular environment’ – ‘unbalanced, extra-organism reactions that represent the supply to or removal of metabolites from the extra-organism “space”’ – reactions with a formula such as: ‘met_e -> ‘ or ‘ -> met_e’ or ‘met_e <=> ‘

Exchange reactions differ from demand reactions in that the metabolites are removed from or added to the extracellular environment only. With this the uptake or secretion of a metabolite is modeled, respectively.

References

[1]Thiele, I., & Palsson, B. Ø. (2010, January). A protocol for generating a high-quality genome-scale metabolic reconstruction. Nature protocols. Nature Publishing Group. http://doi.org/10.1038/nprot.2009.203
memote.support.helpers.find_interchange_biomass_reactions(model, biomass=None)[source]

Return the set of all transport, boundary, and biomass reactions.

These reactions are either pseudo-reactions, or incorporated to allow metabolites to pass between compartments. Some tests focus on purely metabolic reactions and hence exclude this set.

Parameters:
model : cobra.Model

The metabolic model under investigation.

biomass : list or cobra.Reaction, optional

A list of cobrapy biomass reactions.

memote.support.helpers.run_fba(model, rxn_id, direction='max', single_value=True)[source]

Return the solution of an FBA to a set objective function.

Parameters:
model : cobra.Model

The metabolic model under investigation.

rxn_id : string

A string containing the reaction ID of the desired FBA objective.

direction: string

A string containing either “max” or “min” to specify the direction of the desired FBA objective function.

single_value: boolean

Indicates whether the results for all reactions are gathered from the solver, or only the result for the objective value.

Returns:
cobra.solution

The cobra solution object for the corresponding FBA problem.

memote.support.helpers.get_biomass_flux(model: cobra.Model, rxn_id: str) → float[source]

Compute the maximal objective value.

Parameters:
model : cobra.Model

The metabolic model under investigation.

rxn_id : string

A string containing the reaction ID of the desired FBA objective.

Returns:
float

The objective value which takes infeasibility and solver tolerances into account.

memote.support.helpers.close_boundaries_sensibly(model)[source]

Return a cobra model with all boundaries closed and changed constraints.

In the returned model previously fixed reactions are no longer constrained as such. Instead reactions are constrained according to their reversibility. This is to prevent the FBA from becoming infeasible when trying to solve a model with closed exchanges and one fixed reaction.

Parameters:
model : cobra.Model

The metabolic model under investigation.

Returns:
cobra.Model

A cobra model with all boundary reactions closed and the constraints of each reaction set according to their reversibility.

memote.support.helpers.open_exchanges(model)[source]

Open all exchange reactions.

Parameters:
model : cobra.Model

The metabolic model under investigation.

memote.support.helpers.open_boundaries(model)[source]

Open all boundary reactions.

Parameters:
model : cobra.Model

The metabolic model under investigation.

memote.support.helpers.metabolites_per_compartment(model, compartment_id)[source]

Identify all metabolites that belong to a given compartment.

Parameters:
model : cobra.Model

The metabolic model under investigation.

compartment_id : string

Model specific compartment identifier.

Returns:
list

List of metabolites belonging to a given compartment.

memote.support.helpers.largest_compartment_id_met(model)[source]

Return the ID of the compartment with the most metabolites.

Parameters:
model : cobra.Model

The metabolic model under investigation.

Returns:
string

Compartment ID of the compartment with the most metabolites.

memote.support.helpers.find_compartment_id_in_model(model, compartment_id)[source]

Identify a model compartment by looking up names in COMPARTMENT_SHORTLIST.

Parameters:
model : cobra.Model

The metabolic model under investigation.

compartment_id : string

Memote internal compartment identifier used to access compartment name shortlist to look up potential compartment names.

Returns:
string

Compartment identifier in the model corresponding to compartment_id.

memote.support.helpers.find_met_in_model(model, mnx_id, compartment_id=None)[source]

Return specific metabolites by looking up IDs in METANETX_SHORTLIST.

Parameters:
model : cobra.Model

The metabolic model under investigation.

mnx_id : string

Memote internal MetaNetX metabolite identifier used to map between cross-references in the METANETX_SHORTLIST.

compartment_id : string, optional

ID of the specific compartment where the metabolites should be found. Defaults to returning matching metabolites from all compartments.

Returns:
list

cobra.Metabolite(s) matching the mnx_id.

memote.support.helpers.find_objective_function(model)[source]

Return reactions that are part of the objective function.

Parameters:
model : cobra.Model

The metabolic model under investigation.

memote.support.helpers.find_bounds(model)[source]

Return the median upper and lower bound of the metabolic model.

Bounds can vary from model to model. Cobrapy defaults to (-1000, 1000) but this may not be the case for merged or autogenerated models. In these cases, this function is used to iterate over all the bounds of all the reactions and find the median bound values in the model, which are then used as the ‘most common’ bounds.

Parameters:
model : cobra.Model

The metabolic model under investigation.