这种任务没有内置函数。正如您已经提到的,依赖 ID 通常不是一个好主意,因为这些 ID 在不同的数据库、模型和组之间可能会有所不同(例如,如果有人决定仅列举来自r1
till的反应和/或来自till的rn
代谢物,则基于 ID 的过滤会失败)。相反,人们可以利用该物种的领域。在 CBMPy 中,您可以通过以下方式访问物种的隔间m1
mm
compartment
import cbmpy as cbm
import pandas as pd
mod = cbm.CBRead.readSBML3FBC('iMM904.xml.gz')
mod.getSpecies('M_atp_c').getCompartmentId()
# will return 'c'
# run a FBA
cbm.doFBA(mod)
这可用于查找隔室之间的所有通量,因为可以检查其试剂所在隔室的每个反应。一个可能的实现如下所示:
def get_fluxes_associated_with_compartments(model_object, compartments, return_values=True):
# check whether provided compartment IDs are valid
if not isinstance(compartments, (list, set) or not set(compartments).issubset(model_object.getCompartmentIds())):
raise ValueError("Please provide valid compartment IDs as a list!")
else:
compartments = set(compartments)
# all reactions in the model
model_reactions = model_object.getReactionIds()
# check whether provided compartments are identical with the ones of the reagents of a reaction
return_reaction_ids = [ri for ri in model_reactions if compartments == set(si.getCompartmentId() for si in
model_object.getReaction(ri).getSpeciesObj())]
# return reaction along with its value
if return_values:
return {ri: model_object.getReaction(ri).getValue() for ri in return_reaction_ids}
# return only a list with reaction IDs
return return_reaction_ids
因此,您传递您的模型对象和隔间列表,然后对于每个反应,检查指定隔间中是否至少有一种试剂。
在您的情况下,您将按如下方式使用它:
# compartment IDs for mitochondria and cytosol
comps = ['c', 'm']
# you only want the reaction IDs; remove the ', return_values=False' part if you also want the corresponding values
trans_cyt_mit = get_fluxes_associated_with_compartments(mod, ['c', 'm'], return_values=False)
然后,该列表trans_cyt_mit
将包含所有所需的反应 ID(也是您在问题中指定的两个),然后您可以将其传递给doFVA
函数。
关于你问题的第二部分。我强烈建议将这些反应存储在一个组中,而不是使用注释:
# create an empty group
mod.createGroup('group_trans_cyt_mit')
# get the group object so that we can manipulate it
cyt_mit = mod.getGroup('group_trans_cyt_mit')
# we can only add objects to a group so we get the reaction object for each transport reaction
reaction_objects = [mod.getReaction(ri) for ri in trans_cyt_mit]
# add all the reaction objects to the group
cyt_mit.addMember(reaction_objects)
当您现在导出模型时,例如使用
cbm.CBWrite.writeSBML3FBCV2(mod, 'iMM904_with_groups.xml')
该组也将存储在 SBML 中。如果同事再次阅读 SBML,他/她可以FVA
通过访问组成员轻松地运行相同的反应,这比解析注释要容易得多:
# do an FVA; fva_res: Reaction, Reduced Costs, Variability Min, Variability Max, abs(Max-Min), MinStatus, MaxStatus
fva_res, rea_names = cbm.doFVA(mod, selected_reactions=mod.getGroup('group_trans_cyt_mit').getMemberIDs())
fva_dict = dict(zip(rea_names, fva_res.tolist()))
# store results in a dataframe which makes the selection of reactions easier
fva_df = pd.DataFrame.from_dict(fva_dict, orient='index')
fva_df = fva_df.rename({0: "flux_value", 1: "reduced_cost_unscaled", 2: "variability_min", 3: "variability_max",
4: "abs_diff_var", 5: "min_status", 6: "max_status"}, axis='columns')
现在您可以轻松地查询数据框并在您的组中找到灵活和不灵活的反应:
# filter the reactions with flexibility
fva_flex = fva_df.query("abs_diff_var > 10 ** (-4)")
# filter the reactions that are not flexible
fva_not_flex = fva_df.query("abs_diff_var <= 10 ** (-4)")