Skip to content

Instantly share code, notes, and snippets.

@Przemol
Last active February 21, 2017 17:07
Show Gist options
  • Save Przemol/8d889e75c6cc80a1b27c147fedf32982 to your computer and use it in GitHub Desktop.
Save Przemol/8d889e75c6cc80a1b27c147fedf32982 to your computer and use it in GitHub Desktop.
# devtools::source_gist('8d889e75c6cc80a1b27c147fedf32982', filename='BigWigSummary.R')
BigWigSummary <- function(files, ranges) {
library(rtracklayer)
library(tidyverse)
require(pbmcapply)
out_list <- pbmclapply(files, function(file) {
vc <- mean(import.bw(file, selection=BigWigSelection(ranges), as='RleList')[ranges])
names(vc) <- NULL
return(vc)
}, mc.cores = parallel::detectCores()/2 )
output <- tbl_df(data.frame(coordinates=gsub(':\\*', '', paste0(ranges)), out_list, stringsAsFactors=FALSE))
return(output)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment