[BioC] graph classes: how to combine multiple graphs into a single graph

Paul Shannon pshannon at systemsbiology.org
Wed Mar 9 19:32:03 CET 2011


Hi Nishant,

After too long a delay, I am getting back to you on this.  I apologize for that delay and also for this:  as you point out, and as I sheepishly realize, I HAD asked this question before, and you had answered it.

My confusion persists, however, in this form:  it appears that the graphBAM class handles union nicely, but the graphNEL class does not.  

Do you recommend moving all graph work away from graphNEL and graphAM classes, to graphBAM?  That graphBAM and your new multiGraph are the graphs of the future?

 - Paul

On Feb 18, 2011, at 9:44 AM, Nishant Gopalakrishnan wrote:

> 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