R/limmaSelection.R

setGeneric("limmaSelection", function(expression, ...)
           {standardGeneric("limmaSelection")})

setMethod("limmaSelection", "matrix", 
          function(expression, classes, ...)
{
  features <- rownames(expression)
  groupsTable <- data.frame(class = classes, row.names = colnames(expression))   
  exprSet <- ExpressionSet(expression, AnnotatedDataFrame(groupsTable))
  if(length(features) > 0) featureNames(exprSet) <- features
  limmaSelection(ExpressionSet(expression, AnnotatedDataFrame(groupsTable)), ...)
})

setMethod("limmaSelection", "ExpressionSet", 
          function(expression, datasetName, trainParams, predictParams, resubstituteParams, ...,
                   selectionName = "Moderated t-test", verbose = 3)
{
  if(!requireNamespace("limma", quietly = TRUE))
    stop("The package 'limma' could not be found. Please install it.")            
  if(verbose == 3)
    message("Doing feature selection.")
  exprMatrix <- exprs(expression)
  classes <- pData(expression)[, "class"]
  allFeatures <- featureNames(expression)
  
  fitParams <- list(exprMatrix, model.matrix(~ classes))
  if(!missing(...))
    fitParams <- append(fitParams, ...)
  prognosisModel <- do.call(limma::lmFit, fitParams)
  prognosisModel <- limma::eBayes(prognosisModel)
  orderedFeatures <- match(rownames(limma::topTable(prognosisModel, 2, number = Inf, sort.by = "p")),
                           allFeatures)
  
  .pickRows(expression, datasetName, trainParams, predictParams, resubstituteParams, orderedFeatures,
            selectionName, verbose)
})

Try the ClassifyR package in your browser

Any scripts or data that you put into this service are public.

ClassifyR documentation built on Nov. 17, 2017, 1:42 p.m.