Closed jayhesselberth closed 2 years ago
I think that's a good idea. I've also usedrtracklayer::import
to read gtf
or gff
into data.frames, so it might be useful to have a read_gtf()
variant as well.
e.g.
#' Import and convert GTF/GFF from rtracklayer into tidy bed format
#' @param path path to gtf or gff file
#' @param zero_based_coords if TRUE, convert to zero based
read_gtf <- function(path, zero_based_coords = TRUE){
gtf <- rtracklayer::import(path)
gtf <- as.data.frame(gtf)
gtf <- dplyr::mutate_if(gtf, is.factor, as.character)
res <- dplyr::rename(gtf, chrom = seqnames)
if(zero_based_coords) {
res <- dplyr::mutate(res, start = start - 1L)
}
tibble::as_tibble(res)
}
closed by #382
Should we add to valr? Requires
rtracklayer
import.