5  Single-Cell Analysis

Most of these code are reliant on Seurat. You may now and then have to use scanpy in python, or revert to the SingleCellExperiment object utilized in scater.

5.2 Seurat

5.2.1 Integration

  • applying sctransform to each sample in the list
  • selecting integration features,
  • finding integration anchors,
  • integrate data at this point, DefaultAssay is integrated, and there is an associated VariableFeatures, which really is output of SelectIntegrationFetures. rownames(integrated[[“SCT”]](scale.data?)) is the same as SelectIntegration Features again.
    https://github.com/satijalab/seurat/issues/6185 explanation of the different variable gene options from sct integrated models

After merge() variable features that have been calculated by SCTransform is reset.

5.2.2 Plotting

Use scCustomize for improved plotting over Seurat’s defaults.

To plot heatmaps with extra metadata information, use the scillius package.

To get statistics on differential gene levels, use the package ggbetweenstats from ggstatsplot.

cell_expression <- rna_integrated@assays$RNA@data[c("MIPOL1", "ETV1", "DGKB", "FOXA2", "AR", "SYP"),] %>% as.matrix() %>% t()
meta_data <- rna_integrated@meta.data
plot_data <- cbind(meta_data, cell_expression)
saveRDS(plot_data, "scRNAseq_violin.RDS")

5.2.3 Utility functions

Renaming all identities

cell_types <- c("0" = "", "1" = "", "2" = "", "3" = "", "4" = "", "5" = "", "6" = "")
Idents(merged) <- "SCT_snn_res.0.2"
merged <- RenameIdents(merged, cell_types)
merged$status <- Idents(merged)
DimPlot_scCustom(integrated, group.by = "cell_types", colors_use = polychrome_pal)
merged$status <- factor(merged$status, 
                        levels = c("")) # useful for rearranging levels
Idents(merged) <- "status"

Renaming a few identities

new_groups <- case_when(seu_obj$clust == "a" ~ "Tumor",
          .default = seu_obj$clust) %>% as.factor()
names(new_groups) <- names(seu_obj$clust)
seu_obj$new_groups <- new_groups
seu_obj$new_groups <- factor(seu_obj$new_groups, 
                        levels = c("")) # have to do this again

Adding new clusters, cluster 13 was not present previously

seu_obj$manual_clusters <- seu_obj$integrated_snn_res.0.6
levels(seu_obj$manual_clusters) <- c(levels(seu_obj$manual_clusters), "13")
seu_obj$manual_clusters[names(seu_obj$manual_clusters) %in% select_cells] <- "13"