def ParseReactionFormula(name, formula): """ parse a two-sided formula such as: 2 C00001 = C00002 + C00003 return the set of substrates, products and the direction of the reaction """ try: left, right = formula.split(' = ', 1) except ValueError: raise KeggParseException("There should be exactly one '=' sign") sparse_reaction = {} for cid, amount in NistRowData.ParseReactionFormulaSide( left).iteritems(): sparse_reaction[cid] = -amount for cid, amount in NistRowData.ParseReactionFormulaSide( right).iteritems(): if (cid in sparse_reaction): raise KeggParseException( "C%05d appears on both sides of this formula" % cid) sparse_reaction[cid] = amount reaction = Reaction([name], sparse_reaction, None, '=>') kegg = Kegg.getInstance() rid = kegg.reaction2rid(reaction) or kegg.reaction2rid( reaction.reverse()) reaction.rid = rid return reaction
def ParseReactionFormula(name, formula): """ parse a two-sided formula such as: 2 C00001 = C00002 + C00003 return the set of substrates, products and the direction of the reaction """ try: left, right = formula.split(' = ', 1) except ValueError: raise KeggParseException("There should be exactly one '=' sign") sparse_reaction = {} for cid, amount in NistRowData.ParseReactionFormulaSide(left).iteritems(): sparse_reaction[cid] = -amount for cid, amount in NistRowData.ParseReactionFormulaSide(right).iteritems(): if (cid in sparse_reaction): raise KeggParseException("C%05d appears on both sides of this formula" % cid) sparse_reaction[cid] = amount reaction = Reaction([name], sparse_reaction, None, '=>') kegg = Kegg.getInstance() rid = kegg.reaction2rid(reaction) or kegg.reaction2rid(reaction.reverse()) reaction.rid = rid return reaction