2016-04-19 5 views
0

Ich habe dieses Stück Code:Leistungsvorschläge in 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) 

aber es ist sehr langsam. BP ist einfach ein Vektor. Haben Sie Leistungsvorschläge? Ich möchte es schneller laufen lassen, aber das ist alles, was ich im Moment tun kann.

Antwort

0

schlage ich folgende Verbesserungen:

  • Ihre Funktionen in RProfile.site hinzufügen und kompilieren sie cmpfun
  • Verwendung foreach und dopar statt normaler Verwendung für
  • immer löschen die variables Sie nicht mehr benötigen und Rufen Sie dann den Garbage Collector