[BioC] graph classes: how to combine multiple graphs into a single graph
Nishant Gopalakrishnan
ngopalak at fhcrc.org
Fri Feb 18 18:44:27 CET 2011
Hi Paul
I believe that you had posted this question on the mailing list before
and I had responded to it
here https://stat.ethz.ch/pipermail/bioconductor/2010-December/036706.html
The only change made to the graphBAM class (which supports the kind of
attribute preserving behavior you are looking for )
since then was to add support for the edgeDataDefaults and
nodeDatadefaults methods that you had requested. The nodes of the graphs
being combined here need not be identical as can be seen from the
example below.
With these changes, you can do the following to combine two graphs
using the union method.
from = c("a", "b", "d", "d")
to = c("b", "c", "y", "x")
weight=c(1.2, 2.4, 5.4, 3.2)
df <- data.frame(from, to, weight)
g1 <- graphBAM(df, edgemode = "directed")
edgeDataDefaults(g1, attr = "color") <- "green"
edgeData(g1, from = c("a","b"), to = c("b", "c") , attr = "color") <-
c("yellow", "blue")
from = c("a", "b", "b", "d", "d")
to = c("b", "c", "d", "c", "x")
weight=c(1.2, 4.2, 5.6, 2.1, 3.2)
df <- data.frame(from, to, weight)
g2 <- graphBAM(df, nodes = c("a","b","c", "d", "x", "y", "z"),
edgemode = "directed")
edgeDataDefaults(g2, attr ="color") <- "green"
edgeData(g2, from = c("a","b"), to = c("b", "c") , attr = "color") <-
c("yellow", "cyan")
## confilicting attributes are filled with NA in the result
g <- graphUnion(g1, g2)
edgeData(g, attr = "weight")
edgeData(g, attr = "color")
## Provide a function for resolving conflicting weight attribute, I want
the sum of
## weights in case of conflict
g <- graphUnion(g1, g2, edgeFun = list(weight = sum))
edgeData(g, attr = "weight")
edgeData(g, attr = "color")
If you wanted to resolve the conflict for the attribute color for the
edges, you could write a function
myFun <- function(x, y) {
## resolve conflict here
}
and pass it an argument to the graphUnion method.
g <- graphUnion(g1, g2, edgeFun = list(weight = sum, color = myFun))
If the union method illustrated above does not meet your needs or if you
have some other way of combining graphs in mind, please let me know and
we can try to work towards a solution.
Nishant
On 02/11/2011 10:14 AM, Paul Shannon wrote:
> help (package='graph') describes many methods, but none of those mentioned seem to combine two graphs into a third -- perhaps even combining attributes along the way.
>
> graph::union looked promising, but is defined such that it only works if the nodes in each graph are identical.
>
> Any suggestions? Perhaps objects of the new multigraph class can be constructed from multiple graphs?
>
> Thanks -
>
> - Paul
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at r-project.org
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor
>
More information about the Bioconductor
mailing list