<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Mapping Path2Models whole genome metabolism model to KEGG pathway
Software Requirements
pandas
python-libsbml
Step1:  Retrieving the whole-genome metabolic model from path2models
Whole Genome Metabolism of Escherichia coli str. K-12 substr. MG1655 http
Step2:  reading path2models SBML
Step3:  construct regex patterns
Step4:  create pandas dataframe for reactions
Step5:  Integrating path2models dataframe with KEGG pathway
importing E.coli glycolysis(eco00010) pathway
<ASSISTANT_TASK:>
Python Code:
import libsbml
import pandas as pd
import re
Explanation: Mapping Path2Models whole genome metabolism model to KEGG pathway
Software Requirements
pandas
python-libsbml
End of explanation
!curl -o BMID000000140222.xml http://www.ebi.ac.uk/biomodels-main/download?mid=BMID000000140222
Explanation: Retrieving the whole-genome metabolic model from path2models
Whole Genome Metabolism of Escherichia coli str. K-12 substr. MG1655 http://www.ebi.ac.uk/biomodels-main/download?mid=BMID000000140222
This file is big, so I recommend you download this once.
End of explanation
document = libsbml.readSBML('BMID000000140222.xml')
model = document.getModel()
Explanation: reading path2models SBML
End of explanation
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>')
Explanation: construct regex patterns
End of explanation
id_ary = []
bigg_ary = []
brenda_ary = []
gene_association_ary = []
kegg_ary = []
metacyc_ary =[]
for i in range(0,model.getNumReactions()):
    r = model.getReaction(i)
    notes = r.getNotesString()
    bigg_re = bigg.search(notes)
    brenda_re = brenda.search(notes)
    gene_association_re = gene_association.search(notes)
    kegg_re = kegg.search(notes)
    metacyc_re = metacyc.search(notes)
    
    id_ary.append(r.id)
    bigg_ary.append(None)
    brenda_ary.append(None)
    gene_association_ary.append(None)
    kegg_ary.append(None)
    metacyc_ary.append(None)
    if bigg_re:
        bigg_ary.pop()
        big = bigg_re.group()[6:-4]
        bigg_ary.append(big)
    if brenda_re:
        brenda_ary.pop()
        br = brenda_re.group()[8:-4]
        brenda_ary.append(br)
    if gene_association_re:
        gene_association_ary.pop()
        gene = gene_association_re.group()[18:-4]
        gene_association_ary.append(gene)
    if kegg_re:
        kegg_ary.pop()
        keg = kegg_re.group()[6:-4]
        kegg_ary.append(keg)
    if metacyc_re:
        metacyc_ary.pop()
        meta = metacyc_re.group()[9:-4]
        metacyc_ary.append(meta)
id_se = pd.Series(id_ary, name='ID')
bigg_se = pd.Series(bigg_ary, name='BIGG')
brenda_se = pd.Series(brenda_ary, name='BRENDA')
gene_association_se = pd.Series(gene_association_ary, name='GENE_ASSOCIATION')
kegg_se = pd.Series(kegg_ary, name='KEGG')
metacyc_se = pd.Series(metacyc_ary, name='METACYC')
df = pd.concat([id_se, bigg_se, brenda_se, gene_association_se, kegg_se, metacyc_se], axis=1)
df.head()
Explanation: create pandas dataframe for reactions
End of explanation
import requests
import json
# Basic Setup
PORT_NUMBER = 1234
BASE_URL = "http://localhost:" + str(PORT_NUMBER) + "/v1/"
# Header for posting data to the server as JSON
HEADERS = {'Content-Type': 'application/json'}
requests.get(BASE_URL)
pathway_location = "http://rest.kegg.jp/get/eco00010/kgml"
res1 = requests.post(BASE_URL + "networks?source=url", data=json.dumps([pathway_location]), headers=HEADERS)
result = json.loads(res1.content)
pathway_suid = result[0]["networkSUID"][0]
print("Pathway SUID = " + str(pathway_suid))
Explanation: Integrating path2models dataframe with KEGG pathway
importing E.coli glycolysis(eco00010) pathway
End of explanation
<END_TASK>