-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path1DP_11_MCAO_scsn.Rmd
1708 lines (1443 loc) · 68.7 KB
/
1DP_11_MCAO_scsn.Rmd
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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "MCAO_scsn"
author: "Daniel Zucha"
date: "2023-06-07"
output: html_document
---
A markdown for the analysis of the processed single-nucleus and single-cell datasets.
=== Essential chunks. Always load. ===
```{r libraries}
library(Seurat)
library(SeuratWrappers)
library(dplyr)
library(tibble)
library(magrittr)
library(dittoSeq)
library(openxlsx)
library(stringr)
library(ggplot2)
library(RColorBrewer)
library(gridExtra)
library(patchwork)
library(plotly)
library(pheatmap)
options(Seurat.object.assay.version = "v3")
## sourcing helper functions
source("code/supporting_functions_MCAO.R")
```
```{r working space and lists}
if(!dir.exists("ws")){dir.create("ws"); ws <- "ws"}else{ws <- "ws"}
# lists
seurat.plots <- list()
seurat.results <- list()
```
load data
```{r load seurats}
# spatial data
spatial.seurat <- readRDS(file.path("data", "seurat_spatial_1DP_06.Rds"))
# single-nucleus data
sn.seurat <- readRDS("data/seurat_all_UMAP_soupX.rds")
sn.seurat %<>% SetIdent(value = "cell_type_1")
```
=== All cell types. ===
Basic QC filtering
```{r QC filtering}
# check and remove doublets
{
sn.seurat$Doublet %>% table
sn.seurat %<>% SetIdent(value = "Doublet")
sn.seurat %>% DimPlot(reduction = "umap", pt.size = 1.5)
sn.seurat %<>% subset(idents = "Singlet") ## keep only singlets
sn.seurat %<>% SetIdent(value = "cell_type_1")
}
# ncount, nfeature, mito and ribo content
sn.seurat %<>% PercentageFeatureSet(pattern = "^mt-|^Mt-", col.name = "percent.mt", assay = "RNA")
sn.seurat %<>% PercentageFeatureSet(pattern = "^Rpl|^Rps", col.name = "percent.rib", assay = "RNA")
sn.seurat$nCount_RNA %>% summary
sn.seurat$nFeature_RNA %>% summary
sn.seurat$percent.mt %>% hist(breaks = 100)
sn.seurat$percent.rib %>% summary
# filter high mito content
## cell_type_1 counts
seurat.plots[["BarPlot_celltypes1"]] <- sn.seurat$cell_type_1 %>% table %>%
barplot(col = col.list$alloursn, ylab = "Cell count", xlab = "cell types", cex.names = 0.8, las = 1, horiz = T)
seurat.plots[["BarPlot_celltypes1_HighpercMT"]] <- sn.seurat$cell_type_1[(sn.seurat$percent.mt > 10)] %>% table %>%
barplot(col = col.list$alloursn, ylab = "Cell count", xlab = "cell types", cex.names = 0.8, las = 1, horiz = T)
sn.seurat %>% VlnPlot(features = "percent.mt", group.by = "cell_type_1", cols = col.list$alloursn)
sn.seurat %>% VlnPlot(features = "nFeature_RNA", group.by = "cell_type_1", cols = col.list$alloursn)
# Filter low QC cells
{
sn.seurat %<>% subset(nFeature_RNA > 200)
sn.seurat %<>% subset(percent.mt < 15)
sn.seurat %>% glimpse
}
seurat.plots[["basicQC"]] <- sn.seurat %>%
FeaturePlot(features = c("nCount_RNA", "nFeature_RNA", "percent.mt", "percent.rib"), reduction = "umap", pt.size = 1, max.cutoff = 'q99', label = T, ncol = 2) & NoAxes()
```
A look at the dataset.
```{r sn seurat plots}
# cell_type_1 annotation
seurat.plots[["UMAP_Celltype1"]] <- sn.seurat %>%
DimPlot(reduction = "umap", pt.size = 1, label = T, group.by = 'cell_type_1', cols = col.list$alloursn) + NoLegend()
seurat.plots[["UMAP_Celltype1"]] %>%
ggsave(filename = file.path(ws, "UMAPplot_ourSN_AllCelltypes_labeled.tiff"), device = 'tiff', dpi = 300, units = 'cm', width = 12, height = 12)
# cell_type_1 annotation but no legend and modified plotting theme
seurat.plots[["UMAP_Celltype1_v2"]] <- sn.seurat %>%
DimPlot(reduction = "umap", pt.size = 0.25, label = F, group.by = 'cell_type_1', cols = col.list$alloursn) + NoLegend() + NoAxes() + ggtitle(label = NULL) + theme(plot.background = element_blank(), panel.background = element_blank())
seurat.plots[["UMAP_Celltype1_v2"]] %>%
ggsave(filename = file.path(ws, "UMAPplot_ourSN_AllCelltypes.tiff"), device = 'tiff', dpi = 300, units = 'cm', width = 12, height = 12)
```
Cluster using RNA assay
```{r log(RNA)-driven UMAP and clustering}
# Normalize and scale
{
DefaultAssay(sn.seurat) <- "RNA"
sn.seurat %<>% NormalizeData(normalization.method = "LogNormalize", verbose = T)
sn.seurat %<>% FindVariableFeatures(selection.method = "vst", nfeatures = 3000)
sn.seurat %<>% ScaleData()
}
# Explore the gene expression distribution across cells
## total gene counts
sn.seurat[["RNA"]]@data %>% rowSums() %>% summary
sn.seurat[["RNA"]]@data %>% rowSums() %>% sort(decreasing = T) %>% head(50) ## the most expressed genes overall
sn.seurat[["RNA"]]@data %>% rowSums() %>% hist(breaks = 100)
## gene exp positivity across cells
seurat.results[["nonzero genes"]] <- (sn.seurat[["RNA"]]@data > 0) %>% rowMeans() %>% "*"(100) ## gene expression positivity across cells
seurat.results[["nonzero genes"]] %>% hist(breaks = 100) ## >30k genes are expressed in less than 1 % of cells
## closer look at the variable genes
seurat.results[["rna_varfeat"]] <- sn.seurat %>% HVFInfo(assay = "RNA")
seurat.results[["rna_varfeat"]] %>% arrange(desc(variance.standardized)) %>% top_n(30) ## top 30 variance contributors
sn.seurat %>% VariableFeaturePlot(assay = "RNA")
## select variable features with standardized variance >1.5
selected.var.features <- rownames(seurat.results[["rna_varfeat"]])[(seurat.results[["rna_varfeat"]][["variance.standardized"]] > 1.5)]
selected.var.features %<>% stringr::str_subset(pattern = "^mt-|^Mt-", negate = T) # remove mitochondrial genes
## how many cells express these highly variable genes?
seurat.results[["nonzero genes"]][names(seurat.results[["nonzero genes"]]) %in% selected.var.features] %>%
hist(breaks = 100, main = "In how many % of cells are the variable genes expressed?", xlab = "% of gene positive cells")
(seurat.results[["nonzero genes"]][names(seurat.results[["nonzero genes"]]) %in% selected.var.features] < 5) %>% sum ## 1k (= half) var genes are expressed in less than 5% of cells!
## how many counts do these low cell-present genes have?
lowpresent.vars <- seurat.results[["nonzero genes"]][names(seurat.results[["nonzero genes"]]) %in% selected.var.features] %>% sort() %>% head(400) ## take the bottom 400 genes (= <1% cell-positive genes)
seurat.results[["gene_sums"]] <- sn.seurat[["RNA"]]@counts %>% rowSums()
seurat.results[["gene_sums"]][names(seurat.results[["gene_sums"]]) %in% names(lowpresent.vars)] %>%
hist(breaks = 100, main = "Summed expression of variable features for the bottom % cell-positive genes", xlab = "Summed gene count") ## they have maximum of 300 counts across 8k cells!
## in conclusion, let's evade using the bottom 400 genes, as we want to include only more robust expressers
present.var.features <- selected.var.features[!(selected.var.features %in% names(lowpresent.vars))]
## PCA
{
sn.seurat %<>% RunPCA(assay = "RNA", features = present.var.features, npcs = 50, verbose = T)
sn.seurat %>% DimPlot(reduction = "pca", dims = c(1,2), cols = col.list$alloursn)
sn.seurat %>% ElbowPlot(ndims = 50) | sn.seurat %>% PC_var_explained()
sn.seurat %>% DimHeatmap(cells = 200, reduction = "pca", balanced = T, dims = 1:15)
}
## Explore the 3D PCA
{
dims <- c(1, 2, 3) ## PCs to plot
df <- data.frame(
"ElementName" = sn.seurat@[email protected] %>% rownames(),
"X" = sn.seurat@[email protected][, dims[1]],
"Y" = sn.seurat@[email protected][, dims[2]],
"Z" = sn.seurat@[email protected][, dims[3]],
"Annotation" = sn.seurat$cell_type_1
)
df %<>% sample_n(size = 1000) # (optional) to increase plotting speed
df %>% plot_ly(x = .[["X"]], y = .[["Y"]], z = .[["Z"]], type="scatter3d", mode = "markers", color = .[["Annotation"]], colors = col.list$alloursn)
}
## UMAP
pc_dims <- 1:15
{
sn.seurat %<>% RunUMAP(reduction = "pca", dims = pc_dims, verbose = T)
sn.seurat %>% DimPlot(reduction = "umap", group.by = "cell_type_1", label = T)
}
## Clustering
{
sn.seurat %<>% FindNeighbors(reduction = "pca", dims = pc_dims, verbose = T)
for(res in c(0.6, 0.8, 1, 1.2, 1.4)){
sn.seurat %<>% FindClusters(resolution = res, algorithm = 1, verbose = T)
}
}
seurat.plots[["UMAP_RNA_res1.4"]] <- sn.seurat %>% DimPlot(reduction = "umap", pt.size = 1, group.by = "RNA_snn_res.1.4", cols = col.list$big_col_palette, label = T)
```
Cluster using SCT
```{r SCT-driven UMAP and clustering}
DefaultAssay(sn.seurat) <- "RNA"
sn.seurat[["SCT"]] <- NULL
sn.seurat %<>% SetIdent(value = "cell_type_1")
## compute SCT assay and identifying variable features
sn.seurat %<>% SCTransform(variable.features.n = 2000, return.only.var.genes = T)
sn.seurat %>% VariableFeaturePlot()
## let's hand-select genes that are robustly expressed, are of nuclear origin
{
seurat.results[["sct_varfeat"]] <- sn.seurat[["SCT"]] %>% VariableFeatures()
seurat.results[["sct_varfeat"]] %<>% stringr::str_subset(pattern = "^mt-|^Mt-", negate = T) # remove mitochondrial genes
seurat.results[["sct_varfeat"]] %>% length()
}
## in how many cells are the variable genes present?
seurat.results[["nonzero genes"]][names(seurat.results[["nonzero genes"]]) %in% seurat.results[["sct_varfeat"]]] %>%
hist(breaks = 100, main = "% of cells expressing the variable gene")
## PCA
{
sn.seurat %<>% RunPCA(assay = "SCT", features = seurat.results[["sct_varfeat"]], npcs = 50, verbose = T, reduction.name = "sct.pca")
sn.seurat %>% DimPlot(reduction = "sct.pca", dims = c(1,2), cols = col.list$alloursn)
sn.seurat %>% ElbowPlot(ndims = 50)
sn.seurat %>% PC_var_explained()
sn.seurat %>% DimHeatmap(cells = 200, reduction = "sct.pca", balanced = T, dims = 1:15)
}
# exploring PCA
{
sn.seurat %>% DimPlot(reduction = "sct.pca", dims = c(1,2), cols = col.list$alloursn)
sn.seurat %>% DimPlot(reduction = "sct.pca", dims = c(1,3), cols = col.list$alloursn)
sn.seurat %>% DimPlot(reduction = "sct.pca", dims = c(3,4), cols = col.list$alloursn)
sn.seurat %>% DimPlot(reduction = "sct.pca", dims = c(10,11), cols = col.list$alloursn)
}
## exploring 3D PCA plot
{
dims <- c(11, 12, 13) ## PCs to plot
df <- data.frame(
"ElementName" = sn.seurat@[email protected] %>% rownames(),
"X" = sn.seurat@[email protected][, dims[1]],
"Y" = sn.seurat@[email protected][, dims[2]],
"Z" = sn.seurat@[email protected][, dims[3]],
"Annotation" = sn.seurat$cell_type_1
)
df %<>% sample_n(size = 1000) # (optional) to increase plotting speed
df %>% plot_ly(x = .[["X"]], y = .[["Y"]], z = .[["Z"]], type="scatter3d", mode = "markers", color = .[["Annotation"]], colors = col.list$alloursn)
}
## UMAP
pc_dims <- 1:15
{
sn.seurat %<>% RunUMAP(reduction = "sct.pca", dims = pc_dims, verbose = T, reduction.name = "sct.umap")
sn.seurat %>% DimPlot(reduction = "sct.umap", group.by = "cell_type_1", label = T)
}
## Clustering
{
sn.seurat %<>% FindNeighbors(reduction = "sct.pca", dims = pc_dims, verbose = T)
for(res in c(0.6, 0.8, 1, 1.2)){
sn.seurat %<>% FindClusters(resolution = res, algorithm = 1, verbose = T)
}
}
## plot the different resolutions
{
seurat.plots[["UMAP_SCT_res0.6"]] <- sn.seurat %>% DimPlot(reduction = "sct.umap", group.by = "SCT_snn_res.0.6", label = T)
seurat.plots[["UMAP_SCT_res0.8"]] <- sn.seurat %>% DimPlot(reduction = "sct.umap", group.by = "SCT_snn_res.0.8", label = T)
seurat.plots[["UMAP_SCT_res1"]] <- sn.seurat %>% DimPlot(reduction = "sct.umap", group.by = "SCT_snn_res.1", label = T)
seurat.plots[["UMAP_SCT_res1.2"]] <- sn.seurat %>% DimPlot(reduction = "sct.umap", group.by = "SCT_snn_res.1.2", label = T)
}
```
Since both variants produce similar output, we decided to stick with RNA assay as it is better interpretable and does not require re-normalization after every subset. Also, the work of Eltze & Huber, Nat Methods (2023) discussed that although sct does not perform poorly, the robustness of log(RNA) for analysis overshadows these more sophisticated tools.
```{r Removing SCT assay}
sn.seurat[["SCT"]] <- NULL
```
Exploring seurat to filter low quality clusters
```{r explore for cluster removal}
sn.seurat %<>% SetIdent(value = "RNA_snn_res.1.4")
## UMAP with current RNA clustering
seurat.plots[["UMAP_RNA_res1.4"]] <- sn.seurat %>%
DimPlot(reduction = "umap", group.by = "RNA_snn_res.1.4", label = T, pt.size = 1, cols = col.list$big_col_palette) & NoLegend() & NoAxes()
## UMAP with Conditions
seurat.plots[["UMAP_Cond"]] <- sn.seurat %>%
DimPlot(reduction = "umap", group.by = "Condition", pt.size = 1, cols = col.list$Condition, shuffle = T) & NoAxes()
## dittoBarplot with Condition
seurat.plots[["dittoBarplot_Condition"]] <- sn.seurat %>%
dittoBarPlot(var = "Condition", group.by = "RNA_snn_res.1.4", color.panel = col.list$Condition, retain.factor.levels = T) + xlab("")
## dittoBarplot with Phase
seurat.plots[["dittoBarplot_Phase"]] <- sn.seurat %>%
dittoBarPlot(var = "Phase", group.by = "RNA_snn_res.1.4", color.panel = col.list$Phase, retain.factor.levels = T) + xlab("")
## previous cell_type_1 annotation in the new clusters
seurat.plots[["UMAP_celltype1"]] <- sn.seurat %>%
DimPlot(reduction = "umap", group.by = "cell_type_1", label = T) & NoAxes() + theme(legend.position = "none")
## Markers of the res1.4 clusters
seurat.results[["Markers_res1.4"]] <- sn.seurat %>%
FindAllMarkers(assay = "RNA", logfc.threshold = 1, min.pct = 0.3, only.pos = T, verbose = T) %>%
filter(p_val_adj < 0.01) %>%
arrange(p_val_adj) %>%
split(f = .[["cluster"]])
## Background? Even after soupX, there is a lot of neuronal RNA in all cells!
seurat.plots[["NeuronalBackground"]] <- (sn.seurat %>% FeaturePlot(
features = c("Meg3", "Rbfox3"), max.cutoff = 'q99', repel = T, label.size = 1,
reduction = "umap", label = T, raster = F, pt.size = 0.2, ncol = 1, cols = c("white", "#AE0900")) & NoAxes() & NoLegend()) | (
sn.seurat %>% DotPlot(features = c("Meg3", "Rbfox3"), cols = c("white", "#AE0900"), assay = "RNA")
)
## Marker genes and their FeaturePlot
seurat.results[["canonical_markers"]] <- c(
"Rbfox3", "Slc17a7", "Gad1", # Neurons all, GLUT, GABA
"Sox4", # Neuroblast
"Ccdc153", # Ependymal cells
"Slc1a3", "Gfap", # Astrocyte
"Plp1", "Klk6", # Oligodendrocyte
"Serpina3n",
"Pdgfra", # OPC
"Csf1r", "Spp1", # Microglia
"Ptgds", # VLMC
"Flt1" # Vasculature
)
seurat.plots[["FeaturePlot_CanMarkers"]] <- sn.seurat %>% FeaturePlot(
features = seurat.results[["canonical_markers"]], max.cutoff = 'q99', reduction = "umap",
label = F, raster = F, pt.size = 0.2, ncol = 5, cols = c("white", "#AE0900")) & NoAxes() & theme(legend.position = "none")
## VlnPlot for Neuronal markers
seurat.plots[["VlnPlot_NeuronalMarkers"]] <- sn.seurat %>%
VlnPlot(features = c("Rbfox3", "Slc17a7", "Gad1"), group.by = "RNA_snn_res.1.4", pt.size = 0, layer = "RNA", slot = "data", raster = F, ncol = 1, cols = col.list$big_col_palette) & geom_boxplot(width=0.1, fill="white", outlier.size = 0.2) & NoLegend()
## VlnPlot for Glial markers
seurat.plots[["VlnPlot_GlialMarkers"]] <- sn.seurat %>%
VlnPlot(features = c("Slc1a3", "Plp1", "Pdgfra"), group.by = "RNA_snn_res.1.4", pt.size = 0, layer = "RNA", slot = "data", raster = F, ncol = 1, cols = col.list$big_col_palette) & geom_boxplot(width=0.1, fill="white", outlier.size = 0.2) & NoLegend()
## Ridgeplot on nFeatures per cluster (observing double or triple peaks?)
seurat.plots[["RidgePlot_nFeature_RNA"]] <- sn.seurat %>%
RidgePlot(features = "nFeature_RNA", cols = col.list$big_col_palette) & NoLegend()
## Ridgeplot on percent mt
seurat.plots[["RidgePlot_percentMT"]] <- sn.seurat %>%
RidgePlot(features = "percent.mt", cols = col.list$big_col_palette) + theme(legend.position = "none")
## FeaturePlot percent mt
seurat.plots[["FeatPlot_mito"]] <- sn.seurat %>% FeaturePlot(
features = "percent.mt", reduction = "umap",
max.cutoff = 'q99', label = F, raster = F, pt.size = 0.5,
ncol = 1, cols = RColorBrewer::brewer.pal(n = 9, name = "Blues")) + theme(legend.position = "none")
## featureplot percent ribosomal
seurat.plots[["FeatPlot_rib"]] <- sn.seurat %>% FeaturePlot(
features = "percent.rib", reduction = "umap",
max.cutoff = 'q99', label = F, raster = F, pt.size = 0.5,
ncol = 1, cols = RColorBrewer::brewer.pal(n = 9, name = "Greens")) + theme(legend.position = "none")
## ScatterPlot
sn.seurat %>% FeatureScatter(feature1 = "nCount_RNA", feature2 = "Apoe", group.by = "cell_type_1", cols = col.list$alloursn, pt.size = 1.5)
# == Wrap Plots ==
seurat.plots[["WrapPlots_beforeAnnotation"]] <- wrap_plots(seurat.plots[c("UMAP_celltype1", "UMAP_RNA_res1.4", "dittoBarplot_Condition",
"FeaturePlot_CanMarkers", "RidgePlot_nFeature_RNA", "RidgePlot_percentMT",
"FeatPlot_mito", "FeatPlot_rib", "dittoBarplot_Phase"
)], ncol = 6,
design = "AABBCC
DDDEEF
DDDEEF
GGHHII") + plot_annotation(
title = "Zucha 2023: Exploratory view pre-annotation",
subtitle = "After basic QC. n = 7,558 nuclei.")
seurat.plots[["WrapPlots_beforeAnnotation"]] %>% ggsave_tiff(plotname = "WrapPlots_sn_Zucha2023_AfterBasicQC_preAnnotation", height = 30, width = 30)
```
Cluster annotation
```{r cluster annotation and save QC filtered seurat}
# annotate
[email protected] %<>% mutate("Celltypes" = factor(case_when(
RNA_snn_res.1.4 == 0 ~ "OLs",
RNA_snn_res.1.4 == 1 ~ "NeuronsGABA",
RNA_snn_res.1.4 == 2 ~ "NeuronsGABA",
RNA_snn_res.1.4 == 3 ~ "NeuronsGLUT",
RNA_snn_res.1.4 == 4 ~ "Astrocytes",
RNA_snn_res.1.4 == 5 ~ "NeuronsGLUT",
RNA_snn_res.1.4 == 6 ~ "NeuronsGABA",
RNA_snn_res.1.4 == 7 ~ "NeuronsGABA",
RNA_snn_res.1.4 == 8 ~ "NeuronsGLUT",
RNA_snn_res.1.4 == 9 ~ "OLs",
RNA_snn_res.1.4 == 10 ~ "Microglia",
RNA_snn_res.1.4 == 11 ~ "NeuronsGLUT",
RNA_snn_res.1.4 == 12 ~ "NeuronsGLUT",
RNA_snn_res.1.4 == 13 ~ "NeuronsGABA",
RNA_snn_res.1.4 == 14 ~ "NeuronsGLUT",
RNA_snn_res.1.4 == 15 ~ "OPCs",
RNA_snn_res.1.4 == 16 ~ "NeuronsGLUT",
RNA_snn_res.1.4 == 17 ~ "EndothelialCells",
RNA_snn_res.1.4 == 18 ~ "NeuronsGLUT",
RNA_snn_res.1.4 == 19 ~ "VLMCs",
RNA_snn_res.1.4 == 20 ~ "debris",
RNA_snn_res.1.4 == 21 ~ "Astrocytes",
RNA_snn_res.1.4 == 22 ~ "EpendymalCells",
RNA_snn_res.1.4 == 23 ~ "NeuronsGLUT",
RNA_snn_res.1.4 == 24 ~ "Neuroblasts",
RNA_snn_res.1.4 == 25 ~ "NeuronsGABA",
RNA_snn_res.1.4 == 26 ~ "Microglia"
)))
[email protected] %<>% mutate("CelltypesDetailed" = factor(case_when(
RNA_snn_res.1.4 == 0 ~ "OLs1",
RNA_snn_res.1.4 == 1 ~ "NeuronsGABA1",
RNA_snn_res.1.4 == 2 ~ "NeuronsGABA2",
RNA_snn_res.1.4 == 3 ~ "NeuronsGLUT1",
RNA_snn_res.1.4 == 4 ~ "Astrocytes",
RNA_snn_res.1.4 == 5 ~ "NeuronsGLUT2",
RNA_snn_res.1.4 == 6 ~ "NeuronsGABA3",
RNA_snn_res.1.4 == 7 ~ "NeuronsGABA4",
RNA_snn_res.1.4 == 8 ~ "NeuronsGLUT3",
RNA_snn_res.1.4 == 9 ~ "OLs2",
RNA_snn_res.1.4 == 10 ~ "Microglia1",
RNA_snn_res.1.4 == 11 ~ "NeuronsGLUT4",
RNA_snn_res.1.4 == 12 ~ "NeuronsGLUT5",
RNA_snn_res.1.4 == 13 ~ "NeuronsGABA5",
RNA_snn_res.1.4 == 14 ~ "NeuronsGLUT6",
RNA_snn_res.1.4 == 15 ~ "OPCs",
RNA_snn_res.1.4 == 16 ~ "NeuronsGLUT7",
RNA_snn_res.1.4 == 17 ~ "EndothelialCells",
RNA_snn_res.1.4 == 18 ~ "NeuronsGLUT8",
RNA_snn_res.1.4 == 19 ~ "VLMCs",
RNA_snn_res.1.4 == 20 ~ "debris",
RNA_snn_res.1.4 == 21 ~ "Astrocytes2",
RNA_snn_res.1.4 == 22 ~ "EpendymalCells",
RNA_snn_res.1.4 == 23 ~ "NeuronsGLUT9",
RNA_snn_res.1.4 == 24 ~ "Neuroblasts",
RNA_snn_res.1.4 == 25 ~ "NeuronsGABA6",
RNA_snn_res.1.4 == 26 ~ "Microglia2"
)))
## remove debris
sn.seurat %<>% SetIdent(value = "Celltypes")
sn.seurat %<>% subset(idents = c("debris"), invert = T)
sn.seurat$Celltypes %<>% droplevels()
sn.seurat$CelltypesDetailed %<>% droplevels()
{
sn.seurat %<>% FindNeighbors(reduction = "pca", dims = 1:15)
sn.seurat %<>% FindClusters(resolution = 1, cluster.name = "RNA_DebrisFilt_res1")
sn.seurat %<>% RunUMAP(reduction = "pca", dims = 1:15, reduction.name = "umap.filt")
}
seurat.plots[["UMAP_DebrisFiltered"]] <- sn.seurat %>%
DimPlot(reduction = "umap", group.by = "RNA_DebrisFilt_res1", label = T, pt.size = 1, cols = col.list$big_col_palette) & NoLegend() & NoAxes()
# save the filtered seurat
saveRDS(sn.seurat, file = "data/Seurat_sn_MCAO_Zucha2023_QCFiltered.Rds")
```
Markers of annotated clusters
```{r markers of annotated clusters}
DefaultAssay(sn.seurat) <- "RNA"
sn.seurat %<>% SetIdent(value = "Celltypes")
seurat.results[["allmarkers"]] <- FindAllMarkers(sn.seurat, logfc.threshold = 1, assay = 'RNA', verbose = T, only.pos = T) %>%
arrange(p_val_adj) %>%
filter(p_val_adj < 0.01) %>%
split(f = .[["cluster"]])
```
Summarizing plots of finalized sn dataset
```{r summary plots of whole sn dataset}
DefaultAssay(sn.seurat) <- "RNA"
sn.seurat %<>% SetIdent(value = "Celltypes")
# UMAP of Celltypes
seurat.plots[["UMAP of Celltypes"]] <- sn.seurat %>%
DimPlot(reduction = "umap", pt.size = 1, label = T, group.by = 'Celltypes', cols = col.list$Celltypes) + NoLegend() + NoAxes()
# UMAP of Cell subtypes
seurat.plots[["UMAP of Cell Subtypes"]] <- sn.seurat %>%
DimPlot(reduction = "umap", pt.size = 1, label = F, group.by = 'CelltypesDetailed', cols = col.list$CelltypesDetailed) + NoLegend() + NoAxes()
# Cell type frequencies
seurat.plots[["Barplot of Celltypes"]] <- sn.seurat %>%
total_barplot(groupvar = "Celltypes", ylim = 2550)
# Cell Subtype frequencies
seurat.plots[["Barplot of CellSubtypes"]] <- sn.seurat %>%
total_barplot(groupvar = "CelltypesDetailed", ylim = 900)
# Cell type proportions
# Markers dotplot
features <- c('Stmn1', 'Sox4', 'Ccnd2', 'Dcx', # Neuroblast
'Usp29', 'Snhg11', 'Nhs', # Other Neurons
'Gad1', 'Gad2', # GABAergic
'Meg3', 'Rbfox3', 'Nrgn', 'Slc17a6', 'Slc17a7', # Glutamatergic
'Ccdc153', 'Foxj1', # Ependymal
'Aqp4', 'Aldh1l1', 'Slc1a3', 'Gfap', # Astrocyte
'Pdgfra', 'Cspg4', 'Vcan', # OPC
'Mbp', 'Mobp', 'Plp1', 'Cldn11', # Oligo
'Cx3cr1', 'Csf1r', # Microglia
'Slc47a1', 'Mgp', 'Ptgds', # VLMC
'Pdgfrb', 'Flt1', 'Pecam1' # Vasculature
)
seurat.plots[["Dotplot_Markers"]] <- sn.seurat %>%
dittoSeq::dittoDotPlot(vars = features, group.by = "Celltypes", scale = T)
# Displaying a specific gene
sn.seurat %>%
dittoSeq::dittoPlot(var = "Apoe", group.by = "Celltypes", plots = c("ridgeplot", "jitter") , assay = "RNA", slot = "data", color.panel = col.list$Celltypes) + theme(legend.position = "none")
```
Population proportions
```{r proportions}
## proportions
library(dittoSeq)
sn.seurat$Condition %>% table
sn.seurat %>% dittoBarPlot(var = "Condition", group.by = "Celltypes", scale = "count")
sn.seurat %>% dittoBarPlot(var = "Condition", group.by = "Celltypes", scale = "percent")
sn.seurat[['Condition2']] <- case_when( ## simplifying the conditions
sn.seurat$Condition == 'sham' ~ 'Ctrl',
sn.seurat$Condition == 'D1' ~ 'D1',
sn.seurat$Condition == 'D3' ~ 'D3',
sn.seurat$Condition == 'D7' ~ 'D7') %>% factor(levels = c('Ctrl', 'D1', 'D3', 'D7'))
ids <- [email protected]$Condition2 %>% levels; categories <- [email protected]$cell_type_1_simplified %>% levels; counts <- matrix(nrow=length(ids), ncol=length(categories)); rownames(counts) <- ids; colnames(counts) <- categories
for (i in seq_along(ids)) {
for (j in seq_along(categories)) {
count <- [email protected] %>%
filter(Condition2 == ids[i], cell_type_1_simplified == categories[j]) %>%
nrow()
counts[i, j] <- count
}
}; rm(i,j)
counts_mm_0 <- reshape2::melt(counts, id = "rownames") ## total count proportions
ggplot(data = counts_mm_0, aes(x = Var2, y = value, fill = Var1)) +
geom_col(position = "dodge") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) +
ylab('Proportion of cells')
counts <- counts/rowSums(counts)
counts_mm_1 <- reshape2::melt(counts, id = "rownames") ## percent count proportions
## BarPlot on percentage of count proportions
seurat.plots[["BarPlot_sn_CellTypes1simp_bySample"]] <- ggplot(data = counts_mm_1, aes(x = Var2, y = value, fill = Var1)) + ## percent count proportions
geom_col(position = "dodge") +
theme_classic() +
theme(axis.text.x = element_text(angle = 105, hjust = 1, vjust = 0), axis.text.y = element_text(angle = 90, hjust = 0.5, vjust = 0.5)) +
ylab('Proportion of nuclei') +
xlab("") + ggtitle("") + NoLegend() +
theme(axis.text = element_text(family = "OpenSans", size = 25, color = "black"),
axis.title = element_text(family = "OpenSans", size = 25),
plot.background = element_rect(fill = 'transparent', color = NA),
panel.background = element_rect(fill = 'transparent', color = NA)) +
scale_fill_manual(values = c("#525475", "#F1D7AB", "#E6B188", "#D18080")); p
seurat.plots[["BarPlot_sn_CellTypes1simp_bySample"]]
```
=== Astroependymal populations ===
Loading the seurat
```{r seurat load}
astro.seurat <- readRDS("data/seurat_ASTRO_names_soupX.rds")
DefaultAssay(astro.seurat) <- "SCT"
```
```{r seurat object clean up}
astro.seurat %<>% SetIdent(value = "cell_type_2")
astro.seurat$cell_type_2 %>% levels
astro.seurat %<>% subset(idents = "mix", invert = T) ## removing the Meg3+ astrocytes (maternal non-coding RNA), as in Habib et al 2020
# recode the cell type annotations
[email protected] %<>%
mutate(cell_type_2 = recode(cell_type_2,
"ASTRO_TE" = "TE Astrocytes",
"ASTRO_DE" = "DE Astrocytes",
"progenitor Astro" = "Activated Astrocytes",
"reactive Astro" = "Reactive Astrocytes",
"EPEN" = "Ependymal",
"NB" = "Neuroblasts",
"CHORO" = "ChoroidPlexus"
) %>%
factor(levels = c("Neuroblasts",
"Ependymal",
"ChoroidPlexus",
"TE Astrocytes",
"DE Astrocytes",
"Activated Astrocytes",
"Reactive Astrocytes")),
Condition = recode(Condition,
"sham" = "Sham",
"D1" = "1DPI",
"D3" = "3DPI",
"D7" = "7DPI") %>%
factor(levels = c("Sham",
"1DPI",
"3DPI",
"7DPI"))
)
astro.seurat %<>% SetIdent(value = "cell_type_2")
# add ribo and mito percentages
astro.seurat %<>% PercentageFeatureSet(pattern = "mt-", col.name = "percent_mt")
astro.seurat %<>% PercentageFeatureSet(pattern = "Rpl|Rps", col.name = "percent_rib")
```
Overall Markers
```{r Markers}
seurat.results[["Markers_ast_all"]] <-
astro.seurat %>%
FindAllMarkers(
logfc.threshold = 0.58,
assay = 'SCT',
verbose = T,
only.pos = T) %>%
arrange(desc(avg_log2FC)) %>%
split(f = .[["cluster"]])
names(seurat.results[["Markers_ast_all"]]) <- paste0("SN_Ast_", names(seurat.results[["Markers_ast_all"]]))
write.xlsx(seurat.results[["Markers_ast_all"]],
file = file.path(ws, "Markers_sn_AstroEpe.xlsx"), overwrite = T)
astro.seurat %>% FeaturePlot(features = c("Dcx", "Foxj1", "Tmem72"), label = T)
## dotplot
astro.seurat$cell_type_2 %>% levels
{
features_test <- c('Dcx', 'Nrxn3', "Adarb2", # Neuroblasts
'Foxj1', 'Adamts20', 'Tmem212', # Ependymal
'Tmem72', 'Htr2c', "Otx2os1", # Choroid Plexus cells
'Grm3', 'Rgs7', 'Htra1', # TE Astro
'Slc1a3', # astro general
"Gria1", "Fry", "Slc6a11", "Mgat4c", # DE Astro
'Ogt', 'Fam107a', 'Cox8a', 'Aldoc', "Shank1", "Nrgn", # Activated Astro
"Ctsd", 'Gfap', "Clu", 'Apoe', "Ptn", "Gpm6b", "Cd9", "Vim", "Thbs4" # Reactive astro
)
p <- DotPlot(astro.seurat, assay = "SCT", features = features_test, group.by = "cell_type_2", cols = c("#FFF7FB", "#014636")) +
theme_mk +
theme(axis.text.x = element_text(angle = 45,
hjust = 1,
vjust = 1)) +
xlab(NULL) +
ylab(NULL)
print(p)
}
```
Gene ontology analysis for Reactive Astrocytes
```{r Reactive AST markers and GO}
# Direct marker comparison between Reactive and Homeostatic AST
seurat.results[["Markers_ast_ReactiveAST"]] <- astro.seurat %>%
FindMarkers(
ident.1 = "Reactive Astrocytes",
ident.2 = c("DE Astrocytes", "TE Astrocytes"),
logfc.threshold = 0.58,
only.pos = T,
assay = 'SCT',
verbose = T
) %>%
arrange(desc(avg_log2FC)) %>%
rownames_to_column(var = "GeneSymbol") %>%
filter(p_val_adj < 0.01 & !str_detect(GeneSymbol, "^Rp") & !str_detect(GeneSymbol, "^mt"))
write.xlsx(seurat.results[["Markers_ast_ReactiveAST"]],
file = file.path(ws, "Markers_sn_ReacAstro_vs_HomeoAstro.xlsx"))
# Gene Ontology
library(clusterProfiler)
library("org.Mm.eg.db", character.only = TRUE)
organism <- org.Mm.eg.db
background <- rownames(astro.seurat[["SCT"]])
marker_genes <- seurat.results[["Markers_ast_ReactiveAST"]] %>% pull(GeneSymbol)
seurat.results[["ORA_ast_ReactiveAST"]] <-
clusterProfiler::enrichGO(gene = marker_genes,
universe = background, # 'potential DEGs'
keyType = "SYMBOL", # or ENSEMBL
OrgDb = organism,
ont = "ALL", # BP = biological process, MF = molecular function, CC = cellular component
pAdjustMethod = "fdr",
pvalueCutoff = 0.01, #
qvalueCutoff = 0.2,
readable = F,
minGSSize = 5) %>%
clusterProfiler::simplify()
# Add as module
astro.seurat %<>% AddModuleScore(features = list(marker_genes), name = "ReactiveAST_module", assay = 'SCT')
astro.seurat %>% FeaturePlot(features = "ReactiveAST_module1", reduction = "umap")
astro.seurat %>%
enh_vlnplot(feature = "ReactiveAST_module1",
grouping = "cell_type_2",
colors = col.list$astro_cols,
compare_means = F)
# save the results
seurat.results[["ORA_ast_ReactiveAST"]] %>%
write.xlsx(file = file.path(ws, "ORAlist_sn_ReacAstro_vs_HomeoAstro.xlsx"), overwrite = T)
```
Gene Ontology analysis Activated Astrocytes
```{r Activated AST markers and GO}
# Direct marker comparison between Reactive and Homeostatic AST
seurat.results[["Markers_ast_ActivatedAST"]] <- astro.seurat %>%
FindMarkers(
ident.1 = "Activated Astrocytes",
ident.2 = c("DE Astrocytes", "TE Astrocytes"),
logfc.threshold = 0.58,
only.pos = T,
assay = 'SCT',
verbose = T
) %>%
arrange(desc(avg_log2FC)) %>%
rownames_to_column(var = "GeneSymbol") %>%
filter(p_val_adj < 0.01 & !str_detect(GeneSymbol, "^Rp") & !str_detect(GeneSymbol, "^mt"))
# Gene Ontology
library(clusterProfiler)
library("org.Mm.eg.db", character.only = TRUE)
organism <- org.Mm.eg.db
background <- rownames(astro.seurat[["SCT"]])
marker_genes <- seurat.results[["Markers_ast_ActivatedAST"]] %>% pull(GeneSymbol)
seurat.results[["ORA_ast_ActivatedAST"]] <-
clusterProfiler::enrichGO(gene = marker_genes,
universe = background, # 'potential DEGs'
keyType = "SYMBOL", # or ENSEMBL
OrgDb = organism,
ont = "ALL", # BP = biological process, MF = molecular function, CC = cellular component
pAdjustMethod = "fdr",
pvalueCutoff = 0.01, #
qvalueCutoff = 0.2,
readable = F,
minGSSize = 5) %>%
clusterProfiler::simplify()
# Add as module
astro.seurat %<>% AddModuleScore(features = list(marker_genes), name = "ActivatedAST_module", assay = 'SCT')
astro.seurat %>% FeaturePlot(features = "ActivatedAST_module1", reduction = "umap")
astro.seurat %>%
enh_vlnplot(feature = "ActivatedAST_module1",
grouping = "cell_type_2",
colors = col.list$astro_cols,
compare_means = F)
# save the results
seurat.results[["ORA_ast_ActivatedAST"]] %>%
write.xlsx(file = file.path(ws, "ORAlist_sn_ActivatedAstro_vs_HomeoAstro.xlsx"), overwrite = T)
```
Comparing markers from published datasets with our reactive population. Visualizing the metadata list in our spatial data
```{r astrocytes metanalysis}
DefaultAssay(astro.seurat) <- "SCT"
if(!exists("Markers_ast_ReactiveAST", where = seurat.results)){
seurat.results[["Markers_ast_ReactiveAST"]] <- read_all_sheets(
file = file.path(ws, "Markers_sn_ReacAstro_vs_HomeoAstro.xlsx"))
}
# read in the metadata file
seurat.results[["Metadata_reactive_astro"]] <-
read_all_sheets(
file = "data/SupplementaryTable4_Metanalysis_GlialReactivityMarkers.xlsx") %>%
.[names(.) %>% grep(pattern = "astro|DAA", ignore.case = T)] %>% ## keep the astro-related populations
lapply(\(df){as.character(df[[1]])}) # convert dfs to strings
# find intersetions with the metadata list
meta.intersects <-
mapply(\(meta_name, meta_values){
our_markers <- seurat.results[["Markers_ast_ReactiveAST"]] %>% pull(GeneSymbol)
intersection <- intersect(our_markers, meta_values)
cat(crayon::bgBlack(paste0(length(intersection), " genes intersect with ", meta_name, ".", "\n")))
return(intersection)
},
names(seurat.results[["Metadata_reactive_astro"]]),
seurat.results[["Metadata_reactive_astro"]],
SIMPLIFY = FALSE)
# Testing the intersection significance
meta.signif <-
mapply(\(meta_name, meta_values){
background_size <- astro.seurat[["SCT"]] %>% nrow
intersection_size <- meta_values %>% length
meta_set_size <- seurat.results[["Metadata_reactive_astro"]][[meta_name]] %>% length
test <- phyper(
q = intersection_size - 1, ## number of red marbles in the draw -1 (see below)
m = meta_set_size, ## number of red marbles in urn
n = background_size - meta_set_size, ## number of green marbles in urn
k = seurat.results[["Markers_ast_ReactiveAST"]] %>% nrow, ## number of drawn marbles
lower.tail = FALSE ## compute P(X > overlap), hence the '-1' in the q argument
)
return(test)
},
names(meta.intersects),
meta.intersects,
SIMPLIFY = FALSE)
meta.signif %<>% p.adjust(method = "fdr")
meta.signif
# Gene intersection with Habib's Reactive Astrocytes
meta.intersects[["Habib2020_DAA_5XFAD"]]
# Module differences
[email protected] %>% glimpse
astro.seurat %>% enh_vlnplot(
feature = "Astro_DAA_vs_homeostatic_Habib2020_up_1",
grouping = "cell_type_2",
idents = c("TE Astrocytes", "DE Astrocytes", "Reactive Astrocytes"),
colors = col.list$astro_cols,
compare_means = F,
ref.group = "Reactive Astrocytes",
stat_test = "t.test",
paired = F
) +
theme_mk +
remove_grid +
NoLegend() +
xlab("MCAO-induced Astrocyte Populations") +
ylab("Module Score") +
ylim(c(-0.11, 0.9)) +
labs(title = "DAA Signature") +
annotate(geom = "text", x = 3, y = 0.9, label = expression(italic("***P < 0.001")), size = 2.45)
```
Reactive astrocytes (our, metadata) in the spatial data
```{r astrocytes in spatial}
# Add Metadata to spatial
spatial.seurat %<>%
AddModuleScore(
features = seurat.results[["Metadata_reactive_astro"]],
name = names(seurat.results[["Metadata_reactive_astro"]]))
# Add our Reactive Astro to spatial
spatial.seurat %<>%
AddModuleScore(features = list(seurat.results[["Markers_ast_ReactiveAST"]] %>% pull(GeneSymbol),
seurat.results[["Markers_ast_ActivatedAST"]] %>% pull(GeneSymbol)),
name = c("Zucha_sn_reactive_astro", "Zucha_sn_activated_astro"))
## Show the astro modules
spatial.seurat %>% SpatialPlot(
features = c("Habib2020_DAA_5XFAD3", "Zucha_sn_reactive_astro1", "Zucha_sn_activated_astro2"),
images = c("Ctrl", "1DPI", "3DPI", "7DPI"),
image.alpha = 0.1,
stroke = 0,
crop = T
) &
scale_fill_gradientn(colours = c("#4D4D4D", "#FFFFFF", "#016C59")) &
scale_alpha_continuous(c(0.8, 1)) &
theme_mk &
remove_grid &
NoLegend() &
NoAxes()
# perform correlation test
cor.test([email protected][["Habib2020_DAA_5XFAD3"]],
[email protected][["Zucha_sn_reactive_astro1"]],
method = "pearson")
plot(x = [email protected][["Habib2020_DAA_5XFAD3"]],
y = [email protected][["Zucha_sn_reactive_astro1"]])
ggplot(aes(x = Zucha_sn_reactive_astro1, y = Habib2020_DAA_5XFAD3)) +
geom_point(aes(color = Zucha_sn_reactive_astro1), size = 0.5) +
scale_color_gradientn(colors = c("#3690C0", "#014636")) +
geom_smooth(method = 'lm', se = F, color = "black") +
annotate(geom = "text", x = 1.2, y = 0.2, label = expression(italic(rho == 0.946)), hjust = 1, size = 2.45) +
annotate(geom = "text", x = 1.2, y = 0.1, label = expression(italic("***P < 0.001")), hjust = 1, size = 2.45) +
xlab("Reactive Astrocyte signature") +
ylab("DAA signature") +
theme_mk +
theme(legend.position = "none")
```
Projections on how the origin of the astro populations, based on the Zeisel et al annotation. Calculation of the projections is in a separate markdown.
```{r Brain region projections}
## plot
astro.seurat@assays %>% names
DefaultAssay(astro.seurat) <- "prediction_ASTRO_region" ## azimuth projection based on Zeisel et al
astro.seurat@assays$prediction_ASTRO_region %>% dimnames %>% .[1] ## brain region names
## where are the reactive astro populations from?
astro.seurat %>% VlnPlot(features = "Telencephalon", group.by = "cell_type_2") ## telencephalon
astro.seurat %>% VlnPlot(features = "Hypothalamus,Thalamus,Midbrain dorsal,Midbrain ventral,Pons,Medulla,Spinal cord", group.by = "cell_type_2") ##diencephalon
(FeaturePlot(astro.seurat, features = c("Telencephalon"), pt.size = 0.25, cols = brewer.pal(n = 9, name = "BuGn")[3:9]) + ## telencephalon projection
theme(plot.background = element_blank(), panel.background = element_blank()))
(FeaturePlot(astro.seurat, features = c("Hypothalamus,Thalamus,Midbrain dorsal,Midbrain ventral,Pons,Medulla,Spinal cord"), pt.size = 0.25, cols = brewer.pal(n = 9, name = "BuGn")[3:9]) + ## diencephalon projection
theme(plot.background = element_blank(), panel.background = element_blank()))
```
save processed astro for visual markdown
```{r save astro seurat}
saveRDS(astro.seurat, "data/seurat_ASTRO_1DP_11.rds")
```
=== Microglial populations. ===
Loading the microglial sn seurat
```{r seurat load}
mg.seurat <- readRDS("data/seurat_MG_names_soupX.rds")
DefaultAssay(mg.seurat) <- "SCT"
```
```{r seurat clean up}
mg.seurat %<>% SetIdent(value = "cell_type_2")
mg.seurat$cell_type_2 %>% levels
mg.seurat %<>% subset(idents = "debris", invert = T) ## remove dead cells
[email protected] %<>%
mutate(cell_type_2 = recode(cell_type_2,
"homeostatic" = "Homeostatic",
"TAM" = "Reactive") %>%
factor(levels = c("Homeostatic", "Reactive")),
Condition = recode(Condition,
"sham" = "Sham",
"D1" = "1DPI",
"D3" = "3DPI",
"D7" = "7DPI") %>%
factor(levels = c("Sham",
"1DPI",
"3DPI",
"7DPI"))
)
[email protected] %>% glimpse
```
Marker genes, dotplot, volcano plot.
```{r Markers and Volcano}
mg.seurat %<>% SetIdent(value = "cell_type_2")
# Calculate Markers
seurat.results[["Markers_sn_MG"]] <-
mg.seurat %>%
FindAllMarkers(
assay = "SCT",
logfc.threshold = 0.58,
verbose = T,
only.pos = T) %>%
arrange(desc(avg_log2FC)) %>%
filter(p_val_adj < 0.01) %>%
split(f = .[["cluster"]])
names(seurat.results[["Markers_sn_MG"]]) <- paste0("SN_MG_", names(seurat.results[["Markers_sn_MG"]]))
# save the marker list
seurat.results[["Markers_sn_MG"]] %>%
write.xlsx(file = file.path(ws, "Markers_sn_MG.xlsx"), overwrite = T)
## Dotplot ####
{
features_test <- c('Hexb', 'Cx3cr1', 'P2ry12', 'Tmem119', # homeo MG
'Apoe', 'Ctsb', 'Abca1', 'Hif1a', 'Spp1', 'Sash1', 'H2-D1', 'Lyz2', 'Trem2', 'Igf1', "Lgals3", 'Gpnmb' ## reactive mg
)
p <- DotPlot(mg.seurat,
assay = "SCT",
features = features_test,
group.by = "cell_type_2",
cols = c("#FFF7FB", "#A50F15")) +
theme_mk +
theme(axis.text.x = element_text(angle = 45,
hjust = 1,
vjust = 1)) +
xlab(NULL) +
ylab(NULL)
print(p)
}
## Volcano plot ####
library(EnhancedVolcano)
marker.df <- mg.seurat.markers.TAM
keyvals.colour <- ifelse(
marker.df$avg_log2FC < -0.58 & marker.df$p_val_adj < 0.01, '#3288BD',
ifelse(marker.df$avg_log2FC > 0.58 & marker.df$p_val_adj < 0.01, '#D53E4F',
'#E7E7E7'))
names(keyvals.colour)[keyvals.colour == '#3288BD'] <- 'downregulated'; names(keyvals.colour)[keyvals.colour == '#D53E4F'] <- 'upregulated'; names(keyvals.colour)[keyvals.colour == '#E7E7E7'] <- 'insignificant'