R/trans_freq.R

Defines functions trans_freq

Documented in trans_freq

#' @title Extract numbers of transcripts containing single or multiple exons
#'
#' @description This function takes a dataframe of annotations provided by Gencode as input. It calculates the number of different exons of a transcript. The output is a dataframe containing the number of transcripts having 1,2,3... or several exons and their percentage.
#' @usage trans_freq(x)
#' @param x The name of the downloaded  gtf file from GENCODE website
#' @export
#' @keywords
#' @seealso
#' @return A dataframe of number of transcripts and their percentage
#' examples \dontrun {
#' # You don't have to run this
#' load_gtf("gencode.v27.lncRNAs.gtf")
#' genes_freq(gencode.v27.lncRNAs.gtf)
#’}
trans_freq<- function(x) {
  bb <- subset(x, x$type=="exon")
  cc <- subset(bb, select = c("transcript_id", "exon_number"))
  dd <- as.data.frame(table(cc$transcript_id))
  ee <- as.data.frame(table(dd$Freq))
  colnames(ee) <- c("num_of_exons", "trans_freq")
  ee$percentage <- round(ee$trans_freq / sum(ee$trans_freq) * 100, digits = 3)
  assign(deparse(substitute(trans_freq_df)), ee, envir = .GlobalEnv)
}
monahton/GencodeInterrogator documentation built on Dec. 24, 2019, 1:31 p.m.