看教程不够直观,那就看视频吧! >>点击加载视频
从KEGG(Kyoto
Encyclopedia of Genes and Genomes)网站上获得差异表达基因所富集通路的XML文件。使用R包XML提取这些XML文件中的relation,entry和group关系。然后利用脚本组合它们从中提取其中基因的互作信息,构建KEGG通路基因互作网络从KEGG(Kyoto
Encyclopedia of Genes and Genomes)网站上获得差异表达基因所富集通路的XML文件。使用R包XML提取这些XML文件中的relation,entry和group关系。然后利用脚本组合它们从中提取其中基因的互作信息,构建KEGG通路基因互作网络
kegg.ppi=function(hsas){
library(curl)
library("XML")
library("methods")
all.ppi=rbind()
pal=0
for(hs in hsas){
url <- paste0("http://rest.kegg.jp/get/",hs,"/kgml")
tmp <- tempfile()
curl_download(url, tmp)
result <- xmlParse(file = tmp)
rootnode <- xmlRoot(result)
xmlNet=rbind()
pal=pal+1
print(paste0('parse:',hs,'...',pal,'/',length(hsas)))
for(a in xmlApply(rootnode, xmlToList)){
ns=names(a$.attrs)
which(ns=='id')
e1=a$.attrs['entry1']
e2=a$.attrs['entry2']
tp=a$.attrs['type']
id=a$.attrs['id']
name=a$.attrs['name']
xmlNet=rbind(xmlNet,c(id,name,e1,e2,tp))
}
genes=xmlNet[which(xmlNet[,5]=='gene'),]
ppi=xmlNet[is.na(xmlNet[,1]),]
ppi=cbind(node1=gsub('hsa:','',genes[match(ppi[,3],genes[,1]),2]),
node2=gsub('hsa:','',genes[match(ppi[,4],genes[,1]),2]),type=ppi[,5])
ppi=ppi[!is.na(ppi[,1])&!is.na(ppi[,2]),]
all.ppi=rbind(all.ppi,ppi)
}
all.gid=rbind()
for(i in 1:nrow(all.ppi)){
lk1=unlist(strsplit(all.ppi[i,1],' '))
lk2=unlist(strsplit(all.ppi[i,2],' '))
tmp=rbind()
for(g in lk1){
tmp=rbind(tmp,cbind(rep(g,length(lk2)),lk2))
}
all.gid=rbind(all.gid,cbind(tmp,rep(all.ppi[i,3],nrow(tmp))))
}
colnames(all.gid)=c('Node1','Node2','type')
all.gid=all.gid[match(unique(paste0(all.gid[,1],'-',all.gid[,2])),paste0(all.gid[,1],'-',all.gid[,2])),]
return(all.gid)
}

如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!
