graph classes: how to combine multiple graphs into a single graph
2
0
Entering edit mode
Paul Shannon ★ 1.1k
@paul-shannon-578
Last seen 7.3 years ago
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
graph graph • 685 views
ADD COMMENT
0
Entering edit mode
@moshe-olshansky-4491
Last seen 7.3 years ago
Hi Paul, If I understand you correctly, one possibility would be to take a union of the nodes of the two (or several) graphs, start with an empty adjacency matrix (or list of edges) and then add all the edges appearing in all the graphs. Then you should be able to build a graph from that adjacency matrix (or a list of nodes and a list of edges). Regards, Moshe. > 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 > ______________________________________________________________________ The information in this email is confidential and intend...{{dropped:4}}
ADD COMMENT
0
Entering edit mode
@nishant-gopalakrishnan-3253
Last seen 7.3 years ago
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 >
ADD COMMENT

Login before adding your answer.

Traffic: 398 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6