利用kegg数据库的pathway信息,构建基因和基因的互作网络关系,并用cytoscape展示,可以方便研究者更好的探索那些基因是在生命过程中发挥重要作用的关键基因。
kegg pathway中的基因与基因的互作关系,可以从kegg官方提供的kgml文件中获取。
获取方法参考网址:https://www.kegg.jp/kegg/rest/keggapi.html
确定是否存在对应pathway的kgml文件:http://rest.kegg.jp/get/hsa04390/kgml
其中:hsa04390为pathway编号,可以替换为自己关注的pathway编号
脚本参考:https://blog.csdn.net/weixin_43569478/article/details/108079035
R语言批量下载关注pathway编号的kgml文件:
library(curl)
library("XML")
library("methods")
library(KEGGgraph)
interested_pathway <- c('hsa04390','hsa04371')
for (i in interested_pathway){
url <- paste0("http://rest.kegg.jp/get/",i,"/kgml")
assign(paste0(i,"_kgml"), tempfile())
curl_download(url, paste0(i,"_kgml"))
}
##############生成进行网络图绘制的边文件和节点文件#####################
for (i in interested_pathway){
mapkG <- parseKGML2Graph(paste0(i,"_kgml"),expandGenes=TRUE, genesOnly = TRUE)
mapkNodes <- nodes(mapkG)
mapkEdges <- edges(mapkG)
mapkEdges <- mapkEdges[sapply(mapkEdges, length) > 0]
res <- lapply(1:length(mapkEdges), function(t){
name <- names(mapkEdges)[t]
len <- length(mapkEdges[[t]])
do.call(rbind, lapply(1:len, function(n){
c(name, mapkEdges[[t]][n])
}))
})
result <- data.frame(do.call(rbind, res))
write.table(result, "edges.txt", sep = "\t", row.names = F, col.names = F, quote = F ,append = T)
write.table(mapkNodes, "nodes.txt", sep = "\t", row.names = F, col.names = F, quote = F ,append = T)
}