-
Notifications
You must be signed in to change notification settings - Fork 2
/
preprocess_pbmc3k.R
47 lines (37 loc) · 2.03 KB
/
preprocess_pbmc3k.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Annotate PBMC3k following seurat tutorial
rm(list = ls())
library(dplyr)
library(Seurat)
library(patchwork)
# Load the PBMC dataset
pbmc.data <- Read10X(data.dir = "./pbmc3k/filtered_gene_bc_matrices/hg19/")
# Initialize the Seurat object with the raw (non-normalized data).
pbmc <- CreateSeuratObject(counts = pbmc.data, project = "pbmc3k", min.cells = 3, min.features = 200)
# The [[ operator can add columns to object metadata. This is a great place to stash QC stats
pbmc[["percent.mt"]] <- PercentageFeatureSet(pbmc, pattern = "^MT-")
VlnPlot(pbmc, features = c("nFeature_RNA", "nCount_RNA", "percent.mt"), ncol = 3)
pbmc <- NormalizeData(pbmc, normalization.method = "LogNormalize", scale.factor = 10000)
pbmc <- FindVariableFeatures(pbmc, selection.method = "vst", nfeatures = 2000)
all.genes <- rownames(pbmc)
pbmc <- ScaleData(pbmc, features = all.genes)
pbmc <- RunPCA(pbmc, features = VariableFeatures(object = pbmc))
pbmc <- FindNeighbors(pbmc, dims = 1:10)
pbmc <- FindClusters(pbmc, resolution = 0.5)
pbmc <- RunUMAP(pbmc, dims = 1:10)
DimPlot(pbmc, reduction = "umap")
FeaturePlot(pbmc, features = c("MS4A1", "GNLY", "CD3E", "CD14", "FCER1A", "FCGR3A", "LYZ", "PPBP",
"CD8A"))
FeaturePlot(pbmc, features = c("S100A4"))
new.cluster.ids <- c("Naive CD4 T", "CD14+ Mono", "Memory CD4 T", "B", "CD8 T", "FCGR3A+ Mono",
"NK", "DC", "Platelet")
names(new.cluster.ids) <- levels(pbmc)
pbmc <- RenameIdents(pbmc, new.cluster.ids)
DimPlot(pbmc, reduction = "umap", label = TRUE, pt.size = 0.5) + NoLegend()
celltype <- as.vector(Idents(pbmc))
celltype[which(celltype == "Memory CD4 T")] <- "CD4 T"
celltype[which(celltype == "Naive CD4 T")] <- "CD4 T"
pbmc <- AddMetaData(object = pbmc, metadata = celltype, col.name = "celltype")
DimPlot(pbmc, reduction = "umap", label = TRUE, pt.size = 0.5, group.by = "celltype") + NoLegend()
save(pbmc, file = "./pbmc3k/pbmc.RData")
# load("/import/home/share/scUNIT-revision/snBrain-scBlood/pbmc3k/pbmc.RData")
# DimPlot(pbmc, reduction = "umap", group.by = "celltype")