Extracts or select the top variable genes from an input SingleCellExperiment object. Note that the variability metrics must be computed using the runFeatureSelection method before extracting the feature names of the top variable features. getTopHVG only returns a character vector of the HVG selection, while with setTopHVG, a logical vector of the selection will be saved in the rowData, and optionally, a subset object for the HVGs can be stored in the altExps slot at the same time.

getTopHVG(
  inSCE,
  method = c("vst", "dispersion", "mean.var.plot", "modelGeneVar", "seurat", "seurat_v3",
    "cell_ranger"),
  hvgNumber = 2000,
  useFeatureSubset = NULL,
  featureDisplay = metadata(inSCE)$featureDisplay
)

setTopHVG(
  inSCE,
  method = c("vst", "dispersion", "mean.var.plot", "modelGeneVar", "seurat", "seurat_v3",
    "cell_ranger"),
  hvgNumber = 2000,
  featureSubsetName = NULL,
  genes = NULL,
  genesBy = NULL,
  altExp = FALSE
)

Arguments

inSCE

Input SingleCellExperiment object

method

Specify which method to use for variable gene extraction from Seurat "vst", "mean.var.plot", "dispersion" or Scran "modelGeneVar" or Scanpy "seurat", "cell_ranger", "seurat_v3". Default "vst"

hvgNumber

Specify the number of top variable genes to extract.

useFeatureSubset

Get the feature names in the HVG list set by setTopHVG. Will ignore method and hvgNumber if not NULL. Default NULL.

featureDisplay

A character string for the rowData variable name to indicate what type of feature ID should be displayed. If set by setSCTKDisplayRow, will by default use it. If NULL, will use rownames(inSCE).

featureSubsetName

A character string for the rowData variable name to store a logical index of selected features. Default NULL, will be determined basing on other parameters.

genes

A customized character vector of gene list to be set as a rowData variable. Will ignore method and hvgNumber if set. Default NULL.

genesBy

If setting customized genes, where should it be found in rowData? Leave NULL for matching rownames. Default NULL.

altExp

TRUE for also creating a subset inSCE object with the selected HVGs and store this subset in the altExps slot, named by hvgListName. Default FALSE.

Value

getTopHVG

A character vector of the top hvgNumber variable feature names

setTopHVG

The input inSCE object with the logical vector of HVG selection updated in rowData, and related parameter updated in metadata. If altExp is TRUE, an altExp is also added

Author

Irzam Sarfraz, Yichen Wang

Examples

data("scExample", package = "singleCellTK")
sce <- runSeuratFindHVG(sce)
#> Sat Mar 18 10:27:57 2023 ... Feature subset variable 'hvf' created.
hvgs <- getTopHVG(sce, hvgNumber = 10)
sce <- setTopHVG(sce, method = "vst", hvgNumber = 5)
#> Sat Mar 18 10:27:57 2023 ... Feature subset variable 'HVG_vst5' created.