Fastest way to get the distances between pairs of graph nodes
1
0
Entering edit mode
rubi ▴ 110
@rubi-6462
Last seen 6.3 years ago

I have a vector GO IDs (go.vec) for which I'd like to measure the shortest-path distance in the GO DAG graphNEL.

The only way I can think of is to get the GO DAG:

  library(GO.db)
  library(graph)
  library(RBGL)
  go.df <- toTable(GOBPPARENTS)
  go.dag <- ftM2graphNEL(as.matrix(go.df[, 1:2]), W=rep(1,dim(go.df)[1]))

And then to measure the distances between all pairs in go.vec using: 

  go.dist.df <- expand.grid(go1=go.vec,go2=go.vec,stringsAsFactors=F)
  rm.idx <- which(go.dist.df$go1 == go.dist.df$go2)
  go.dist.df  <- go.dist.df [-rm.idx,]

 

  go.dist.df$distance <- slapply(1:nrow(go.dist.df),function(n) {
    dists <- dag.sp(go.dag,start=go.dist.df$go1[n])[[1]]
    idx <- which(names(dists) == go.dist.df$go2[n])
    if(length(idx) > 0){
      res <- dists[idx]
    } else{
      res <- NA
    }
    return(res)
  })

However this is very slow. Any way to do it faster?

 

 

graph rgbl dag • 1.2k views
ADD COMMENT
1
Entering edit mode
@wolfgang-huber-3550
Last seen 11 weeks ago
EMBL European Molecular Biology Laborat…

How about dijkstra.sp in the RBGL package?

ADD COMMENT

Login before adding your answer.

Traffic: 531 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