Entering edit mode
Nishant Gopalakrishnan
▴
340
@nishant-gopalakrishnan-3253
Last seen 10.2 years ago
Hi Paul,
The join/union/ intersect methods for the graph objects do not
preserve
the edge or the node attributes. I do not think there are any plans to
add this feature the old graph classes.
However, the new graphBAM class has methods that will hopefully do
what
you are looking for . The graphUnion method performs union of two
graphs
while preserving the node and edge attributes. If there is a conflict
of attributes, it is filled with NA. You do have the option of
resolving
the conflict by providing a named list of functions to the edgeFun or
nodeFun arguments of the graphUnion method.
The function should
1. take in two arguments and returns a conflict resolved value for
the
attribute.
2. have the same name as the attribute
I shall illustrate with some simple examples for the edge attributes
below
### Create two graphs g1 and g2 with color and weight edge
attributes
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")
edgeData(g1, attr = "color") <- "green" ## set the default
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")
edgeData(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))
Node attributes if present are also handled in exactly the same
manner.
If conflicting node attributes occur in the union process , there is
another argument nodeFun that you can use to pass in a function for
resolving the conflict.
I hope that answers your question.
Nishant
On 11/29/2010 09:11 AM, Paul Shannon wrote:
> I have two well-annotated kegg pathway graphs I wish to merge.
>
> Using graph::join, the nodes and edges merge nicely, but all the
edge and node attributes are lost, and a new edge attribute 'weight'
is added.
>
>
>> names (nodeDataDefaults (g.05200))
>>
> [1] "type" "label" "desc" "BP" "MF" "CC" "phase"
"score" "lfc" "pval"
>
>> names (nodeDataDefaults (g.04010))
>>
> [1] "type" "label" "desc" "BP" "MF" "CC" "phase"
"score" "lfc" "pval"
>
>> names (nodeDataDefaults (g.both))
>>
> NULL
>
>
>
>> names (edgeDataDefaults (g.04010))
>>
> [1] "edgeType" "pmid" "abstract" "reciprocal" "score"
"source"
>
>> names (edgeDataDefaults (g.05200))
>>
> [1] "edgeType" "pmid" "abstract" "reciprocal" "score"
"source"
>
>> names (edgeDataDefaults (g.both))
>>
> [1] "weight"
>
> Is there any graph method, current or planned, which will preserve
node and edge attributes? I realize that attribute conflicts can
arise, and some strategy is required to handle these.
>
> - Paul
>
>
>
>> sessionInfo ()
>>
> R version 2.12.0 (2010-10-15)
> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
>
> locale:
> [1] en_US.utf-8/en_US.utf-8/C/C/en_US.utf-8/en_US.utf-8
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>
> other attached packages:
> [1] RCytoscape_1.1.6 org.Mm.eg.db_2.4.1 RCurl_1.4-3
bitops_1.0-4.1 GOstats_2.16.0 Category_2.16.0
GO.db_2.4.5
> [8] GSEABase_1.11.2 annotate_1.28.0 KEGG.db_2.4.1
KEGGgraph_1.4.0 graph_1.26.0 XML_3.2-0
SPIA_1.8.0
> [15] org.Hs.eg.db_2.4.6 RSQLite_0.9-2 DBI_0.2-5
AnnotationDbi_1.11.8 Biobase_2.10.0 RUnit_0.4.26
>
> loaded via a namespace (and not attached):
> [1] genefilter_1.32.0 RBGL_1.25.0 splines_2.12.0
survival_2.35-8 tools_2.12.0 XMLRPC_0.2-2 xtable_1.5-6
> _______________________________________________
> 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
>