当前位置: 首页>>代码示例>>Python>>正文


Python Model.update方法代码示例

本文整理汇总了Python中cobra.Model.update方法的典型用法代码示例。如果您正苦于以下问题:Python Model.update方法的具体用法?Python Model.update怎么用?Python Model.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cobra.Model的用法示例。


在下文中一共展示了Model.update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: matlab_cobra_struct_to_python_cobra_object

# 需要导入模块: from cobra import Model [as 别名]
# 或者: from cobra.Model import update [as 别名]

#.........这里部分代码省略.........
            the_csense = matlab_struct.csense
            _constraint_sense = [the_csense[i] for i in range(len(the_csense))]
        else:
            _constraint_sense = matlab_cell_to_python_list(matlab_struct.csense)
    else:
        _constraint_sense = ['E']*len(cobra_metabolites)
    if 'metFormulas' in struct_fields:
        _metabolite_formulas = matlab_cell_to_python_list(matlab_struct.metFormulas)
    else:
        _metabolite_formulas = ['']*len(the_model.metabolites)
    if 'metCharge' in struct_fields:
        _metabolite_charges = matlab_struct.metCharge.flatten().tolist()
    else:
        _metabolite_charges = [None]*len(cobra_metabolites)
    if 'metCASID' in struct_fields:
        _metabolite_cas_id = matlab_cell_to_python_list(matlab_struct.metCASID)
    else:
        _metabolite_cas_id = [None]*len(cobra_metabolites)
    if 'metKeggID' in struct_fields:
        _metabolite_kegg_id = matlab_cell_to_python_list(matlab_struct.metKeggID)
    else:
        _metabolite_kegg_id = [None]*len(cobra_metabolites)
    the_compartments = {}
    for the_metabolite, b, n, c, f, ch, cas, kegg in zip(cobra_metabolites,
                                                         _b,
                                                         _metabolite_names,
                                                         _constraint_sense,
                                                         _metabolite_formulas,
                                                         _metabolite_charges,
                                                         _metabolite_cas_id,
                                                         _metabolite_kegg_id):
        the_metabolite._bound = b[0]
        the_metabolite.name = n
        the_metabolite._constraint_sense = c
        the_metabolite.formula = Formula(f)
        the_metabolite.charge = int(ch)
        the_compartments[the_metabolite.compartment] = the_metabolite.compartment
        if ch is not None:
            the_metabolite.notes['CHARGE'] = int(ch)
        if cas is not None and cas != '':
            the_metabolite.notes['CASID'] = cas
        if kegg is not None and kegg != '':
            the_metabolite.notes['KEGGID'] = kegg
            
    metabolite_dict = dict([(x.id, x)
                            for x in cobra_metabolites])
    #Reaction section
    cobra_reactions = map(Reaction, matlab_cell_to_python_list(matlab_struct.rxns))
    _objective_coefficients = deepcopy(matlab_struct.c).tolist()
    _lower_bounds = deepcopy(matlab_struct.lb).tolist()
    _upper_bounds = deepcopy(matlab_struct.ub).tolist()
    _reversibility = deepcopy(matlab_struct.rev).tolist()
    if 'rxnNames' in struct_fields:
        _reaction_names = matlab_cell_to_python_list(matlab_struct.rxnNames)
    else:
        _reaction_names = ['']*len(the_model.reactions)
    if 'grRules' in struct_fields:
        _gene_reaction_rules = matlab_cell_to_python_list(matlab_struct.grRules)
    else:
        _gene_reaction_rules = ['']*len(the_model.reactions)
    if 'subSystems' in struct_fields:
        _subsystems = matlab_cell_to_python_list(matlab_struct.subSystems)
    else:
        _subsystems = ['']*len(the_model.reactions)
    for the_reaction, o, l, u, n, r, s, rev in zip(cobra_reactions,
                                              _objective_coefficients,
                                              _lower_bounds,
                                              _upper_bounds,
                                              _reaction_names,
                                              _gene_reaction_rules,
                                              _subsystems, _reversibility ):
        the_reaction.objective_coefficient = o[0]
        the_reaction.lower_bound = l[0]
        the_reaction.upper_bound = u[0]
        the_reaction.name = n
        the_reaction.gene_reaction_rule = r
        the_reaction.subsystem = s
        the_reaction.reversibility = rev[0]
        the_reaction.parse_gene_association()
    index_to_reaction = dict(zip(range(len(cobra_reactions)),
                                 cobra_reactions))
    index_to_metabolite = dict(zip(range(len(cobra_metabolites)),
                                 cobra_metabolites))
    for k, coefficient in _S_dok.items():
        the_reaction = index_to_reaction[k[1]]
        the_metabolite = index_to_metabolite[k[0]]
        the_reaction.add_metabolites({the_metabolite: coefficient})
    #solution needs to be redesigned from a matlab proxy.
    #Now populate all of the reactions
    #NOTE: Having a metabolite referenece here would be a good idea
    compartment_dict = {'e': 'extracellular',
                        'c': 'cytosol',
                        'p': 'periplasm'}
    for the_key in the_compartments:
        if the_key in compartment_dict:
            the_compartments[the_key] = compartment_dict[the_key]
    the_model.add_reactions(cobra_reactions)
    the_model.compartments = the_compartments
    the_model.update()
    return the_model
开发者ID:mp11,项目名称:cobra_ext,代码行数:104,代码来源:mlab.py


注:本文中的cobra.Model.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。