topGradientsCellType: Get top genes with largest/smallest gradients per cell type

View source: R/interGradientsDL.R

topGradientsCellTypeR Documentation

Get top genes with largest/smallest gradients per cell type

Description

Retrieve feature names with the largest/smallest gradients per cell type. These genes can be used to plot the calculated gradients as a heatmap (plotGradHeatmap function).

Usage

topGradientsCellType(object, method = "class", top.n.genes = 15)

Arguments

object

DigitalDLSorter object with a DigitalDLSorterDNN object containing gradients in the interpret.gradients slot.

method

Method gradients were calculated by. It can be either 'class' (gradients of predicted classes w.r.t. inputs) or 'loss' (gradients of loss w.r.t. input features).

top.n.genes

Top n genes (positive and negative) taken per cell type.

Value

List of gene names with the top positive and negative gradients per cell type.

See Also

interGradientsDL trainDDLSModel

Examples


set.seed(123)
sce <- SingleCellExperiment::SingleCellExperiment(
  assays = list(
    counts = matrix(
      rpois(30, lambda = 5), nrow = 15, ncol = 10,
      dimnames = list(paste0("Gene", seq(15)), paste0("RHC", seq(10)))
    )
  ),
  colData = data.frame(
    Cell_ID = paste0("RHC", seq(10)),
    Cell_Type = sample(x = paste0("CellType", seq(2)), size = 10,
                       replace = TRUE)
  ),
  rowData = data.frame(
    Gene_ID = paste0("Gene", seq(15))
  )
)
DDLS <- createDDLSobject(
  sc.data = sce,
  sc.cell.ID.column = "Cell_ID",
  sc.gene.ID.column = "Gene_ID",
  sc.filt.genes.cluster = FALSE
)
prop.design <- data.frame(
  Cell_Type = paste0("CellType", seq(2)),
  from = c(1, 30),
  to = c(15, 70)
)
DDLS <- generateBulkCellMatrix(
  object = DDLS,
  cell.ID.column = "Cell_ID",
  cell.type.column = "Cell_Type",
  prob.design = prop.design, 
  num.bulk.samples = 50,
  verbose = TRUE
)
DDLS <- simBulkProfiles(DDLS)
DDLS <- trainDDLSModel(
  object = DDLS,
  batch.size = 12,
  num.epochs = 5
)
## calculating gradients
DDLS <- interGradientsDL(DDLS)
listGradients <- topGradientsCellType(DDLS)
lapply(listGradients, head, n = 5)

  

digitalDLSorteR documentation built on Sept. 13, 2024, 5:06 p.m.