[BioC] Gene Ontology graphs: root at the top?
De Bondt, An-7114 [PRDBE]
ADBONDT at PRDBE.jnj.com
Fri Jan 20 12:54:31 CET 2006
Dear Adrian,
Thanks a lot for this efficient solution which results in exactly what I had
in mind!
Regards,
An
-----Original Message-----
From: Adrian Alexa [mailto:adrian.alexa at gmail.com]
Sent: Wednesday, 18 January 2006 9:50
To: De Bondt, An-7114 [PRDBE]
Subject: Re: [BioC] Gene Ontology graphs: root at the top?
Hi,
I think what you need to do is to reverse the edges of the graph (to
go from the root to more specific nodes) when plotting the graph.
To change the direction of the edges in your graph you can use:
> basic_graph <- GOGraph(goid, GOBPPARENTS)
> basic_graph <- as(t(as(basic_graph, 'matrix')), 'graphNEL')
that is, you compute the adjacency matrix and then by transposing it
you change the direction of the edges. You should use the as()
function for small graphs since this transformation depends
quadratically on the number of nodes in the graph. For larger graphs
you can use the graph2SparseM() and sparseM2Graph() functions from the
SparseM package.
I'm also working with GO graphs and I use the following function for
changing the direction of the edges:
reverseArch <- function(dirGraph, useAlgo = 'sparse', useWeights = T) {
if(edgemode(dirGraph) != 'directed')
stop('The graph is not directed. Nothing to do')
if(numEdges(dirGraph) == 0) {
cat('Nothing to do:\n')
return(dirGraph)
}
if(useAlgo == 'sparse') {
nodNames <- nodes(dirGraph)
ret.gr <- sparseM2Graph(t(graph2SparseM(dirGraph, useWeights)),
nodNames)
edgemode(ret.gr) <- 'directed'
return(ret.gr)
}
return(as(t(as(dirGraph, 'matrix')), 'graphNEL'))
}
I hope that this helped,
Adrian Alexa
On 1/18/06, De Bondt, An-7114 [PRDBE] <ADBONDT at prdbe.jnj.com> wrote:
>
> Dear BioC users,
>
> Is it possible to make a hierarchical graph with the root at the top?
>
> The code I used so far is something like:
>
> library(GOstats)
> library(Rgraphviz)
> goid <- c("GO:0006882", "GO:0016049")
> basic_graph <- GOGraph(goid, GOBPPARENTS)
> Attrs <- list()
> node_color <- c(rep("red",length(nodes(basic_graph))))
> Attrs$fillcolor <- node_color
> node_fontsize <- c(rep(40,length(nodes(basic_graph))))
> Attrs$fontsize <- node_fontsize
> node_shape <- rep("ellipse", length(nodes(basic_graph)))
> Attrs$shape <- node_shape
> node_fixedsize <- rep(FALSE, length(nodes(basic_graph)))
> Attrs$fixedsize <- node_fixedsize
> Attrs <- lapply(Attrs, function(x) {
> names(x) <- nodes(basic_graph)
> x
> })
> basic_nodes <- buildNodeList(basic_graph, nodeAttrs = Attrs)
> basic_edges <- buildEdgeList(basic_graph)
> colored_graph <- agopen(name = "foo", nodes = basic_nodes, edges =
> basic_edges, edgeMode = "undirected")
> plot(colored_graph)
> This last line will show a graph with the root at the bottom and the most
> specific GOs at the top. Also plot(basic_graph) will show such a graph
(but
> with the standard attributes like white nodes in the shape of a circle
etc).
> I would like to show it up side down (root at the top).
> I can specify a layout when plotting the object called "basic_graph" using
> the plot() function. The layouts I know are dot (default), neato, twopi,
> circo and fdp. However, these options do not result in what I have in
mind.
> So far, I have not yet found the parameter(s) which define(s) the position
> of a node (e.g. x,y coordinates) on the plot. Could anyone give me a hint?
> Thanks in advance!
> Best regards,
> An
> Scientist Functional Genomics
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
>
--
Adrian Alexa
Max-Planck-Institut fuer Informatik
Stuhlsatzenhausweg 85 / Room 513
66123 Saarbruecken, Germany
More information about the Bioconductor
mailing list