-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster
162 lines (159 loc) · 10.1 KB
/
cluster
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
rm(list=ls())
library(Seurat)
library(ggplot2)
library(patchwork)
library(cowplot)
library(dplyr)
library(tibble)
library(hdf5r)
setwd("/2020simpleDuckweeds/spatial/maizev7")
maize_in <- readRDS("/2020simpleDuckweeds/spatial/maizev7/1maize_in.rds") #This is an integrated file of four slides
table(maize_in@meta.data$orig.ident)
maize_in@meta.data[1:10,1:8]
#################################### Dimension reduction, clustering, and visualization ###################################################
maize_in <- FindClusters(maize_in, resolution = 1.2,verbose = FALSE)
#cols.orgi <- c(
"#7fc97f","#beaed4","#fdc086","#386cb0","#ecb9e5","#f0027f","#666666","#1b9e77","#d95f02","#7570b3",
"#efbd25","#43acde","#d01b2a","#B4EEB4","#743fd2","#2f8400","#d9d73b","#aed4ff","#a34e3b","#e6908e",
"#813139","#cd4275","#434b7e","#214a00","#ef6100","#7d9974","#e63c66","#cf48c7","#ffe40a","#a76e93",
"#d9874a","#adc64a","#5466df","#d544a1","#54d665","#5e99c7","#006874","#d2ad2c","#b5d7a5","#9e8442",
"#4e1737","#e482a7","#6f451d","#2ccfe4","#ae6174","#a666be","#a32b2b","#ffff99","#3fdacb","#bf5b17")
p1 <- DimPlot(maize_in, reduction = "umap", label=T,repel=T);p1 # Visualize all spots, regardless of source
p2 <- DimPlot(maize_in, reduction = "umap", group.by = "orig.ident");p2
p4 <- DimPlot(maize_in, reduction = "umap", group.by = "ident", split.by = "orig.ident",label = TRUE,repel = TRUE);p4
p5 <- SpatialFeaturePlot(maize_in, features = "nCount_Spatial") + theme(legend.position = "right");p5 #pre-standardization
p6 <- SpatialDimPlot(maize_in,cols=cols.orgi,stroke=0.1);p6 #pdf("merge_umap_slice1.pdf",width=10,height=5);#dev.off()
#####################################Draw a single primitive cluster diagram
SpatialPlot(maize_in,cols=cols.orgi,label = TRUE,images = "slice1") #S12D_1
SpatialPlot(maize_in,cols=cols.orgi,stroke=0.1,images = "slice1.1")#S18D_1
SpatialPlot(maize_in,cols=cols.orgi,stroke=0.1,images = "slice1.2")#S18D_2
SpatialPlot(maize_in,cols=cols.orgi,stroke=0.1,images = "slice1.3")#S24D_1
SpatialPlot(maize_in,cols=cols.orgi) #S12D_1
LinkedDimPlot(maize_in,image="slice1.1")
############ S12D_1:
SpatialDimPlot(maize_in,cols=cols.orgi,label = TRUE,label.size=2,images="slice1")
S12D_1 <- subset(maize_in, orig.ident=="S12D_1")
DimPlot(S12D_1,cols=cols.orgi,label = TRUE,label.size=2)
############ S18D_1:
SpatialDimPlot(maize_in,cols=cols.orgi,label = TRUE,label.size=2,images="slice1.1")
S18D_1 <- subset(maize_in, orig.ident=="S18D_1")
DimPlot(S18D_1,cols=cols.orgi,label = TRUE,label.size=2)
############ S18D_2:
SpatialDimPlot(maize_in,cols=cols.orgi,label = TRUE,label.size=2,images="slice1.2")
S18D_2 <- subset(maize_in, orig.ident=="S18D_2")
DimPlot(S18D_2,cols=cols.orgi,label = TRUE,label.size=2)
############ S24D_1:
SpatialDimPlot(maize_in,cols=cols.orgi,label = TRUE,label.size=2,images="slice1.3")
S24D_1 <- subset(maize_in, orig.ident=="S24D_1")
DimPlot(S24D_1,cols=cols.orgi,label = TRUE,label.size=2)
############################ Merge
maize_in <- RenameIdents(maize_in,`10` = "PC",`15` ="PE",`26` ="PE",`8` ="PE",`20` ="PE",`4`="AL",`23`="BETL",
`12`="CZ",`14`="CZ",`0`="SE",`7`="SE",`1`="SE",`2`="SE",`3`="VE",`11`="VE",`21`="VE",`25`="SE",`9`="VE",
`6`="SE",`24`="SE",`16`="VE",`13`="EAS",`5`="SCU",`18`="SCU",`17`="SCU",`19`="RA",`22`="RA")
cols <- c("#97C9DC","#EF0002","#FACD5C","#FEEC70","#F8A33F","#B9D5AD","#BBD864","#FF52E5","#55ACD9","#FAECA9","#FFB6DE")
names(cols) <- c("PE","ESR","VE","SE","AL","SCU","RA","EAS","PC","CZ","BETL")
cols #"#FFFFFF"
#######Add the clustering tag new cluster into meta.data, and then use its partitions to graph
maize_in@meta.data$newclusters <- Idents(maize_in)
head(maize_in@meta.data)
table(Idents(maize_in))### table() See how many cells are in each type
############ S12D_1:
DimPlot(S12D_1,cols=cols.orgi,label = TRUE,label.size=2)
LinkedDimPlot(maize_in,image="slice1",reduction = "tsne")
############ S18D_1:
DimPlot(S18D_1,cols=cols.orgi,label = TRUE,label.size=2)
LinkedDimPlot(maize_in,image="slice1.1")
############ S18D_2:
DimPlot(S18D_2,cols=cols.orgi,label = TRUE,label.size=2)
LinkedDimPlot(maize_in,image="slice1.2")
############ S24D_1:
DimPlot(S24D_1,cols=cols.orgi,label = TRUE,label.size=2)
LinkedDimPlot(maize_in,image="slice1.3")
############
maize_in@meta.data$newclusters <- as.character(maize_in@meta.data$newclusters)
################################## S12D_1 ##################################
LinkedDimPlot(maize_in,image="slice1")
esr <- subset(S12D_1, UMAP_1 > 9 & UMAP_2 < -3,idents="17")
maize_in@meta.data[rownames(maize_in@meta.data) %in% Cells(esr),]$newclusters <- "ESR"
################# S12D_1 AL
not_al <- subset(S12D_1, Zm00001d013907 < 5.5,idents="4")
Idents(not_al)
maize_in@meta.data[rownames(maize_in@meta.data) %in% Cells(not_al),]$newclusters <- "PE"
al <- subset(S12D_1, UMAP_1 < 5 & UMAP_2 < 6,idents="4")
Idents(al)
maize_in@meta.data[rownames(maize_in@meta.data) %in% Cells(al),]$newclusters <- "AL"
################# S12D_1
cz <- subset(S12D_1, UMAP_1 < -5 & UMAP_2 > 5,idents="6")
maize_in@meta.data[rownames(maize_in@meta.data) %in% Cells(cz),]$newclusters <- "CZ"
################# S12D_1
se <- subset(S12D_1, idents="27") #S12D_1
maize_in@meta.data[rownames(maize_in@meta.data) %in% Cells(se),]$newclusters <- "SE"
################# S12D_1
eas12D_1 <- subset(S12D_1, UMAP_1 < 10 & UMAP_2 > 5,idents="13")
maize_in@meta.data[rownames(maize_in@meta.data) %in% Cells(eas12D_1),]$newclusters <- "VE"
ve <- subset(S12D_1, UMAP_1 < 2.5 & UMAP_2 > -5.5,idents="13")
maize_in@meta.data[rownames(maize_in@meta.data) %in% Cells(ve),]$newclusters <- "VE"
pe1 <- subset(S12D_1, UMAP_1 < -2 & UMAP_2 > -5,idents="24")
maize_in@meta.data[rownames(maize_in@meta.data) %in% Cells(pe1),]$newclusters <- "PE"
pe2 <- subset(S12D_1, UMAP_1 > 5 & UMAP_2 < 5,idents="10")
maize_in@meta.data[rownames(maize_in@meta.data) %in% Cells(pe2),]$newclusters <- "PE"
maize_in@meta.data[rownames(maize_in@meta.data)=="GCTAGAGTAGAGATGT-1_1",]$newclusters <- "bg"
maize_in@meta.data[rownames(maize_in@meta.data)=="AGGCAGATGCGTAAAC-1_1",]$newclusters <- "CZ"
maize_in@meta.data[rownames(maize_in@meta.data)=="CTTGTTGCTGAGTCAA-1_1",]$newclusters <- "EAS"
maize_in@meta.data[rownames(maize_in@meta.data)=="GGATCCGGAATATACT-1_1",]$newclusters <- "EAS"
Idents(maize_in) <- maize_in@meta.data$newclusters ###Change area name
SpatialDimPlot(maize_in, cols=cols,group.by="newclusters",images="slice1")
ve <- subset(S18D_1, idents="27")
maize_in@meta.data[rownames(maize_in@meta.data) %in% Cells(ve),]$newclusters <- "VE"
################# S18D_1
eas18D_1a <- subset(S18D_1, UMAP_1 < 1,idents="13")
maize_in@meta.data[rownames(maize_in@meta.data) %in% Cells(eas18D_1a),]$newclusters <- "VE"
eas18D_1b <- subset(S18D_1, UMAP_1 > 3 & UMAP_2 > -4,idents="13")
maize_in@meta.data[rownames(maize_in@meta.data) %in% Cells(eas18D_1b),]$newclusters <- "SCU"
eas18D_1c <- subset(S18D_1, UMAP_1 < 3 & UMAP_2 < -5,idents="13")
maize_in@meta.data[rownames(maize_in@meta.data) %in% Cells(eas18D_1c),]$newclusters <- "CZ"
maize_in@meta.data[rownames(maize_in@meta.data)=="AAGAGATGAATCGGTA-1_2",]$newclusters <- "SCU"
maize_in@meta.data[rownames(maize_in@meta.data)=="TTGATCTAACTTTGTC-1_2",]$newclusters <- "SE"
maize_in@meta.data[rownames(maize_in@meta.data)=="CTGGAAATGGATGCTT-1_2",]$newclusters <- "SE"
maize_in@meta.data[rownames(maize_in@meta.data)=="TCCGGCCTAGCGTACA-1_2",]$newclusters <- "EAS"
LinkedDimPlot(maize_in,image="slice1.1")
Idents(maize_in) <- maize_in@meta.data$newclusters
SpatialDimPlot(maize_in, cols=cols,group.by="newclusters",images="slice1.1")
################################## S18D_2 ##################################
scu <- subset(S18D_2, idents="27")
maize_in@meta.data[rownames(maize_in@meta.data) %in% Cells(scu),]$newclusters <- "SCU"
eas18D_2a <- subset(S18D_2, UMAP_1 < 2.5 & UMAP_2 > -5,idents="13")
maize_in@meta.data[rownames(maize_in@meta.data) %in% Cells(eas18D_2a),]$newclusters <- "VE"
maize_in@meta.data[rownames(maize_in@meta.data)=="GTACGTCACGTATTAA-1_3",]$newclusters <- "EAS"
LinkedDimPlot(maize_in,image="slice1.2")
Idents(maize_in) <- maize_in@meta.data$newclusters
SpatialDimPlot(maize_in, cols=cols,group.by="newclusters",images="slice1.2")
################################## S24D_1 ##################################
LinkedDimPlot(maize_in,image="slice1.3")
maize_in@meta.data[rownames(maize_in@meta.data) %in% Cells(scu),]$newclusters <- "SCU"
eas24D_1a <- subset(S24D_1, UMAP_1 < 3 & UMAP_2 > -4,idents="13")
maize_in@meta.data[rownames(maize_in@meta.data) %in% Cells(eas24D_1a),]$newclusters <- "VE"
eas24D_1b <- subset(S24D_1, UMAP_1 < 3 & UMAP_2 < -4,idents="13")
maize_in@meta.data[rownames(maize_in@meta.data) %in% Cells(eas24D_1b),]$newclusters <- "CZ"
cz <- subset(S24D_1, UMAP_1 < 3 & UMAP_2 < -4,idents="23")
maize_in@meta.data[rownames(maize_in@meta.data) %in% Cells(cz),]$newclusters <- "CZ"
maize_in@meta.data[rownames(maize_in@meta.data)=="GGTCGGATAAACGGCG-1_4",]$newclusters <- "SCU"
Idents(maize_in) <- maize_in@meta.data$newclusters
LinkedDimPlot(maize_in,image="slice1.3")
SpatialDimPlot(maize_in, cols=cols,group.by="newclusters",images="slice1.3")
maize_in@meta.data$newclusters <- as.factor(maize_in@meta.data$newclusters) #Restore the properties of the newclusters factor
############################ Draw the final partition diagram
SpatialDimPlot(maize_in, cols=cols,group.by="newclusters",images="slice1")
SpatialDimPlot(maize_in, cols=cols,group.by="newclusters", images="slice1.1")
SpatialDimPlot(maize_in, cols=cols,group.by="newclusters",images="slice1.2")
SpatialDimPlot(maize_in, cols=cols,group.by="newclusters",images="slice1.3")
DimPlot(maize_in, cols=cols,group.by="newclusters",label = T, label.size = 2,split.by = "orig.ident") #View the divided UMAP point map
maize_in <- RunTSNE(maize_in, dims = 1:30, verbose = FALSE)
DimPlot(maize_in, reduction = "tsne",cols=cols,group.by="newclusters",label = T, label.size = 2,split.by = "orig.ident")
DimPlot(maize_in, reduction = "pca",cols=cols,group.by="newclusters",label = T, label.size = 2,split.by = "orig.ident")
table(Idents(maize_in))
Idents(maize_in) <- maize_in@meta.data$newclusters
head(maize_in@meta.data)
table(Idents(maize_in))
SpatialDimPlot(maize_in, cols=cols,images="slice1")
saveRDS(maize_in,file="2maize_in.rds")