コード例 #1
0
def test_bounds():
    """Test changing bounds."""
    config = Configuration()
    config.bounds = 100.0, 10000.0
    assert config.bounds == (100.0, 10000.0)
    # Restore default values.
    config.bounds = -1000.0, 1000.0
コード例 #2
0
def test_toy_model_tolerance_with_different_default():
    """Verify that different default tolerance is respected by Model."""
    config = Configuration()
    config.tolerance = 1e-05

    toy_model = Model(name="toy model")
    assert toy_model.tolerance == 1e-05
コード例 #3
0
def test_bounds():
    """Test changing bounds."""
    config = Configuration()
    config.bounds = 100.0, 10000.0
    assert config.bounds == (100.0, 10000.0)
    # Restore default values.
    config.bounds = -1000.0, 1000.0
コード例 #4
0
def test_toy_model_tolerance_with_different_default():
    """Verify that different default tolerance is respected by Model."""
    config = Configuration()
    config.tolerance = 1e-05

    toy_model = Model(name="toy model")
    assert toy_model.tolerance == 1e-05
コード例 #5
0
def test_default_tolerance(model):
    """Verify the default solver tolerance."""
    config = Configuration()
    config.solver = "glpk"
    assert config.tolerance == 1e-07
    # Test the consistency between cobra.core.Configuration.tolerance and
    # cobra.core.Model.tolerance
    assert config.tolerance == model.tolerance
コード例 #6
0
def test_default_tolerance(model):
    """Verify the default solver tolerance."""
    config = Configuration()
    config.solver = "glpk"
    assert config.tolerance == 1e-07
    # Test the consistency between cobra.core.Configuration.tolerance and
    # cobra.core.Model.tolerance
    assert config.tolerance == model.tolerance
コード例 #7
0
def test_solver():
    """Test assignment of different solvers."""
    config = Configuration()
    config.solver = "glpk"
    assert interface_to_str(config.solver) == "glpk"
    config.solver = "glpk_exact"
    assert interface_to_str(config.solver) == "glpk_exact"
    # Restore default solver.
    config.solver = "glpk"
コード例 #8
0
def test_solver():
    """Test assignment of different solvers."""
    config = Configuration()
    config.solver = "glpk"
    assert interface_to_str(config.solver) == "glpk"
    config.solver = "glpk_exact"
    assert interface_to_str(config.solver) == "glpk_exact"
    # Restore default solver.
    config.solver = "glpk"
コード例 #9
0
def test_default_bounds():
    """Verify the default bounds."""
    config = Configuration()
    assert config.bounds == (-1000.0, 1000.0)
コード例 #10
0
    import libsbml
except ImportError:
    libsbml = None
else:
    from cobra.io.sbml import create_cobra_model_from_sbml_file as read_sbml2
    from cobra.io.sbml import write_cobra_model_to_sbml_file as write_sbml2

try:
    from optlang.symbolics import Basic
except ImportError:

    class Basic:
        pass


CONFIGURATION = Configuration()

# deal with namespaces
namespaces = {
    "fbc": "http://www.sbml.org/sbml/level3/version1/fbc/version2",
    "sbml": "http://www.sbml.org/sbml/level3/version1/core",
    "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "bqbiol": "http://biomodels.net/biology-qualifiers/"
}
for key in namespaces:
    register_namespace(key, namespaces[key])


def ns(query):
    """replace prefixes with namespace"""
    for prefix, uri in iteritems(namespaces):
コード例 #11
0
ファイル: variability.py プロジェクト: carrascomj/cobrapy
from warnings import warn

from numpy import zeros
from optlang.symbolics import Zero
from pandas import DataFrame

from cobra.core import Configuration, get_solution
from cobra.flux_analysis.deletion import single_gene_deletion, single_reaction_deletion
from cobra.flux_analysis.helpers import normalize_cutoff
from cobra.flux_analysis.loopless import loopless_fva_iter
from cobra.flux_analysis.parsimonious import add_pfba
from cobra.util import ProcessPool
from cobra.util import solver as sutil

logger = logging.getLogger(__name__)
configuration = Configuration()


def _init_worker(model, loopless, sense):
    """Initialize a global model object for multiprocessing."""
    global _model
    global _loopless
    _model = model
    _model.solver.objective.direction = sense
    _loopless = loopless


def _fva_step(reaction_id):
    global _model
    global _loopless
    rxn = _model.reactions.get_by_id(reaction_id)
コード例 #12
0
ファイル: test_core_reaction.py プロジェクト: cgaray/cobrapy
"""Test functions of cobra.core.reaction ."""

import warnings
from typing import Iterable

import numpy as np
import pytest

from cobra.core import Configuration, Metabolite, Model, Reaction

config = Configuration()
stable_optlang = ["glpk", "cplex", "gurobi"]


def test_gpr() -> None:
    """Test GPR evaluation."""
    model = Model()
    reaction = Reaction("test")

    # Set GPR to a reaction not in a model
    reaction.gene_reaction_rule = "(g1 or g2) and g3"
    assert reaction.gene_reaction_rule == "(g1 or g2) and g3"
    assert len(reaction.genes) == 3

    # Adding reaction with a GPR propagates to the model
    model.add_reactions([reaction])
    assert len(model.genes) == 3

    # Ensure the gene objects are the same in the model and reaction
    reaction_gene = list(reaction.genes)[0]
    model_gene = model.genes.get_by_id(reaction_gene.id)