如何设定通量比作为约束?

时间:2018-05-16 19:14:04

标签: python cbmpy

在某些数据集中,我有时会观察固定的通量比率,我希望将其纳入我的模拟中。我怎么能在CBMPy中做到这一点?

例如,我有来自here的模型,现在想要将琥珀酸外排和丙酮酸外排的比例限制在2.0。我知道如何设定对个别反应的限制:

import cbmpy

# downloaded from http://bigg.ucsd.edu/models/e_coli_core
ecoli = cbmpy.CBRead.readSBML3FBC('e_coli_core.xml')

ecoli.setReactionBounds('R_EX_pyr_e', 1.0, 1000.0)
ecoli.setReactionBounds('R_EX_succ_e', 2.0, 1000.0)

# solve the model
cbmpy.doFBA(ecoli)

# get all reaction values
solution = ecoli.getReactionValues()
print(solution['R_EX_pyr_e'])
print(solution['R_EX_succ_e'])

对于这种情况,比率是正确的,但是如何将其添加为约束条件以满足所有条件?

1 个答案:

答案 0 :(得分:1)

这确实是通量平衡分析(FBA)中的常用方法,您可以使用函数addUserConstraint来实现此目的。

整个代码示例可能如下所示(以下说明):

import cbmpy as cbm

# downloaded from http://bigg.ucsd.edu/models/e_coli_core
ecoli = cbm.CBRead.readSBML3FBC('e_coli_core.xml')

# make a clone of the original model
ecoli_ratio = ecoli.clone()

# add the desired user constraint; explanation follows below
ecoli_ratio.addUserConstraint("pyr_succ_ratio", fluxes=[(1.0, 'R_EX_pyr_e' ),(-0.5, 'R_EX_succ_e')], operator='=', rhs=0.0)

# now we have to set only one flux bound; if you think it is naturally excreted, this step is not needed
ecoli_ratio.setReactionBounds('R_EX_succ_e', 4.0, cbm.INF)

cbm.doFBA(ecoli_ratio)
solution = ecoli_ratio.getReactionValues()
print("{}: {}".format("succinate excretion rate", solution['R_EX_succ_e']))
print("{}: {}".format("pyruvate excretion rate", solution['R_EX_pyr_e']))

这将打印

succinate excretion rate: 4.0
pyruvate excretion rate: 2.0

正如您所见,该比率为2.0

更多解释:

约束是

J_succ / J_pyr = 2.0

可以改写为

J_succ = 2.0 J_pyr

最后

J_pyr - 0.5 J_succ = 0

这正是我们传递给fluxes中的addUserConstraint

fluxes=[(1.0, 'R_EX_pyr_e' ),(-0.5, 'R_EX_succ_e')], operator='=', rhs=0.0)

您可以通过打印来检查用户定义的约束:

print(ecoli_ratio.user_constraints)
{'pyr_succ_ratio': {'operator': 'E', 'rhs': 0.0, 'fluxes': [(1.0, 'R_EX_pyr_e'), (-0.5, 'R_EX_succ_e')]}}

由于这是一本字典,您只需执行以下操作即可删除约束:

del ecoli_ratio.user_constraints['pyr_succ_ratio']
print(ecoli_ratio.user_constraints)
{}

但我强烈建议您每次引入模型的主要更改时都创建一个克隆。