Skip to content

Instantly share code, notes, and snippets.

@Jfortin1
Created November 20, 2014 22:54
Show Gist options
  • Save Jfortin1/cc03d5ecfa9cccc402f2 to your computer and use it in GitHub Desktop.
Save Jfortin1/cc03d5ecfa9cccc402f2 to your computer and use it in GitHub Desktop.
Extract a block from bigWig files
extract.block <- function(files, chr, start, end, verbose = TRUE){
rl <- IRanges::RangesList(IRanges::IRanges(start=start, end=end))
names(rl) <- chr
cat("[extract.block] Reading in the files \n")
rles <- lapply(files, function(xx) {
#if (verbose){
# cat("Reading", xx, "\n")
#}
import(xx, as = "Rle", format = "bw", selection = BigWigSelection(rl))
})
cat("[extract.block] Building the block \n")
megaMatrix <- do.call(cbind, lapply(rles, function(xx) as.numeric(xx[[chr]][start:end])))
megaMatrix
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment