Advertisement
Guest User

gene conversion microbenchmarking

a guest
Nov 24th, 2014
184
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. library(Homo.sapiens)
  3. library(hash)
  4. library(org.Hs.eg.db)
  5.  
  6. DisplayName.1 <- function(NM){
  7.   if(length(NM)>1)
  8.     return(unlist(lapply(NM,DisplayName)))
  9.   if(length(NM)==0)
  10.     return("NA")
  11.   #else; do one:
  12.   j <- tryCatch(EG_to_Name(RefSeq_to_EG(NM)), error=function(e) NM )
  13.   if( is.na(j) || nchar(j)<2 )
  14.     j <- NM;
  15.   return_or_null(j)
  16. }
  17.  
  18. DisplayName.2 <- function(NMs)
  19.   select(org.Hs.eg.db,keytype="REFSEQ",
  20.          keys=NMs, multiVals="first",
  21.          columns=c('SYMBOL'))$SYMBOL
  22.  
  23. DisplayName.3 <- function(NMs)
  24.   select(Homo.sapiens, keys=NMs, keytype="REFSEQ",
  25.          columns=c("SYMBOL"))$SYMBOL
  26.  
  27.  
  28. refseqs = AnnotationDbi::keys(org.Hs.eg.db,keytype="REFSEQ")
  29. roi5 <- sample(refseqs,5,replace=FALSE)
  30. roi50 <- sample(refseqs,50,replace=FALSE)
  31.  
  32. #what if we pre-cache:
  33. system.time( hash(refseqs, DisplayName.2(refseqs)) )
  34. PRECACHE <- hash(refseqs, DisplayName.2(refseqs))
  35. DisplayName.4 <- function(NMs) hash::values(PRECACHE[NMs])
  36.  
  37. res <- microbenchmark(DisplayName.1(roi5),
  38.                       DisplayName.2(roi5),
  39.                       DisplayName.3(roi5),
  40.                       DisplayName.4(roi5), times=40L)
  41. print(res)
  42.  
  43. res <- microbenchmark(DisplayName.1(roi50),
  44.                       DisplayName.2(roi50),
  45.                       DisplayName.3(roi50),
  46.                       DisplayName.4(roi50),times=30L)
  47. print(res)
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement