本文整理汇总了Python中cobra.core.Reaction.add_metabolites方法的典型用法代码示例。如果您正苦于以下问题:Python Reaction.add_metabolites方法的具体用法?Python Reaction.add_metabolites怎么用?Python Reaction.add_metabolites使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cobra.core.Reaction
的用法示例。
在下文中一共展示了Reaction.add_metabolites方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_reaction_context
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import add_metabolites [as 别名]
def test_add_reaction_context(model):
old_reaction_count = len(model.reactions)
old_metabolite_count = len(model.metabolites)
dummy_metabolite_1 = Metabolite("test_foo_1")
dummy_metabolite_2 = Metabolite("test_foo_2")
actual_metabolite = model.metabolites[0]
copy_metabolite = model.metabolites[1].copy()
dummy_reaction = Reaction("test_foo_reaction")
dummy_reaction.add_metabolites({dummy_metabolite_1: -1,
dummy_metabolite_2: 1,
copy_metabolite: -2,
actual_metabolite: 1})
dummy_reaction.gene_reaction_rule = 'dummy_gene'
with model:
model.add_reaction(dummy_reaction)
assert model.reactions.get_by_id(
dummy_reaction.id) == dummy_reaction
assert len(model.reactions) == old_reaction_count + 1
assert len(model.metabolites) == old_metabolite_count + 2
assert dummy_metabolite_1._model == model
assert 'dummy_gene' in model.genes
assert len(model.reactions) == old_reaction_count
assert len(model.metabolites) == old_metabolite_count
with pytest.raises(KeyError):
model.reactions.get_by_id(dummy_reaction.id)
assert dummy_metabolite_1._model is None
assert 'dummy_gene' not in model.genes
示例2: test_solve_mip
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import add_metabolites [as 别名]
def test_solve_mip(self, solver_test):
solver, old_solution, infeasible_model = solver_test
if not hasattr(solver, "_SUPPORTS_MILP") or not solver._SUPPORTS_MILP:
pytest.skip("no milp support")
cobra_model = Model('MILP_implementation_test')
constraint = Metabolite("constraint")
constraint._bound = 2.5
x = Reaction("x")
x.lower_bound = 0.
x.objective_coefficient = 1.
x.add_metabolites({constraint: 2.5})
y = Reaction("y")
y.lower_bound = 0.
y.objective_coefficient = 1.
y.add_metabolites({constraint: 1.})
cobra_model.add_reactions([x, y])
float_sol = solver.solve(cobra_model)
# add an integer constraint
y.variable_kind = "integer"
int_sol = solver.solve(cobra_model)
assert abs(float_sol.f - 2.5) < 10 ** -5
assert abs(float_sol.x_dict["y"] - 2.5) < 10 ** -5
assert int_sol.status == "optimal"
assert abs(int_sol.f - 2.2) < 10 ** -3
assert abs(int_sol.x_dict["y"] - 2.0) < 10 ** -3
示例3: test__normalize_pseudoreaction_exchange_error_bad_coeff
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import add_metabolites [as 别名]
def test__normalize_pseudoreaction_exchange_error_bad_coeff():
reaction = Reaction('EX_gone')
reaction.add_metabolites({Metabolite('glu__L_e'): -2})
with pytest.raises(ConflictingPseudoreaction) as excinfo:
_ = _normalize_pseudoreaction(reaction.id, reaction)
assert 'with coefficient' in str(excinfo.value)
assert reaction.id == 'EX_gone'
示例4: test_inequality
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import add_metabolites [as 别名]
def test_inequality(self, solver_test):
solver, old_solution, infeasible_model = solver_test
# The space enclosed by the constraints is a 2D triangle with
# vertexes as (3, 0), (1, 2), and (0, 1)
# c1 encodes y - x > 1 ==> y > x - 1
# c2 encodes y + x < 3 ==> y < 3 - x
c1 = Metabolite("c1")
c2 = Metabolite("c2")
x = Reaction("x")
x.lower_bound = 0
y = Reaction("y")
y.lower_bound = 0
x.add_metabolites({c1: -1, c2: 1})
y.add_metabolites({c1: 1, c2: 1})
c1._bound = 1
c1._constraint_sense = "G"
c2._bound = 3
c2._constraint_sense = "L"
m = Model()
m.add_reactions([x, y])
# test that optimal values are at the vertices
m.objective = "x"
assert abs(solver.solve(m).f - 1.0) < 10 ** -3
assert abs(solver.solve(m).x_dict["y"] - 2.0) < 10 ** -3
m.objective = "y"
assert abs(solver.solve(m).f - 3.0) < 10 ** -3
assert abs(
solver.solve(m, objective_sense="minimize").f - 1.0) < 10 ** -3
示例5: test_change_coefficient
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import add_metabolites [as 别名]
def test_change_coefficient(self, solver_test):
solver, old_solution, infeasible_model = solver_test
c = Metabolite("c")
c._bound = 6
x = Reaction("x")
x.lower_bound = 1.
y = Reaction("y")
y.lower_bound = 0.
x.add_metabolites({c: 1})
z = Reaction("z")
z.add_metabolites({c: 1})
z.objective_coefficient = 1
m = Model("test_model")
m.add_reactions([x, y, z])
# change an existing coefficient
lp = solver.create_problem(m)
solver.solve_problem(lp)
sol1 = solver.format_solution(lp, m)
assert sol1.status == "optimal"
solver.change_coefficient(lp, 0, 0, 2)
solver.solve_problem(lp)
sol2 = solver.format_solution(lp, m)
assert sol2.status == "optimal"
assert abs(sol1.f - 5.0) < 10 ** -3
assert abs(sol2.f - 4.0) < 10 ** -3
# change a new coefficient
z.objective_coefficient = 0.
y.objective_coefficient = 1.
lp = solver.create_problem(m)
solver.change_coefficient(lp, 0, 1, 2)
solver.solve_problem(lp)
solution = solver.format_solution(lp, m)
assert solution.status == "optimal"
assert abs(solution.x_dict["y"] - 2.5) < 10 ** -3
示例6: test_iadd
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import add_metabolites [as 别名]
def test_iadd(model):
PGI = model.reactions.PGI
EX_h2o = model.reactions.EX_h2o_e
original_PGI_gpr = PGI.gene_reaction_rule
PGI += EX_h2o
assert PGI.gene_reaction_rule == original_PGI_gpr
assert PGI.metabolites[model.metabolites.h2o_e] == -1.0
# Original should not change
assert EX_h2o.gene_reaction_rule == ''
assert EX_h2o.metabolites[model.metabolites.h2o_e] == -1.0
# Add a reaction not in the model
new_reaction = Reaction("test")
new_reaction.add_metabolites({Metabolite("A"): -1, Metabolite("B"): 1})
PGI += new_reaction
assert PGI.gene_reaction_rule == original_PGI_gpr
assert len(PGI.gene_reaction_rule) == 5
# And vice versa
new_reaction += PGI
assert len(new_reaction.metabolites) == 5 # not
assert len(new_reaction.genes) == 1
assert new_reaction.gene_reaction_rule == original_PGI_gpr
# Combine two GPRs
model.reactions.ACKr += model.reactions.ACONTa
expected_rule = '(b2296 or b3115 or b1849) and (b0118 or b1276)'
assert model.reactions.ACKr.gene_reaction_rule == expected_rule
assert len(model.reactions.ACKr.genes) == 5
示例7: test_add_reactions_single_existing
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import add_metabolites [as 别名]
def test_add_reactions_single_existing(self, model):
rxn = model.reactions[0]
r1 = Reaction(rxn.id)
r1.add_metabolites({Metabolite('A'): -1, Metabolite('B'): 1})
r1.lower_bound, r1.upper_bound = -999999., 999999.
model.add_reactions([r1])
assert rxn in model.reactions
assert r1 is not model.reactions.get_by_id(rxn.id)
示例8: test__normalize_pseudoreaction_exchange_error_has_gpr
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import add_metabolites [as 别名]
def test__normalize_pseudoreaction_exchange_error_has_gpr():
reaction = Reaction('EX_gone')
reaction.add_metabolites({Metabolite('glu__L_e'): -1})
reaction.gene_reaction_rule = 'b1779'
with pytest.raises(ConflictingPseudoreaction) as excinfo:
_ = _normalize_pseudoreaction(reaction.id, reaction)
assert 'has a gene_reaction_rule' in str(excinfo.value)
assert reaction.id == 'EX_gone'
示例9: test__normalize_pseudoreaction_sink
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import add_metabolites [as 别名]
def test__normalize_pseudoreaction_sink():
reaction = Reaction('SInk_gone')
reaction.add_metabolites({Metabolite('glu__L_c'): -1})
reaction.lower_bound = -1000
reaction.upper_bound = 0
pseudo_id = _normalize_pseudoreaction(reaction.id, reaction)
assert pseudo_id == 'SK_glu__L_c'
assert reaction.subsystem == 'Intracellular source/sink'
示例10: test__normalize_pseudoreaction_exchange
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import add_metabolites [as 别名]
def test__normalize_pseudoreaction_exchange():
reaction = Reaction('EX_gone')
reaction.add_metabolites({Metabolite('glu__L_e'): -1})
reaction.lower_bound = -1000
reaction.upper_bound = 0
pseudo_id = _normalize_pseudoreaction(reaction.id, reaction)
assert pseudo_id == 'EX_glu__L_e'
assert reaction.subsystem == 'Extracellular exchange'
示例11: test__normalize_pseudoreaction_demand
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import add_metabolites [as 别名]
def test__normalize_pseudoreaction_demand():
reaction = Reaction('DM_gone')
reaction.add_metabolites({Metabolite('glu__L_c'): -1})
reaction.lower_bound = 0
reaction.upper_bound = 1000
pseudo_id = _normalize_pseudoreaction(reaction.id, reaction)
assert pseudo_id == 'DM_glu__L_c'
assert reaction.subsystem == 'Intracellular demand'
示例12: test__normalize_pseudoreaction_demand_reversed_prefer_sink_name
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import add_metabolites [as 别名]
def test__normalize_pseudoreaction_demand_reversed_prefer_sink_name():
reaction = Reaction('sink_gone')
reaction.add_metabolites({Metabolite('glu__L_c'): 1})
reaction.lower_bound = -1000
reaction.upper_bound = 0
_normalize_pseudoreaction(reaction)
assert list(reaction.metabolites.values()) == [-1]
assert reaction.lower_bound == 0
assert reaction.upper_bound == 1000
assert reaction.id == 'SK_glu__L_c'
示例13: test__normalize_pseudoreaction_exchange_reversed
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import add_metabolites [as 别名]
def test__normalize_pseudoreaction_exchange_reversed():
reaction = Reaction('EX_gone')
reaction.add_metabolites({Metabolite('glu__L_e'): 1})
reaction.lower_bound = 0
reaction.upper_bound = 1000
pseudo_id = _normalize_pseudoreaction(reaction.id, reaction)
assert pseudo_id == 'EX_glu__L_e'
assert reaction.lower_bound == -1000
assert reaction.upper_bound == 0
assert list(reaction.metabolites.values()) == [-1]
示例14: test__normalize_pseudoreaction_atpm
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import add_metabolites [as 别名]
def test__normalize_pseudoreaction_atpm():
reaction = Reaction('notATPM')
reaction.add_metabolites({Metabolite('atp_c'): -1,
Metabolite('h2o_c'): -1,
Metabolite('pi_c'): 1,
Metabolite('h_c'): 1,
Metabolite('adp_c'): 1})
pseudo_id = _normalize_pseudoreaction(reaction.id, reaction)
assert pseudo_id == 'ATPM'
assert reaction.subsystem == 'Biomass and maintenance functions'
示例15: test__normalize_pseudoreaction_sink_reversed
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import add_metabolites [as 别名]
def test__normalize_pseudoreaction_sink_reversed():
reaction = Reaction('Sink_gone')
reaction.add_metabolites({Metabolite('glu__L_c'): 1})
reaction.lower_bound = 0
reaction.upper_bound = 50
pseudo_id = _normalize_pseudoreaction(reaction.id, reaction)
assert list(reaction.metabolites.values()) == [-1]
assert reaction.lower_bound == -50
assert reaction.upper_bound == 0
assert pseudo_id == 'SK_glu__L_c'