R/gencode_compare.R

Defines functions gencode_compare

Documented in gencode_compare

#' @title Compare Annotated Numbers between 2 Different Releases from GENCODE
#'
#' @description This function compares the number of annotated genes, transcripts, exons or introns from 2 dataframes. It is used to comapre the different annotations between different releases from GENCODE
#' @usage gencode_compare(data1, data2, type)
#' @param data1 The name of the downloaded gtf file from GENCODE website of a particular release
#' @param data2 The name of the downloaded gtf file from GENCODE website of another release
#' @param type A string specifying the genetic element to be compared
#' @export
#' @keywords
#' @seealso
#' @return Delta: The difference between annotated numbers of a particular genetic element. Percentage: the percentage of delta
#' examples \dontrun {
#' # You don't have to run this
#' data1 <- load_gtf("gencode.v27.lncRNAs.gtf")
#' data2 <- load_gtf("gencode.v27.lncRNAs.gtf")
#' gencode_compare(data1, data2, "gene")
#' gencode_compare(data1, data2, "transcript")
#' gencode_compare(data1, data2, "exon")
#’}
gencode_compare <- function(data1, data2, type){
  if(type=="gene") {
    a <- subset(data1, data1$type=="gene")
    b <- subset(data2, data2$type=="gene")
    c <- nrow(b) - nrow(a)
    d <- abs(c)
    e <- d/nrow(b)*100
    f <- round(e, digits = 3)
    print(paste0("Delta: ", d))
    print(paste0("Percentage: ", f))
  } else if (type=="transcript") {
    a <- subset(data1, data1$type=="transcript")
    b <- subset(data2, data2$type=="transcript")
    c <- nrow(b) - nrow(a)
    d <- abs(c)
    e <- d/nrow(b)*100
    f <- round(e, digits = 3)
    print(paste0("Delta: ", d))
    print(paste0("Percentage: ", e))
  } else if (type=="exon") {
    a <- subset(data1, data1$type=="exon")
    b <- subset(data2, data2$type=="exon")
    c <- nrow(b) - nrow(a)
    d <- abs(c)
    e <- d/nrow(b)*100
    f <- round(e, digits = 3)
    print(paste0("Delta: ", d))
    print(paste0("Percentage: ", e))
  } else if (type=="exon") {
    a <- subset(data1, data1$type=="exon")
    b <- subset(data2, data2$type=="exon")
    c <- nrow(b) - nrow(a)
    d <- abs(c)
    e <- d/nrow(b)*100
    f <- round(e, digits = 3)
    print(paste0("Delta: ", d))
    print(paste0("Percentage: ", e)) }
    else {
    print("No comparisons are found")
  }
}
monahton/GencodeInterrogator documentation built on Dec. 24, 2019, 1:31 p.m.