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?