本文整理汇总了Python中cobra.core.Reaction.build_reaction_from_string方法的典型用法代码示例。如果您正苦于以下问题:Python Reaction.build_reaction_from_string方法的具体用法?Python Reaction.build_reaction_from_string怎么用?Python Reaction.build_reaction_from_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cobra.core.Reaction
的用法示例。
在下文中一共展示了Reaction.build_reaction_from_string方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_reverse_reaction
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import build_reaction_from_string [as 别名]
def test_reverse_reaction():
model = Model()
reaction = Reaction('AB')
model.add_reaction(reaction)
reaction.build_reaction_from_string('a --> b')
_reverse_reaction(reaction)
assert reaction.reaction == 'b <-- a'
示例2: test_gapfilling
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import build_reaction_from_string [as 别名]
def test_gapfilling(self, salmonella):
m = Model()
m.add_metabolites([Metabolite(m_id) for m_id in ["a", "b", "c"]])
exa = Reaction("EX_a")
exa.add_metabolites({m.metabolites.a: 1})
b2c = Reaction("b2c")
b2c.add_metabolites({m.metabolites.b: -1, m.metabolites.c: 1})
dmc = Reaction("DM_c")
dmc.add_metabolites({m.metabolites.c: -1})
m.add_reactions([exa, b2c, dmc])
m.objective = 'DM_c'
universal = Model()
a2b = Reaction("a2b")
a2d = Reaction("a2d")
universal.add_reactions([a2b, a2d])
a2b.build_reaction_from_string("a --> b", verbose=False)
a2d.build_reaction_from_string("a --> d", verbose=False)
# # GrowMatch
# result = gapfilling.growMatch(m, universal)[0]
result = gapfilling.gapfill(m, universal)[0]
assert len(result) == 1
assert result[0].id == "a2b"
# # SMILEY
# result = gapfilling.SMILEY(m, "b", universal)[0]
with m:
m.objective = m.add_boundary(m.metabolites.b, type='demand')
result = gapfilling.gapfill(m, universal)[0]
assert len(result) == 1
assert result[0].id == "a2b"
# # 2 rounds of GrowMatch with exchange reactions
# result = gapfilling.growMatch(m, None, ex_rxns=True, iterations=2)
result = gapfilling.gapfill(m, None, exchange_reactions=True,
iterations=2)
assert len(result) == 2
assert len(result[0]) == 1
assert len(result[1]) == 1
assert {i[0].id for i in result} == {"EX_b", "EX_c"}
# somewhat bigger model
universal = Model("universal_reactions")
with salmonella as model:
for i in [i.id for i in model.metabolites.f6p_c.reactions]:
reaction = model.reactions.get_by_id(i)
universal.add_reactions([reaction.copy()])
model.remove_reactions([reaction])
gf = gapfilling.GapFiller(model, universal,
penalties={'TKT2': 1e3},
demand_reactions=False)
solution = gf.fill()
assert 'TKT2' not in {r.id for r in solution[0]}
assert gf.validate(solution[0])
示例3: test_custom_hashes
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import build_reaction_from_string [as 别名]
def test_custom_hashes():
# These hashes are generated from old IDs in models (in reaction strings),
# and they match to these corrected BiGG reaction IDs
cases = [
('39b5f90a1919aef07473e2f835ce63af', 'EX_frmd_e', 'foam_e <=>'),
('92f1047c72db0a36413d822863be514e', 'EX_phllqne_e', 'phyQ_e <=>'),
]
model = Model()
for reaction_hash, bigg_id, reaction_string in cases:
reaction = Reaction(bigg_id)
model.add_reaction(reaction)
reaction.build_reaction_from_string(reaction_string)
lookup_dict = {m.id: m.id for m in model.metabolites}
assert hash_reaction(reaction, lookup_dict) == reaction_hash
示例4: test_gapfilling
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import build_reaction_from_string [as 别名]
def test_gapfilling(self):
try:
get_solver_name(mip=True)
except SolverNotFound:
pytest.skip("no MILP solver found")
m = Model()
m.add_metabolites(map(Metabolite, ["a", "b", "c"]))
r = Reaction("EX_A")
m.add_reaction(r)
r.add_metabolites({m.metabolites.a: 1})
r = Reaction("r1")
m.add_reaction(r)
r.add_metabolites({m.metabolites.b: -1, m.metabolites.c: 1})
r = Reaction("DM_C")
m.add_reaction(r)
r.add_metabolites({m.metabolites.c: -1})
r.objective_coefficient = 1
U = Model()
r = Reaction("a2b")
U.add_reaction(r)
r.build_reaction_from_string("a --> b", verbose=False)
r = Reaction("a2d")
U.add_reaction(r)
r.build_reaction_from_string("a --> d", verbose=False)
# GrowMatch
result = gapfilling.growMatch(m, U)[0]
assert len(result) == 1
assert result[0].id == "a2b"
# SMILEY
result = gapfilling.SMILEY(m, "b", U)[0]
assert len(result) == 1
assert result[0].id == "a2b"
# 2 rounds of GrowMatch with exchange reactions
result = gapfilling.growMatch(m, None, ex_rxns=True, iterations=2)
assert len(result) == 2
assert len(result[0]) == 1
assert len(result[1]) == 1
assert {i[0].id for i in result} == {"SMILEY_EX_b", "SMILEY_EX_c"}
示例5: test_gapfilling
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import build_reaction_from_string [as 别名]
def test_gapfilling(salmonella):
"""Test Gapfilling."""
m = Model()
m.add_metabolites([Metabolite(m_id) for m_id in ["a", "b", "c"]])
exa = Reaction("EX_a")
exa.add_metabolites({m.metabolites.a: 1})
b2c = Reaction("b2c")
b2c.add_metabolites({m.metabolites.b: -1, m.metabolites.c: 1})
dmc = Reaction("DM_c")
dmc.add_metabolites({m.metabolites.c: -1})
m.add_reactions([exa, b2c, dmc])
m.objective = 'DM_c'
universal = Model()
a2b = Reaction("a2b")
a2d = Reaction("a2d")
universal.add_reactions([a2b, a2d])
a2b.build_reaction_from_string("a --> b", verbose=False)
a2d.build_reaction_from_string("a --> d", verbose=False)
# # GrowMatch
# result = gapfilling.growMatch(m, universal)[0]
result = gapfill(m, universal)[0]
assert len(result) == 1
assert result[0].id == "a2b"
# # SMILEY
# result = gapfilling.SMILEY(m, "b", universal)[0]
with m:
m.objective = m.add_boundary(m.metabolites.b, type='demand')
result = gapfill(m, universal)[0]
assert len(result) == 1
assert result[0].id == "a2b"
# # 2 rounds of GrowMatch with exchange reactions
# result = gapfilling.growMatch(m, None, ex_rxns=True, iterations=2)
result = gapfill(m, None, exchange_reactions=True,
iterations=2)
assert len(result) == 2
assert len(result[0]) == 1
assert len(result[1]) == 1
assert {i[0].id for i in result} == {"EX_b", "EX_c"}
# # Gapfilling solution adds metabolites not present in original model
# test for when demand = T
# a demand reaction must be added to clear new metabolite
universal_noDM = Model()
a2b = Reaction("a2b")
universal_noDM.add_reactions([a2b])
a2b.build_reaction_from_string("a --> b + d", verbose=False)
result = gapfill(m, universal_noDM,
exchange_reactions=False,
demand_reactions=True)[0]
# add reaction a2b and demand reaction to clear met d
assert len(result) == 2
assert "a2b" in [x.id for x in result]
# test for when demand = False
# test for when metabolites are added to the model and
# must be cleared by other reactions in universal model
# (i.e. not necessarily a demand reaction)
universal_withDM = universal_noDM.copy()
d_dm = Reaction("d_dm")
universal_withDM.add_reactions([d_dm])
d_dm.build_reaction_from_string("d -->", verbose=False)
result = gapfill(m, universal_withDM,
exchange_reactions=False,
demand_reactions=False)[0]
assert len(result) == 2
assert "a2b" in [x.id for x in result]
# somewhat bigger model
universal = Model("universal_reactions")
with salmonella as model:
for i in [i.id for i in model.metabolites.f6p_c.reactions]:
reaction = model.reactions.get_by_id(i)
universal.add_reactions([reaction.copy()])
model.remove_reactions([reaction])
gf = GapFiller(model, universal,
penalties={'TKT2': 1e3},
demand_reactions=False)
solution = gf.fill()
assert 'TKT2' not in {r.id for r in solution[0]}
assert gf.validate(solution[0])