R/nameTOentrez_I.R

Defines functions nameTOentrez_I

Documented in nameTOentrez_I

#' Function "nameTOentrez_I"
#'
#' This function can be called without DESeq, input a gene expression matrix based on gene names
#' and output the corresponding matrix based on entrez IDs
#' @importFrom plyr join
#' @param geneExp a data object with gene names as rownames
#' @param geneSymbol a data frame with all gene annotation information
#' @param condition character vector containing group condition
#' @param n1 the number of one condition in "condition"
#' @param n2 the numbe of the second condition in "condition"
#' @return an ExpressionSet object with matrix based on entrez gene IDs
#' @export

nameTOentrez_I <- function(geneExp, geneSymbol, condition, n1, n2) {
  geneExpI <- as.data.frame(geneExp)
  geneExpI$external_gene_name <- row.names(geneExp)
  geneExpI <- join(geneExpI, geneSymbol[, c("entrezgene_id", "external_gene_name")], by="external_gene_name")
  geneExpI <- aggregate(geneExpI[, 1:ncol(geneExp)], by=list(entrez=geneExpI$entrezgene_id), FUN=mean)
  row.names(geneExpI) <- as.character(geneExpI$entrez)
  geneExpI <- as.matrix(geneExpI)[, -1]
  
  # create phenotype file
  meta.phe <- data.frame(SampleID = colnames(geneExpI),
                         Group = factor(c(rep(condition[1], n1), rep(condition[2], n2))),
                         row.names = colnames(geneExpI))
  meta_phe <- data.frame(labelDescription=c('SampleID', 'Group'),
                         row.names=c('SampleID', 'Group'))
  gene.phe <- new("AnnotatedDataFrame", data=meta.phe, varMetadata=meta_phe)
  
  # construct ExpressionSet object from gene.exp and gene.phe
  gene.es <- ExpressionSet(assayData=geneExpI,
                           phenoData=gene.phe,
                           annotation="hgu95av2")
  
  # return result
  return(gene.es)
}
Coraline66/RNASeqAnalysis documentation built on Nov. 25, 2019, 8:03 a.m.