knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

library(dplyr)
library(scmisc)
library(Seurat)

set.seed(1)

Convert toy data to Seurat object

This toy dataset contains 493 cells from mice in a SingleCellExperiment object.

x <- as.Seurat(sce)
x

Preprocess

x <- NormalizeData(x, verbose = FALSE)
x <- FindVariableFeatures(x, verbose = FALSE)
x <- ScaleData(x, verbose = FALSE)
x <- RunPCA(x, verbose = FALSE)
x <- RunUMAP(x, dims = 1:10, verbose = FALSE)
x <- FindNeighbors(x, verbose = FALSE)
x <- FindClusters(x, verbose = FALSE)
DimPlot(x, label = TRUE) + NoLegend()

Find differentially expressed genes

deg <- FindAllMarkers(x, verbose = FALSE)
head(deg)

Add entrezgene annotations

db <- org.Mm.eg.db::org.Mm.eg.db
deg <- deg |> mutate(entrezgene = AnnotationDbi::mapIds(db, deg$gene, "ENTREZID", "SYMBOL"))

Functional enrichment

res <- run_enrichment(deg, type = "kegg", org = "Mm")
head(res)
res |> filter(adj.P.Up < 0.01) |> arrange(desc(Up))
res |> filter(adj.P.Down < 0.01) |> arrange(desc(Down))
plot_enrichment_barplot(res)


ddiez/scmisc documentation built on July 21, 2024, 11:35 a.m.