本文整理汇总了Python中cobra.core.Reaction.upper_bound方法的典型用法代码示例。如果您正苦于以下问题:Python Reaction.upper_bound方法的具体用法?Python Reaction.upper_bound怎么用?Python Reaction.upper_bound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cobra.core.Reaction
的用法示例。
在下文中一共展示了Reaction.upper_bound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_complicated_model
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import upper_bound [as 别名]
def test_complicated_model(self):
"""Difficult model since the online mean calculation is numerically
unstable so many samples weakly violate the equality constraints."""
model = Model('flux_split')
reaction1 = Reaction('V1')
reaction2 = Reaction('V2')
reaction3 = Reaction('V3')
reaction1.lower_bound = 0
reaction2.lower_bound = 0
reaction3.lower_bound = 0
reaction1.upper_bound = 6
reaction2.upper_bound = 8
reaction3.upper_bound = 10
A = Metabolite('A')
reaction1.add_metabolites({A: -1})
reaction2.add_metabolites({A: -1})
reaction3.add_metabolites({A: 1})
model.add_reactions([reaction1])
model.add_reactions([reaction2])
model.add_reactions([reaction3])
optgp = OptGPSampler(model, 1, seed=42)
achr = ACHRSampler(model, seed=42)
optgp_samples = optgp.sample(100)
achr_samples = achr.sample(100)
assert any(optgp_samples.corr().abs() < 1.0)
assert any(achr_samples.corr().abs() < 1.0)
# > 95% are valid
assert(sum(optgp.validate(optgp_samples) == "v") > 95)
assert(sum(achr.validate(achr_samples) == "v") > 95)
示例2: test__normalize_pseudoreaction_exchange
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import upper_bound [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'
示例3: test__normalize_pseudoreaction_sink
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import upper_bound [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'
示例4: test__normalize_pseudoreaction_demand
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import upper_bound [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'
示例5: test__normalize_pseudoreaction_demand_reversed_prefer_sink_name
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import upper_bound [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'
示例6: test__normalize_pseudoreaction_exchange_reversed
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import upper_bound [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]
示例7: test__normalize_pseudoreaction_demand_reversed
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import upper_bound [as 别名]
def test__normalize_pseudoreaction_demand_reversed():
reaction = Reaction('DM_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 list(reaction.metabolites.values()) == [-1]
assert reaction.lower_bound == 0
assert reaction.upper_bound == 1000
assert pseudo_id == 'DM_glu__L_c'
示例8: test__normalize_pseudoreaction_sink_reversed
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import upper_bound [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'
示例9: test_make_lhs_irreversible_reversible
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import upper_bound [as 别名]
def test_make_lhs_irreversible_reversible(model):
rxn = Reaction('test')
rxn.add_metabolites(
{model.metabolites[0]: -1., model.metabolites[1]: 1.})
rxn.lower_bound = -1000.
rxn.upper_bound = -100
model.add_reaction(rxn)
assert rxn.lower_bound == -1000.
assert rxn.upper_bound == -100.
assert rxn.forward_variable.lb == 0.
assert rxn.forward_variable.ub == 0.
assert rxn.reverse_variable.lb == 100.
assert rxn.reverse_variable.ub == 1000.
rxn.upper_bound = 666.
assert rxn.lower_bound == -1000.
assert rxn.upper_bound == 666.
assert rxn.forward_variable.lb == 0.
assert rxn.forward_variable.ub == 666
assert rxn.reverse_variable.lb == 0.
assert rxn.reverse_variable.ub == 1000.
示例10: construct_loopless_model
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import upper_bound [as 别名]
def construct_loopless_model(cobra_model):
"""Construct a loopless model.
This adds MILP constraints to prevent flux from proceeding in a loop, as
done in http://dx.doi.org/10.1016/j.bpj.2010.12.3707
Please see the documentation for an explanation of the algorithm.
This must be solved with an MILP capable solver.
"""
# copy the model and make it irreversible
model = cobra_model.copy()
convert_to_irreversible(model)
max_ub = max(model.reactions.list_attr("upper_bound"))
# a dict for storing S^T
thermo_stoic = {"thermo_var_" + metabolite.id: {}
for metabolite in model.metabolites}
# Slice operator is so that we don't get newly added metabolites
original_metabolites = model.metabolites[:]
for reaction in model.reactions[:]:
# Boundary reactions are not subjected to these constraints
if len(reaction._metabolites) == 1:
continue
# populate the S^T dict
bound_id = "thermo_bound_" + reaction.id
for met, stoic in iteritems(reaction._metabolites):
thermo_stoic["thermo_var_" + met.id][bound_id] = stoic
# I * 1000 > v --> I * 1000 - v > 0
reaction_ind = Reaction(reaction.id + "_indicator")
reaction_ind.variable_kind = "integer"
reaction_ind.upper_bound = 1
reaction_ub = Metabolite(reaction.id + "_ind_ub")
reaction_ub._constraint_sense = "G"
reaction.add_metabolites({reaction_ub: -1})
reaction_ind.add_metabolites({reaction_ub: max_ub})
# This adds a compensating term for 0 flux reactions, so we get
# S^T x - (1 - I) * 1001 < -1 which becomes
# S^T x < 1000 for 0 flux reactions and
# S^T x < -1 for reactions with nonzero flux.
reaction_bound = Metabolite(bound_id)
reaction_bound._constraint_sense = "L"
reaction_bound._bound = max_ub
reaction_ind.add_metabolites({reaction_bound: max_ub + 1})
model.add_reaction(reaction_ind)
for metabolite in original_metabolites:
metabolite_var = Reaction("thermo_var_" + metabolite.id)
metabolite_var.lower_bound = -max_ub
model.add_reaction(metabolite_var)
metabolite_var.add_metabolites(
{model.metabolites.get_by_id(k): v
for k, v in iteritems(thermo_stoic[metabolite_var.id])})
return model
示例11: solver_test
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import upper_bound [as 别名]
def solver_test(request):
solver = solvers.solver_dict[request.param]
old_solution = 0.8739215
infeasible_model = Model()
metabolite_1 = Metabolite("met1")
reaction_1 = Reaction("rxn1")
reaction_2 = Reaction("rxn2")
reaction_1.add_metabolites({metabolite_1: 1})
reaction_2.add_metabolites({metabolite_1: 1})
reaction_1.lower_bound = 1
reaction_2.upper_bound = 2
infeasible_model.add_reactions([reaction_1, reaction_2])
return solver, old_solution, infeasible_model
示例12: test__normalize_pseudoreaction_atpm_reversed
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import upper_bound [as 别名]
def test__normalize_pseudoreaction_atpm_reversed():
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})
reaction.lower_bound = -50
reaction.upper_bound = 100
pseudo_id = _normalize_pseudoreaction(reaction.id, reaction)
assert pseudo_id == 'ATPM'
assert reaction.lower_bound == -100
assert reaction.upper_bound == 50
示例13: construct_difference_model
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import upper_bound [as 别名]
def construct_difference_model(model_1, model_2, norm_type='euclidean'):
"""Combine two models into a larger model that is designed to calculate differences
between the models
"""
#Get index mappings
common_dict = {}
#Using copies of the models so things are modified above
combined_model = model_1 = model_1.copy()
model_2 = model_2.copy()
for reaction_1 in model_1.reactions:
try:
reaction_2 = model_2.reactions.get_by_id(reaction_1.id)
common_dict[reaction_1] = reaction_2
except:
continue
#Add a prefix in front of the mutant_model metabolites and reactions to prevent
#name collisions in DictList
for the_dict_list in [model_2.metabolites,
model_2.reactions]:
[setattr(x, 'id', 'mutant_%s'%x.id)
for x in the_dict_list]
the_dict_list._generate_index() #Update the DictList.dicts
combined_model.add_reactions(model_2.reactions)
[setattr(x, 'objective_coefficient', 0.)
for x in combined_model.reactions]
#Add in the difference reactions. The mutant reactions and metabolites are already added.
#This must be a list to maintain the correct order when adding the difference_metabolites
difference_reactions = [] #Add the difference reactions at the end to speed things up
difference_metabolites = []
for reaction_1, reaction_2 in iteritems(common_dict):
reaction_1._difference_partner = reaction_2
reaction_2._difference_partner = reaction_1
difference_reaction = Reaction('difference_%s'%reaction_1.id)
difference_reactions.append(difference_reaction)
difference_reaction.upper_bound = 100000
difference_reaction.lower_bound = -1* difference_reaction.upper_bound
difference_metabolite = Metabolite('difference_%s'%reaction_1.id)
difference_metabolites.append(difference_metabolite)
if norm_type == 'linear':
difference_metabolite._constraint_sense = 'G'
reaction_1.add_metabolites({difference_metabolite: -1.}, add_to_container_model=False)
reaction_2.add_metabolites({difference_metabolite: 1.}, add_to_container_model=False)
difference_reaction.add_metabolites({difference_metabolite: 1.}, add_to_container_model=False)
combined_model.add_metabolites(difference_metabolites)
combined_model.add_reactions(difference_reactions)
return(combined_model)
示例14: add_reaction
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import upper_bound [as 别名]
def add_reaction(model, id, name, sparse,
lower_bound=0, upper_bound=1000):
"""
Adds a reaction to the model
"""
# convert the sparse representation using the metabolites in the model
for key in sparse.keys():
if key not in model.metabolites:
raise Exception("cannot find the cytoplasmic metabolite %s in the model" % key)
r = dict([(model.metabolites[model.metabolites.index(key)], val)
for key, val in sparse.iteritems()])
reaction = Reaction(name)
reaction.id = id
reaction.add_metabolites(r)
reaction.lower_bound = lower_bound
reaction.upper_bound = upper_bound
model.add_reactions([reaction])
return reaction
示例15: convert_to_irreversible
# 需要导入模块: from cobra.core import Reaction [as 别名]
# 或者: from cobra.core.Reaction import upper_bound [as 别名]
def convert_to_irreversible(cobra_model):
"""Split reversible reactions into two irreversible reactions
These two reactions will proceed in opposite directions. This
guarentees that all reactions in the model will only allow
positive flux values, which is useful for some modeling problems.
cobra_model: A Model object which will be modified in place.
"""
warn("deprecated, not applicable for optlang solvers", DeprecationWarning)
reactions_to_add = []
coefficients = {}
for reaction in cobra_model.reactions:
# If a reaction is reverse only, the forward reaction (which
# will be constrained to 0) will be left in the model.
if reaction.lower_bound < 0:
reverse_reaction = Reaction(reaction.id + "_reverse")
reverse_reaction.lower_bound = max(0, -reaction.upper_bound)
reverse_reaction.upper_bound = -reaction.lower_bound
coefficients[
reverse_reaction] = reaction.objective_coefficient * -1
reaction.lower_bound = max(0, reaction.lower_bound)
reaction.upper_bound = max(0, reaction.upper_bound)
# Make the directions aware of each other
reaction.notes["reflection"] = reverse_reaction.id
reverse_reaction.notes["reflection"] = reaction.id
reaction_dict = {k: v * -1
for k, v in iteritems(reaction._metabolites)}
reverse_reaction.add_metabolites(reaction_dict)
reverse_reaction._model = reaction._model
reverse_reaction._genes = reaction._genes
for gene in reaction._genes:
gene._reaction.add(reverse_reaction)
reverse_reaction.subsystem = reaction.subsystem
reverse_reaction._gene_reaction_rule = reaction._gene_reaction_rule
reactions_to_add.append(reverse_reaction)
cobra_model.add_reactions(reactions_to_add)
set_objective(cobra_model, coefficients, additive=True)