r format(Sys.time(), "%d %B, %Y; %R")
knitr::opts_chunk$set(echo=TRUE, warning=FALSE, message=FALSE, error=TRUE)
suppressWarnings(library('tidyverse')) suppressWarnings(library('magrittr')) suppressWarnings(library('rtracklayer')) suppressWarnings(library('microbenchmark'))
bedfile <- system.file("extdata", "Chen_PROMPT_TSSs_liftedTohg38.bed", package = "RMetaTools") regions <- rtracklayer::import(bedfile) bw <- system.file("extdata", "GSM1573841_mNET_8WG16_siLuc_plus_hg38.bw", package = "RMetaTools")
microbenchmark( import(bw, which=regions, as = c("GRanges")), import(bw, which=regions, as = c("RleList")), import(bw, which=regions, as = c("NumericList")))
--> the import type almost does not matter, RleList is slightly slower than the others though.
sums_via_GRanges <- function(bw, regions){ sapply(seq_along(regions), function(i) { hits <- import(bw, which=regions[i], as = c("GRanges")) if(length(hits) > 0){ return(sum(hits$score*width(hits))) }else{ return(0) } }) } microbenchmark(sums_via_GRanges(bw, regions), times=1)
sums_via_NumericList <- function(bw, regions){ sapply(import(bw, which=regions, as = c("NumericList")), sum) } microbenchmark(sums_via_NumericList(bw, regions), times=1)
sessionInfo()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.