cameo.core package

Submodules

cameo.core.gene module

class cameo.core.gene.Gene(id=None, name=”, functional=True)[source]

Bases: cobra.core.Gene.Gene

Species is a class for holding information regarding a chemical Species

Attributes

Methods

classmethod clone(gene, model=None)[source]
id
knock_out(time_machine=None)[source]

Knockout gene by marking as non-functional and set all its affected reactions’ bounds to zero

Parameters:= TimeMachine (time_machine) – A time TimeMachine instance can be provided to easily undo the knockout.
Returns:
Return type:None

cameo.core.manipulation module

Manage manipulations such as swapping reaction cofactors, over-express or down-regulate genes and reactions.

cameo.core.manipulation.increase_flux(reaction, ref_value, value, time_machine=None)[source]

lb 0 ub |--------------------------- ' ---------------------------|

<- - -|———-‘
‘———-|- - - ->
Parameters:
  • reaction (cameo.Reaction) – The reaction to over-express.
  • ref_value (float) – The flux value to come from.
  • value (float) – The flux value to achieve.
  • time_machine (TimeMachine) – The action stack manager.
cameo.core.manipulation.decrease_flux(reaction, ref_value, value, time_machine=None)[source]

lb 0 ub |--------------------------- ' ---------------------------|

|- - >———-‘
‘———-<- - - -|
Parameters:
  • reaction (cameo.Reaction) – The reaction to down_regulate.
  • ref_value (float) – The flux value to come from.
  • value (float) – The flux value to achieve.
  • time_machine (TimeMachine) – The action stack manager.
cameo.core.manipulation.reverse_flux(reaction, ref_value, value, time_machine=None)[source]

Forces a reaction to have a minimum flux level in the opposite direction of a reference state.

lb 0 ub |--------------------------- ' ---------------------------|

<———-‘- - - - - - - ->
Parameters:
  • reaction (cameo.Reaction) – The reaction that will be inverted.
  • ref_value (float) – The flux value to come from.
  • value (float) – The flux value to achieve.
  • time_machine (TimeMachine) – The action stack manager.
cameo.core.manipulation.swap_cofactors(reaction, model, swap_pairs, inplace=True, time_machine=None)[source]

Swaps the cofactors of a reaction. For speed, it can be done inplace which just changes the coefficients. If not done inplace, it will create a new Reaction, add it to the model, and knockout the original reaction.

Parameters:
  • reaction (cameo.Reaction) – The reaction to swap.
  • model (cameo.SolverBasedModel) – A constraint-based model.
  • swap_pairs (tuple) – A tuple of (cofactors, equivalent_cofactors)
  • inplace (bool) – If replace is done inplace, it changes the coefficients in the matrix. Otherwise, it creates a new reaction with the other cofactors and adds it to the model.
  • time_machine (: TimeMachine) – The action stack manager.
Returns:

A reaction with swapped cofactors (the same if inplace).

Return type:

Reaction

cameo.core.metabolite module

class cameo.core.metabolite.Metabolite(id=None, formula=None, name=”, charge=None, compartment=None)[source]

Bases: cobra.core.Metabolite.Metabolite

Metabolite is a class for holding information regarding a metabolite in a cobra.Reaction object.

Attributes

Methods

classmethod clone(metabolite, model=None)[source]
remove_from_model(method=’subtractive’, **kwargs)[source]

Removes the association from self.model

method: ‘subtractive’ or ‘destructive’.
If ‘subtractive’ then the metabolite is removed from all associated reactions. If ‘destructive’ then all associated reactions are removed from the Model.
n_carbon

number of carbon atoms

Returns:number of carbons in this metabolite
Return type:int
constraint
knock_out(time_machine=None, force_steady_state=False)[source]

‘Knockout’ a metabolite. This can be done in 2 ways:

  1. Implementation follows the description in [1]
    “All fluxes around the metabolite M should be restricted to only produce the metabolite,
    for which balancing constraint of mass conservation is relaxed to allow nonzero values of the incoming fluxes whereas all outgoing fluxes are limited to zero.”
  2. Force steady state
    All reactions consuming the metabolite are restricted to only produce the metabolite. A demand reaction is added to sink the metabolite produced to keep the problem feasible under the S.v = 0 constraint.

Knocking out a metabolite overrules the constraints set on the reactions producing the metabolite.

Parameters:
  • time_machine (TimeMachine) – An action stack to reverse actions
  • force_steady_state (bool) – If True, uses approach 2.

References

[R1]Kim, P.-J., Lee, D.-Y., Kim, T. Y., Lee, K. H., Jeong, H., Lee, S. Y., & Park, S. (2007). Metabolite essentiality elucidates robustness of Escherichia coli metabolism. PNAS, 104(34), 13638-13642
id

cameo.core.pathway module

This module implements a pathway data structure that can be added to a model for example.

class cameo.core.pathway.Pathway(reactions, *args, **kwargs)[source]

Bases: object

Representation of a pathway (a set of reactions)

reactions

list o Reaction – The list of reactions in the pathway.

Attributes

Methods

data_frame
classmethod from_file(file_path, sep=’\t’)[source]

Read a pathway from a file. The file format is: reaction_id<sep>equation<sep>lower_limit<sep>upper_limit<sep>name<sep>comments

The equation is defined by: coefficient * substrate_name#substrate_id + … <=> coefficient * product_name#product_id

Parameters:
  • file_path (str) – The path to the file containing the pathway
  • sep (str) – The separator between elements in the file (default: ” “)
Returns:

Return type:

Pathway

to_file(file_path, sep=’\t’)[source]

Writes the pathway to a file.

Parameters:
  • file_path (str) – The path to the file where the pathway will be written
  • sep (str) – The separator between elements in the file (default: ” “)
plug_model(model, tm=None)[source]

Plugs the pathway to a model. If a TimeMachine is provided, the reactions will be removed after reverting the TimeMachine.

Metabolites are matched in the model by id. For metabolites with no ID in the model, an exchange reaction is added to the model

Parameters:
  • model (SolverBasedModel) – The model to plug in the pathway
  • tm (TimeMachine) – Optionally, a TimeMachine object can be added to the operation

cameo.core.reaction module

class cameo.core.reaction.Reaction(id=None, name=”, subsystem=”, lower_bound=0, upper_bound=1000)[source]

Bases: cobra.core.Reaction.Reaction

This class extends the cobrapy Reaction class to work with SolverBasedModel.

Notes

See also documentation for cobra.core.Reaction.Reaction for an extensive list of inherited attributes.

Attributes

Methods

classmethod clone(reaction, model=None)[source]

Clone a reaction.

Parameters:
  • reaction (Reaction, cobra.core.Reaction.Reaction) –
  • model (model, optional) –
Returns:

Return type:

Reaction

gene_reaction_rule
reversibility

Whether the reaction can proceed in both directions (reversible)

This is computed from the current upper and lower bounds.

flux_expression

An optlang variable representing the forward flux (if associated with model), otherwise None. Representing the net flux if model.reversible_encoding == ‘unsplit’

forward_variable

An optlang variable representing the forward flux (if associated with model), otherwise None.

reverse_variable

An optlang variable representing the reverse flux (if associated with model), otherwise None.

functional

reaction is functional

Returns:True if the gene-protein-reaction (GPR) rule is fulfilled for this reaction, or if reaction is not associated to a model, otherwise False.
Return type:bool
lower_bound
upper_bound
model

returns the model the reaction is a part of

objective_coefficient
effective_lower_bound
effective_upper_bound
flux
reduced_cost
is_exchange
add_metabolites(metabolites, combine=True, **kwargs)[source]

Add metabolites and stoichiometric coefficients to the reaction. If the final coefficient for a metabolite is 0 then it is removed from the reaction.

metabolites: dict
{str or Metabolite: coefficient}
combine: Boolean.
Describes behavior a metabolite already exists in the reaction. True causes the coefficients to be added. False causes the coefficient to be replaced. True and a metabolite already exists in the
add_to_container_model: Boolean.
Add the metabolite to the Model the reaction is associated with (i.e. self.model)
id
knock_out(time_machine=None)[source]

Knockout reaction by setting its bounds to zero.

Parameters:= TimeMachine (time_machine) – A time TimeMachine instance can be provided to undo the knockout eventually.
Returns:
Return type:None
pop(metabolite_id)[source]

Removes a given metabolite from the reaction stoichiometry, and returns the coefficient.

remove_from_model(model=None, remove_orphans=False)[source]

Removes the reaction from the model while keeping it intact

remove_orphans: Boolean
Remove orphaned genes and metabolites from the model as well

model: deprecated argument, must be None

delete(remove_orphans=False)[source]

Completely delete a reaction

This removes all associations between a reaction the associated model, metabolites and genes (unlike remove_from_model which only dissociates the reaction from the model).

remove_orphans: Boolean
Remove orphaned genes and metabolites from the model as well
change_bounds(lb=None, ub=None, time_machine=None)[source]

Changes one or both of the reaction bounds and allows the changes to be reversed with a TimeMachine

n_carbon

number of carbon atoms

Returns:number of carbons for all metabolites involved in a reaction
Return type:int

cameo.core.result module

class cameo.core.result.MetaInformation(*args, **kwargs)[source]

Bases: object

Attributes

system_info
responsible
timestamp

doc string

human_readable_timestamp
class cameo.core.result.Result(*args, **kwargs)[source]

Bases: object

Attributes

Methods

meta_information
data_frame
plot(grid=None, width=None, height=None, title=None, *args, **kwargs)[source]

cameo.core.solution module

class cameo.core.solution.SolutionBase(model)[source]

Bases: object

Attributes

Methods

data_frame
as_cobrapy_solution()[source]

Convert into a cobrapy Solution.

Returns:
Return type:cobra.core.Solution.Solution
get_primal_by_id(reaction_id)[source]

Return a flux/primal value for a reaction.

Parameters:reaction_id (str) – A reaction ID.
x_dict
x
y_dict
y
objective_value
class cameo.core.solution.Solution(model, *args, **kwargs)[source]

Bases: cameo.core.solution.SolutionBase

This class mimicks the cobrapy Solution class.

fluxes

OrderedDict – A dictionary of flux values.

reduced_costs

OrderedDict – A dictionary of reduced costs.

Notes

See also documentation for cobra.core.Solution.Solution for an extensive list of inherited attributes.

Attributes

Methods

class cameo.core.solution.LazySolution(model, *args, **kwargs)[source]

Bases: cameo.core.solution.SolutionBase

This class implements a lazy evaluating version of the cobrapy Solution class.

model

SolverBasedModel

fluxes

OrderedDict – A dictionary of flux values.

reduced_costs

OrderedDict – A dictionary of reduced costs.

Notes

See also documentation for cobra.core.Solution.Solution for an extensive list of inherited attributes.

Attributes

Methods

status
f
fluxes
reduced_costs
shadow_prices
get_primal_by_id(reaction_id)[source]

Return a flux/primal value for a reaction.

Parameters:reaction_id (str) – A reaction ID.

cameo.core.solver_based_model module

A solver-based model class and other extensions of cobrapy objects.

cameo.core.solver_based_model.to_solver_based_model(cobrapy_model, solver_interface=<module ‘optlang’ from ‘/home/travis/virtualenv/python3.6.1/lib/python3.6/site-packages/optlang/__init__.py’>)[source]

Convert a cobrapy model into a solver-based model.

Parameters:
  • cobrapy_model (cobra.core.Model) –
  • solver_interface (solver_interface, optional) – For example, optlang.glpk_interface or any other optlang interface (the default is optlang.interface).
class cameo.core.solver_based_model.SolverBasedModel(description=None, solver_interface=<module ‘optlang’ from ‘/home/travis/virtualenv/python3.6.1/lib/python3.6/site-packages/optlang/__init__.py’>, **kwargs)[source]

Bases: cobra.core.Model.Model

Implements a model with an attached optlang solver instance.

Every model manipulation is immediately reflected in the solver instance.

Attributes

Methods

non_functional_genes

All non-functional genes in this model :returns: set with the genes that are marked as non-functional :rtype: frozenset

copy()[source]

Needed for compatibility with cobrapy.

objective

The model objective.

solver

Attached solver instance.

Very useful for accessing the optimization problem directly. Furthermore, can be used to define additional non-metabolic constraints.

Examples

>>> new_constraint_from_objective = model.solver.interface.Constraint(model.objective.expression, lb=0.99)
>>> model.solver.add(new_constraint)
exchanges

Exchange reactions in model.

Reactions that either don’t have products or substrates.

add_metabolites(metabolite_list)[source]

Will add a list of metabolites to the the object, if they do not exist and then expand the stochiometric matrix

metabolite_list: A list of Metabolite objects

add_metabolite(metabolite)[source]
add_reactions(reaction_list)[source]

Will add a cobra.Reaction object to the model, if reaction.id is not in self.reactions.

reaction_list: A list of Reaction objects

remove_reactions(the_reactions, delete=True, remove_orphans=False)[source]

remove reactions from the model

reactions: [Reaction] or [str]
The reactions (or their id’s) to remove
delete: Boolean
Whether or not the reactions should be deleted after removal. If the reactions are not deleted, those objects will be recreated with new metabolite and gene objects.
remove_orphans: Boolean
Remove orphaned genes and metabolites from the model as well
add_demand(metabolite, prefix=’DM_’, time_machine=None)[source]
add_exchange(metabolite, demand=True, prefix=’DM_’, bound=1000.0, time_machine=None)[source]

Add an exchange reaction for a metabolite (demand=TRUE: metabolite –> Ø or demand=False: 0 –> metabolite )

Parameters:
  • metabolite (Metabolite) –
  • demand (bool, optional) – True for sink type exchange, False for uptake type exchange
  • prefix (str, optional) – A prefix that will be added to the metabolite ID to be used as the demand reaction’s ID (defaults to ‘DM_’).
  • bound (float, optional) – Upper bound for sink reaction / lower bound for uptake (multiplied by -1)
  • time_machine (TimeMachine, optional) – A TimeMachine instance that enables undoing.
Returns:

The created demand reaction.

Return type:

Reaction

fix_objective_as_constraint(time_machine=None, fraction=1)[source]

Fix current objective as an additional constraint (e.g., ..math`c^T v >= max c^T v`).

Parameters:time_machine (TimeMachine, optional) – A TimeMachine instance can be provided, making it easy to undo this modification.
Returns:
Return type:None
add_ratio_constraint(expr1, expr2, ratio, prefix=’ratio_constraint_’)[source]

Adds a ratio constraint (expr1/expr2 = ratio) to the model.

Parameters:
  • expr1 (str, Reaction, list or sympy.Expression) – A reaction, a reaction ID or a linear expression.
  • expr2 (str, Reaction, list or sympy.Expression) – A reaction, a reaction ID or a linear expression.
  • ratio (float) – The ratio in expr1/expr2 = ratio
  • prefix (str) – The prefix that will be added to the constraint ID (defaults to ‘ratio_constraint_’).
Returns:

The constraint name will be composed of prefix and the two reaction IDs (e.g. ‘ratio_constraint_reaction1_reaction2’).

Return type:

optlang.Constraint

Examples

>>> model.add_ratio_constraint('r1', 'r2', 0.5)
>>> print(model.solver.constraints['ratio_constraint_r1_r2'])
ratio_constraint: ratio_constraint_r1_r2: 0 <= -0.5 * r1 + 1.0 * PGI <= 0
optimize(objective_sense=None, solution_type=<class ‘cameo.core.solution.Solution’>, **kwargs)[source]

OptlangBasedModel implementation of optimize.

Exists only for compatibility reasons. Uses model.solve() instead.

solve(solution_type=<class ‘cameo.core.solution.LazySolution’>, *args, **kwargs)[source]

Optimize model.

Parameters:solution_type (Solution or LazySolution, optional) – The type of solution that should be returned (defaults to LazySolution).
Returns:
Return type:Solution or LazySolution
essential_metabolites(threshold=1e-06, force_steady_state=False)[source]

Return a list of essential metabolites.

This can be done in 2 ways:

  1. Implementation follows the description in [1]:
    “All fluxes around the metabolite M should be restricted to only produce the metabolite,
    for which balancing constraint of mass conservation is relaxed to allow nonzero values of the incoming fluxes whereas all outgoing fluxes are limited to zero.”
  2. Force Steady State approach:
    All reactions consuming the metabolite are restricted to only produce the metabolite. A demand reaction is added to sink the metabolite produced to keep the problem feasible under the S.v = 0 constraint.

Briefly, for each metabolite, all reactions that consume that metabolite are blocked and if that makes the model either infeasible or results in near-zero flux in the model objective, then the metabolite is considered essential.

Parameters:
  • threshold (float (default 1e-6)) – Minimal objective flux to be considered viable.
  • force_steady_state (bool) – If True, uses approach 2.

References

[R2]Kim, P.-J., Lee, D.-Y., Kim, T. Y., Lee, K. H., Jeong, H., Lee, S. Y., & Park, S. (2007). Metabolite essentiality elucidates robustness of Escherichia coli metabolism. PNAS, 104(34), 13638–13642
essential_reactions(threshold=1e-06)[source]

Return a list of essential reactions.

Parameters:threshold (float (default 1e-6)) – Minimal objective flux to be considered viable.
Returns:List of essential reactions
Return type:list
essential_genes(threshold=1e-06)[source]

Return a list of essential genes.

Parameters:threshold (float (default 1e-6)) – Minimal objective flux to be considered viable.
Returns:List of essential genes
Return type:list
S
medium

Current medium.

load_medium(medium, copy=False, delimiter=’\t’)[source]

Loads a medium into the model. If copy is true it will return a copy of the model. Otherwise it applies the medium to itself. Supported formats TODO

Parameters:
  • medium (str, pandas.DataFrame, dict.) –
  • copy (boolean, optional) – If True copies the model, otherwise the changes will happen inplace.
  • delimiter (str) – Only if loading the medium from a file.
Returns:

If copy=True, returns a copy of the model.

Return type:

SolverBasedModel

change_objective(value, time_machine=None)[source]

Changes the objective of the model to the given value. Allows passing a time machine to revert the change later

cameo.core.solver_based_model_dual module

cameo.core.solver_based_model_dual.convert_to_dual(model)[source]
cameo.core.solver_based_model_dual.to_dual_model(solver_based_model, solver_interface=None)[source]
class cameo.core.solver_based_model_dual.SolverBasedModelDual(*args, **kwargs)[source]

Bases: cameo.core.solver_based_model.SolverBasedModel

A SolverBasedModel that also contains the dual variables and constraints, allowing primal and dual problems to be combined.

Dual variables corresponding to stoichiometric constraints are prefixed by lambda Dual variables corresponding to flux bounds are prefixed by mu Other constraints are not supported at the moment!

Dual constraints will be set according to the original primal objective. The objective can be changed subsequently to optimize an outer problem.

Attributes

Methods

objective
dual_objective
primal_objective()[source]

cameo.core.strain_design module

Core implementation of strain design. It contains core structures. Targets (and subclasses) are identified by strain design methods.

class cameo.core.strain_design.StrainDesignMethod(*args, **kwargs)[source]

Bases: object

Methods

run(*args, **kwargs)[source]
class cameo.core.strain_design.StrainDesign(targets)[source]

Bases: object

A StrainDesign is a collection of targets in a COBRA model. The targets, identified by a StrainDesignMethod, map elements in the model that need to be modified to achieve the objective of the design method.

Methods

apply(model, time_machine=None)[source]
to_gnomic()[source]
class cameo.core.strain_design.StrainDesignMethodResult(designs, *args, **kwargs)[source]

Bases: cameo.core.result.Result

Attributes

Methods

data_frame
display_on_map(index, map_name)[source]
plot(grid=None, width=None, height=None, title=None, *args, **kwargs)[source]

cameo.core.target module

class cameo.core.target.ReactionCofactorSwapTarget(id, swap_pairs, *args, **kwargs)[source]

Bases: cameo.core.target.Target

Swap cofactors of a given reaction.

Attributes

Methods

apply(model, time_machine=None)[source]
swap_str
to_gnomic()[source]
class cameo.core.target.ReactionKnockinTarget(id, value, *args, **kwargs)[source]

Bases: cameo.core.target.KnockinTarget

Methods

apply(model, time_machine=None)[source]
to_gnomic()[source]
class cameo.core.target.GeneModulationTarget(id, value, reference_value, *args, **kwargs)[source]

Bases: cameo.core.target.FluxModulationTarget

Attributes

Methods

get_model_target(model)[source]
class cameo.core.target.GeneKnockoutTarget(id, *args, **kwargs)[source]

Bases: cameo.core.target.GeneModulationTarget

Gene Knockout Target. Knockout a gene present in a COBRA model.

Attributes

Methods

apply(model, time_machine=None)[source]
to_gnomic()[source]
class cameo.core.target.ReactionModulationTarget(id, value, reference_value)[source]

Bases: cameo.core.target.FluxModulationTarget

Attributes

Methods

get_model_target(model)[source]
class cameo.core.target.ReactionKnockoutTarget(id)[source]

Bases: cameo.core.target.ReactionModulationTarget

Reaction Knockout Target. Knockout a reaction present in a COBRA model.

Attributes

Methods

apply(model, time_machine=None)[source]

Module contents

This package implements the basic data structures (models, reactions etc.) used in cameo.