Skip to content

Instantly share code, notes, and snippets.

@kozo2
Created October 16, 2014 11:46
Show Gist options
  • Save kozo2/ac87bc775353034374f8 to your computer and use it in GitHub Desktop.
Save kozo2/ac87bc775353034374f8 to your computer and use it in GitHub Desktop.
import libsbml
document = libsbml.readSBML('BMID000000140222.xml')
model = document.getModel()
f = open('hoge.txt', 'w')

f.write('id\tBIGG\tBRENDA\tGENE_ASSOCIATION\tKEGG\tMETACYC\tREACTOME\tRHEA\tSEED\tUPA\n')

import re

bigg = re.compile(r'BIGG:.*</p>')
brenda = re.compile(r'BRENDA:.*</p>')
gene_association = re.compile(r'GENE_ASSOCIATION:.*</p>')
kegg = re.compile(r'KEGG:.*</p>')
metacyc = re.compile(r'METACYC:.*</p>')
reactome = re.compile(r'REACTOME:.*</p>')
rhea = re.compile(r'RHEA:.*</p>')
seed = re.compile(r'SEED:.*</p>')
upa = re.compile(r'UPA:.*</p>')

for i in range(0,model.getNumReactions()):
    r = model.getReaction(i)

    notes = r.getNotesString()

    biggr = bigg.search(notes)
    brendar = brenda.search(notes)
    gene_associationr = gene_association.search(notes)
    keggr = kegg.search(notes)
    metacycr = metacyc.search(notes)
    reactomer = reactome.search(notes)
    rhear = rhea.search(notes)
    seedr = seed.search(notes)
    upar = upa.search(notes)

    if biggr:
        big = biggr.group()[6:-4]
    else:
        big = ""
    if brendar:
        br = brendar.group()[8:-4]
    else:
        br = ""
    if gene_associationr:
        gene = gene_associationr.group()[18:-4]
    else:
        gene = ""
    if keggr:
        keg = keggr.group()[6:-4]
    else:
        keg = ""
    if metacycr:
        meta = metacycr.group()[9:-4]
    else:
        meta = ""
    if reactomer:
        react = reactomer.group()[10:-4]
    else:
        react = ""
    if rhear:
        rh = rhear.group()[6:-4]
    else:
        rh = ""
    if seedr:
        se = seedr.group()[6:-4]
    else:
        se = ""
    if upar:
        up = upar.group()[5:-4]
    else:
        up = ""

    f.write("\t".join([r.id, big, br, gene, keg, meta, react, rh, se, up]) + "\n")

f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment