How to use cameo - 10 common examples

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_util.py View on Github external
def test_str_handles_different_types_of_stored_operations(self):
        tm = TimeMachine()

        def normal_function():
            pass

        partial_function = partial(str, 1)
        tm(do=normal_function, undo=partial_function)
        assert tm.__str__().split('\n')[2:-1] == ["undo: " + str(str) + " (1,) {}", 'redo: normal_function']
github biosustain / cameo / tests / test_strain_design_heuristics.py View on Github external
def test_run_with_time_limit(self, model):
        # TODO: make optlang deterministic so this results can be permanently stored.
        objective = biomass_product_coupled_yield(
            "Biomass_Ecoli_core_N_lp_w_fsh_GAM_rp__Nmet2", "EX_ac_lp_e_rp_", "EX_glc_lp_e_rp_")

        rko = ReactionKnockoutOptimization(model=model,
                                           simulation_method=fba,
                                           objective_function=objective)

        start_time = time.time()
        rko.run(max_evaluations=3000000, pop_size=10, view=SequentialView(), seed=SEED, max_time=(1, 0))
        elapsed_time = time.time() - start_time

        assert elapsed_time < 1.25 * 60
github biosustain / cameo / tests / test_strain_design_heuristics.py View on Github external
def test_initializer(self):
        def evaluation_function(x):
            return 1

        evaluator = EvaluatorWrapper(config.default_view, evaluation_function)
        assert hasattr(evaluator, '__call__')
        assert hasattr(evaluator, 'view')
        assert hasattr(evaluator, 'evaluator')
        assert evaluator.view == config.default_view
        assert evaluator.evaluator == evaluation_function
github biosustain / cameo / tests / test_flux_analysis.py View on Github external
def test_flux_variability_sequential_remove_cycles(self, core_model):
        original_objective = core_model.objective
        fva_solution = flux_variability_analysis(core_model, fraction_of_optimum=0.999999419892,
                                                 remove_cycles=True,
                                                 view=SequentialView())
        assert REFERENCE_FVA_SOLUTION_ECOLI_CORE['upper_bound']['FRD7'] > 666.
        assert round(abs(fva_solution['upper_bound']['FRD7'] - 0.), 7) == 0
        for key in fva_solution.data_frame.index:
            if REFERENCE_FVA_SOLUTION_ECOLI_CORE['lower_bound'][key] > -666:
                assert abs(
                    fva_solution['lower_bound'][key] - REFERENCE_FVA_SOLUTION_ECOLI_CORE['lower_bound'][key]) < 0.0001
            if REFERENCE_FVA_SOLUTION_ECOLI_CORE['upper_bound'][key] < 666:
                assert abs(
                    fva_solution['upper_bound'][key] - REFERENCE_FVA_SOLUTION_ECOLI_CORE['upper_bound'][key]) < 0.0001

        cycle_reac = Reaction("minus_PGI")  # Create fake cycle
        cycle_reac.lower_bound = -1000
        core_model.add_reaction(cycle_reac)
        cycle_reac.add_metabolites({met: -c for met, c in core_model.reactions.PGI.metabolites.items()})
        fva_solution = flux_variability_analysis(core_model, remove_cycles=False, reactions=["PGI"])
        assert fva_solution.data_frame.loc["PGI", "upper_bound"] == 1000
github biosustain / cameo / tests / test_flux_analysis.py View on Github external
def test_one_variable_sequential(self, core_model):
        ppp = phenotypic_phase_plane(core_model, ['EX_o2_LPAREN_e_RPAREN_'], view=SequentialView())
        assert_data_frames_equal(ppp, REFERENCE_PPP_o2_EcoliCore, sort_by=['EX_o2_LPAREN_e_RPAREN_'])
        ppp = phenotypic_phase_plane(core_model, 'EX_o2_LPAREN_e_RPAREN_', view=SequentialView())
        assert_data_frames_equal(ppp, REFERENCE_PPP_o2_EcoliCore, sort_by=['EX_o2_LPAREN_e_RPAREN_'])
github biosustain / cameo / tests / test_flux_analysis.py View on Github external
def test_one_variable_sequential_metabolite(self, core_model):
        ppp = phenotypic_phase_plane(core_model, ['EX_o2_LPAREN_e_RPAREN_'], core_model.metabolites.ac_c,
                                     view=SequentialView())
        assert_data_frames_equal(ppp, REFERENCE_PPP_o2_EcoliCore_ac, sort_by=['EX_o2_LPAREN_e_RPAREN_'])
github biosustain / cameo / tests / test_strain_design_heuristics.py View on Github external
def test_run_single_objective(self, reaction_ko_single_objective):
        # TODO: make optlang deterministic so this results can be permanently stored.
        _, result_file = mkstemp('.pkl')
        results = reaction_ko_single_objective.run(max_evaluations=3000, pop_size=10, view=SequentialView(), seed=SEED)
        assert len(results.data_frame.targets) > 0
        assert len(results.data_frame.targets) == len(results.data_frame.targets.apply(tuple).unique())

        with open(result_file, 'wb') as in_file:
            pickle.dump(results, in_file)

        with open(result_file, 'rb') as in_file:
            if six.PY3:
                expected_results = pickle.load(in_file, encoding="latin1")
            else:
                expected_results = pickle.load(in_file)

        assert results.seed == expected_results.seed
github biosustain / cameo / tests / test_strain_design_heuristics.py View on Github external
def test_run_gene_ko_single_objective_benchmark(self, gene_ko_single_objective, benchmark):
        benchmark(gene_ko_single_objective.run, max_evaluations=3000, pop_size=10, view=SequentialView(), seed=SEED)
github biosustain / cameo / tests / test_util.py View on Github external
iterables = [
            [1, 2, 3, 4, 5, 6, 7, 8, 9],
            {5, 3, 8, 3, 8, 5, 8, 0, 10, 11, 15},
            range(29)
        ]
        for fixture in iterables:
            test_output = partition(fixture, chunks)
            assert len(fixture) == sum(map(len, test_output))
            assert len(test_output) == chunks
            assert list(fixture) == list(chain(*test_output))
            for out_chunk in test_output:
                assert set(out_chunk).issubset(set(fixture))

        bad_input = 5
        with pytest.raises(TypeError):
            partition(bad_input, chunks)
github biosustain / cameo / tests / test_core_strain_design.py View on Github external
def test_design_to_gnomic(self, cad_reaction):
        from gnomic import Genotype
        t1 = ReactionKnockoutTarget('PGI')
        t2 = ReactionKnockoutTarget('GAPD')
        t3 = ReactionKnockinTarget("CAD", cad_reaction)

        strain_design1 = StrainDesign([t1, t2, t3])

        sd_gnomic = strain_design1.to_gnomic()

        assert isinstance(sd_gnomic, Genotype)
        assert len(sd_gnomic.added_features) == 1
        assert len(sd_gnomic.removed_features) == 2