How to use the cameo.load_model function in cameo

To help you get started, we’ve selected a few cameo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github biosustain / cameo / tests / test_io.py View on Github external
def test_load_model_pickle_path(self, solver_interface):
        model = load_model(os.path.join(TESTDIR, 'data/iJO1366.pickle'), solver_interface=solver_interface)
        assert abs(model.optimize().f - 0.9823718127269768) < 10e-6
github biosustain / cameo / tests / test_api.py View on Github external
# limitations under the License.

import os
import pickle
import re

import pytest

from cameo import api, load_model
from cameo import models, config
from cameo.api.hosts import Host
from cameo.api.products import Compound

MODELS = os.path.dirname(models.__file__)

UNIVERSALMODEL = load_model(os.path.join(MODELS, 'json/iJO1366.json'))
UNIVERSALMODEL.remove_reactions(UNIVERSALMODEL.exchanges)


def test_api():
    mock_host = Host('core',
                     models=['e_coli_core'],
                     biomass=['BIOMASS_Ecoli_core_w_GAM'],
                     carbon_sources=['EX_glc__D_e'])

    api.design.debug = True
    pathways = api.design.predict_pathways(product=UNIVERSALMODEL.metabolites.ser__L_c, hosts=[mock_host],
                                           database=UNIVERSALMODEL, aerobic=True)
    optimization_reports = api.design.optimize_strains(pathways, config.default_view, aerobic=True)
    pickle.loads(pickle.dumps(optimization_reports))
    assert len(optimization_reports) > 0
github biosustain / cameo / tests / test_io.py View on Github external
def test_load_model_pickle_handle(self, solver_interface):
        with open(os.path.join(TESTDIR, 'data/iJO1366.pickle'), 'rb') as handle:
            model = load_model(handle, solver_interface=solver_interface)
        assert abs(model.optimize().f - 0.9823718127269768) < 10e-6
github biosustain / cameo / tests / data / make-data-sets.py View on Github external
from cameo import load_model
from cameo.flux_analysis import phenotypic_phase_plane
import os

TESTDIR = os.path.dirname(__file__)
CORE_MODEL = load_model(os.path.join(TESTDIR, 'EcoliCore.xml'), sanitize=False)

model = CORE_MODEL.copy()
model.solver = 'glpk'
ppp = phenotypic_phase_plane(model, ['EX_o2_LPAREN_e_RPAREN_'])
ppp.data_frame.to_csv(os.path.join(TESTDIR, 'REFERENCE_PPP_o2_EcoliCore.csv'), float_format='%.3f')

model = CORE_MODEL.copy()
model.solver = 'glpk'
ppp2d = phenotypic_phase_plane(model, ['EX_o2_LPAREN_e_RPAREN_', 'EX_glc_LPAREN_e_RPAREN_'])
ppp2d.data_frame.to_csv(os.path.join(TESTDIR, 'REFERENCE_PPP_o2_glc_EcoliCore.csv'), float_format='%.3f')

model = CORE_MODEL.copy()
model.solver = 'glpk'
objective = model.add_boundary(model.metabolites.ac_c, type='demand')
model.objective = objective
ppp = phenotypic_phase_plane(model, ['EX_o2_LPAREN_e_RPAREN_'])
github biosustain / cameo / tests / test_strain_design_heuristics.py View on Github external
from random import Random
import unittest
import inspyred

from cameo import load_model
from cameo.strain_design.heuristic import HeuristicOptimization
from cameo.strain_design.heuristic.archivers import SolutionTuple, BestSolutionArchiver
from cameo.strain_design.heuristic.decoders import ReactionKnockoutDecoder, KnockoutDecoder, GeneKnockoutDecoder
from cameo.strain_design.heuristic.generators import set_generator, unique_set_generator
from cameo.strain_design.heuristic.objective_functions import biomass_product_coupled_yield, product_yield, \
    number_of_knockouts
from cobra.manipulation.delete import find_gene_knockout_reactions

MODEL_PATH = os.path.join(os.path.dirname(__file__), "data/EcoliCore.xml")

TEST_MODEL = load_model(MODEL_PATH)

SOLUTIONS = [
    [[1, 2, 3], 0.1],
    [[1, 3, 2, 4], 0.1],
    [[2, 3, 4], 0.45],
    [[62, 51, 4], 0.2],
    [[5, 3, 4, 51], 0.9],
    [[5, 23, 41, 51], 0.9],
    [[5, 3, 4, 51, 31], 0.9],
    [[5, 3, 4, 51], 0.9],
    [[44, 12, 42, 51], 0.0],
    [[52, 22, 4, 11], 0.0]
]


class TestBestSolutionArchiver(unittest.TestCase):
github biosustain / cameo / tests / data / update-pickles.py View on Github external
import pickle

import cobra
from cobra.test import create_test_model
from optlang import glpk_interface

from cameo import load_model


config = cobra.Configuration()
config.solver = "glpk"


ijo = load_model('iJO1366.xml', glpk_interface)
with open('iJO1366.pickle', 'wb') as out:
    pickle.dump(ijo, out, protocol=2)

salmonella = create_test_model('salmonella')
with open('salmonella.pickle', 'wb') as out:
    pickle.dump(salmonella, out, protocol=2)
github biosustain / cameo / tests / test_pathway_predictions.py View on Github external
def pathway_predictor(request, data_directory, universal_model):
    core_model = load_model(join(data_directory, 'EcoliCore.xml'), sanitize=False)
    core_model.solver = request.param
    predictor = PathwayPredictor(core_model, universal_model=universal_model)
    return core_model, predictor
github biosustain / cameo / cameo / api / hosts.py View on Github external
def lazy_model_init(path):
                model = load_model(path)
                setattr(model, "biomass", biomass)
                setattr(model, "carbon_source", carbon_source)
                return model
            model = Proxy(partial(lazy_model_init, os.path.join(MODEL_DIRECTORY, id + '.json')))
github biosustain / cameo / cameo / solver_based_model.py View on Github external
model.reactions.get_by_id(row[0]).lower_bound = float(row[1])
                    model.reactions.get_by_id(row[0]).upper_bound = float(row[2])

    @staticmethod
    def _load_medium_from_dataframe(model, medium):
        for i in xrange(len(medium) - 1):
            rid = medium['reaction_id'][i]
            if model.reactions.has_id(rid):
                model.reactions.get_by_id(rid).lower_bound = medium['lower_bound'][i]
                model.reactions.get_by_id(rid).upper_bound = medium['upper_bound'][i]


if __name__ == '__main__':
    from cameo import load_model

    model = load_model('../../test/data/EcoliCore.xml')
github biosustain / cameo / examples / OptGene2.py View on Github external
from random import Random
from random import sample, randint
import inspyred
from inspyred.ec import GA
from cameo import load_model

model = load_model("../tests/data/EcoliCore.xml")
def eval_individual(individual, args):

    rxns_to_ko = [model.reactions[index] for index in individual]
    original_bounds = [(reaction.lower_bound, reaction.upper_bound) for reaction in rxns_to_ko]
    for reaction in rxns_to_ko:
        reaction.lower_bound = 0
        reaction.upper_bound = 0
    solution = model.optimize()
    for rxn, bounds in zip(rxns_to_ko, original_bounds):
        rxn.lower_bound = bounds[0]
        rxn.upper_bound = bounds[1]
    if solution.status == 'optimal':
        try:
            fitness = (solution.f * model.solution.x_dict['EX_ac_LPAREN_e_RPAREN_'])/abs(model.solution.x_dict['EX_glc_LPAREN_e_RPAREN_'])
        except ZeroDivisionError:
            fitness = 0