cameo package¶
Subpackages¶
- cameo.api package
- cameo.core package
- cameo.data package
- cameo.flux_analysis package
- cameo.models package
- cameo.network_analysis package
- cameo.strain_design package
- cameo.ui package
- cameo.visualization package
Submodules¶
cameo.config module¶
cameo.exceptions module¶
cameo.io module¶
- cameo.io.load_model(path_or_handle, solver_interface=<module 'optlang' from '/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/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(*args, **kwargs)[source]¶
Bases:
cameo.util.Singleton
Provides a parallel view (similar to IPython)
- Attributes
- pool
Methods
apply
apply_async
imap
map
shutdown
- property pool¶
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
clear
()copy
()fromkeys
(iterable[, value])Create a new dictionary with keys from iterable and values set to value.
get
(key[, default])Return the value for key if key is in the dictionary, else default.
items
()keys
()pop
(k[,d])If key is not found, d is returned if given, otherwise KeyError is raised
popitem
()Remove and return a (key, value) pair as a 2-tuple.
setdefault
(k[, d])Insert key with a value of default if key is not in the dictionary.
update
([E, ]**F)If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
values
()- popitem()[source]¶
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- pop(k[, d]) v, remove specified key and return the corresponding value. [source]¶
If key is not found, d is returned if given, otherwise KeyError is raised
- 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
- model
Methods
add_constraint
(constraint_id, create, ...)Adds a new cached constraint.
add_variable
(variable_id, create, update, ...)Adds a new cached variable.
Creates a time point.
reset
()Removes all constraints and variables from the cache.
rollback
()Returns to the previous transaction start point.
add_objective
- begin_transaction()[source]¶
Creates a time point. If rollback is called, the variables and constrains will be reverted to this point.
- property 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
variable_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
- class cameo.util.RandomGenerator(seed=None)[source]¶
Bases:
object
Methods
randint
random
sample
seed
uniform
- class cameo.util.AutoVivification[source]¶
Bases:
dict
Implementation of perl’s autovivification feature. Checkout http://stackoverflow.com/a/652284/280182
Methods
clear
()copy
()fromkeys
(iterable[, value])Create a new dictionary with keys from iterable and values set to value.
get
(key[, default])Return the value for key if key is in the dictionary, else default.
items
()keys
()pop
(k[,d])If key is not found, d is returned if given, otherwise KeyError is raised
popitem
(/)Remove and return a (key, value) pair as a 2-tuple.
setdefault
(key[, default])Insert key with a value of default if key is not in the dictionary.
update
([E, ]**F)If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
values
()
- class cameo.util.TimeMachine[source]¶
Bases:
object
Travel back and forth in time.
Methods
__call__
([do, undo, bookmark])Call self as a function.
redo
reset
undo
- class cameo.util.Timer(name=None)[source]¶
Bases:
object
Taken from http://stackoverflow.com/a/5849861/280182
- 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.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_groupslist
A list with dictionaries (element: relative_coefficient)
- reactionslist, 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 (cobra.Model) – 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’)
# optimize the model and print the objective value solution = model.optimize() print ‘Objective value:’, solution.objective_value
# 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”,
- 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)