Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(Homo.sapiens)
- library(hash)
- library(org.Hs.eg.db)
- DisplayName.1 <- function(NM){
- if(length(NM)>1)
- return(unlist(lapply(NM,DisplayName)))
- if(length(NM)==0)
- return("NA")
- #else; do one:
- j <- tryCatch(EG_to_Name(RefSeq_to_EG(NM)), error=function(e) NM )
- if( is.na(j) || nchar(j)<2 )
- j <- NM;
- return_or_null(j)
- }
- DisplayName.2 <- function(NMs)
- select(org.Hs.eg.db,keytype="REFSEQ",
- keys=NMs, multiVals="first",
- columns=c('SYMBOL'))$SYMBOL
- DisplayName.3 <- function(NMs)
- select(Homo.sapiens, keys=NMs, keytype="REFSEQ",
- columns=c("SYMBOL"))$SYMBOL
- refseqs = AnnotationDbi::keys(org.Hs.eg.db,keytype="REFSEQ")
- roi5 <- sample(refseqs,5,replace=FALSE)
- roi50 <- sample(refseqs,50,replace=FALSE)
- #what if we pre-cache:
- system.time( hash(refseqs, DisplayName.2(refseqs)) )
- PRECACHE <- hash(refseqs, DisplayName.2(refseqs))
- DisplayName.4 <- function(NMs) hash::values(PRECACHE[NMs])
- res <- microbenchmark(DisplayName.1(roi5),
- DisplayName.2(roi5),
- DisplayName.3(roi5),
- DisplayName.4(roi5), times=40L)
- print(res)
- res <- microbenchmark(DisplayName.1(roi50),
- DisplayName.2(roi50),
- DisplayName.3(roi50),
- DisplayName.4(roi50),times=30L)
- print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement