r 将MAPK途径磷酸化下载到R中的igraph对象中

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了r 将MAPK途径磷酸化下载到R中的igraph对象中相关的知识,希望对你有一定的参考价值。

g_nell <- tempfile() %T>%
    {KEGGgraph::retrieveKGML("04010", organism="hsa", destfile=., method="curl", quiet=TRUE)} %>%
    {KEGGgraph::parseKGML2Graph(., expandGenes=FALSE)} 
vertex_list <- KEGGgraph::getKEGGnodeData(g_nell) %>%
    {data.frame(
      kegg = unlist(lapply(., function(item) item@name[1])),
      label = unlist(lapply(., function(item)
        strsplit(item@graphics@name, ",")[[1]][1])), stringsAsFactors = F)}
g_init <- igraph.from.graphNEL(g_nell) 
V(g_init)$name <- vertex_list$kegg 
vertex_list <- dplyr::filter(vertex_list, !duplicated(kegg))
edge_list <- KEGGgraph::getKEGGedgeData(g_nell) %>%
  lapply(function(item){
    if(length(item@subtype) > 0){
      subtype_info <- item@subtype
      # KEGG uses a hierarchy of term for describing terms
      # for example, the first edge type is "activation", the second is "phosphorylation"
      # where phosphorylation is a type of activation.  The second term is more specific than
      # the first, so when it is provided, use it in lieu of the first type.
      if(length(subtype_info) > 1) {
        return(subtype_info[[2]]@name)
      } else {
        return(subtype_info$subtype@name)
      }
    } 
    NA
    }) %>%
    unlist %>%
    {cbind(get.edgelist(g_init), type = .)} %>%
    data.frame %>%
    {dplyr::filter(.,type == "phosphorylation")}
edge_list <- edge_list %>%
    as.data.frame %>%
    unique
vertex_list <- vertex_list %>%
    unique %>%
    {dplyr::filter(., !duplicated(kegg))}
g <- graph.data.frame(edge_list, directed = TRUE, vertices = vertex_list)
V(g)$kid <- V(g)$name
V(g)$name <- V(g)$label
g <- g - V(g)[igraph::degree(g) == 0]
rm(vertex_list)
rm(edge_list)
rm(g_init)
rm(g_nell)

以上是关于r 将MAPK途径磷酸化下载到R中的igraph对象中的主要内容,如果未能解决你的问题,请参考以下文章

如何将值向量分配给R中igraph中的顶点标签?

R语言使用igraph包进行网络(network)可视化实战:将变量映射到网络节点(vertex)将变量映射到网络的边(edge)

如何在 R 中删除 igraph 中的节点?

R将egor对象转换为igraph /使用可视化应用程序(错误:重复的顶点名称)

R中的delete_vertices igraph

r 直接从Neo4j REST API获取图形数据到R.对于R igraph用户有用。