R中的绩效建议

时间:2016-04-19 08:32:52

标签: r

我有这段代码:

library("GO.db")
lookParents <- function(x) {
  parents <- subset(yy[x][[1]], labels(yy[x][[1]])=="is_a")
  for (parent in parents) {
    m[index,1] <<- Term(x)
    m[index,2] <<- Term(parent)
    m[index,3] <<- -log2(go_freq[x,1]/go_freq_all)
    m[index,4] <<- log2(go1_freq2[x])
    m[index,5] <<- x
    m[index,6] <<- parent
    index <<- index + 1
  }
  if (is.null(parents)) {
    return(c())
  } else {
    return(parents)
  }
}

getTreeMap <- function(GOlist, xx, m) {
  print(paste("Input list has",length(GOlist), "terms", sep=" "))
  count <- 1
  for (go in GOlist) {
    parents <- lookParents(go)
    if (count %% 100 == 0) {
      print(count)
    }
    while (length(parents) != 0) {
      x <- parents[1]
      parents <- parents[-1]
      parents <- c(lookParents(x), parents)
    }
    count <- count + 1
  }
}

xx <- c(as.list(GOBPANCESTOR), as.list(GOCCANCESTOR), as.list(GOMFANCESTOR))
go1_freq2 <- table(as.character(unlist(xx[go1])))
xx <- c(as.list(GOBPPARENTS), as.list(GOCCPARENTS), as.list(GOMFPARENTS))

m <- as.data.frame(matrix(nrow=1,ncol=6))
m[1,] <- c("all", "null", 0, 0, "null","null")
##biological processes
index <- 2
getTreeMap(BP, xx, m)

但它真的很慢。 BP只是一个向量。你有申请表现的建议吗?我想让它跑得更快,但这就是我现在所能做的一切。

1 个答案:

答案 0 :(得分:0)

我建议进行以下改进:

  • 将您的功能添加到RProfile.site并使用cmpfun
  • 进行编译
  • 使用foreachdopar代替正常
  • 始终删除您不再需要的variables,然后调用垃圾收集器