R/importGFF3.R

Defines functions importGFF3

Documented in importGFF3

#' importGFF3
#' 
#' Import a GFF3 file
#' 
#' This function imports a standard gff3 file.
#' 
#' @param gff file or folder
#' @param chromosomes The chromosome to import
#' 
#' @return A gff object
#' 
#' @author Daniel Fischer
#' 
#' @export


importGFF3 <- function(gff, chromosomes){
# fread zip support is OS dependend
  os <- "linux"
  if(grepl("Windows", sessionInfo()$running)) os <- "windows"

  # Now create the input string, depending on the os
  if(os=="linux"){
    inputString <-  paste('zcat',gff)
  } else if(os=="windows"){
    inputString <- paste("gzip -dc",gff)
  }
    
  tmpDT <- fread(inputString, sep="\n", header=FALSE)
  #commentRows <- which(substring(tmpDT[[1]], 1, 1)=="#")
  #keepThose <- 1:nrow(tmpDT)
  #keepThose <- keepThose[!is.element(keepThose,commentRows)]
  
  rowStarts <- substring(tmpDT[[1]], 1, max(nchar(chromosomes)))
  chromosomeRows <- grep(paste(chromosomes,collapse="|"), rowStarts, value=FALSE)
  
  tmpDT2 <- tmpDT[chromosomeRows,]
  V1 <- NULL # For the Cran check...
  tmpDT2[, c(paste("V",1:9, sep="") ) := tstrsplit(V1, "\t", fixed=TRUE)]
  tmpDT2
}

Try the GenomicTools.fileHandler package in your browser

Any scripts or data that you put into this service are public.

GenomicTools.fileHandler documentation built on March 26, 2020, 7:23 p.m.