-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTime_Course_scRNA.Rmd
1821 lines (1547 loc) · 96.1 KB
/
Time_Course_scRNA.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: "Time course dataset"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(dplyr)
library(Seurat)
library(patchwork)
library(ggplot2)
library(RColorBrewer)
library(scDblFinder)
library(SummarizedExperiment)
library(stringr)
library(tidyr)
library(ggforce)
library(cluster)
library(rBCS)
library(ggrepel)
library(reshape2)
library(ComplexHeatmap)
library(circlize)
```
```{r}
# Define colors
custom_colors <- list()
colors_dutch <- c(
'#FFC312','#C4E538','#12CBC4','#FDA7DF','#ED4C67',
'#F79F1F','#A3CB38','#1289A7','#D980FA','#B53471',
'#EE5A24','#009432','#0652DD','#9980FA','#833471',
'#EA2027','#006266','#1B1464','#5758BB','#6F1E51'
)
colors_spanish <- c(
'#40407a','#706fd3','#f7f1e3','#34ace0','#33d9b2',
'#2c2c54','#474787','#aaa69d','#227093','#218c74',
'#ff5252','#ff793f','#d1ccc0','#ffb142','#ffda79',
'#b33939','#cd6133','#84817a','#cC31e35','#ccae62'
)
custom_colors$discrete <- c(colors_dutch, colors_spanish)
```
```{r}
## Read the pilot data.
D34_r0_P.data <- Read10X(data.dir = "/gau/isilon/int/singlecell_runs/211106_10x_iPSCpacemaker/d34_P_r1/outs/filtered_feature_bc_matrix")
D34_r0_P <- CreateSeuratObject(counts = D34_r0_P.data, project = "D34_r0_P")
```
```{r}
## Read other pacemaker cell samples in the study phase data.
for (file in c("D3_r1","D3_r2","D4_r1","D4_r2","D6_r1","D6_r2","D10_r1","D10_r2","D23_r1","D23_r2","D34_r1_P", "D34_r2_P")){
seurat_data <- Read10X(data.dir = paste0("/gau/isilon/int/singlecell_runs/220207_10x_iPSC_pacemaker_studyphase_RNA/", file, "/outs/filtered_feature_bc_matrix"))
seurat_obj <- CreateSeuratObject(counts = seurat_data,
project = file)
assign(file, seurat_obj)
}
```
```{r}
## Merge all pacemaker samples together
Pacemaker.cell.samples <- merge(D3_r1, y = c(D3_r2, D4_r1, D4_r2, D6_r1, D6_r2, D10_r1, D10_r2, D23_r1, D23_r2, D34_r0_P, D34_r1_P, D34_r2_P), add.cell.ids = c("D3_r1", "D3_r2", "D4_r1", "D4_r2", "D6_r1", "D6_r2", "D10_r1", "D10_r2", "D23_r1", "D23_r2", "D34_r0_P", "D34_r1_P", "D34_r2_P"), project = "Pacemaker.cell.samples")
head(colnames(Pacemaker.cell.samples))
table(Pacemaker.cell.samples$orig.ident)
```
```{r}
# Visualize the number of cell counts per sample
tmp.meta.data <- [email protected]
tmp.meta.data$orig.ident=factor(tmp.meta.data$orig.ident, levels = names(sort(table(tmp.meta.data$orig.ident))))
tmp.meta.data %>%
ggplot(aes(x=orig.ident, fill=orig.ident)) +
geom_bar() +
#theme_classic() +
theme(axis.text.x = element_text(angle = 0, vjust = 1, hjust=1)) +
theme(plot.title = element_text(hjust=0.5, face="bold"), legend.position = 'none') +
ggtitle("NCells") +
scale_fill_manual(values = custom_colors$discrete) +
coord_flip() + ylab("Cell Count") + xlab("Sample")
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QC_Metrics/Cell_Counts.pdf", height = 5, width = 6)
```
```{r}
# Identify doublets for each sample separately.
#sce <- data.frame(orig.ident=c(), nCount_RNA=c(),nFeature_RNA=c(),ident=c(),scDblFinder.weighted=c(),scDblFinder.ratio=c(), scDblFinder.score=c(), scDblFinder.class=c())
sce <- data.frame()
for(sample in c("D3_r1", "D3_r2", "D4_r1", "D4_r2", "D6_r1", "D6_r2", "D10_r1", "D10_r2", "D23_r1", "D23_r2", "D34_r0_P", "D34_r1_P", "D34_r2_P")){
tmp_subset <- subset(Pacemaker.cell.samples, subset = orig.ident == sample)
tmp_sce <- scDblFinder(as.SingleCellExperiment(tmp_subset))
sce <- rbind(sce, as.data.frame(colData(tmp_sce)))
p1 <- ggplot(as.data.frame(colData(tmp_sce)), aes(x =scDblFinder.class, y = nCount_RNA, fill = scDblFinder.class)) +
geom_violin(draw_quantiles = c(0.5), scale = 'area', trim = FALSE) +
theme_bw() +
scale_fill_manual(values = custom_colors$discrete) +
#scale_x_discrete(limits = rev(levels([email protected]$multiplet_class))) +
scale_y_log10(labels = scales::comma) +
labs(title = 'Number of transcripts', subtitle = 'log-scale') +
theme(
axis.title = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
legend.position = 'none'
) +
coord_flip()
p2 <- ggplot(as.data.frame(colData(tmp_sce)), aes(x = scDblFinder.class, y = nFeature_RNA, fill = scDblFinder.class)) +
geom_violin(draw_quantiles = c(0.5), scale = 'area', trim = FALSE) +
theme_bw() +
scale_fill_manual(values = custom_colors$discrete) +
#scale_x_discrete(limits = rev(levels([email protected]$multiplet_class))) +
scale_y_log10(labels = scales::comma) +
labs(title = 'Number of expressed genes', subtitle = 'log-scale') +
theme(
axis.title = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
legend.position = 'none'
) +
coord_flip()
ggsave(
paste0("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QC_Metrics/QC_ncount_nfeature_by_multiplet_class_",sample,".png"),
p1 + p2 + plot_layout(ncol = 2),
height = 7, width = 10
)
}
# Check the doublet vs. singlet when putting the results for all samples together.
p1 <- ggplot(sce, aes(x =scDblFinder.class, y = nCount_RNA, fill = scDblFinder.class)) +
geom_violin(draw_quantiles = c(0.5), scale = 'area', trim = FALSE) +
theme_bw() +
scale_fill_manual(values = custom_colors$discrete) +
#scale_x_discrete(limits = rev(levels([email protected]$multiplet_class))) +
scale_y_log10(labels = scales::comma) +
labs(title = 'Number of transcripts', subtitle = 'log-scale') +
theme(
axis.title = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
legend.position = 'none'
) +
coord_flip()
p2 <- ggplot(sce, aes(x = scDblFinder.class, y = nFeature_RNA, fill = scDblFinder.class)) +
geom_violin(draw_quantiles = c(0.5), scale = 'area', trim = FALSE) +
theme_bw() +
scale_fill_manual(values = custom_colors$discrete) +
#scale_x_discrete(limits = rev(levels([email protected]$multiplet_class))) +
scale_y_log10(labels = scales::comma) +
labs(title = 'Number of expressed genes', subtitle = 'log-scale') +
theme(
axis.title = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
legend.position = 'none'
) +
coord_flip()
ggsave(
paste0("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QC_Metrics/QC_ncount_nfeature_by_multiplet_class_","all_samples",".png"),
p1 + p2 + plot_layout(ncol = 2),
height = 7, width = 10
)
# Deposit the multiplet class to Seurat Object.
table(rownames(sce)==rownames([email protected]))
#sce <- rbind(sce, as.data.frame(colData(sce_D3_r1)))
#subset_D3_r1 <- subset(Pacemaker.cell.samples, subset = orig.ident == "D3_r1")
#sce_D3_r1 <- scDblFinder(as.SingleCellExperiment(subset_D3_r1))
#hahaha<-as.SingleCellExperiment(Pacemaker.cell.samples)
Pacemaker.cell.samples$multiplet_class <- sce$scDblFinder.class
doublet_count <- [email protected] %>%
filter(multiplet_class != 'singlet') %>%
group_by(orig.ident) %>%
summarize(count = n()) %>%
as.data.frame() %>%
arrange(count)
doublet_count$orig.ident = factor(doublet_count$orig.ident, levels = levels(tmp.meta.data$orig.ident))
ggplot(doublet_count, aes(x = orig.ident, y = count, fill = orig.ident)) +
geom_col(color = 'black') +
theme_bw() +
scale_fill_manual(values = custom_colors$discrete) +
scale_y_continuous(name = 'Number of doublets', labels = scales::comma) +
theme(
axis.title.y = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
legend.position = 'none'
) +
coord_flip()
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QC_Metrics/QC_number_of_doublets_by_sample.pdf", height = 5, width = 6)
# Calculate ratio of doublet.
tmp.cell.count <- as.data.frame(table(tmp.meta.data$orig.ident))
doublet_ratio <- merge(doublet_count, tmp.cell.count, by.x = "orig.ident", by.y = "Var1")
names(doublet_ratio) <- c("orig.ident", "doublet.count", "cell.count")
doublet_ratio <- mutate(doublet_ratio, doublet.ratio = doublet.count/cell.count)
doublet_ratio <- arrange(doublet_ratio, doublet.ratio)
doublet_ratio$orig.ident = factor(doublet_ratio$orig.ident, levels = doublet_ratio$orig.ident)
ggplot(doublet_ratio, aes(x = orig.ident, y = doublet.ratio, fill = orig.ident)) +
geom_col(color = 'black') +
theme_bw() +
scale_fill_manual(values = custom_colors$discrete) +
scale_y_continuous(name = 'Proportion of doublets', labels = scales::comma) +
theme(
axis.title.y = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
legend.position = 'none'
) +
coord_flip()
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QC_Metrics/QC_proportion_of_doublets_by_sample.pdf", height = 5, width = 6)
write.table(doublet_ratio, "/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QC_Metrics/QC_proportion_of_doublets_by_sample.txt", sep = "\t", quote = F, row.names = F)
```
```{r}
# Add number of genes per UMI for each cell to metadata
Pacemaker.cell.samples$log10GenesPerUMI <- log10(Pacemaker.cell.samples$nFeature_RNA) / log10(Pacemaker.cell.samples$nCount_RNA)
```
```{r}
## Calculate the percentage of reads that map to the mitochondrial genome
Pacemaker.cell.samples[["percent.mt"]] <- PercentageFeatureSet(Pacemaker.cell.samples, pattern = "^MT-")
head([email protected], 5)
# Create .RData object to load at any time
#save(Pacemaker.cell.samples, file="/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Pacemaker.Cell.Samples.seurat.RData")
#load("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/D34_seurat.RData")
```
```{r}
# Visualize QC metrics as a violin plot
median_nFeature <- median(Pacemaker.cell.samples$nFeature_RNA)
# 4364
mad_nFeature <- mad(Pacemaker.cell.samples$nFeature_RNA)
# [1] 1673.855
Pacemaker.cell.samples$orig.ident = factor(Pacemaker.cell.samples$orig.ident, levels = unique(Pacemaker.cell.samples$orig.ident))
VlnPlot(Pacemaker.cell.samples, features = "nFeature_RNA", group.by = "orig.ident", pt.size = 0, sort = FALSE, cols = c(brewer.pal(12,"Paired"),brewer.pal(12,"Set3")[12])) + geom_hline(yintercept = c(500, 2000, 10000), linetype = 2) + scale_y_continuous(breaks=seq(0,10000,1000)) + scale_x_discrete(limits = c("D3_r1", "D3_r2", "D4_r1", "D4_r2", "D6_r1", "D6_r2", "D10_r1", "D10_r2", "D23_r1", "D23_r2", "D34_r0_P", "D34_r1_P", "D34_r2_P"))
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QC_Metrics/nFeature_RNA.pdf")
median_nCount <- median(Pacemaker.cell.samples$nCount_RNA)
median_nCount
# 17280
mad_nCount <- mad(Pacemaker.cell.samples$nCount_RNA)
mad_nCount
# 10809.64
VlnPlot(Pacemaker.cell.samples, features = "nCount_RNA", group.by = "orig.ident", pt.size = 0, sort = FALSE, cols = c(brewer.pal(12,"Paired"),brewer.pal(12,"Set3")[12])) + geom_hline(yintercept = c(1500, 5000, 80000), linetype = 2) + scale_y_continuous(breaks=seq(0,150000,30000)) + scale_x_discrete(limits = c("D3_r1", "D3_r2", "D4_r1", "D4_r2", "D6_r1", "D6_r2", "D10_r1", "D10_r2", "D23_r1", "D23_r2", "D34_r0_P", "D34_r1_P", "D34_r2_P"))
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QC_Metrics/nCount_RNA.pdf")
median_percent.mt <- median(Pacemaker.cell.samples$percent.mt)
median_percent.mt
# 5.313547
mad_percent.mt <- mad(Pacemaker.cell.samples$percent.mt)
mad_percent.mt
# 3.095939
VlnPlot(Pacemaker.cell.samples, features = "percent.mt", group.by = "orig.ident", pt.size = 0, sort = FALSE, cols = c(brewer.pal(12,"Paired"),brewer.pal(12,"Set3")[12])) + geom_hline(yintercept = c(10, 15, 40), linetype = 2) + scale_y_continuous(breaks=seq(0,100,20)) + scale_x_discrete(limits = c("D3_r1", "D3_r2", "D4_r1", "D4_r2", "D6_r1", "D6_r2", "D10_r1", "D10_r2", "D23_r1", "D23_r2", "D34_r0_P", "D34_r1_P", "D34_r2_P"))
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QC_Metrics/percent.mt.pdf")
```
```{r}
# Visualize the number UMIs/transcripts per cell
tmp.meta.data %>%
ggplot(aes(color=orig.ident, x=nCount_RNA, fill= orig.ident)) +
geom_density(alpha = 0.2) +
scale_x_log10() +
theme_classic() +
ylab("Cell density") +
geom_vline(xintercept = c(1500, 80000))
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QC_Metrics/UMI_Counts_DensityPlot.pdf")
```
```{r}
# Visualize the distribution of genes detected per cell via histogram
tmp.meta.data %>%
ggplot(aes(color=orig.ident, x=nFeature_RNA, fill= orig.ident)) +
geom_density(alpha = 0.2) +
theme_classic() +
scale_x_log10() +
geom_vline(xintercept = c(500, 1000, 7000, 9000, 10000)) +
#scale_color_manual(values = c(brewer.pal(12,"Paired"),brewer.pal(12,"Set3")[12]))
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QC_Metrics/Gene_Counts_DensityPlot.pdf")
```
```{r}
# Visualize the correlation between genes detected and number of UMIs and determine whether strong presence of cells with low numbers of genes/UMIs
tmp.meta.data = [email protected]
tmp.meta.data$orig.ident=factor(tmp.meta.data$orig.ident, levels = unique(tmp.meta.data$orig.ident))
tmp.meta.data %>%
ggplot(aes(x=nCount_RNA, y=nFeature_RNA, color=percent.mt)) +
geom_point() +
scale_colour_gradient(low = "gray90", high = "orange") +
stat_smooth(method=lm) +
scale_x_log10() +
scale_y_log10() +
theme_classic() +
geom_vline(xintercept = 500) +
geom_hline(yintercept = 250) +
facet_wrap(~orig.ident)
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QC_Metrics/Cor_UMI&Genes.pdf", width = 20, height = 15)
```
```{r}
# Visualize the distribution of mitochondrial gene expression detected per cell
tmp.meta.data %>%
ggplot(aes(color=orig.ident, x=percent.mt, fill=orig.ident)) +
geom_density(alpha = 0.2) +
#scale_x_log10() +
theme_classic() +
geom_vline(xintercept =c(30,40,50))
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QC_Metrics/percent.mt_DensityPlot.pdf")
```
```{r}
# Visualize the overall complexity of the gene expression by visualizing the genes detected per UMI
tmp.meta.data %>%
ggplot(aes(x=log10GenesPerUMI, color = orig.ident, fill=orig.ident)) +
geom_density(alpha = 0.2) +
theme_classic() +
geom_vline(xintercept = 0.8)
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QC_Metrics/Complexity_DensityPlot.pdf")
```
```{r}
# Filter out low quality cells using selected thresholds - these will change with experiment
# Apply more stringent cutoff for percent.mt for early time points.
Pacemaker.cell.samples
#An object of class Seurat
#36601 features across 122589 samples within 1 assay
#Active assay: RNA (36601 features, 0 variable features)
D3toD6.pacemaker.samples <- subset(x = Pacemaker.cell.samples,
subset= orig.ident == "D3_r1" |
orig.ident == "D3_r2" |
orig.ident == "D4_r1" |
orig.ident == "D4_r2" |
orig.ident == "D6_r1" |
orig.ident == "D6_r2")
D3toD6.pacemaker.samples
#An object of class Seurat
#36601 features across 58189 samples within 1 assay
#Active assay: RNA (36601 features, 0 variable features)
Filtered.D3toD6.pacemaker.samples <- subset(x = D3toD6.pacemaker.samples,
subset = (nCount_RNA > 5000) &
(nCount_RNA < 80000) &
(nFeature_RNA > 2000) &
(nFeature_RNA < 10000) &
(percent.mt < 10))
Filtered.D3toD6.pacemaker.samples
#An object of class Seurat
#36601 features across 48697 samples within 1 assay
#Active assay: RNA (36601 features, 0 variable features)
D10toD23.pacemaker.samples <- subset(x = Pacemaker.cell.samples,
subset= orig.ident == "D10_r1" |
orig.ident == "D10_r2" |
orig.ident == "D23_r1" |
orig.ident == "D23_r2")
D10toD23.pacemaker.samples
#An object of class Seurat
#36601 features across 39364 samples within 1 assay
#Active assay: RNA (36601 features, 0 variable features)
Filtered.D10toD23.pacemaker.samples <- subset(x = D10toD23.pacemaker.samples,
subset = (nCount_RNA > 5000) &
(nCount_RNA < 80000) &
(nFeature_RNA > 2000) &
(nFeature_RNA < 10000) &
(percent.mt < 15))
Filtered.D10toD23.pacemaker.samples
#An object of class Seurat
#36601 features across 34761 samples within 1 assay
#Active assay: RNA (36601 features, 0 variable features)
D34.pacemaker.samples <- subset(x = Pacemaker.cell.samples,
subset= orig.ident == "D34_r0_P" |
orig.ident == "D34_r1_P" |
orig.ident == "D34_r2_P")
D34.pacemaker.samples
#An object of class Seurat
#36601 features across 25036 samples within 1 assay
#Active assay: RNA (36601 features, 0 variable features)
Filtered.D34.pacemaker.samples <- subset(x = D34.pacemaker.samples,
subset = (nCount_RNA > 5000) &
(nCount_RNA < 80000) &
(nFeature_RNA > 2000) &
(nFeature_RNA < 10000) &
(percent.mt < 40))
Filtered.D34.pacemaker.samples
#An object of class Seurat
#36601 features across 19038 samples within 1 assay
#Active assay: RNA (36601 features, 0 variable features)
# Merge the filtered samples back together.
filtered.pacemaker.samples <- merge(Filtered.D3toD6.pacemaker.samples, y = c(Filtered.D10toD23.pacemaker.samples, Filtered.D34.pacemaker.samples), project = "Filtered.pacemaker.samples")
Filtered.pacemaker.samples
#An object of class Seurat
#36601 features across 102496 samples within 1 assay
#Active assay: RNA (36601 features, 0 variable features)
rm(Filtered.D3toD6.pacemaker.samples)
rm(Filtered.D10toD23.pacemaker.samples)
rm(Filtered.D34.pacemaker.samples)
rm(D3toD6.pacemaker.samples)
rm(D10toD23.pacemaker.samples)
rm(D34.pacemaker.samples)
```
```{r}
# Gene-level filtering
# Extract counts
counts <- GetAssayData(object = filtered.pacemaker.samples, slot = "counts")
# Output a logical matrix specifying for each gene on whether or not there are more than zero counts per cell
nonzero <- counts > 0
# Try different cutoffs to choose a min.cell cutoff.
ngenes_retained <- c()
for(i in seq(10,100,10)){
tmp_keep_genes <- Matrix::rowSums(nonzero) >= i
tmp_filtered_counts <- counts[tmp_keep_genes, ]
ngenes_retained <- c(ngenes_retained,dim(tmp_filtered_counts)[1])
}
pdf("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QC_Metrics/Min.cell.cutoffs.Vs.NGenes.pdf")
plot(seq(10,100,10), ngenes_retained, type = "o")
dev.off()
# Decide only keeping those genes expressed in more than 30 cells
keep_genes <- Matrix::rowSums(nonzero) >= 30
filtered_counts <- counts[keep_genes, ]
# Reassign to filtered Seurat object
filtered.pacemaker.samples <- CreateSeuratObject(filtered_counts, meta.data = [email protected])
filtered.pacemaker.samples
#An object of class Seurat
#27586 features across 102496 samples within 1 assay
#Active assay: RNA (27586 features, 0 variable features)
table([email protected]$orig.ident)
# D10_r1 D10_r2 D23_r1 D23_r2 D3_r1 D3_r2 D34_r0_P D34_r1_P
# 7556 10364 8627 8214 5401 5874 4336 8414
#D34_r2_P D4_r1 D4_r2 D6_r1 D6_r2
# 6288 8302 8661 10144 10315
write.table(as.data.frame(table([email protected]$orig.ident)), "/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QC_Metrics/NCells_Postfiltering.txt", quote = F, sep = "\t", row.names = F)
```
```{r}
# Re-assess QC metrics
# Check the number of retained doublets. Turns out most of them retained.
write.table(as.data.frame(table([email protected]$orig.ident, [email protected]$multiplet_class)),"/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QC_Metrics/NDoublets_Postfiltering.txt", quote = F, sep = "\t", row.names = F)
# Save filtered subset to new metadata
metadata_clean <- [email protected]
#Perform all of the same QC plots using the filtered data.
filtered.pacemaker.samples$orig.ident = factor(filtered.pacemaker.samples$orig.ident, levels = unique(filtered.pacemaker.samples$orig.ident))
VlnPlot(filtered.pacemaker.samples, features = "nFeature_RNA", pt.size = 0, sort = FALSE, cols = c(brewer.pal(12,"Paired"),brewer.pal(12,"Set3")[12]), group.by = "orig.ident") + geom_hline(yintercept = c(500, 2000, 10000), linetype = 2) + scale_y_continuous(breaks=seq(0,10000,1000)) + scale_x_discrete(limits = c("D3_r1", "D3_r2", "D4_r1", "D4_r2", "D6_r1", "D6_r2", "D10_r1", "D10_r2", "D23_r1", "D23_r2", "D34_r0_P", "D34_r1_P", "D34_r2_P"))
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QCed_Metrics/nFeature_RNA.pdf")
VlnPlot(filtered.pacemaker.samples, features = "nCount_RNA", pt.size = 0, sort = FALSE, cols = c(brewer.pal(12,"Paired"),brewer.pal(12,"Set3")[12]), group.by = "orig.ident") + geom_hline(yintercept = c(1500, 5000, 80000), linetype = 2) + scale_y_continuous(breaks=seq(0,150000,30000)) + scale_x_discrete(limits = c("D3_r1", "D3_r2", "D4_r1", "D4_r2", "D6_r1", "D6_r2", "D10_r1", "D10_r2", "D23_r1", "D23_r2", "D34_r0_P", "D34_r1_P", "D34_r2_P"))
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QCed_Metrics/nCount_RNA.pdf")
VlnPlot(filtered.pacemaker.samples, features = "percent.mt", pt.size = 0, sort = FALSE, cols = c(brewer.pal(12,"Paired"),brewer.pal(12,"Set3")[12]), group.by = "orig.ident") + geom_hline(yintercept = c(10, 15, 40), linetype = 2) + scale_y_continuous(breaks=seq(0,100,20)) + scale_x_discrete(limits = c("D3_r1", "D3_r2", "D4_r1", "D4_r2", "D6_r1", "D6_r2", "D10_r1", "D10_r2", "D23_r1", "D23_r2", "D34_r0_P", "D34_r1_P", "D34_r2_P"))
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QCed_Metrics/percent.mt.pdf")
# Visualize the number of cell counts per sample
tmp.meta.data <- metadata_clean
tmp.meta.data$orig.ident=factor(tmp.meta.data$orig.ident, levels = names(sort(table(tmp.meta.data$orig.ident))))
tmp.meta.data %>%
ggplot(aes(x=orig.ident, fill=orig.ident)) +
geom_bar() +
#geom_text(aes(label = stat(y), group = orig.ident), stat = 'summary', fun = sum, vjust = -1) +
theme_classic() +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1)) +
theme(plot.title = element_text(hjust=0.5, face="bold")) +
ggtitle("NCells") +
scale_fill_manual(values = c(brewer.pal(12,"Paired"),brewer.pal(12,"Set3")[12]))
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QCed_Metrics/Cell_Counts.pdf")
# Visualize the number UMIs/transcripts per cell
tmp.meta.data %>%
ggplot(aes(color=orig.ident, x=nCount_RNA, fill= orig.ident)) +
geom_density(alpha = 0.2) +
scale_x_log10() +
theme_classic() +
ylab("Cell density") +
geom_vline(xintercept = c(1500, 5000, 80000))
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QCed_Metrics/UMI_Counts_DensityPlot.pdf")
# Visualize the distribution of genes detected per cell via histogram
tmp.meta.data %>%
ggplot(aes(color=orig.ident, x=nFeature_RNA, fill= orig.ident)) +
geom_density(alpha = 0.2) +
theme_classic() +
scale_x_log10() +
geom_vline(xintercept = c(500, 1000, 2000, 7000, 9000, 10000))
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QCed_Metrics/Gene_Counts_DensityPlot.pdf")
# Visualize the correlation between genes detected and number of UMIs and determine whether strong presence of cells with low numbers of genes/UMIs
tmp.meta.data$orig.ident=factor(tmp.meta.data$orig.ident, levels = unique(tmp.meta.data$orig.ident))
tmp.meta.data %>%
ggplot(aes(x=nCount_RNA, y=nFeature_RNA, color=percent.mt)) +
geom_point() +
scale_colour_gradient(low = "gray90", high = "black") +
stat_smooth(method=lm) +
scale_x_log10() +
scale_y_log10() +
theme_classic() +
geom_vline(xintercept = 500) +
geom_hline(yintercept = 250) +
xlim(4000, 81000) +
ylim(1000, 11000) +
theme(axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1)) +
facet_wrap(~orig.ident)
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QCed_Metrics/Cor_UMI&Genes.pdf")
# Visualize the distribution of mitochondrial gene expression detected per cell
tmp.meta.data %>%
ggplot(aes(color=orig.ident, x=percent.mt, fill=orig.ident)) +
geom_density(alpha = 0.2) +
#scale_x_log10() +
theme_classic() +
geom_vline(xintercept =c(10, 15, 40))
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QCed_Metrics/percent.mt_DensityPlot.pdf")
# Visualize the overall complexity of the gene expression by visualizing the genes detected per UMI
tmp.meta.data %>%
ggplot(aes(x=log10GenesPerUMI, color = orig.ident, fill=orig.ident)) +
geom_density(alpha = 0.2) +
theme_classic() +
geom_vline(xintercept = 0.8)
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/QCed_Metrics/Complexity_DensityPlot.pdf")
```
```{r}
# Create .RData object to load at any time
save(filtered.pacemaker.samples, file="/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/filtered.pacemaker.samples.RData")
```
```{r}
# Normalize the counts
seurat_phase <- NormalizeData(filtered.pacemaker.samples)
```
Evaluating effects of cell cycle.
```{r}
# A list of cell cycle markers, from Tirosh et al, 2015, is loaded with Seurat. We can segregate this list into markers of G2/M phase and markers of S phase
s.genes <- cc.genes$s.genes
g2m.genes <- cc.genes$g2m.genes
# Score cells for cell cycle
seurat_phase <- CellCycleScoring(seurat_phase,
g2m.features = g2m.genes,
s.features = s.genes)
## Error
#Warning: The following features are not present in the object: MLF1IP, not searching for symbol synonyms
#Warning: The following features are not present in the object: FAM64A, HN1, not searching for symbol synonyms
# Manually check the ENSG ID for these three genes and found that:
## MLF1IP is CENPU in our reference (ENSG00000151725)
## FAM64A is PIMREG in our reference (ENSG00000129195)
## HN1 is JPT1 in our reference (ENSG00000189159)
intersect(c("FAM64A", "HN1", "MLF1IP"), s.genes)
#[1] "MLF1IP"
intersect(c("FAM64A", "HN1", "MLF1IP"), g2m.genes)
#[1] "FAM64A" "HN1"
# Manually change the names of these cell cycle genes.
s.genes[s.genes=="MLF1IP"] = "CENPU"
g2m.genes[g2m.genes=="FAM64A"] = "PIMREG"
g2m.genes[g2m.genes=="HN1"] = "JPT1"
# Redo score cells for cell cycle
seurat_phase <- CellCycleScoring(seurat_phase,
g2m.features = g2m.genes,
s.features = s.genes)
# Calculate the percentage of cells in different phases.
phase_count <- table([email protected]$orig.ident, [email protected]$Phase)
phase_per <- prop.table(table([email protected]$orig.ident, [email protected]$Phase), 1)*100
write.table(phase_count, "/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/Covariates/CellCyclePhaseCount.txt", quote = F, sep = "\t")
write.table(phase_per, "/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/Covariates/CellCyclePhasePercentage.txt", quote = F, sep = "\t")
# Visualize the distribution of cell cycle markers across
RidgePlot(seurat_phase, features = c("PCNA", "TOP2A", "MCM6", "MKI67"), group.by = "Phase", ncol = 2) & scale_fill_manual(values = c(brewer.pal(12,"Paired"),brewer.pal(12,"Set3")[12]))
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/Covariates/Cell.cycle.markers.by.phase.pdf")
RidgePlot(seurat_phase, features = c("PCNA", "TOP2A", "MCM6", "MKI67"), group.by = "orig.ident", ncol = 2) & scale_y_discrete(limits = rev(c("D3_r1", "D3_r2", "D4_r1", "D4_r2", "D6_r1", "D6_r2", "D10_r1", "D10_r2", "D23_r1", "D23_r2", "D34_r0_P", "D34_r1_P", "D34_r2_P"))) & scale_fill_manual(values = c(brewer.pal(12,"Paired"),brewer.pal(12,"Set3")[12]))
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/Covariates/Cell.cycle.markers.by.sample.pdf")
```
```{r}
# Identify the most variable genes
seurat_phase <- FindVariableFeatures(seurat_phase,
selection.method = "vst",
nfeatures = 4000,
verbose = FALSE)
# Scale the counts
seurat_phase <- ScaleData(seurat_phase)
# Perform PCA
seurat_phase <- RunPCA(seurat_phase, ndims.print = 1:40, nfeatures.print = 10)
# Run UMAP
seurat_phase <- RunUMAP(seurat_phase, dims = 1:40)
# Plot the UMAP colored by cell cycle phase
DimPlot(seurat_phase,
reduction = "umap",
group.by= "Phase",
split.by = "Phase")
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/Covariates/SplitCellCyclePlot.pdf")
DimPlot(seurat_phase,
reduction = "umap",
group.by= "Phase")
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/Covariates/MergedCellCyclePlot.pdf")
DimPlot(seurat_phase,
reduction = "umap",
label = TRUE,
repel = TRUE,
group.by= "orig.ident") + scale_color_discrete(limits = c("D3_r1", "D3_r2", "D4_r1", "D4_r2", "D6_r1", "D6_r2", "D10_r1", "D10_r2", "D23_r1", "D23_r2", "D34_r0_P", "D34_r1_P", "D34_r2_P"))
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/Covariates/MergedCellCyclePlot_Samples.pdf")
#DimHeatmap(seurat_phase, dims = c(8, 10))
```
We do see large differences due to cell cycle. Based on this plot, we would regress out the variation due to cell cycle.
Evaluating effects of mitochodrial expression.
```{r}
# Check quartile values
summary([email protected]$percent.mt)
# Min. 1st Qu. Median Mean 3rd Qu. Max.
# 0.000 3.804 5.183 7.177 7.987 39.948
# Turn mitoRatio into categorical factor vector based on quartile values
[email protected]$mitoFr <- cut([email protected]$percent.mt,
breaks=c(-Inf, 3.804, 5.183, 7.987, Inf),
labels=c("Low","Medium","Medium high", "High"))
# Plot the PCA colored by mitoFr
DimPlot(seurat_phase,
reduction = "umap",
group.by= "mitoFr",
split.by = "mitoFr")
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/Covariates/SplitMitoFrPlot.pdf")
DimPlot(seurat_phase,
reduction = "umap",
group.by= "mitoFr")
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/Covariates/MergedMitoFrPlot.pdf")
```
We do not see large differences due to mitochondrial percentage for the same timepoint. Based on this plot, we would not regress out the variation due to mitochondrial percentage.
Add cell cycle score to filtered.pacemaker.samples for SCTransform.
```{r}
table(rownames([email protected])==rownames([email protected]))
[email protected] <- mutate([email protected], S.Score = [email protected]$S.Score, G2M.Score = [email protected]$G2M.Score, Phase = [email protected]$Phase)
```
Apply sctransform normalization while regress out cell cycle scoring.
```{r}
# SCTranform
## Adjust the limit for allowable object sizes within R (Default is 500 * 1024 ^ 2 = 500 Mb) using the following code:
#options(future.globals.maxSize = 10000 * 1024^2)
filtered.pacemaker.samples <- SCTransform(filtered.pacemaker.samples, method = "glmGamPoi", vars.to.regress = c("S.Score", "G2M.Score"), variable.features.n = 5000)
# Save the seurat object
saveRDS(filtered.pacemaker.samples, "/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/SCTransform.filtered.pacemaker.samples.rds")
#filtered.samples <- readRDS("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/SCTransform.filtered.samples.rds")
```
```{r}
filtered.pacemaker.samples <- RunPCA(filtered.pacemaker.samples)
DimPlot(filtered.pacemaker.samples, reduction = "pca", group.by = "orig.ident") + scale_color_manual(limits = c("D3_r1", "D3_r2", "D4_r1", "D4_r2", "D6_r1", "D6_r2", "D10_r1", "D10_r2", "D23_r1", "D23_r2", "D34_r0_P", "D34_r1_P", "D34_r2_P"), values = c(brewer.pal(12,"Paired"),brewer.pal(12,"Set3")[12]))
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/PCs/MergedPCAPlot.pdf")
filtered.pacemaker.samples$orig.ident <- factor(filtered.pacemaker.samples$orig.ident, levels = unique(filtered.pacemaker.samples$orig.ident))
DimPlot(filtered.pacemaker.samples, reduction = "pca", split.by = "orig.ident", group.by = "orig.ident") + scale_color_manual(limits = c("D3_r1", "D3_r2", "D4_r1", "D4_r2", "D6_r1", "D6_r2", "D10_r1", "D10_r2", "D23_r1", "D23_r2", "D34_r0_P", "D34_r1_P", "D34_r2_P"), values = c(brewer.pal(12,"Paired"),brewer.pal(12,"Set3")[12]))
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/PCs/SplitPCAPlot.pdf", width = 30, height = 5)
```
Determining how many PCs to include in the clustering step to ensure that we are capturing the majority of the variation, or cell types, present in our dataset.
```{r}
# Explore heatmap of PCs
pdf("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/PCs/HeatmapOfPCs_1_12.pdf", width = 25, height = 15)
#DimHeatmap(filtered.pacemaker.samples, dims = 1:25, cells = 500, balanced = TRUE, fast = FALSE)
DimHeatmap(filtered.pacemaker.samples, dims = 1:12, cells = 500, balanced = TRUE)
dev.off()
pdf("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/PCs/HeatmapOfPCs_13_24.pdf", width = 25, height = 15)
DimHeatmap(filtered.pacemaker.samples, dims = 13:24, cells = 500, balanced = TRUE)
dev.off()
pdf("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/PCs/HeatmapOfPCs_25_36.pdf", width = 25, height = 15)
DimHeatmap(filtered.pacemaker.samples, dims = 25:36, cells = 500, balanced = TRUE)
dev.off()
pdf("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/PCs/HeatmapOfPCs_37_48.pdf", width = 25, height = 15)
DimHeatmap(filtered.pacemaker.samples, dims = 37:48, cells = 500, balanced = TRUE)
dev.off()
pdf("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/PCs/HeatmapOfPCs_49_50.pdf", width = 25, height = 15)
DimHeatmap(filtered.pacemaker.samples, dims = 49:50, cells = 500, balanced = TRUE)
dev.off()
# Plot the elbow plot
ElbowPlot(object = filtered.pacemaker.samples, ndims = 50)
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/PCs/ElbowPlot.pdf")
```
Decision: Use the first 40 PCs to generate the clusters.
Cluster the cells
```{r}
# Determine the K-nearest neighbor graph
filtered.pacemaker.samples <- FindNeighbors(object = filtered.pacemaker.samples,
dims = 1:40)
# Determine the clusters for various resolutions
filtered.pacemaker.samples <- FindClusters(object = filtered.pacemaker.samples,
resolution = c(0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 3.0))
# Add more resolution later.
filtered.pacemaker.samples <- FindClusters(object = filtered.pacemaker.samples,
resolution = c(0.1, 0.3, 0.5, 0.7, 0.9, 1.1, 1.3, 1.5, 1.7, 1.9, 2.1))
# Output newly added resolution to import into bioturing.
add.resolution <- as.data.frame([email protected])
add.resolution <- mutate(add.resolution, Barcodes = rownames(add.resolution)) %>% select(Barcodes, 25:35)
write.table(add.resolution, "/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/add.resolution.txt", sep = "\t", quote = F, row.names = F)
# Look at cluster IDs of the first 5 cells
head(Idents(filtered.pacemaker.samples), 5)
# Count the number of clusters at different resolutions.
Ncluster <- c()
for(res in c(12:22)){
Ncluster <- c(Ncluster, length(unique(as.vector([email protected][,res]))))
#unique([email protected]$SCT_snn_res.2)
}
res_ncluster <- data.frame(Res = c(0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 3.0), Ncluster = Ncluster)
write.table(res_ncluster,"/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/ResolutionVsNclusters.txt", quote = F, sep = "\t", row.names = F)
```
Run non-linear dimensional reduction (UMAP/tSNE)
```{r}
filtered.pacemaker.samples <- RunUMAP(filtered.pacemaker.samples, dims = 1:40)
# Plot the UMAP
# Assign identity of clusters
Idents(object = filtered.pacemaker.samples) <- "SCT_snn_res.0.6"
DimPlot(filtered.pacemaker.samples,
reduction = "umap",
label = TRUE,
repel = TRUE,
label.size = 6)
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/UMAP.res.0.6.pdf", width = 10, height = 8)
# Flip the UMAP coordinates so that early time points are on the left.
tmp_umap_coordinates <- filtered.pacemaker.samples[["umap"]]@cell.embeddings
tmp_umap_coordinates <- -tmp_umap_coordinates
filtered.pacemaker.samples[["umap"]]@cell.embeddings <- tmp_umap_coordinates
DimPlot(filtered.pacemaker.samples,
reduction = "umap",
label = TRUE,
repel = TRUE,
label.size = 6)
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/UMAP.res.0.6.pdf", width = 10, height = 8)
DimPlot(filtered.pacemaker.samples,
reduction = "umap",
label = TRUE,
repel = TRUE,
cols = c(paletteer_d("ggthemes::Tableau_20"),paletteer_d("ggthemes::Miller_Stone")),
label.size = 6)
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/UMAP.res.0.6.Tableau_20.color.pdf", width = 10, height = 8)
```
Test color palettes.
```{r}
DimPlot(filtered.pacemaker.samples,
reduction = "umap",
label = TRUE,
repel = TRUE,
cols = DiscretePalette(n = 30, palette = "glasbey"),
label.size = 6)
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/UMAP.res.0.6.glasbey.color.pdf", width = 10, height = 8)
DimPlot(filtered.pacemaker.samples,
reduction = "umap",
label = TRUE,
repel = TRUE,
cols = paletteer_d("ggsci::default_igv"),
label.size = 6)
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/UMAP.res.0.6.ggsci.color.pdf", width = 10, height = 8)
DimPlot(filtered.pacemaker.samples,
reduction = "umap",
label = TRUE,
repel = TRUE,
cols = custom_colors$discrete,
label.size = 6)
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/UMAP.res.0.6.custom.color.pdf", width = 10, height = 8)
DimPlot(filtered.pacemaker.samples,
reduction = "umap",
label = TRUE,
repel = TRUE,
cols = c(paletteer_d("ggthemes::Classic_20"),paletteer_d("ggthemes::Classic_Green_Orange_12")[7:12],paletteer_d("ggthemes::hc_fg")),
label.size = 6)
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/UMAP.res.0.6.ggthemes.color.pdf", width = 10, height = 8)
DimPlot(filtered.pacemaker.samples,
reduction = "umap",
label = TRUE,
repel = TRUE,
cols = c(paletteer_d("ggsci::planetexpress_futurama"),paletteer_d("ggsci::springfield_simpsons")),
label.size = 6)
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/UMAP.res.0.6.planetexpress_futurama.color.pdf", width = 10, height = 8)
DimPlot(filtered.pacemaker.samples,
reduction = "umap",
label = TRUE,
repel = TRUE,
cols = c(paletteer_d("ggthemes::Classic_Green_Orange_12"),paletteer_d("ggthemes::Classic_Blue_Red_12"),paletteer_d("ggthemes::Classic_Purple_Gray_12")),
label.size = 6)
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/UMAP.res.0.6.Classic_Green_Orange.color.pdf", width = 10, height = 8)
DimPlot(filtered.pacemaker.samples,
reduction = "umap",
label = TRUE,
repel = TRUE,
cols = c("#fcff5d","#7dfc00","#0ec434","#228c68","#8ad8e8","#235b54","#29bdab","#3998f5","#37294f","#277da7","#3750db","#f22020","#991919","#ffcba5","#e68f66","#c56133","#96341c","#632819","#ffc413","#f47a22","#2f2aa0","#b732cc","#772b9d","#f07cab","#d30b94","#edeff3","#c3a5b4","#946aa2","#5d4C316"),
label.size = 6)
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/UMAP.res.0.6.artist.color.pdf", width = 10, height = 8)
# Plot UMAP for resolution 1.0.
Idents(filtered.pacemaker.samples) <- "SCT_snn_res.1"
DimPlot(filtered.pacemaker.samples,
reduction = "umap",
label = TRUE,
repel = TRUE,
cols = c(paletteer_d("ggthemes::Tableau_20"), rev(paletteer_d("ggthemes::Miller_Stone")), paletteer_d("ggthemes::Summer")),
label.size = 6)
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/UMAP.res.1.Tableau_20.color.pdf", width = 10, height = 8)
```
Decision: Use resolution 1.0.
Segregation of clusters by sample
```{r}
# Extract identity and sample information from seurat object to determine the number of cells per cluster per sample
n_cells <- FetchData(filtered.pacemaker.samples,
vars = c("ident", "orig.ident")) %>%
dplyr::count(ident, orig.ident) %>%
tidyr::spread(ident, n)
write.table(n_cells,"/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/N_Cells_For_Each_Clusters.txt", quote = F, sep = "\t", row.names = F)
# UMAP of cells in each cluster by sample
DimPlot(filtered.pacemaker.samples,
label = TRUE,
split.by = "orig.ident") + NoLegend()
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/SplitSamples.UMAP.res.0.6.pdf", width = 40, height = 5)
DimPlot(filtered.pacemaker.samples,
label = TRUE,
#cols = DiscretePalette(11, palette = "stepped")[c(1,5,9,2,6,10,3,7,11)],
#cols = DiscretePalette(12, palette = "stepped")[c(1,5,9,3,7,11,4,8,12)],
repel = TRUE,
group.by = "orig.ident")
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/MergedSamples.UMAP.res.0.6.pdf", width = 10, height = 8)
DimPlot(filtered.pacemaker.samples,
label = TRUE,
#cols = DiscretePalette(11, palette = "stepped")[c(1,5,9,2,6,10,3,7,11)],
cols = c(brewer.pal(12,"Paired"),brewer.pal(12,"Set3")[12]),
repel = TRUE,
group.by = "orig.ident")
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/MergedSamples.UMAP.res.0.6.diff.colors.pdf", width = 10, height = 8)
# UMAP of cells in each cluster by timepoint
[email protected] <- mutate([email protected],
Timepoint = case_when(str_detect(as.vector([email protected]$orig.ident), "D3_r") ~ "Day3",
str_detect(as.vector([email protected]$orig.ident), "D4_r") ~ "Day4",
str_detect(as.vector([email protected]$orig.ident), "D6_r") ~ "Day6",
str_detect(as.vector([email protected]$orig.ident), "D10_r") ~ "Day10",
str_detect(as.vector([email protected]$orig.ident), "D23_r") ~ "Day23",
str_detect(as.vector([email protected]$orig.ident), "D34_r") ~ "Day34"))
filtered.pacemaker.samples$Timepoint <- factor(filtered.pacemaker.samples$Timepoint, levels = unique(filtered.pacemaker.samples$Timepoint))
DimPlot(filtered.pacemaker.samples,
label = TRUE,
split.by = "Timepoint",
group.by = "Timepoint")
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/Split.Timepoints.UMAP.res.0.6.pdf", width = 30, height = 5)
DimPlot(filtered.pacemaker.samples,
label = TRUE,
#cols = brewer.pal(6,"Dark2"),
group.by = "Timepoint")
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/Merged.Timepoints.UMAP.res.0.6.pdf", width = 10, height = 8)
```
Segregation of clusters by cell cycle phase
```{r}
# Explore whether clusters segregate by cell cycle phase
DimPlot(filtered.pacemaker.samples,
group.by = "Phase")
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/Merged.CellCycle.UMAP.res.0.6.pdf", width = 10, height = 8)
DimPlot(filtered.pacemaker.samples,
group.by = "Phase",
split.by = "Phase")
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/Split.CellCycle.UMAP.res.0.6.pdf", width = 25, height = 10)
```
Segregation of clusters by multiplet class.
```{r}
# Explore whether clusters segregate by singlet vs doublet.
DimPlot(filtered.pacemaker.samples,
group.by = "multiplet_class")
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/Merged.Multiplet.UMAP.res.0.6.pdf", width = 10, height = 8)
DimPlot(filtered.pacemaker.samples,
group.by = "multiplet_class",
split.by = "multiplet_class")
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/Split.Multiplet.UMAP.res.0.6.pdf", width = 10, height = 5)
```
Segregation of clusters by various sources of uninteresting variation
```{r}
# Determine metrics to plot present in [email protected]
metrics <- c("nCount_RNA", "nFeature_RNA", "S.Score", "G2M.Score", "percent.mt")
FeaturePlot(filtered.pacemaker.samples,
reduction = "umap",
features = metrics,
pt.size = 0.4,
order = TRUE,
#min.cutoff = 'q10',
label = TRUE)
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/Metrics.UMAP.res.0.6.pdf", width = 10, height = 10)
```
Exploring known cell type markers
```{r}
# Pan-Cardiac genes
FeaturePlot(filtered.pacemaker.samples,
reduction = "umap",
features = c("NKX2-5", "TNNT2", "MYH6", "MYH7"),
order = FALSE,
#min.cutoff = 'q10',
label = TRUE)
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/Pan_Cardiac_Genes.UMAP.res.0.6.pdf", width = 12, height = 10)
# Violin plot
VlnPlot(filtered.pacemaker.samples, c("NKX2-5", "TNNT2", "MYH6", "MYH7"), group.by = "Timepoint", pt.size = 0, cols = brewer.pal(12,"Paired")[c(2,4,6,8,10,12)], ncol = 4)
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/Pan_Cardiac_Genes.Violin.UMAP.res.0.6.pdf", width = 16, height = 5)
# Pacemaker cell genes
FeaturePlot(filtered.pacemaker.samples,
reduction = "umap",
features = c("TBX18", "SHOX2", "ISL1", "TBX3"),
order = FALSE,
#min.cutoff = 'q10',
label = TRUE)
ggsave("/Data/iPSC_pacemaker/Seurat/Pacemaker_Cells/Second_Round/UMAP/PacemakerCell_Genes.UMAP.res.0.6.pdf", width = 12, height = 10)