Skip to content

Commit

Permalink
Merge pull request #18 from biosustain/cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
phantomas1234 committed Nov 26, 2014
2 parents c65ea31 + 7a9501e commit eaf05a1
Show file tree
Hide file tree
Showing 47 changed files with 427 additions and 422 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -5,7 +5,7 @@
[![Documentation Status](https://readthedocs.org/projects/cameo/badge/?version=latest)](https://readthedocs.org/projects/cameo/?badge=latest)

### Vision
Provide a high-level python library to aid _in silico_ strain design process in metabolic engineering projects. The library provides a modular architecture that enables the efficient construction of custom analysis workflows.
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.

### Dependencies
This library depends on:
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/common.py
@@ -1,11 +1,11 @@
# Copyright 2014 Novo Nordisk Foundation Center for Biosustainability, DTU.

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/flux_analysis.py
@@ -1,11 +1,11 @@
# Copyright 2014 Novo Nordisk Foundation Center for Biosustainability, DTU.

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/model.py
@@ -1,11 +1,11 @@
# Copyright 2014 Novo Nordisk Foundation Center for Biosustainability, DTU.

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/run.py
@@ -1,11 +1,11 @@
# Copyright 2014 Novo Nordisk Foundation Center for Biosustainability, DTU.

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/suite.py
@@ -1,11 +1,11 @@
# Copyright 2014 Novo Nordisk Foundation Center for Biosustainability, DTU.

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
35 changes: 30 additions & 5 deletions cameo/__init__.py
@@ -1,11 +1,11 @@
# Copyright 2014 Novo Nordisk Foundation Center for Biosustainability, DTU.

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -16,11 +16,36 @@
"""
CAMEO: Computer Assisted 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
model = load_model('../tests/data/EcoliCore.xml')
# 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)
"""

from ._version import get_versions
Expand Down
8 changes: 4 additions & 4 deletions cameo/config.py
@@ -1,11 +1,11 @@
# Copyright 2014 Novo Nordisk Foundation Center for Biosustainability, DTU.

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
8 changes: 4 additions & 4 deletions cameo/exceptions.py
@@ -1,11 +1,11 @@
# Copyright 2014 Novo Nordisk Foundation Center for Biosustainability, DTU.

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
46 changes: 6 additions & 40 deletions cameo/flux_analysis/__init__.py
@@ -1,52 +1,18 @@
# Copyright 2014 Novo Nordisk Foundation Center for Biosustainability, DTU.

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from functools import partial
from cobra.manipulation.delete import find_gene_knockout_reactions
from cameo.flux_analysis.simulation import fba
from cameo.exceptions import SolveError
from cameo.util import TimeMachine


def gene_knockout_growth(gene_id, model, threshold=10 ** -6, simulation_method=fba,
normalize=True, biomass=None, biomass_flux=None, *args, **kwargs):

if biomass_flux is None:
s = model.solve()
biomass_flux = s.f
if not 'reference' in kwargs:
kwargs['reference'] = s.x_dict
gene = model.genes.get_by_id(gene_id)
knockouts = find_gene_knockout_reactions(model, [gene])
tm = TimeMachine()

for reaction in knockouts:
tm(do=partial(setattr, reaction, 'lower_bound', 0),
undo=partial(setattr, reaction, 'lower_bound', reaction.lower_bound))
tm(do=partial(setattr, reaction, 'upper_bound', 0),
undo=partial(setattr, reaction, 'upper_bound', reaction.upper_bound))
from .simulation import *
from .analysis import *

try:
s = simulation_method(model, *args, **kwargs)
f = s.get_primal_by_id(biomass)
if f >= threshold:
if normalize:
f = f / biomass_flux
else:
f = 0
except SolveError:
f = float('nan')
finally:
tm.reset()

return f
34 changes: 9 additions & 25 deletions cameo/flux_analysis/analysis.py
@@ -1,23 +1,24 @@
# Copyright 2014 Novo Nordisk Foundation Center for Biosustainability, DTU.

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

__all__ = ['flux_variability_analysis', 'phenotypic_phase_plane', 'fbid']

import itertools
from copy import copy
from collections import OrderedDict
from functools import partial
import numpy
from cobra.core import Reaction
from cameo import config
from cameo.exceptions import UndefinedSolution, Infeasible, Unbounded, SolveError
from cameo.util import TimeMachine, partition
Expand Down Expand Up @@ -358,7 +359,7 @@ def _production_envelope_inner(self, point):
return point + tuple(interval)


def fbip(model, knockouts, view=config.default_view, method="fva"):
def fbid(model, knockouts, view=config.default_view, method="fva"):
"""
Flux balance impact degree by Zhao et al 2013
Expand All @@ -370,14 +371,14 @@ def fbip(model, knockouts, view=config.default_view, method="fva"):
"""

if method == "fva":
_fbip_fva(model, knockouts, view)
_fbid_fva(model, knockouts, view)
elif method == "em":
raise NotImplementedError("Elementary modes approach is not implemented")
else:
raise ValueError("%s method is not valid to compute FBIP" % method)


def _fbip_fva(model, knockouts, view):
def _fbid_fva(model, knockouts, view):
tm = TimeMachine()
for reaction in model.reactions:
if reaction.reversibility:
Expand Down Expand Up @@ -409,23 +410,6 @@ def _fbip_fva(model, knockouts, view):
return perturbation


def reaction_component_production(model, reaction):
tm = TimeMachine()
for metabolite in reaction.metabolites:
test = Reaction("EX_%s_temp" % metabolite.id)
test._metabolites[metabolite] = -1
# hack frozen set from cobrapy to be able to add a reaction
metabolite._reaction = set(metabolite._reaction)
tm(do=partial(model.add_reactions, [test]), undo=partial(model.remove_reactions, [test]))
tm(do=partial(setattr, model, 'objective', test.id), undo=partial(setattr, model, 'objective', model.objective))
try:
print metabolite.id, "= ", model.solve().f
except SolveError:
print metabolite, " cannot be produced (reactions: %s)" % metabolite.reactions
finally:
tm.reset()


if __name__ == '__main__':
import time
from cameo import load_model
Expand Down
11 changes: 7 additions & 4 deletions cameo/flux_analysis/simulation.py
@@ -1,16 +1,19 @@
# Copyright 2014 Novo Nordisk Foundation Center for Biosustainability, DTU.

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

__all__ = ['fba', 'pfba', 'moma', 'lmoma', 'room']

import sympy

from functools import partial
Expand Down
8 changes: 4 additions & 4 deletions cameo/io.py
@@ -1,11 +1,11 @@
# Copyright 2014 Novo Nordisk Foundation Center for Biosustainability, DTU.

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
2 changes: 1 addition & 1 deletion cameo/parallel.py
Expand Up @@ -4,7 +4,7 @@
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
2 changes: 1 addition & 1 deletion cameo/solver_based_model.py
Expand Up @@ -5,7 +5,7 @@
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
8 changes: 4 additions & 4 deletions cameo/strain_design/__init__.py
@@ -1,11 +1,11 @@
# Copyright 2014 Novo Nordisk Foundation Center for Biosustainability, DTU.

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down

0 comments on commit eaf05a1

Please sign in to comment.