cameo.core package¶
Submodules¶
cameo.core.gene module¶
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:
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
-
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.
-
constraint
¶
-
knock_out
(time_machine=None, force_steady_state=False)[source]¶ ‘Knockout’ a metabolite. This can be done in 2 ways:
- 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.”
- 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: Returns: Return type:
-
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: Returns: Return type:
-
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
-
classmethod
cameo.core.result module¶
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
¶
-
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
-
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_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
- reactions: [
-
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:
-
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:
- 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.”
- 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: 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.
-
cameo.core.solver_based_model_dual module¶
-
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
¶
-
cameo.core.strain_design module¶
Core implementation of strain design. It contains core structures. Targets (and subclasses) are identified by strain design methods.
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
-
swap_str
¶
-
-
class
cameo.core.target.
ReactionKnockinTarget
(id, value, *args, **kwargs)[source]¶ Bases:
cameo.core.target.KnockinTarget
Methods
-
class
cameo.core.target.
GeneModulationTarget
(id, value, reference_value, *args, **kwargs)[source]¶ Bases:
cameo.core.target.FluxModulationTarget
Attributes
Methods
-
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
-
class
cameo.core.target.
ReactionModulationTarget
(id, value, reference_value)[source]¶ Bases:
cameo.core.target.FluxModulationTarget
Attributes
Methods
-
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
Module contents¶
This package implements the basic data structures (models, reactions etc.) used in cameo.