R/spliced_trans_length.R

Defines functions spliced_trans_length

Documented in spliced_trans_length

#' @title Calculate the length of splices transcripts
#'
#' @description This function takes a dataframe of annotations provided by Gencode as input. It calculates the length of the transcripts considering only the length of their corresponding exons.
#' @usage spliced_trans_length(x)
#' @param x The name of the downloaded  gtf file from GENCODE website
#' @export
#' @keywords
#' @seealso
#' @return A dataframe of the transcript ids and their length when spliced
#' examples \dontrun {
#' # You don't have to run this
#' load_gtf("gencode.v27.lncRNAs.gtf")
#' spliced_trans_length(gencode.v27.lncRNAs.gtf)
#’}
spliced_trans_length <- function(x) {
  a <- subset(x, x$type=="exon")
  b <- subset(a, select = c("transcript_id", "width"))
  c <- data.table::setkey(data.table::setDT(b), transcript_id)[, list(width=sum(width)), by=list(transcript_id)]
  assign(deparse(substitute(SplicedTranscriptsLength)), c, envir = .GlobalEnv)
}
monahton/GencodeInterrogator documentation built on Dec. 24, 2019, 1:31 p.m.