R/addAnnotationRnaSeq.R

Defines functions addAnnotationRnaSeq

Documented in addAnnotationRnaSeq

#' Add annotation to EP/IP events
#'
#' @description Adds the associated information for each ranked cassette exon/intron retention event generated by \code{\link{EPrnaseq}}/\code{\link{iPrnaseq}}. The information includes location of the event (chromosome, start, stop, strand), position in genome and the associated gene name.
#'
#' @param fit output of \code{\link{EPrnaseq}}/\code{\link{iPrnaseq}}.
#' @param annotation matrix; contains annotation of exons and introns, created by \code{\link{readMembershipMatrix}}.
#'
#' @return Annotated matrix of ranked cassette exon/intron retention events. Output of addAnnotationRnaSeq can be passed to \code{\link{getPvaluesByContrast}} to find differentially expressed intron retention events in a given contrast.
#' @export
#'

addAnnotationRnaSeq <- function(fit, annotation) {
  if (attr(fit, "name") != "EPrnaSeq" & attr(fit, "name") != "iPrnaSeq") stop('Not an object of EPrnaSeq or iPrnaSeq')
  atNames<- attr(fit, "name")
  #load('Annotation.Rdata')
  index <- match(rownames(fit), annotation[,5])
  rnames <- rownames(fit)
  rownames(fit) <- seq(1, nrow(fit),1)
  fit <- cbind(fit, annotation[index,c(1:4)],rnames)
  fit<- fit[,c(9,5,6,7,8,2,1,3,4)]
  colnames(fit)<- c('event', 'chromosome', 'start', 'stop', 'strand', 'Contrast','EqPvalues','t-statistics', 'gene')
  index<- order(as.numeric(as.vector(fit[,7])))
  fit <- fit[index,,drop=FALSE]
  Location <- paste('chr',as.vector(fit[,2]),':', as.vector(fit[,3]),'-',as.vector(fit[,4]),sep='')
  fit<- cbind(fit,Location)
  fit<- fit[,c(1:5, 10,6:9)]
  attr(fit, "name") <- atNames
  attr(fit, "fun") <- 'addAnnotationRnaSeq'
  return(fit)
}
harshsharma-cb/FASE documentation built on Aug. 6, 2023, 1:37 a.m.