R/assessQualityOfClassification.R

Defines functions assessQualityOfClassification

Documented in assessQualityOfClassification

#' Assess quality of assay classification by yielding per assay quality indicies
#' 
#' The function quantifies the quality of assay for a given threshold classifying samples as positive or negative. It performs analysis in a column-wise manner, where column data belongs to an assay.
#' 
#' @param df A data frame. Represents percent enrichment of condtion in sample (generated by whatever assay). Make sure row.names(df) correspond to row.names(anno)
#' @param anno An annotation of data frame. Make sure annotation has two columns. anno[,1] corresponds to sample name (of character type). anno[,2] corresponds to sample condition (of character type). make sure condition names in anno[,2] are the same as condition column names in df.
#' @param threshold A numeric above which sample is clasified as positive for a given assay, and negative if below the threshold.
#' @export
#' 
assessQualityOfClassification <- function(df,anno, threshold=0.2) {
  # make sure annotation has two columns
  # anno[,1] corresponds to sample name (of character type)
  # anno[,2] corresponds to sample condition (of character type)
  # make sure condition names in anno[,2] are the same as condition column names in df
  # df represents percent enrichment of condtion in sample (generated by whatever assay)
  # make sure row.names(df) correspond to row.names(anno)
  colNam <- colnames(df)
  validationSampleCases <- anno[,2]
  indices_per_classificationS <- list()
  for(i in 1:ncol(df)){
    print(paste("Processing ",colNam[i]))
    
    boolean_For_True_Cases <- colNam[i]==validationSampleCases
    boolean_For_Positive_According_To_Assay <- df[,i]>=threshold
    
    booleanTable <- cbind(boolean_For_True_Cases,boolean_For_Positive_According_To_Assay)
    
    indices_per_classification <- assessTwoBooleanColumnsConcordanceFor.TP.TN.FP.FN.Sens.Spec.FPR.FNR(booleanTable)
    indices_per_classificationS <- lappend(indices_per_classificationS,indices_per_classification)
  }
  names(indices_per_classificationS) <- colNam
  return(indices_per_classificationS)
} 
msxakk89/dat documentation built on Aug. 3, 2020, 6:39 p.m.