-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory_冲突文件_DELL_20230818150816
512 lines (512 loc) · 33.1 KB
/
.Rhistory_冲突文件_DELL_20230818150816
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
Microglia_PID27.combined <- RunPCA(Microglia_PID27.combined, features = VariableFeatures(object = Microglia_PID27.combined))
#Seurat provides several useful ways of visualizing both cells and features that define the PCA, including VizDimReduction(), DimPlot(), and DimHeatmap()
# Examine and visualize PCA results a few different ways
print(Microglia_PID27.combined[["pca"]], dims = 1:5, nfeatures = 5)
#------------------------------Cluster the cells----------------------------------#
Microglia_PID27.combined <- FindNeighbors(Microglia_PID27.combined, dims = 1:20)
#Computing nearest neighbor graph
#Computing SNN
Microglia_PID27.combined <- FindClusters(Microglia_PID27.combined, resolution = 0.2)
# Look at cluster IDs of the first 5 cells
head(Idents(Microglia_PID27.combined), 5)
#---------------Run non-linear dimensional reduction (UMAP/tSNE)------------------#
# If you haven't installed UMAP, you can do so via reticulate::py_install(packages =
# 'umap-learn')
Microglia_PID27.combined <- RunUMAP(Microglia_PID27.combined, dims = 1:20)
DimPlot(Microglia_PID27.combined, reduction = "umap", label = T)
# find markers for every cluster compared to all remaining cells, report only the positive ones
Microglia_PID27.markers <- FindAllMarkers(Microglia_PID27.combined, only.pos = TRUE, min.pct = 0.25, logfc.threshold = 0.25)
Microglia_PID27.markers %>%
group_by(cluster) %>%
slice_max(n = 2, order_by = avg_log2FC)
Microglia_PID27.markers %>%
group_by(cluster) %>%
top_n(n = 10, wt = avg_log2FC) -> top10
DoHeatmap(Microglia_PID27.combined, features = top10$gene) + NoLegend()
# Subset Seurat object based on identity class, also see ?SubsetData
###Cluster.1.8.12.only <- subset(x = seuratA, idents = c('1','8', '12'))
Microglia_PID27a1 <- subset(x = PID27a1, idents = c('0', '22'))
Microglia_PID27a1
# Subset Seurat object based on identity class, also see ?SubsetData
###Cluster.1.8.12.only <- subset(x = seuratA, idents = c('1','8', '12'))
Microglia_PID27c1 <- subset(x = PID27c1, idents = c('2', '20'))
Microglia_PID27c1
Microglia_PID27.combined <- merge(Microglia_PID27a1, y = Microglia_PID27c1, add.cell.ids = c("a1_Exp", "c1_Ctrl"), project = "Microglia_PID27")
Microglia_PID27.combined
#------------------------------------Normalizing the data--------------------------------------------#
Microglia_PID27.combined <- NormalizeData(Microglia_PID27.combined, normalization.method = "LogNormalize", scale.factor = 10000)
#-------------------Identification of highly variable features (feature selection)--------------------#
Microglia_PID27.combined <- FindVariableFeatures(Microglia_PID27.combined, selection.method = "vst", nfeatures = 2000)
#-------------------------------Scaling the data----------------------------------------#
all.genes <- rownames(Microglia_PID27.combined)
Microglia_PID27.combined <- ScaleData(Microglia_PID27.combined, features = all.genes)
#---------------------Perform linear dimensional reduction------------------------------#
#Next we perform PCA on the scaled data. By default, only the previously determined variable features are used as input, but can be defined using features argument if you wish to choose a different subset.
Microglia_PID27.combined <- RunPCA(Microglia_PID27.combined, features = VariableFeatures(object = Microglia_PID27.combined))
#Seurat provides several useful ways of visualizing both cells and features that define the PCA, including VizDimReduction(), DimPlot(), and DimHeatmap()
# Examine and visualize PCA results a few different ways
print(Microglia_PID27.combined[["pca"]], dims = 1:5, nfeatures = 5)
#------------------------------Cluster the cells----------------------------------#
Microglia_PID27.combined <- FindNeighbors(Microglia_PID27.combined, dims = 1:20)
#Computing nearest neighbor graph
#Computing SNN
Microglia_PID27.combined <- FindClusters(Microglia_PID27.combined, resolution = 0.2)
# Look at cluster IDs of the first 5 cells
head(Idents(Microglia_PID27.combined), 5)
#---------------Run non-linear dimensional reduction (UMAP/tSNE)------------------#
# If you haven't installed UMAP, you can do so via reticulate::py_install(packages =
# 'umap-learn')
Microglia_PID27.combined <- RunUMAP(Microglia_PID27.combined, dims = 1:20)
DimPlot(Microglia_PID27.combined, reduction = "umap", label = T)
#-----------------------------------Check whether cluster4 is ctrl or exp. group------------------------------------#
Microglia_combined_c4 <- subset(x = Microglia_PID27.combined, idents = '4')
##############
head(Idents(Microglia_combined_c4), 20)
#-----------------------------------Check whether cluster2 is ctrl or exp. group------------------------------------#
Microglia_combined_c2 <- subset(x = Microglia_PID27.combined, idents = '2')
##############
head(Idents(Microglia_combined_c2), 20)
#-----------------------------------Check whether cluster0 is ctrl or exp. group------------------------------------#
Microglia_combined_c0 <- subset(x = Microglia_PID27.combined, idents = '0')
##############
head(Idents(Microglia_combined_c0), 20)
##############Cluster3 and Cluster1 are cells from Ctrl group
#-----------------------------------Check whether cluster3 is ctrl or exp. group------------------------------------#
Microglia_combined_c3 <- subset(x = Microglia_PID27.combined, idents = '3')
##############
head(Idents(Microglia_combined_c3), 20)
#-----------------------------------Check whether cluster1 is ctrl or exp. group------------------------------------#
Microglia_combined_c1 <- subset(x = Microglia_PID27.combined, idents = '3')
##############
head(Idents(Microglia_combined_c1), 20)
#-----------------------------------Check whether cluster0 is ctrl or exp. group------------------------------------#
Microglia_combined_c0 <- subset(x = Microglia_PID27.combined, idents = '0')
##############
head(Idents(Microglia_combined_c0), 20)
#-----------------------------------Check whether cluster1 is ctrl or exp. group------------------------------------#
Microglia_combined_c1 <- subset(x = Microglia_PID27.combined, idents = '3')
##############
head(Idents(Microglia_combined_c1), 20)
#-----------------------------------Check whether cluster2 is ctrl or exp. group------------------------------------#
Microglia_combined_c2 <- subset(x = Microglia_PID27.combined, idents = '2')
##############
head(Idents(Microglia_combined_c2), 20)
##############Cluster3 and Cluster1 are cells from Ctrl group
#-----------------------------------Check whether cluster3 is ctrl or exp. group------------------------------------#
Microglia_combined_c3 <- subset(x = Microglia_PID27.combined, idents = '3')
##############
head(Idents(Microglia_combined_c3), 20)
#-----------------------------------Check whether cluster4 is ctrl or exp. group------------------------------------#
Microglia_combined_c4 <- subset(x = Microglia_PID27.combined, idents = '4')
##############
head(Idents(Microglia_combined_c4), 20)
#---------Finding differentially expressed features (cluster biomarkers)-----------#
# find all markers of cluster 4
Microglia_C4_exp_diffs <- FindMarkers(Microglia_PID27.combined, ident.1 = c(0,1,2,3), min.pct = 0.25)
head(Microglia_C4_exp_diffs, n = 10)
##############Cluster 4 markers;
FeaturePlot(object = Microglia_PID27.combined, features = rownames(Astro_C4_exp_diffs)[1:9], cols = c("grey", "red"), raster=FALSE, label = T)
FeaturePlot(object = Microglia_PID27.combined, features = c("Hmga2", "Fam189a1", "Klhl1", "Gabrg3", "Tnc", "Cdh13", "Chrm3"), cols = c("grey", "red"), raster=FALSE, label = T)
##############Cluster 4 markers;
FeaturePlot(object = Microglia_PID27.combined, features = rownames(Microglia_C4_exp_diffs)[1:9], cols = c("grey", "red"), raster=FALSE, label = T)
#-----------------------------------Check whether cluster1 is ctrl or exp. group------------------------------------#
Microglia_combined_c1 <- subset(x = Microglia_PID27.combined, idents = '1')
##############
head(Idents(Microglia_combined_c1), 20)
##############
head(Idents(Microglia_combined_c1), 20)
##############
head(Idents(Microglia_combined_c2), 20)
##############Cluster3 and Cluster1 are cells from Ctrl group
#-----------------------------------Check whether cluster3 is ctrl or exp. group------------------------------------#
Microglia_combined_c3 <- subset(x = Microglia_PID27.combined, idents = '3')
##############
head(Idents(Microglia_combined_c3), 20)
#-----------------------------------Check whether cluster4 is ctrl or exp. group------------------------------------#
Microglia_combined_c4 <- subset(x = Microglia_PID27.combined, idents = '4')
##############
head(Idents(Microglia_combined_c4), 20)
##############Cluster3 and Cluster1 are cells from Ctrl group
#-----------------------------------Check whether cluster3 is ctrl or exp. group------------------------------------#
Microglia_combined_c3 <- subset(x = Microglia_PID27.combined, idents = '3')
##############
head(Idents(Microglia_combined_c3), 20)
#-----------------------------------Check whether cluster2 is ctrl or exp. group------------------------------------#
Microglia_combined_c2 <- subset(x = Microglia_PID27.combined, idents = '2')
##############
head(Idents(Microglia_combined_c2), 20)
# find markers for every cluster compared to all remaining cells, report only the positive ones
Microglia_PID27.markers <- FindAllMarkers(Microglia_PID27.combined, only.pos = TRUE, min.pct = 0.25, logfc.threshold = 0.25)
Microglia_PID27.markers %>%
group_by(cluster) %>%
slice_max(n = 2, order_by = avg_log2FC)
Microglia_PID27.markers %>%
group_by(cluster) %>%
top_n(n = 10, wt = avg_log2FC) -> top10
DoHeatmap(Microglia_PID27.combined, features = top10$gene) + NoLegend()
# find all markers of cluster 2
Microglia_C2_exp_diffs <- FindMarkers(Microglia_PID27.combined, ident.1 = c(0,2,3), min.pct = 0.25)
head(Microglia_C2_exp_diffs, n = 10)
# find all markers of cluster 0
Microglia_C2_exp_diffs <- FindMarkers(Microglia_PID27.combined, ident.1 = c(1,2,3,4), min.pct = 0.25)
head(Microglia_C2_exp_diffs, n = 10)
nrow(Microglia_C2_exp_diffs)
#---------Finding differentially expressed features (cluster biomarkers)-----------#
# find all markers of cluster 4
Microglia_C4_exp_diffs <- FindMarkers(Microglia_PID27.combined, ident.1 = c(0,1,2,3), min.pct = 0.25)
head(Microglia_C4_exp_diffs, n = 10)
#---------Finding differentially expressed features (cluster biomarkers)-----------#
# find all markers of cluster 1
Microglia_C1_exp_diffs <- FindMarkers(Microglia_PID27.combined, ident.1 = c(0,2,3,4), min.pct = 0.25)
head(Microglia_C1_exp_diffs, n = 10)
##############Cluster 4 markers;
FeaturePlot(object = Microglia_PID27.combined, features = rownames(Microglia_C1_exp_diffs)[1:9], cols = c("grey", "red"), raster=FALSE, label = T)
rownames(Microglia_C1_exp_diffs)[1:9]
# find all markers of cluster 0
Microglia_C0_exp_diffs <- FindMarkers(Microglia_PID27.combined, ident.1 = c(1,2,3,4), min.pct = 0.25)
head(Microglia_C0_exp_diffs, n = 10)
rownames(Microglia_C0_exp_diffs)[1:9]
##############Cluster 0 markers;
###[1] "H2-Ab1" "H2-Aa" "H2-Eb1" "Cd74" "C1qc" "Apoe" "Gm42418" "C1qb" "Cd81"
FeaturePlot(object = Microglia_PID27.combined, features = rownames(Microglia_C0_exp_diffs)[1:9], cols = c("grey", "red"), raster=FALSE, label = T)
FeaturePlot(object = Microglia_PID27.combined, features = "Tmem119", cols = c("grey", "red"), raster=FALSE, label = T)
FeaturePlot(object = Microglia_PID27.combined, features = "Apoe", cols = c("grey", "red"), raster=FALSE, label = T)
##############################降低UMAP的分群分辨率,把这5群细胞单独分为两群;
#------------------------------Cluster the cells----------------------------------#
Microglia_PID27.combined <- FindNeighbors(Microglia_PID27.combined, dims = 1:20)
#Computing nearest neighbor graph
#Computing SNN
Microglia_PID27.combined <- FindClusters(Microglia_PID27.combined, resolution = 0.1)
# Look at cluster IDs of the first 5 cells
head(Idents(Microglia_PID27.combined), 5)
#Computing nearest neighbor graph
#Computing SNN
Microglia_PID27.combined <- FindClusters(Microglia_PID27.combined, resolution = 0.05)
# Look at cluster IDs of the first 5 cells
head(Idents(Microglia_PID27.combined), 5)
#Computing nearest neighbor graph
#Computing SNN
Microglia_PID27.combined <- FindClusters(Microglia_PID27.combined, resolution = 0.01)
# Look at cluster IDs of the first 5 cells
head(Idents(Microglia_PID27.combined), 5)
#---------------Run non-linear dimensional reduction (UMAP/tSNE)------------------#
# If you haven't installed UMAP, you can do so via reticulate::py_install(packages =
# 'umap-learn')
Microglia_PID27.combined <- RunUMAP(Microglia_PID27.combined, dims = 1:20)
DimPlot(Microglia_PID27.combined, reduction = "umap", label = T)
#-----------------------------------------Analysis DEGs of Microglia in bAVM V.S. Ctrl region-----------------------#
Microglia_C12_exp_diffs <- FindMarkers(Microglia_PID27.combined, ident.1 = c(1,2), min.pct = 0.25)
head(Microglia_C02_exp_diffs, n = 10)
head(Microglia_C12_exp_diffs, n = 10)
####Volcano plot
##data$significant <- as.factor(data$PValue<0.05 & abs(data$logFC) > 1)
##data$gene <- data$GENE_NAME
Microglia_C12_exp_diffs$SYMBOL <- rownames(Microglia_C12_exp_diffs)
colnames(Microglia_C12_exp_diffs)[5] <- "padj"
colnames(Microglia_C12_exp_diffs)[2] <- "log2FoldChange"
data <- Microglia_C12_exp_diffs
data$significant <- as.factor(data$padj<0.05 & abs(data$log2FoldChange) > 1)
#########store gene names
data$gene <- Microglia_C02_exp_diffs$SYMBOL
#########store gene names
data$gene <- Microglia_C12_exp_diffs$SYMBOL
library(ggrepel)
p <- ggplot(data=data, aes(x=log2FoldChange, y =-log10(padj), color=significant)) +
geom_point(alpha=0.8, size=1.2, col="grey50")+
geom_point(data=subset(data, data$padj<0.05 & data$log2FoldChange > 1),alpha=0.8, size=1.2,col="#cf558e")+
geom_point(data=subset(data, data$padj<0.05 & data$log2FoldChange < -1),alpha=0.8, size=1.2,col="#558acf")+
labs(x="log2(Fold Change)",y="-log10 (padj)", title="Microglia, Ctrl vs bAVM(PID27)")+
theme(plot.title = element_text(hjust = 0.4))+
geom_hline(yintercept = -log10(0.05),lty=4,lwd=0.6,alpha=0.8)+
geom_vline(xintercept = c(1,-1),lty=4,lwd=0.6,alpha=0.8)+
theme(legend.position='none')+
theme_bw()+
####remove the border
theme(panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black")) +
geom_point(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange > 2),alpha=0.8, size=3,col="red") +
geom_point(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange < -2),alpha=0.8, size=3,col="blue") +
geom_text_repel(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange > 2), aes(label=gene), col="black", size = 5.5, alpha = 0.8) +
geom_text_repel(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange < -2.5), aes(label=gene), col="black", size = 5.5, alpha = 0.8)
p+ theme(
title = element_text(color="black", size=19, face="bold"),
axis.title.x = element_text(color="black", size=19, face="bold"),
axis.title.y = element_text(color="black", size=19, face="bold"),
axis.text=element_text(size=18,face = "bold"),
line = element_line(size =1)) + scale_x_continuous(name="Log2(Fold change)", limits=c(-5, 8))
#-----------------------------------------Analysis DEGs of Microglia in bAVM V.S. Ctrl region-----------------------#
Microglia_C0_exp_diffs <- FindMarkers(Microglia_PID27.combined, ident.1 = c(0), min.pct = 0.25)
head(Microglia_C0_exp_diffs, n = 10)
####Volcano plot
##data$significant <- as.factor(data$PValue<0.05 & abs(data$logFC) > 1)
##data$gene <- data$GENE_NAME
Microglia_C0_exp_diffs$SYMBOL <- rownames(Microglia_C0_exp_diffs)
####Volcano plot
##data$significant <- as.factor(data$PValue<0.05 & abs(data$logFC) > 1)
##data$gene <- data$GENE_NAME
Microglia_C0_exp_diffs$SYMBOL <- rownames(Microglia_C0_exp_diffs)
colnames(Microglia_C0_exp_diffs)[5] <- "padj"
colnames(Microglia_C0_exp_diffs)[2] <- "log2FoldChange"
data <- Microglia_C0_exp_diffs
data$significant <- as.factor(data$padj<0.05 & abs(data$log2FoldChange) > 1)
#########store gene names
data$gene <- Microglia_C0_exp_diffs$SYMBOL
library(ggrepel)
p <- ggplot(data=data, aes(x=log2FoldChange, y =-log10(padj), color=significant)) +
geom_point(alpha=0.8, size=1.2, col="grey50")+
geom_point(data=subset(data, data$padj<0.05 & data$log2FoldChange > 1),alpha=0.8, size=1.2,col="#cf558e")+
geom_point(data=subset(data, data$padj<0.05 & data$log2FoldChange < -1),alpha=0.8, size=1.2,col="#558acf")+
labs(x="log2(Fold Change)",y="-log10 (padj)", title="Microglia, Ctrl vs bAVM(PID27)")+
theme(plot.title = element_text(hjust = 0.4))+
geom_hline(yintercept = -log10(0.05),lty=4,lwd=0.6,alpha=0.8)+
geom_vline(xintercept = c(1,-1),lty=4,lwd=0.6,alpha=0.8)+
theme(legend.position='none')+
theme_bw()+
####remove the border
theme(panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black")) +
geom_point(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange > 2),alpha=0.8, size=3,col="red") +
geom_point(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange < -2),alpha=0.8, size=3,col="blue") +
geom_text_repel(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange > 2), aes(label=gene), col="black", size = 5.5, alpha = 0.8) +
geom_text_repel(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange < -2.5), aes(label=gene), col="black", size = 5.5, alpha = 0.8)
p+ theme(
title = element_text(color="black", size=19, face="bold"),
axis.title.x = element_text(color="black", size=19, face="bold"),
axis.title.y = element_text(color="black", size=19, face="bold"),
axis.text=element_text(size=18,face = "bold"),
line = element_line(size =1)) + scale_x_continuous(name="Log2(Fold change)", limits=c(-5, 8))
p <- ggplot(data=data, aes(x=log2FoldChange, y =-log10(padj), color=significant)) +
geom_point(alpha=0.8, size=1.2, col="grey50")+
geom_point(data=subset(data, data$padj<0.05 & data$log2FoldChange > 1),alpha=0.8, size=1.2,col="#cf558e")+
geom_point(data=subset(data, data$padj<0.05 & data$log2FoldChange < -1),alpha=0.8, size=1.2,col="#558acf")+
labs(x="log2(Fold Change)",y="-log10 (padj)", title="Microglia, Ctrl vs bAVM(PID27)")+
theme(plot.title = element_text(hjust = 0.4))+
geom_hline(yintercept = -log10(0.05),lty=4,lwd=0.6,alpha=0.8)+
geom_vline(xintercept = c(1,-1),lty=4,lwd=0.6,alpha=0.8)+
theme(legend.position='none')+
theme_bw()+
####remove the border
theme(panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black")) +
geom_point(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange > 2),alpha=0.8, size=3,col="red") +
geom_point(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange < -2),alpha=0.8, size=3,col="blue") +
geom_text_repel(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange > 1.5), aes(label=gene), col="black", size = 5.5, alpha = 0.8) +
geom_text_repel(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange < -2.5), aes(label=gene), col="black", size = 5.5, alpha = 0.8)
p+ theme(
title = element_text(color="black", size=19, face="bold"),
axis.title.x = element_text(color="black", size=19, face="bold"),
axis.title.y = element_text(color="black", size=19, face="bold"),
axis.text=element_text(size=18,face = "bold"),
line = element_line(size =1)) + scale_x_continuous(name="Log2(Fold change)", limits=c(-5, 8))
p <- ggplot(data=data, aes(x=log2FoldChange, y =-log10(padj), color=significant)) +
geom_point(alpha=0.8, size=1.2, col="grey50")+
geom_point(data=subset(data, data$padj<0.05 & data$log2FoldChange > 1),alpha=0.8, size=1.2,col="#cf558e")+
geom_point(data=subset(data, data$padj<0.05 & data$log2FoldChange < -1),alpha=0.8, size=1.2,col="#558acf")+
labs(x="log2(Fold Change)",y="-log10 (padj)", title="Microglia, Ctrl vs bAVM(PID27)")+
theme(plot.title = element_text(hjust = 0.4))+
geom_hline(yintercept = -log10(0.05),lty=4,lwd=0.6,alpha=0.8)+
geom_vline(xintercept = c(1,-1),lty=4,lwd=0.6,alpha=0.8)+
theme(legend.position='none')+
theme_bw()+
####remove the border
theme(panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black")) +
geom_point(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange > 1.5),alpha=0.8, size=3,col="red") +
geom_point(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange < -2),alpha=0.8, size=3,col="blue") +
geom_text_repel(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange > 1.5), aes(label=gene), col="black", size = 5.5, alpha = 0.8) +
geom_text_repel(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange < -2.5), aes(label=gene), col="black", size = 5.5, alpha = 0.8)
p+ theme(
title = element_text(color="black", size=19, face="bold"),
axis.title.x = element_text(color="black", size=19, face="bold"),
axis.title.y = element_text(color="black", size=19, face="bold"),
axis.text=element_text(size=18,face = "bold"),
line = element_line(size =1)) + scale_x_continuous(name="Log2(Fold change)", limits=c(-5, 8))
p <- ggplot(data=data, aes(x=log2FoldChange, y =-log10(padj), color=significant)) +
geom_point(alpha=0.8, size=1.2, col="grey50")+
geom_point(data=subset(data, data$padj<0.05 & data$log2FoldChange > 1),alpha=0.8, size=1.2,col="#cf558e")+
geom_point(data=subset(data, data$padj<0.05 & data$log2FoldChange < -1),alpha=0.8, size=1.2,col="#558acf")+
labs(x="log2(Fold Change)",y="-log10 (padj)", title="Microglia, Ctrl vs bAVM(PID27)")+
theme(plot.title = element_text(hjust = 0.4))+
geom_hline(yintercept = -log10(0.05),lty=4,lwd=0.6,alpha=0.8)+
geom_vline(xintercept = c(1,-1),lty=4,lwd=0.6,alpha=0.8)+
theme(legend.position='none')+
theme_bw()+
####remove the border
theme(panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black")) +
geom_point(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange > 1.8),alpha=0.8, size=3,col="red") +
geom_point(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange < -2),alpha=0.8, size=3,col="blue") +
geom_text_repel(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange > 1.5), aes(label=gene), col="black", size = 5.5, alpha = 0.8) +
geom_text_repel(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange < -2.5), aes(label=gene), col="black", size = 5.5, alpha = 0.8)
p+ theme(
title = element_text(color="black", size=19, face="bold"),
axis.title.x = element_text(color="black", size=19, face="bold"),
axis.title.y = element_text(color="black", size=19, face="bold"),
axis.text=element_text(size=18,face = "bold"),
line = element_line(size =1)) + scale_x_continuous(name="Log2(Fold change)", limits=c(-5, 8))
p <- ggplot(data=data, aes(x=log2FoldChange, y =-log10(padj), color=significant)) +
geom_point(alpha=0.8, size=1.2, col="grey50")+
geom_point(data=subset(data, data$padj<0.05 & data$log2FoldChange > 1),alpha=0.8, size=1.2,col="#cf558e")+
geom_point(data=subset(data, data$padj<0.05 & data$log2FoldChange < -1),alpha=0.8, size=1.2,col="#558acf")+
labs(x="log2(Fold Change)",y="-log10 (padj)", title="Microglia, Ctrl vs bAVM(PID27)")+
theme(plot.title = element_text(hjust = 0.4))+
geom_hline(yintercept = -log10(0.05),lty=4,lwd=0.6,alpha=0.8)+
geom_vline(xintercept = c(1,-1),lty=4,lwd=0.6,alpha=0.8)+
theme(legend.position='none')+
theme_bw()+
####remove the border
theme(panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black")) +
geom_point(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange > 1.6),alpha=0.8, size=3,col="red") +
geom_point(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange < -2),alpha=0.8, size=3,col="blue") +
geom_text_repel(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange > 1.5), aes(label=gene), col="black", size = 5.5, alpha = 0.8) +
geom_text_repel(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange < -2.5), aes(label=gene), col="black", size = 5.5, alpha = 0.8)
p+ theme(
title = element_text(color="black", size=19, face="bold"),
axis.title.x = element_text(color="black", size=19, face="bold"),
axis.title.y = element_text(color="black", size=19, face="bold"),
axis.text=element_text(size=18,face = "bold"),
line = element_line(size =1)) + scale_x_continuous(name="Log2(Fold change)", limits=c(-5, 8))
p <- ggplot(data=data, aes(x=log2FoldChange, y =-log10(padj), color=significant)) +
geom_point(alpha=0.8, size=1.2, col="grey50")+
geom_point(data=subset(data, data$padj<0.05 & data$log2FoldChange > 1),alpha=0.8, size=1.2,col="#cf558e")+
geom_point(data=subset(data, data$padj<0.05 & data$log2FoldChange < -1),alpha=0.8, size=1.2,col="#558acf")+
labs(x="log2(Fold Change)",y="-log10 (padj)", title="Microglia, Ctrl vs bAVM(PID27)")+
theme(plot.title = element_text(hjust = 0.4))+
geom_hline(yintercept = -log10(0.05),lty=4,lwd=0.6,alpha=0.8)+
geom_vline(xintercept = c(1,-1),lty=4,lwd=0.6,alpha=0.8)+
theme(legend.position='none')+
theme_bw()+
####remove the border
theme(panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black")) +
geom_point(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange > 1.6),alpha=0.8, size=3,col="red") +
geom_point(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange < -2),alpha=0.8, size=3,col="blue") +
geom_text_repel(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange > 1.6), aes(label=gene), col="black", size = 5.5, alpha = 0.8) +
geom_text_repel(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange < -2.5), aes(label=gene), col="black", size = 5.5, alpha = 0.8)
p+ theme(
title = element_text(color="black", size=19, face="bold"),
axis.title.x = element_text(color="black", size=19, face="bold"),
axis.title.y = element_text(color="black", size=19, face="bold"),
axis.text=element_text(size=18,face = "bold"),
line = element_line(size =1)) + scale_x_continuous(name="Log2(Fold change)", limits=c(-5, 8))
p <- ggplot(data=data, aes(x=log2FoldChange, y =-log10(padj), color=significant)) +
geom_point(alpha=0.8, size=1.2, col="grey50")+
geom_point(data=subset(data, data$padj<0.05 & data$log2FoldChange > 1),alpha=0.8, size=1.2,col="#cf558e")+
geom_point(data=subset(data, data$padj<0.05 & data$log2FoldChange < -1),alpha=0.8, size=1.2,col="#558acf")+
labs(x="log2(Fold Change)",y="-log10 (padj)", title="Microglia, Ctrl vs bAVM(PID27)")+
theme(plot.title = element_text(hjust = 0.4))+
geom_hline(yintercept = -log10(0.05),lty=4,lwd=0.6,alpha=0.8)+
geom_vline(xintercept = c(1,-1),lty=4,lwd=0.6,alpha=0.8)+
theme(legend.position='none')+
theme_bw()+
####remove the border
theme(panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black")) +
geom_point(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange > 1.7),alpha=0.8, size=3,col="red") +
geom_point(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange < -2),alpha=0.8, size=3,col="blue") +
geom_text_repel(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange > 1.7), aes(label=gene), col="black", size = 5.5, alpha = 0.8) +
geom_text_repel(data=subset(data, data$padj < 1*10^(-3) & data$log2FoldChange < -2.5), aes(label=gene), col="black", size = 5.5, alpha = 0.8)
p+ theme(
title = element_text(color="black", size=19, face="bold"),
axis.title.x = element_text(color="black", size=19, face="bold"),
axis.title.y = element_text(color="black", size=19, face="bold"),
axis.text=element_text(size=18,face = "bold"),
line = element_line(size =1)) + scale_x_continuous(name="Log2(Fold change)", limits=c(-5, 8))
#####################Upregulated markers:
FeaturePlot(object = Microglia_PID27.combined, features = "Apoe", cols = c("grey", "red"), raster=FALSE, label = T)
FeaturePlot(object = Microglia_PID27.combined, features = "Aoah", cols = c("grey", "red"), raster=FALSE, label = T)
#####################Upregulated markers:
FeaturePlot(object = Microglia_PID27.combined, features = "Apoe", cols = c("grey", "red"), raster=FALSE, label = T)
FeaturePlot(object = Microglia_PID27.combined, features = "Cp", cols = c("grey", "red"), raster=FALSE, label = T)
#####################Downregulated markers:
FeaturePlot(object = Microglia_PID27.combined, features = "Cd74", cols = c("grey", "red"), raster=FALSE, label = T)
FeaturePlot(object = Microglia_PID27.combined, features = "H2-Aa", cols = c("grey", "red"), raster=FALSE, label = T)
FeaturePlot(object = Microglia_PID27.combined, features = "H2-Aa", cols = c("grey", "Blue"), raster=FALSE, label = T)
#####################Downregulated markers:
FeaturePlot(object = Microglia_PID27.combined, features = "Cd74", cols = c("grey", "red"), raster=FALSE, label = T)
#####################Downregulated markers:
FeaturePlot(object = Microglia_PID27.combined, features = "Cd74", cols = c("grey", "Blue"), raster=FALSE, label = T)
FeaturePlot(object = Microglia_PID27.combined, features = "H2-Ab1", cols = c("grey", "red"), raster=FALSE, label = T)
FeaturePlot(object = Microglia_PID27.combined, features = "H2-Ab1", cols = c("grey", "Blue"), raster=FALSE, label = T)
# Subset Seurat object based on identity class, also see ?SubsetData
###Cluster.1.8.12.only <- subset(x = seuratA, idents = c('1','8', '12'))
Astro_PID27a1 <- subset(x = PID27a1, idents = '9')
Astro_PID27a1
# Subset Seurat object based on identity class, also see ?SubsetData
###Cluster.1.8.12.only <- subset(x = seuratA, idents = c('1','8', '12'))
Astro_PID27c1 <- subset(x = PID27c1, idents = '9')
Astro_PID27c1
Astro_PID27.combined <- merge(Astro_PID27a1, y = Astro_PID27c1, add.cell.ids = c("a1_Exp", "c1_Ctrl"), project = "Astro_PID27")
Astro_PID27.combined
#------------------------------------Normalizing the data--------------------------------------------#
Astro_PID27.combined <- NormalizeData(Astro_PID27.combined, normalization.method = "LogNormalize", scale.factor = 10000)
#-------------------Identification of highly variable features (feature selection)--------------------#
Astro_PID27.combined <- FindVariableFeatures(Astro_PID27.combined, selection.method = "vst", nfeatures = 2000)
#-------------------------------Scaling the data----------------------------------------#
all.genes <- rownames(Astro_PID27.combined)
Astro_PID27.combined <- ScaleData(Astro_PID27.combined, features = all.genes)
#---------------------Perform linear dimensional reduction------------------------------#
#Next we perform PCA on the scaled data. By default, only the previously determined variable features are used as input, but can be defined using features argument if you wish to choose a different subset.
Astro_PID27.combined <- RunPCA(Astro_PID27.combined, features = VariableFeatures(object = Astro_PID27.combined))
#Seurat provides several useful ways of visualizing both cells and features that define the PCA, including VizDimReduction(), DimPlot(), and DimHeatmap()
# Examine and visualize PCA results a few different ways
print(Astro_PID27.combined[["pca"]], dims = 1:5, nfeatures = 5)
#------------------------------Cluster the cells----------------------------------#
Astro_PID27.combined <- FindNeighbors(Astro_PID27.combined, dims = 1:20)
#Computing nearest neighbor graph
#Computing SNN
Astro_PID27.combined <- FindClusters(Astro_PID27.combined, resolution = 0.2)
# Look at cluster IDs of the first 5 cells
head(Idents(Astro_PID27.combined), 5)
#---------------Run non-linear dimensional reduction (UMAP/tSNE)------------------#
# If you haven't installed UMAP, you can do so via reticulate::py_install(packages =
# 'umap-learn')
Astro_PID27.combined <- RunUMAP(Astro_PID27.combined, dims = 1:20)
DimPlot(Astro_PID27.combined, reduction = "umap", label = T)
# find markers for every cluster compared to all remaining cells, report only the positive ones
Astro_PID27.markers <- FindAllMarkers(Astro_PID27.combined, only.pos = TRUE, min.pct = 0.25, logfc.threshold = 0.25)
Astro_PID27.markers %>%
group_by(cluster) %>%
slice_max(n = 2, order_by = avg_log2FC)
Astro_PID27.markers %>%
group_by(cluster) %>%
top_n(n = 10, wt = avg_log2FC) -> top10
DoHeatmap(Astro_PID27.combined, features = top10$gene) + NoLegend()
#############################differentiate the exp group cells and ctrl group cells by several
FeaturePlot(Astro_PID27.combined, features = c("Tspan7"), cols = c("grey", "Blue"), raster=FALSE, label = T)
FeaturePlot(Astro_PID27.combined, features = c("Clu"), cols = c("grey", "Blue"), raster=FALSE, label = T)
#############################Upregluated genes in astrocyte;
FeaturePlot(Astro_PID27.combined, features = c("Cdh13"), cols = c("grey", "Red"), raster=FALSE, label = T)
#Computing nearest neighbor graph
#Computing SNN
Astro_PID27.combined <- FindClusters(Astro_PID27.combined, resolution = 0.5)
# Look at cluster IDs of the first 5 cells
head(Idents(Astro_PID27.combined), 5)
#---------------Run non-linear dimensional reduction (UMAP/tSNE)------------------#
# If you haven't installed UMAP, you can do so via reticulate::py_install(packages =
# 'umap-learn')
Astro_PID27.combined <- RunUMAP(Astro_PID27.combined, dims = 1:20)
DimPlot(Astro_PID27.combined, reduction = "umap", label = T)
#############################Upregluated genes in astrocyte;
FeaturePlot(Astro_PID27.combined, features = c("Cdh13"), cols = c("grey", "Red"), raster=FALSE, label = T)
#############################Downregluated genes in astrocyte;
FeaturePlot(Astro_PID27.combined, features = c("Tspan7"), cols = c("grey", "Blue"), raster=FALSE, label = T)
FeaturePlot(Astro_PID27.combined, features = c("Clu"), cols = c("grey", "Blue"), raster=FALSE, label = T)
FeaturePlot(Astro_PID27.combined, features = c("Cst3"), cols = c("grey", "Blue"), raster=FALSE, label = T)