-
Notifications
You must be signed in to change notification settings - Fork 0
/
step2-merge-clusters.R
82 lines (69 loc) · 2.53 KB
/
step2-merge-clusters.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
rm(list = ls())
library(Seurat)
# devtools::install_github('satijalab/seurat-data')
library(SeuratData)
library(ggplot2)
library(patchwork)
library(dplyr)
load(file = 'basic.sce.pbmc.Rdata')
DimPlot(pbmc, reduction = 'umap',
label = TRUE, pt.size = 0.5) + NoLegend()
sce=pbmc
# 参考;https://mp.weixin.qq.com/s/9d4X3U38VuDvKmshF2OjHA
genes_to_check = c('PTPRC', 'CD3D', 'CD3E', 'PRF1' , 'NKG7',
'CD19', 'CD79A', 'MS4A1' ,
'CD68', 'CD163', 'CD14',
"FCER1A", "PPBP")
DotPlot(sce, group.by = 'seurat_clusters',
features = unique(genes_to_check)) + RotatedAxis()
# 参考:https://mp.weixin.qq.com/s/YYJWbluM86rp9y4CNHBKpQ
Idents(sce)
levels(sce)
head([email protected])
# method : 1
new.cluster.ids <- c("T", "Mono", "T",
"B", "T", "Mono",
"T", "DC", "Platelet")
names(new.cluster.ids) <- levels(sce)
sce <- RenameIdents(sce, new.cluster.ids)
DimPlot(sce, reduction = 'umap',
label = TRUE, pt.size = 0.5) + NoLegend()
# method : 2
# 一个向量:
cluster2celltype <- c("0"="T",
"1"="Mono",
"2"="T",
"3"= "B",
"4"= "T",
"5"= "Mono",
"6"= "T",
"7"= "DC",
"8"= "Platelet")
sce[['cell_type']] = unname(cluster2celltype[[email protected]$seurat_clusters])
DimPlot(sce, reduction = 'umap', group.by = 'cell_type',
label = TRUE, pt.size = 0.5) + NoLegend()
# 一个数据框
(n=length(unique([email protected]$seurat_clusters)))
celltype=data.frame(ClusterID=0:(n-1),
celltype='unkown')
celltype[celltype$ClusterID %in% c(0,2,4,6),2]='T'
celltype[celltype$ClusterID %in% c(3),2]='B'
celltype[celltype$ClusterID %in% c(1,5),2]='Mono'
celltype[celltype$ClusterID %in% c(7),2]='DC'
celltype[celltype$ClusterID %in% c(8),2]='Platelet'
[email protected]$celltype = "NA"
for(i in 1:nrow(celltype)){
[email protected][which([email protected]$seurat_clusters == celltype$ClusterID[i]),'celltype'] <- celltype$celltype[i]}
table([email protected]$celltype)
DimPlot(sce, reduction = 'umap', group.by = 'celltype',
label = TRUE, pt.size = 0.5) + NoLegend()
head([email protected])
table([email protected]$cell_type,
[email protected]$celltype)
p1=DimPlot(sce, reduction = 'umap', group.by = 'celltype',
label = TRUE, pt.size = 0.5) + NoLegend()
p2=DotPlot(sce, group.by = 'celltype',
features = unique(genes_to_check)) + RotatedAxis()
library(patchwork)
p1+p2