R/extract_minus.R

Defines functions extract_minus

Documented in extract_minus

#' @title Extract elements on the minus strand from a gtf file.
#'
#' @description This function takes a gtf file from GENCODE or a dataframe containing extracted introns. It returns as a dataframe a specified element; i.e gene, transcript, exon or intron; that are on the reverse strand
#' @usage extract_minus(data1, type)
#' @param data1 The name of the downloaded gtf file from GENCODE website
#' @param type A string that specifies the type of element to be reported
#' @export
#' @keywords
#' @seealso
#' @return A dataframe of elements on the minus strand
#' examples \dontrun {
#' # You don't have to run this
#' load_gtf("gencode.v27.lncRNAs.gtf")
#' data1 <- gencode.v27.lncRNAs.gtf
#' extract_minus(data1, "gene")
#' extract_minus(data1, "transcript")
#' extract_minus(data1, "exon")
#’}
extract_minus <- function(data1, type) {
  if (type=="gene") {
    a <- subset(data1, data1$type=="gene")
    b <- subset(a, a$strand=="-")
    c <- nrow(b)
    print(c)
    assign(deparse(substitute(genes_minus)), b, envir = .GlobalEnv)
  } else if (type=="transcript") {
    a <- subset(data1, data1$type=="transcript")
    b <- subset(a, a$strand=="-")
    c <- nrow(b)
    print(c)
    assign(deparse(substitute(transcripts_minus)), b, envir = .GlobalEnv)
  } else if (type=="exon") {
    a <- subset(data1, data1$type=="exon")
    b <- subset(a, a$strand=="-")
    c <- nrow(b)
    print(c)
    assign(deparse(substitute(exons_minus)), b, envir = .GlobalEnv)
  } else if (type=="intron") {
    a <- subset(data1, data1$type=="intron")
    b <- subset(a, a$strand=="-")
    c <- nrow(b)
    print(c)
    assign(deparse(substitute(introns_minus)), b, envir = .GlobalEnv)
  } else {
    print("Error: operation could not be performed - check the help page for examples")
  }
}
monahton/GencodeInterrogator documentation built on Dec. 24, 2019, 1:31 p.m.