[Bioc-devel] small request on graph::graphBAM()

Valerie Obenchain vobencha at fhcrc.org
Thu Feb 7 17:44:50 CET 2013


Hi Robert,

I will look into this next week. Thanks for providing details and 
examples in the request.

Valerie

On 02/06/2013 04:10 PM, Robert Castelo wrote:
> dear maintainers of the graph package,
>
> i have a small request for the constructor function graphBAM() from the
> graph package.
>
> the current help page of the graphBAM() constructor says the following
> about the argument called 'nodes':
>
> A character vector of node labels. Use this to add degree
> zero nodes to the graph. If ‘NULL’, the set of nodes found
> in ‘from’ and ‘to’ will be used.
>
> It would be great if when nodes != NULL and includes the set of nodes
> found in 'from' and 'to', 'nodes' would be taken as the set of nodes of
> the graph, without re-ordering it.
>
> currently this function has the following line (*):
>
> nodes <- sort(unique(c(as.character(df$from), as.character(df$to), nodes)))
>
> this is a bit of a headache for me because the alphabetical ordering of
> vertices does not respect integer ordering (obviously):
>
> library(graph)
> df <- data.frame(from=paste0("Y", 1:10), to=paste0("Y", 2:11),
> weight=rep(1, 10))
> nodes(graphBAM(df, nodes=paste0("Y", 1:10)))
> [1] "Y1" "Y10" "Y11" "Y2" "Y3" "Y4" "Y5" "Y6" "Y7" "Y8" "Y9"
>
> however, because i often deal with vectors of vertex labels created as
>
> v <- paste0("Y", 1:p)
>
> with p whatever positive integer, my vector of vertex labels is not
> identical to the vector returned by graph::nodes() which complicates the
> way i have to deal with this feature. re-ordering my vector of vertex
> labels by alphabetical order implies doing it *each* time i do one of
> those 'paste0()' calls, which is quite often, and this seems quite
> common, see
> http://simplystatistics.org/2013/01/31/paste0-is-statistical-computings-most-influential-contribution-of-the-21st-century
> :)
>
> for this reason it would be great for me if the argument 'nodes' in
> graphBAM() would have this additional functionality of forcing an
> ordering on the vertex labels when 'nodes' include all vertices forming
> the given edges.
>
> i think this would amount to replacing the line above (*) by
>
> stopifnot(all(!duplicated(nodes))) ## given nodes should be unique
> edgeNodes <- unique(c(as.character(df$from), as.character(df$to))
> if (!all(edgeNodes %in% nodes))
> nodes <- sort(unique(c(nodesEdges, nodes)))
>
> note that with this code when one just adds extra degree zero nodes, the
> behavior does not change with respect to what it is doing right now and
> if one likes to stick to the alphabetical ordering, you can always give
> 'nodes=sort(myvertexlabels)' as argument to the graphBAM() constructor
> function.
>
> thanks!!
> robert.
>
> _______________________________________________
> Bioc-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/bioc-devel



More information about the Bioc-devel mailing list