cameo package

Subpackages

Submodules

cameo.config module

cameo.exceptions module

exception cameo.exceptions.IncompatibleTargets(target1, target2)[source]

Bases: Exception

exception cameo.exceptions.SolveError(message)[source]

Bases: Exception

exception cameo.exceptions.Infeasible(message)[source]

Bases: cameo.exceptions.SolveError

exception cameo.exceptions.Unbounded(message)[source]

Bases: cameo.exceptions.SolveError

exception cameo.exceptions.FeasibleButNotOptimal(message)[source]

Bases: cameo.exceptions.SolveError

exception cameo.exceptions.UndefinedSolution(message)[source]

Bases: cameo.exceptions.SolveError

cameo.io module

cameo.io.load_model(path_or_handle, solver_interface=<module ‘optlang’ from ‘/home/travis/virtualenv/python3.6.1/lib/python3.6/site-packages/optlang/__init__.py’>, sanitize=True)[source]

Read a metabolic model .

Parameters:
  • path_or_handle (path, fhandle or name.) –
    One of:
    • file path of a model file;
    • file handle to a SBML or pickled model; or
    • the identifier of a model in a web database (optflux.org/models)
  • solver_interface (solver_interface, optional) – E.g. optlang.glpk_interface or any other optlang interface.
  • sanitize (boolean, optional) – If reaction and metabolite IDs should be sanitized (works only for SBML models).
cameo.io.sanitize_ids(model)[source]

Makes IDs crippled by the XML specification less annoying.

For example, EX_glc_LPAREN_e_RPAREN_ will be converted to EX_glc_lp_e_rp_. Furthermore, reactions and metabolites will be equipped with a nice_id attribute that provides the original ID, i.e., EX_glc(d).

Parameters:model (model) –

Notes

Will add a nice_id attribute.

cameo.parallel module

class cameo.parallel.MultiprocessingView(processes=2, **kwargs)[source]

Bases: cameo.util.Singleton

Provides a parallel view (similar to IPython)

Attributes

Methods

pool
map(*args, **kwargs)[source]
apply(func, *args, **kwargs)[source]
apply_async(func, *args, **kwargs)[source]
imap(func, *args, **kwargs)[source]
shutdown()[source]
class cameo.parallel.SequentialView[source]

Bases: object

Methods

map(*args, **kwargs)[source]
apply(func, *args, **kwargs)[source]
apply_async(func, *args, **kwargs)[source]
imap(func, *args, **kwargs)[source]
shutdown()[source]

cameo.util module

class cameo.util.frozendict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)[source]

Bases: dict

Methods

popitem()[source]
pop(k, d=None)[source]
setdefault(k, d=None)[source]
update(E=None, **F)[source]
cameo.util.float_ceil(val, decimals=0)[source]

Like ceil but the number of decimals can be set.

Equivalent of $$round(val + 1e^{-decimals}/2, decimals)$$

val: float, numpy.array
The initial value.
decimals: int
The number of decimal places.
Returns:
Return type:float, numpy.array
cameo.util.float_floor(val, decimals=0)[source]

Like floor but the number of decimals can be set.

Equivalent of $$round(val - 1e^{-decimals}/2, decimals)$$

val: float, numpy.array
The initial value.
decimals: int
The number of decimal places.
Returns:
Return type:float, numpy.array
class cameo.util.ProblemCache(model)[source]

Bases: object

Variable and constraint cache for models.

To be used in complex methods that require many extra variables and constraints when one must run simulations with the same method many times.

It allows rollback to the previous state in case one iteration fails to build the problem or generates an invalid state.

Attributes

Methods

begin_transaction()[source]

Creates a time point. If rollback is called, the variables and constrains will be reverted to this point.

model
add_constraint(constraint_id, create, update, *args, **kwargs)[source]

Adds a new cached constraint.

The create and update functions must have the following signatures: >>> create(model, constraint_id, *args) >>> update(model, constraint, *args)

“args” in the first example must match args on the second example.

Parameters:
  • constraint_id (str) – The identifier of the constraint
  • create (function) – A function that creates an optlang.interface.Constraint
  • update (function) – a function that updates an optlang.interface.Constraint
add_variable(variable_id, create, update, *args, **kwargs)[source]

Adds a new cached variable.

The create and update functions must have the following signatures: >>> create(model, variable_id, *args) >>> update(model, variable, *args)

“args” in the first example must match args on the second example.

Parameters:
  • constraint_id (str) – The identifier of the constraint
  • create (function) – A function that creates an optlang.interface.Variable
  • update (function) – a function that updates an optlang.interface.Variable
add_objective(create, update, *args)[source]
reset()[source]

Removes all constraints and variables from the cache.

rollback()[source]

Returns to the previous transaction start point.

class cameo.util.RandomGenerator(seed=None)[source]

Bases: object

Methods

seed(seed)[source]
random()[source]
randint(a, b=None)[source]
sample(population, k)[source]
uniform(low=0.0, high=1.0, size=None)[source]
class cameo.util.Singleton[source]

Bases: object

Singleton class to be extended

class cameo.util.AutoVivification[source]

Bases: dict

Implementation of perl’s autovivification feature. Checkout http://stackoverflow.com/a/652284/280182

Methods

class cameo.util.TimeMachine[source]

Bases: object

Travel back and forth in time.

Methods

undo(bookmark=None)[source]
redo()[source]
reset()[source]
class cameo.util.Timer(name=None)[source]

Bases: object

Taken from http://stackoverflow.com/a/5849861/280182

class cameo.util.IntelliContainer(**kwargs)[source]

Bases: object

cameo.util.inheritdocstring(name, bases, attrs)[source]

Use as metaclass to inherit class and method docstrings from parent. Adapted from http://stackoverflow.com/questions/13937500/inherit-a-parent-class-docstring-as-doc-attribute

cameo.util.partition_(lst, n)[source]

Partition a list into n bite size chunks.

cameo.util.partition(ite, n)[source]

Partition an iterable into n bite size chunks.

cameo.util.flatten(l)[source]
cameo.util.generate_colors(n)[source]
cameo.util.memoize(function, memo={})[source]
cameo.util.get_system_info()[source]
cameo.util.in_ipnb()[source]

Check if it is running inside an IPython Notebook (updated for new notebooks)

cameo.util.str_to_valid_variable_name(s)[source]

Adapted from http://stackoverflow.com/a/3303361/280182

cameo.util.zip_repeat(long_iter, short_iter)[source]

Zips two iterable objects but repeats the second one if it is shorter than the first one.

Parameters:
  • long_iter (iterable) –
  • short_iter (iterable) –
Returns:

Return type:

generator

cameo.util.pick_one(iterable)[source]

Helper function that returns an element of an iterable (it the iterable is ordered this will be the first element).

cameo.util.reduce_reaction_set(reaction_set, groups)[source]

Reduces a set of reactions according to a number of groups of reactions. The reduction will be performed so that the resulting set will contain no more than 1 reaction from each group. Reactions that are not in any of the groups will remain in the set.

Parameters:
  • reaction_set (Set) –
  • groups (Iterable of sets) –
Returns:

Return type:

Set

cameo.util.decompose_reaction_groups(reaction_groups, reactions)[source]
reaction_groups : list
A list with dictionaries (element: relative_coefficient)
reactions : list, set, tuple
A collection of reactions.
Returns:A list of all possible group substitutions.
Return type:list
cameo.util.current_solver_name(model)[source]

Give a string representation for an optlang interface.

Parameters:model (cameo.core.SolverBasedModel) – A model
Returns:The name of the interface as a string
Return type:string

Module contents

CAMEO: Computer Aided Metabolic Engineering & Optimization

Cameo is a high-level python library developed to aid the in silico strain design process in metabolic engineering projects. The library provides a modular architecture that enables the efficient construction of custom analysis workflows.

Example

from cameo import load_model

# load a model from SBML format (can be found under cameo/tests/data) model = load_model(‘EcoliCore.xml’)

# solve the model and print the objective value solution = model.solve() print ‘Objective value:’, solution.f

# Determine a set of gene deletions that will optimize the production # of a desired compound from cameo.strain_design.heuristic import GeneKnockoutOptimization from cameo.strain_design.heuristic.objective_functions import biomass_product_coupled_yield from cameo.flux_analysis.simulation import fba

objective = biomass_product_coupled_yield(“Ec_biomass_iJO1366_core_53p95M”,
EX_succ_lp_e_rp_”, “EX_glc_lp_e_rp_”)
optimization = GeneKnockoutOptimization(model=model, objective_function=of,
simulation_method=fba, heuristic_method=inspyred.ec.GA)
optimization.run(max_evaluations=2000, n=1,
mutation_rate=0.3, view=cameo.parallel.SequentialView(), product=”EX_succ_lp_e_rp_”, num_elites=1)