by Kozo Nishida (Riken, Japan)
This example demonstrates how to integrate transcriptome data (preprocessed with bioconductor packages) with KEGG pathways and visualize it in Cytoscape.
In [1]:
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'}
# Delete all networks in current session
requests.delete(BASE_URL + 'session')
Out[1]:
In [2]:
pathway_location = "http://rest.kegg.jp/get/eco00260/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))
source("http://bioconductor.org/biocLite.R")
biocLite(c("genefilter", "ecoliLeucine"))
library("ecoliLeucine")
library("genefilter")
data("ecoliLeucine")
eset = rma(ecoliLeucine)
r = rowttests(eset, eset$strain)
filtered = r[r$p.value < 0.05,]
write.csv(filtered, file="ttest.csv")
In [3]:
import pandas as pd
ttest_df = pd.read_csv('ttest.csv')
ttest_df.head()
Out[3]:
In [4]:
deftable = requests.get('http://localhost:1234/v1/networks/' + str(pathway_suid) + '/tables/defaultnode.tsv')
handle = open('defaultnode.tsv','w')
handle.write(deftable.content)
handle.close()
deftable_df = pd.read_table('defaultnode.tsv')
deftable_df.head()
Out[4]:
In [5]:
import re
bnum_re = re.compile('b[0-9]{4}')
keggids = []
keggnode_labels = []
for index, probe in ttest_df['Unnamed: 0'].iteritems():
m = bnum_re.search(probe)
if m:
keggids.append(None)
keggnode_labels.append(None)
for i, keggid in deftable_df['KEGG_ID'].iteritems():
if m.group(0) in keggid:
keggids.pop()
keggids.append(keggid)
keggnode_labels.pop()
keggnode_labels.append(deftable_df['KEGG_NODE_LABEL'][i])
else:
keggids.append(None)
keggnode_labels.append(None)
s1 = pd.Series(keggids, name='KEGG_ID_INPATHWAY')
s2 = pd.Series(keggnode_labels, name='KEGG_NODE_LABEL_INPATHWAY')
merged_df = pd.concat([ttest_df, s1, s2], axis=1)
merged_df.head()
Out[5]:
In [6]:
ttestjson = json.loads(merged_df.to_json(orient="records"))
new_table_data = {
"key": "KEGG_NODE_LABEL",
"dataKey": "KEGG_NODE_LABEL_INPATHWAY",
"data" : ttestjson
}
update_table_url = BASE_URL + "networks/" + str(pathway_suid) + "/tables/defaultnode"
print(update_table_url)
requests.put(update_table_url, data=json.dumps(new_table_data), headers=HEADERS)
Out[6]: