[BioC] bug in graph::edgeData()

Robert Castelo robert.castelo at upf.edu
Fri Feb 15 11:49:09 CET 2013


hi,

the function edgeData() from the Bioconductor graph package seems to 
have a problem with the way it stores and retrieves edge atributes. 
After investigating the issue i think it has to do with setting and 
retrieving edge attributes for a subset of the edges, as opposed to 
doing it for all edges at once. here is a minimal example that 
reproduces the problem:

library(graph)

df <- data.frame(from=c("a", "b", "c"),
                  to=c("b", "c", "d"),
                  weight=rep(1, 3), stringsAsFactors=FALSE)
g <- graphBAM(df)
## this builds the undirected graph a-b-c-d

## set a new edge attribute "a" with 0 by default
edgeDataDefaults(g, attr="a") <- 0

## set the "a" attribute of all edges to 1
edgeData(g, from=df$from, to=df$to, attr="a") <- 1

## show the value of the "a" attribute for all edges,
## everything works as expected
edgeData(g, from=df$from, to=df$to, attr="a")
$`a|b`
[1] 1

$`b|c`
[1] 1

$`c|d`
[1] 1

## now repeat the operation but setting the "a" attribute
## only for the first edge a-b

g <- graphBAM(df)

edgeDataDefaults(g, attr="a") <- 0

edgeData(g, from=df$from[1], to=df$to[1], attr="a") <- 1

edgeData(g, from=df$from, to=df$to, attr="a")
$`a|b`
[1] 0

$`b|c`
[1] 1

$`c|d`
[1] 0


as you see, the value 1 is not set for the first edge "a|b" but for the 
second "b|c". if i repeat the operation setting the edge attribute "a" 
for the last two edges, it goes also wrong:

g <- graphBAM(df)

edgeDataDefaults(g, attr="a") <- 0

edgeData(g, from=df$from[2:3], to=df$to[2:3], attr="a") <- 1

edgeData(g, from=df$from, to=df$to, attr="a")
$`a|b`
[1] 1

$`b|c`
[1] 0

$`c|d`
[1] 1

since the attribute is set to edges "a|b" and "c|d" while it should have 
been set to "b|c" instead of "a|b".

i put my sessionInfo() below which correspond to the release version of 
the package but i can also reproduce it in the devel version.

thanks!
robert.

R version 2.15.1 (2012-06-22)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
  [7] LC_PAPER=C                 LC_NAME=C
  [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] graph_1.36.2   vimcom_0.9-7   setwidth_1.0-3 colorout_0.9-9

loaded via a namespace (and not attached):
[1] BiocGenerics_0.4.0 stats4_2.15.1      tools_2.15.1



More information about the Bioconductor mailing list