# cameo.core package¶

## 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)[source]

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

<- - -|———-‘

‘———-|- - - ->

Parameters
• reaction (cobra.Reaction) – The reaction to over-express.

• ref_value (float) – The flux value to come from.

• value (float) – The flux value to achieve.

cameo.core.manipulation.decrease_flux(reaction, ref_value, value)[source]

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

|- - >———-‘

‘———-<- - - -|

Parameters
• reaction (cobra.Reaction) – The reaction to down_regulate.

• ref_value (float) – The flux value to come from.

• value (float) – The flux value to achieve.

cameo.core.manipulation.reverse_flux(reaction, ref_value, value)[source]

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

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

<———-‘- - - - - - - ->

Parameters
• reaction (cobra.Reaction) – The reaction that will be inverted.

• ref_value (float) – The flux value to come from.

• value (float) – The flux value to achieve.

cameo.core.manipulation.swap_cofactors(reaction, model, swap_pairs, inplace=True)[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 (cobra.Reaction) – The reaction to swap.

• model (cameo.cobra.Model) – 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.

Returns

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

Return type

Reaction

## cameo.core.model_dual module¶

cameo.core.model_dual.convert_to_dual(model)[source]
cameo.core.model_dual.to_dual_model(model, solver_interface=None)[source]
class cameo.core.model_dual.ModelDual(*args, **kwargs)[source]

Bases: cobra.core.model.Model

A cobra.Model 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
boundary

Boundary reactions in the model.

compartments
constraints

The constraints in the cobra model.

demands

Demand reactions in model.

description
dual_objective
exchanges

Exchange reactions in model.

id
medium
objective

Get or set the solver objective

objective_direction

Get or set the objective direction.

problem

The interface to the model’s underlying mathematical problem.

sinks

Sink reactions in model.

solver

Get or set the attached solver instance.

tolerance
variables

The mathematical variables in the cobra model.

Methods

 add_boundary(self, metabolite[, type, …]) Add a boundary reaction for a given metabolite. add_cons_vars(self, what, \*\*kwargs) Add constraints and variables to the model’s mathematical problem. add_groups(self, group_list) Add groups to the model. add_metabolites(self, metabolite_list) Will add a list of metabolites to the model object and add new constraints accordingly. add_reaction(self, reaction) Will add a cobra.Reaction object to the model, if reaction.id is not in self.reactions. add_reactions(self, reaction_list) Add reactions to the model. copy(self) Provides a partial ‘deepcopy’ of the Model. get_associated_groups(self, element) Returns a list of groups that an element (reaction, metabolite, gene) is associated with. get_metabolite_compartments(self) Return all metabolites’ compartments. merge(self, right[, prefix_existing, …]) Merge two models to create a model with the reactions from both models. optimize(self[, objective_sense, raise_error]) Optimize the model using flux balance analysis. remove_cons_vars(self, what) Remove variables and constraints from the model’s mathematical problem. remove_groups(self, group_list) Remove groups from the model. remove_metabolites(self, metabolite_list[, …]) Remove a list of metabolites from the the object. remove_reactions(self, reactions[, …]) Remove reactions from the model. repair(self[, rebuild_index, …]) Update all indexes and pointers in a model slim_optimize(self[, error_value, message]) Optimize model without creating a solution object. summary(self[, solution, threshold, fva, …]) Create a summary of the exchange fluxes of the model.
 primal_objective
property objective

Get or set the solver objective

Before introduction of the optlang based problems, this function returned the objective reactions as a list. With optlang, the objective is not limited a simple linear summation of individual reaction fluxes, making that return value ambiguous. Henceforth, use cobra.util.solver.linear_reaction_coefficients to get a dictionary of reactions with their linear coefficients (empty if there are none)

The set value can be dictionary (reactions as keys, linear coefficients as values), string (reaction identifier), int (reaction index), Reaction or problem.Objective or sympy expression directly interpreted as objectives.

When using a HistoryManager context, this attribute can be set temporarily, reversed when the exiting the context.

property dual_objective
primal_objective(self)[source]

## 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

The list of reactions in the pathway.

Type

list o Reaction

Attributes
data_frame

Methods

 from_file(file_path[, sep]) Read a pathway from a file. plug_model(self, model) Plug the pathway to a model. to_file(self, file_path[, sep]) Writes the pathway to a file.
property data_frame
classmethod from_file(file_path, sep='t')[source]

Read a pathway from a file.

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(self, 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(self, model)[source]

Plug the pathway to a model.

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 (cobra.Model) – The model to plug in the pathway

## cameo.core.result module¶

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

Bases: object

Attributes
responsible
system_info
timestamp

doc string

property system_info
property responsible
property timestamp

doc string

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

Bases: object

Attributes
data_frame
meta_information

Methods

 plot
property meta_information
property data_frame
plot(self, grid=None, width=None, height=None, title=None, *args, **kwargs)[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

 __call__(self, \*args, \*\*kwargs) Call self as a function.
 run
run(self, *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 to_gnomic
apply(self, model)[source]
to_gnomic(self)[source]
class cameo.core.strain_design.StrainDesignMethodResult(designs, *args, **kwargs)[source]
Attributes
data_frame
meta_information

Methods

 display_on_map plot
property data_frame
display_on_map(self, index, map_name)[source]
plot(self, 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
swap_str

Methods

 apply(self, model) Apply the modification to the target, depending on the type. to_gnomic(self) If gnomic is available, return a Gnomic representation of the Target.
apply(self, model)[source]

Apply the modification to the target, depending on the type.

property swap_str
to_gnomic(self)[source]

If gnomic is available, return a Gnomic representation of the Target.

class cameo.core.target.ReactionKnockinTarget(id, value, *args, **kwargs)[source]

Bases: cameo.core.target.KnockinTarget

Methods

 apply(self, model) Apply the modification to the target, depending on the type. to_gnomic(self) If gnomic is available, return a Gnomic representation of the Target.
apply(self, model)[source]

Apply the modification to the target, depending on the type.

to_gnomic(self)[source]

If gnomic is available, return a Gnomic representation of the Target.

class cameo.core.target.GeneModulationTarget(id, value, reference_value, *args, **kwargs)[source]

Bases: cameo.core.target.FluxModulationTarget

Methods

 apply(self, model) Applies a change to the flux. to_gnomic(self) If gnomic is available, return a Gnomic representation of the Target.
 get_model_target
get_model_target(self, model)[source]
class cameo.core.target.GeneKnockoutTarget(id, *args, **kwargs)[source]

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

Methods

 apply(self, model) Applies a change to the flux. to_gnomic(self) If gnomic is available, return a Gnomic representation of the Target.
 get_model_target
apply(self, model)[source]

Applies a change to the flux. If the fold change is higher than 0 it increases the flux. If the target flux is zero it applies a knockout. If the fold change is lower than 0, then it decreases the flux.

Parameters

model (cobra.Model) – A model.

to_gnomic(self)[source]

If gnomic is available, return a Gnomic representation of the Target.

class cameo.core.target.ReactionModulationTarget(id, value, reference_value, **kwargs)[source]

Bases: cameo.core.target.FluxModulationTarget

Methods

 apply(self, model) Applies a change to the flux. to_gnomic(self) If gnomic is available, return a Gnomic representation of the Target.
 get_model_target
get_model_target(self, model)[source]
class cameo.core.target.ReactionKnockoutTarget(id)[source]

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

Methods

 apply(self, model) Applies a change to the flux. to_gnomic(self) If gnomic is available, return a Gnomic representation of the Target.
 get_model_target
apply(self, model)[source]

Applies a change to the flux. If the fold change is higher than 0 it increases the flux. If the target flux is zero it applies a knockout. If the fold change is lower than 0, then it decreases the flux.

Parameters

model (cobra.Model) – A model.

## cameo.core.utils module¶

cameo.core.utils.get_reaction_for(model, value, add=True)[source]

Get or create a reaction for a metabolite or a reaction.

If value is a Metabolite or a Metabolite id, return any already existing demand or exchange reaction. If add is true, add a demand reaction if it does not already exist.

Parameters
• model (cobra.Model) – The model to for which to get / create a reaction

• value (str, Reaction or Metabolite) – A reaction identifier, a Reaction or a Metabolite for which an exchange reaction is to be created.

• add (bool) – Adds a demand reaction for a metabolite if a metabolite is found for value

Returns

Return type

Reaction

Raises

KeyError – If value does not match any Reaction or Metabolite

cameo.core.utils.medium(model)[source]

Current medium for this model.

cameo.core.utils.load_medium(model, medium_def, 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
• model (cobra.Model) – The model to load medium for

• medium_def (str, pandas.DataFrame, dict.) – The medium to load

• 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

cobra.Model

## Module contents¶

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