有没有办法使用dot
在Rgraphviz
布局(a-la ggnet
)中绘制DAG?
我的示例是基因本体图,取自topGO
's vignette
:
library(topGO)
library(ALL)
data(ALL)
data(geneList)
affyLib <- paste(annotation(ALL),"db",sep= ".")
library(package=affyLib,character.only=TRUE)
topgo.obj <- new("topGOdata",description="Simple session",ontology="BP",allGenes=geneList,geneSel=topDiffGenes,nodeSize=10,annot=annFUN.db,affyLib=affyLib)
res.fisher <- runTest(topgo.obj,algorithm="classic",statistic="fisher")
res.df <- GenTable(topgo.obj,classicFisher=res.fisher,orderBy="classicFisher",topNodes=length(score(res.fisher)))
为方便起见,我设置了:
res.df$p.value <- as.numeric(res.df$classicFisher)
我只保留topGO
graphNEL
个p值低于0.05的节点及其祖先:
topgo.graph <- graph(topgo.obj)
sig.cutoff <- 0.05
sig.node.names <- dplyr::filter(res.df,p.value < sig.cutoff)$GO.ID
topgo.graph <- reverseArch(inducedGraph(topgo.graph,sig.node.names))
要使用ggnet
我将graphNEL
图表转换为igraph
:
library(ggnet)
library(network)
library(sna)
library(scales)
library(igraph)
library(intergraph)
topgo.igraph <- graph_from_graphnel(topgo.graph,name=TRUE,weight=TRUE,unlist.attrs=TRUE)
topgo.network <- asNetwork(topgo.igraph,amap=attrmap())
ggnet2(net=topgo.network,size=10,arrow.size=12,arrow.gap=0.025)
使用Rgraphviz
&#39; dot
布局的格式我希望ggnet
将其打印出来:
library(Rgraphviz)
nodeAttrs <- list()
edgeAttrs <- list()
graphAttrs <- getDefaultAttrs(layoutType='dot')
graphAttrs$cluster <- NULL
graphAttrs$node$shape <- 'box'
graphAttrs$node$fontsize <- '14'
nodeAttrs$label <- nodes(topgo.graph)
names(nodeAttrs$label) <- nodes(topgo.graph)
graphAttrs$edge$color <- 'black'
plot(agopen(graph=topgo.graph,name="GO",attrs=graphAttrs,nodeAttrs=nodeAttrs,edgeAttrs=edgeAttrs))
所以我的问题是如何让ggnet在这个布局中绘制topgo.network?