Skip to content

Commit

Permalink
headTabix: use fread.gzipped directly on the tabix file
Browse files Browse the repository at this point in the history
should fix issue #141
  • Loading branch information
alexg9010 committed Feb 5, 2019
1 parent 9dc5721 commit aa6a0d1
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions R/tabix.functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,20 @@ getTabixByOverlap<-function(tbxFile,granges,return.type="data.table"){
#' tbxFile=methylRawListDB[[1]]@dbpath
#' headTabix(tbxFile)
#' @noRd
headTabix<-function(tbxFile,nrow=10,return.type="data.table"){
headTabix <- function(tbxFile, nrow = 10,
return.type = c("data.table","data.frame","GRanges") ){

if( class(tbxFile) != "TabixFile" ){
tbxFile <- TabixFile(tbxFile)
open(tbxFile)
returnDt = if(return.type[1] == "data.table") TRUE else FALSE
df <- fread.gzipped(tbxFile,nrow = nrow, stringsAsFactors = TRUE, data.table = returnDt)

if(return.type[1] == "GRanges"){
return( GRanges(seqnames=as.character(df$V1),
ranges=IRanges(start=df$V2, end=df$V3),
strand=df$V4, df[,5:ncol(df)]) )
} else {
return(df)
}

getTabixByChunk( tbxFile,chunk.size=nrow,return.type)
}


Expand Down

0 comments on commit aa6a0d1

Please sign in to comment.