Seurat - Interaction Tips
Compiled: June 24, 2019
Load in the data
This vignette demonstrates some useful features for interacting with the Seurat object. For demonstration purposes, we will be using the 2,700 PBMC object that is created in the first guided tutorial. You can download the pre-computed object here. To simulate the scenario where we have two replicates, we will randomly assign half the cells in each cluster to be from “rep1” and other half from “rep2”.
library(Seurat) pbmc <- readRDS(file = "../data/pbmc3k_final.rds") # pretend that cells were originally assigned to one of two replicates (we assign randomly here) # if your cells do belong to multiple replicates, and you want to add this info to the Seurat # object create a data frame with this information (similar to replicate.info below) set.seed(42) pbmc$replicate <- sample(c("rep1", "rep2"), size = ncol(pbmc), replace = TRUE)
Switch identity class between cluster ID and replicate
# Plot UMAP, coloring cells by cell type (currently stored in object@ident) DimPlot(pbmc, reduction = "umap")
# How do I create a UMAP plot where cells are colored by replicate? First, store the current # identities in a new column of meta.data called CellType pbmc$CellType <- Idents(pbmc) # Next, switch the identity class of all cells to reflect replicate ID Idents(pbmc) <- "replicate" DimPlot(pbmc, reduction = "umap")