R/get_var_genes.R

Defines functions get_var_genes

Documented in get_var_genes

#' Get Variable Genes
#'
#' This will get the variable genes above a threshold, based on quantile.
#'
#' @param input the input sce
#' @param method One of "CV", "Malhanobis", or "Gini
#' @param cutoff The threshold below which a gene will not be returned. Expressed as decimal.
#' @export
#' @details
#'
#' @examples
#' sce <- get_def_assay(sce)

get_var_genes <- function(input,
                          method,
                          cutoff){

  if(!(method%in%c("CV", "Malhanobis", "Gini"))){
    stop("Method must be one of CV, Malhanobis, or Gini")
  }

  if(!(method%in%colnames(rowData(input)))){
    stop("Please use calc_var_genes to calculate genewise statistics before this function.")
  }

  vals <- rowData(input)[,method]
  cut_val <- quantile(vals, cutoff, na.rm = T)
  ind <- which(vals >= cut_val)
  gene_subset <- rownames(input)[ind]

  return(gene_subset)
}

# Doc Check
kgellatl/SignalCell documentation built on Sept. 3, 2020, 8:45 a.m.