-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomp_clust.R
198 lines (146 loc) · 6.81 KB
/
comp_clust.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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# This code is used only for the creation of the plots that compare the clusterings
# it must be executed after the creation of the clustres so after seurat_svm.R hclus.R and naive_bayes.R
library(sqldf)
install.packages('sqldf')
integrated<- readRDS(file = "integrated.rds")
y=c()
for (i in 1:1735) {
y[i]=NA
}
total_cells <- as.data.frame(y)
row.names(total_cells) <- attr(total_labels, "row.names")
# gia seurat
x<-integrated@active.ident
seurat_cells = as.data.frame(x)
#cluster_labels
#total_labels
cardio1 <- filter(seurat_cells, x == "Cardiomyocytes")
cardio1["Cells"] <- attr(cardio1, "row.names")
cardio_sham1<-cardio1[ cardio1$Cells %like% "sham",]
cardio_sham1[,2] <- NULL #Removing the first column
cardio_sham_seurat1 <- attr(cardio_sham1, "row.names")
cardio_mi1<-cardio1[rownames(cardio1) %like% "mi",]
cardio_mi1[,2] <- NULL #Removing the first column
cardio_mi_seurat1 <- attr(cardio_mi1, "row.names")
#cardio1[,2] <- NULL #Removing the first column
fibro1 <- filter(seurat_cells, x == "Fibroblasts" )
fibro1["Cells"] <- attr(fibro1, "row.names")
fibro_seurat1 <- attr(fibro1, "row.names")
endo1 <- filter(seurat_cells, x == "Endothelial")
endo1["Cells"] <- attr(endo1, "row.names")
endo_seurat1 <- attr(endo1, "row.names")
immun1 <- filter(seurat_cells, x == "Immune" )
immun1["Cells"] <- attr(immun1, "row.names")
immun_seurat1 <- attr(immun1, "row.names")
#total_labels_naive
cardio2 <- filter(cluster_labels, x == "Cardiomyocytes")
cardio2["Cells"] <- attr(cardio2, "row.names")
cardio_sham2<-cardio2[ cardio2$Cells %like% "sham",]
cardio_sham2[,2] <- NULL #Removing the first column
cardio_sham_seurat2 <- attr(cardio_sham2, "row.names")
cardio_mi2<-cardio2[rownames(cardio2) %like% "mi",]
cardio_mi2[,2] <- NULL #Removing the first column
cardio_mi_seurat2<- attr(cardio_mi2, "row.names")
#cardio2[,2] <- NULL #Removing the first column
fibro2 <- filter(cluster_labels, x == "Fibroblasts" )
fibro2["Cells"] <- attr(fibro2, "row.names")
fibro_seurat2 <- attr(fibro2, "row.names")
endo2 <- filter(cluster_labels, x == "Endothelial")
endo2["Cells"] <- attr(endo2, "row.names")
endo_seurat2 <- attr(endo2, "row.names")
immun2 <- filter(cluster_labels, x == "Immune" )
immun2["Cells"] <- attr(immun2, "row.names")
immun_seurat2 <- attr(immun2, "row.names")
######################### COMPARE ########################
########### Cardio ##########################
cardio_common <- merge(cardio1, cardio2, by=0, all=F)
cardio_common["x"] <- "common"
rownames(cardio_common) <- cardio_common[,3]
cardio_common[,1:5] <- NULL #Removing from PC9 to PC50
cardio_not_common1 <- anti_join(cardio2, cardio1)
cardio_not_common1["x"] <- "hierarchical"
cardio_not_common1[,2] <- NULL #Removing from PC9 to PC50
cardio_not_common2 <- anti_join(cardio1, cardio2)
cardio_not_common2["x"] <- "seurat"
cardio_not_common2[,2] <- NULL #Removing from PC9 to PC50
cardio_temp <- rbind(cardio_not_common2, cardio_not_common1)
cardio_total <- rbind(cardio_common, cardio_temp)
total_common <- merge(total_cells, cardio_total, by=0, all=T)
rownames(total_common) <- total_common[,1]
total_common[,1:2] <- NULL #Removing from PC9 to PC50
cells_umap <- as.data.frame(integrated@reductions[["umap"]]@cell.embeddings)
cells_umap <- merge(cells_umap, total_common, by=0, all=F)
rownames(cells_umap) <-cells_umap[,1]
#cells_umap[,1] <- NULL #Removing the first column
colnames(cells_umap)[4] <- "Type"
ggplot(cells_umap) +
geom_point(aes(x = UMAP_1, y= UMAP_2, color = Type)) + ggtitle("Cardiomyocytes")
########### Fibroblasts ##########################
cardio_common <- merge(fibro1, fibro2, by=0, all=F)
cardio_common["x"] <- "common"
rownames(cardio_common) <- cardio_common[,3]
cardio_common[,1:5] <- NULL #Removing from PC9 to PC50
cardio_not_common1 <- anti_join(fibro2, fibro1)
cardio_not_common1["x"] <- "hierarchical"
cardio_not_common1[,2] <- NULL #Removing from PC9 to PC50
cardio_not_common2 <- anti_join(fibro1, fibro2)
cardio_not_common2["x"] <- "seurat"
cardio_not_common2[,2] <- NULL #Removing from PC9 to PC50
cardio_temp <- rbind(cardio_not_common2, cardio_not_common1)
cardio_total <- rbind(cardio_common, cardio_temp)
total_common <- merge(total_cells, cardio_total, by=0, all=T)
rownames(total_common) <- total_common[,1]
total_common[,1:2] <- NULL #Removing from PC9 to PC50
cells_umap <- as.data.frame(integrated@reductions[["umap"]]@cell.embeddings)
cells_umap <- merge(cells_umap, total_common, by=0, all=F)
rownames(cells_umap) <-cells_umap[,1]
#cells_umap[,1] <- NULL #Removing the first column
colnames(cells_umap)[4] <- "Type"
ggplot(cells_umap) +
geom_point(aes(x = UMAP_1, y= UMAP_2, color = Type)) + ggtitle("Fibroblasts")
########### Endothelial ##########################
cardio_common <- merge(endo1, endo2, by=0, all=F)
cardio_common["x"] <- "common"
rownames(cardio_common) <- cardio_common[,3]
cardio_common[,1:5] <- NULL #Removing from PC9 to PC50
cardio_not_common1 <- anti_join(endo2, endo1)
cardio_not_common1["x"] <- "svm"
cardio_not_common1[,2] <- NULL #Removing from PC9 to PC50
cardio_not_common2 <- anti_join(endo1, endo2)
cardio_not_common2["x"] <- "seurat"
cardio_not_common2[,2] <- NULL #Removing from PC9 to PC50
cardio_temp <- rbind(cardio_not_common2, cardio_not_common1)
cardio_total <- rbind(cardio_common, cardio_temp)
total_common <- merge(total_cells, cardio_total, by=0, all=T)
rownames(total_common) <- total_common[,1]
total_common[,1:2] <- NULL #Removing from PC9 to PC50
cells_umap <- as.data.frame(integrated@reductions[["umap"]]@cell.embeddings)
cells_umap <- merge(cells_umap, total_common, by=0, all=F)
rownames(cells_umap) <-cells_umap[,1]
#cells_umap[,1] <- NULL #Removing the first column
colnames(cells_umap)[4] <- "Type"
ggplot(cells_umap) +
geom_point(aes(x = UMAP_1, y= UMAP_2, color = Type)) + ggtitle("Endothelial")
########### Immune ##########################
cardio_common <- merge(immun1, immun2, by=0, all=F)
cardio_common["x"] <- "common"
rownames(cardio_common) <- cardio_common[,3]
cardio_common[,1:5] <- NULL #Removing from PC9 to PC50
cardio_not_common1 <- anti_join(immun2, immun1)
cardio_not_common1["x"] <- "svm"
cardio_not_common1[,2] <- NULL #Removing from PC9 to PC50
cardio_not_common2 <- anti_join(immun1, immun2)
cardio_not_common2["x"] <- "seurat"
cardio_not_common2[,2] <- NULL #Removing from PC9 to PC50
cardio_temp <- rbind(cardio_not_common2, cardio_not_common1)
cardio_total <- rbind(cardio_common, cardio_temp)
total_common <- merge(total_cells, cardio_total, by=0, all=T)
rownames(total_common) <- total_common[,1]
total_common[,1:2] <- NULL #Removing from PC9 to PC50
cells_umap <- as.data.frame(integrated@reductions[["umap"]]@cell.embeddings)
cells_umap <- merge(cells_umap, total_common, by=0, all=F)
rownames(cells_umap) <-cells_umap[,1]
#cells_umap[,1] <- NULL #Removing the first column
colnames(cells_umap)[4] <- "Type"
ggplot(cells_umap) +
geom_point(aes(x = UMAP_1, y= UMAP_2, color = Type)) + ggtitle("Immune")