-
Notifications
You must be signed in to change notification settings - Fork 0
/
SARS-CoV-2_variants_analysis_script.Rmd
3468 lines (2854 loc) · 254 KB
/
SARS-CoV-2_variants_analysis_script.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: "SARS-CoV-2 ACE2 variant combinations"
output: github_document
---
```{r Set up the analysis script}
## Clear existing environment
rm(list = ls())
## Load basic useful packages
library(tidyverse)
library(ggrepel)
library(ggbeeswarm)
library(reshape)
library(sf)
library(here)
library(ggfortify)
library(googlesheets4)
library(rpart)
library(rpart.plot)
library(ggbreak)
library(ggVennDiagram)
library(network)
library(GGally)
library(ggdendro)
## Set the seed for immediate reproducibility
set.seed(1234567)
## Set the base theme to what I like
theme_set(theme_bw())
theme_update(legend.title = element_blank(), panel.grid.minor = element_blank(), text = element_text(size = 10))
## Setting some universal thresholds for some of the subsequent analyses
quantile_cutoff <- 0.99
minquant_fraction <- 0.2
to_single_notation <- function(arg1){
if(toupper(arg1) == "ALA"){return("A")}
if(toupper(arg1) == "CYS"){return("C")}
if(toupper(arg1) == "ASP"){return("D")}
if(toupper(arg1) == "GLU"){return("E")}
if(toupper(arg1) == "GLH"){return("E")}
if(toupper(arg1) == "PHE"){return("F")}
if(toupper(arg1) == "GLY"){return("G")}
if(toupper(arg1) == "HIS"){return("H")}
if(toupper(arg1) == "ILE"){return("I")}
if(toupper(arg1) == "LYS"){return("K")}
if(toupper(arg1) == "LEU"){return("L")}
if(toupper(arg1) == "MET"){return("M")}
if(toupper(arg1) == "ASN"){return("N")}
if(toupper(arg1) == "PRO"){return("P")}
if(toupper(arg1) == "GLN"){return("Q")}
if(toupper(arg1) == "ARG"){return("R")}
if(toupper(arg1) == "SER"){return("S")}
if(toupper(arg1) == "THR"){return("T")}
if(toupper(arg1) == "VAL"){return("V")}
if(toupper(arg1) == "TRP"){return("W")}
if(toupper(arg1) == "TYR"){return("Y")}
if(toupper(arg1) == "TER"){return("X")}
}
```
```{r Writing a function capable of calculating the enrichments in the sequencing data for Nextseq 3 data where one index had to be 9nt bc of sequencing issues}
### Next make a function for analyzing the enrichment of the virus in hygromycin antibiotic (thus selecting for infected cells)
index_key1 <- read.csv(file = "Keys/9ntR1_10ntR2.csv", header = T, stringsAsFactors = F) %>% mutate(primer1 = primer, primer2 = primer)
sample_key1 <- read.csv(file = "Keys/Barcode_receptor_samples.csv", header = T, stringsAsFactors = F)
sample_index_key1 <- merge(sample_key1[,c("gene","ortholog","mutant","protease","kozak","plasmid_template","primer1","primer2","concat")], index_key1[,c("primer2","index")], by = "primer2", all.x = T)
sample_index_key1 <- merge(sample_index_key1, index_key1[,c("primer1","index")], by = "primer1", all.x = T)
sample_index_key1$X <- paste(sample_index_key1$index.x,"N",sample_index_key1$index.y, sep = "")
sample_index_key1$sequence <- sample_index_key1$X
## Current list of NGS data
myfiles = list.files(path="Data/Dbl_barcode_NS3", pattern="*.tsv", full.names=TRUE)
myfiles_df <- data.frame("number" = seq(1,length(myfiles)), "index" = myfiles)
## Now defining the function to analyze the enrichement with the NGS data
list_of_indexes <- c(4,5,8,9) ## Delete whenever. Only for troubleshooting.
makeExperimentFrame1 <- function(list_of_indexes){
## Deal with the unselected data first
rep1 <- read.delim(myfiles[list_of_indexes[1]], sep = "\t") %>% mutate(log10_count = log10(count))
# First filter is to only look at actual designer barcodes
rep1_filtered1 <- rep1 %>% filter(X %in% sample_index_key1$X)
# Second filter will be to ignore barcodes with counts so low they are unlikely real
rep1_filtered2 <- rep1_filtered1 %>% filter(log10_count > (mean(log10_count) - sd(log10_count) * 2))
## Repeat the process for the second replicate
rep2 <- read.delim(myfiles[list_of_indexes[2]], sep = "\t") %>% mutate(log10_count = log10(count))
rep2_filtered1 <- rep2 %>% filter(X %in% sample_index_key1$X)
rep2_filtered2 <- rep2_filtered1 %>% filter(log10_count > (mean(log10_count) - sd(log10_count) * 2))
unsel <- merge(rep1_filtered2, rep2_filtered2, by = "X", all = T)
unsel[is.na(unsel)] <- 0
unsel$rep1_freq <- unsel$count.x / sum(unsel$count.x)
unsel$rep2_freq <- unsel$count.y / sum(unsel$count.y)
unsel$u_freq <- 10^((log10(unsel$rep1_freq) + log10(unsel$rep2_freq))/2)
## Deal with the HygroR data next
hygro <- merge(read.delim(myfiles[list_of_indexes[3]], sep = "\t"), read.delim(myfiles[list_of_indexes[4]], sep = "\t"), by = "X", all = T)
## Combine the data; this should also take care of the filtering, since the unsel was already filtered
combined_frame <- merge(unsel[,c("X","u_freq")], hygro[,c("X","count.x","count.y")], by = "X", all.x = T) %>%
mutate(sel_freq1 = count.x / sum(count.x), sel_freq2 = count.y / sum(count.y)) %>%
mutate(h_freq = 10^((log10(sel_freq1) + log10(sel_freq2))/2))
return_frame <- combined_frame[,c("X","u_freq","h_freq")]
## Do some additional analysis before returning the data frame
return_frame$h_enrichment <- return_frame$h_freq / return_frame$u_freq
colnames(return_frame) <- c("sequence","u_freq","h_freq","h_enrichment")
return_frame2_troubleshooting <- merge(return_frame, sample_index_key1[,c("gene","ortholog","mutant","protease","kozak","plasmid_template","concat","sequence")], by = "sequence", all = T)
return_frame2 <- merge(return_frame, sample_index_key1[,c("gene","ortholog","mutant","protease","kozak","plasmid_template","concat","sequence")], by = "sequence", all.x = T)
return(return_frame2)
}
```
```{r Looking at correlations of the uninfected cells with library v1.0 in Nextseq3}
i0192 <- read.delim(file = "Data/Dbl_barcode_NS3/I0192_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0193 <- read.delim(file = "Data/Dbl_barcode_NS3/I0193_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0194 <- read.delim(file = "Data/Dbl_barcode_NS3/I0194_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0195 <- read.delim(file = "Data/Dbl_barcode_NS3/I0195_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0196 <- read.delim(file = "Data/Dbl_barcode_NS3/I0196_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0197 <- read.delim(file = "Data/Dbl_barcode_NS3/I0197_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0198 <- read.delim(file = "Data/Dbl_barcode_NS3/I0198_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0199 <- read.delim(file = "Data/Dbl_barcode_NS3/I0199_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0200 <- read.delim(file = "Data/Dbl_barcode_NS3/I0200_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0201 <- read.delim(file = "Data/Dbl_barcode_NS3/I0201_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0202 <- read.delim(file = "Data/Dbl_barcode_NS3/I0202_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0203 <- read.delim(file = "Data/Dbl_barcode_NS3/I0203_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0204 <- read.delim(file = "Data/Dbl_barcode_NS3/I0204_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0205 <- read.delim(file = "Data/Dbl_barcode_NS3/I0205_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0206 <- read.delim(file = "Data/Dbl_barcode_NS3/I0206_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0207 <- read.delim(file = "Data/Dbl_barcode_NS3/I0207_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0208 <- read.delim(file = "Data/Dbl_barcode_NS3/I0208_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0192_filtered <- i0192 %>% filter(X %in% sample_index_key1$X)
i0193_filtered <- i0193 %>% filter(X %in% sample_index_key1$X)
i0194_filtered <- i0194 %>% filter(X %in% sample_index_key1$X)
i0195_filtered <- i0195 %>% filter(X %in% sample_index_key1$X)
i0196_filtered <- i0196 %>% filter(X %in% sample_index_key1$X)
i0197_filtered <- i0197 %>% filter(X %in% sample_index_key1$X)
i0198_filtered <- i0198 %>% filter(X %in% sample_index_key1$X)
i0199_filtered <- i0199 %>% filter(X %in% sample_index_key1$X)
i0200_filtered <- i0200 %>% filter(X %in% sample_index_key1$X)
i0201_filtered <- i0201 %>% filter(X %in% sample_index_key1$X)
i0202_filtered <- i0202 %>% filter(X %in% sample_index_key1$X)
i0203_filtered <- i0203 %>% filter(X %in% sample_index_key1$X)
i0204_filtered <- i0204 %>% filter(X %in% sample_index_key1$X)
i0205_filtered <- i0205 %>% filter(X %in% sample_index_key1$X)
i0206_filtered <- i0206 %>% filter(X %in% sample_index_key1$X)
i0207_filtered <- i0207 %>% filter(X %in% sample_index_key1$X)
i0208_filtered <- i0208 %>% filter(X %in% sample_index_key1$X)
ns3_negs_filtered <- merge(merge(merge(merge(merge(merge(merge(merge(merge(merge(merge(merge(merge(merge(merge(merge(i0192_filtered,i0193_filtered,by = "X", all = T),i0194_filtered,by = "X", all = T),i0195_filtered,by = "X", all = T),i0196_filtered,by = "X", all = T),i0197_filtered,by = "X", all = T),i0198_filtered,by = "X", all = T),i0199_filtered,by = "X", all = T),i0200_filtered,by = "X", all = T),i0201_filtered,by = "X", all = T),i0202_filtered,by = "X", all = T),i0203_filtered,by = "X", all = T),i0204_filtered,by = "X", all = T),i0205_filtered,by = "X", all = T),i0206_filtered,by = "X", all = T),i0207_filtered,by = "X", all = T),i0208_filtered,by = "X", all = T)
colnames(ns3_negs_filtered) <- c("X","ns3_u1","ns3_u2","ns3_u3","ns3_u4","ns3_u5","ns3_u6","ns3_u7","ns3_u8","ns3_u9","ns3_u10","ns3_u11","ns3_u12","ns3_u13","ns3_u14","ns3_u15","ns3_u16","ns3_u17")
ns3_negs_filtered$ns3_u1 <- ns3_negs_filtered$ns3_u1 / sum(ns3_negs_filtered$ns3_u1, na.rm = T)
ns3_negs_filtered$ns3_u2 <- ns3_negs_filtered$ns3_u2 / sum(ns3_negs_filtered$ns3_u2, na.rm = T)
ns3_negs_filtered$ns3_u3 <- ns3_negs_filtered$ns3_u3 / sum(ns3_negs_filtered$ns3_u3, na.rm = T)
ns3_negs_filtered$ns3_u4 <- ns3_negs_filtered$ns3_u4 / sum(ns3_negs_filtered$ns3_u4, na.rm = T)
ns3_negs_filtered$ns3_u5 <- ns3_negs_filtered$ns3_u5 / sum(ns3_negs_filtered$ns3_u5, na.rm = T)
ns3_negs_filtered$ns3_u6 <- ns3_negs_filtered$ns3_u6 / sum(ns3_negs_filtered$ns3_u6, na.rm = T)
ns3_negs_filtered$ns3_u7 <- ns3_negs_filtered$ns3_u7 / sum(ns3_negs_filtered$ns3_u7, na.rm = T)
ns3_negs_filtered$ns3_u8 <- ns3_negs_filtered$ns3_u8 / sum(ns3_negs_filtered$ns3_u8, na.rm = T)
ns3_negs_filtered$ns3_u9 <- ns3_negs_filtered$ns3_u9 / sum(ns3_negs_filtered$ns3_u9, na.rm = T)
ns3_negs_filtered$ns3_u10 <- ns3_negs_filtered$ns3_u10 / sum(ns3_negs_filtered$ns3_u10, na.rm = T)
ns3_negs_filtered$ns3_u11 <- ns3_negs_filtered$ns3_u11 / sum(ns3_negs_filtered$ns3_u11, na.rm = T)
ns3_negs_filtered$ns3_u12 <- ns3_negs_filtered$ns3_u12 / sum(ns3_negs_filtered$ns3_u12, na.rm = T)
ns3_negs_filtered$ns3_u13 <- ns3_negs_filtered$ns3_u13 / sum(ns3_negs_filtered$ns3_u13, na.rm = T)
ns3_negs_filtered$ns3_u14 <- ns3_negs_filtered$ns3_u14 / sum(ns3_negs_filtered$ns3_u14, na.rm = T)
ns3_negs_filtered$ns3_u15 <- ns3_negs_filtered$ns3_u15 / sum(ns3_negs_filtered$ns3_u15, na.rm = T)
ns3_negs_filtered$ns3_u16 <- ns3_negs_filtered$ns3_u16 / sum(ns3_negs_filtered$ns3_u16, na.rm = T)
ns3_negs_filtered$ns3_u17 <- ns3_negs_filtered$ns3_u17 / sum(ns3_negs_filtered$ns3_u17, na.rm = T)
ggplot() + scale_x_log10() + scale_y_log10() +
geom_point(data = ns3_negs_filtered, aes(x = ns3_u1, y = ns3_u2))
ggplot() + scale_x_log10() + scale_y_log10() +
geom_point(data = ns3_negs_filtered, aes(x = ns3_u1, y = ns3_u3))
ggplot() + scale_x_log10() + scale_y_log10() +
geom_point(data = ns3_negs_filtered, aes(x = ns3_u2, y = ns3_u3))
Neg_cntrl_count_correlations <- ggplot() +
labs(x = "Variant frequency in\nreplicate 1", y = "Variant frequency in\nreplicate 2") +
scale_x_log10() + scale_y_log10() +
geom_hline(yintercept = 1e-5, linetype = 2) +
geom_vline(xintercept = 1e-5, linetype = 2) +
geom_abline(slope = 1, linetype = 2, alpha = 0.3) +
geom_point(data = ns3_negs_filtered, aes(x = ns3_u1, y = ns3_u2), alpha = 0.5) +
#geom_point(data = ns3_negs_filtered, aes(x = freq192, y = freq194), alpha = 0.5) +
#geom_point(data = ns3_negs_filtered, aes(x = freq193, y = freq194), alpha = 0.5)
NULL
Neg_cntrl_count_correlations
ggsave(file = "Plots/Neg_cntrl_count_correlations.pdf", Neg_cntrl_count_correlations, height = 1.75, width = 2)
# Correlations are reasonable, suggesting we can indeed reproducibly quantitate things
# R^2 values to report
paste("The R^2 for the unselected frequency counts shown:", round(cor(ns3_negs_filtered$ns3_u1, ns3_negs_filtered$ns3_u2, use = "complete")^2,2))
```
```{r Calculating the enrichment scores in Nextseq 3}
ns3_g740d1 <- makeExperimentFrame1(c(4,5,18,18)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment)) ## 195, 196, 209, 210
ns3_g740d2 <- makeExperimentFrame1(c(4,5,19,19)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment)) ## 195, 196, 209, 210
ns3_alpha1 <- makeExperimentFrame1(c(6,7,20,20)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
ns3_alpha2 <- makeExperimentFrame1(c(6,7,21,21)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
ns3_beta1 <- makeExperimentFrame1(c(8,9,22,22)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
ns3_beta2 <- makeExperimentFrame1(c(8,9,23,23)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
ns3_delta1 <- makeExperimentFrame1(c(10,11,24,24)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
ns3_delta2 <- makeExperimentFrame1(c(10,11,25,25)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
ns3_gamma1 <- makeExperimentFrame1(c(12,13,26,26)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment)) ## 203, 204, 217, 218
ns3_gamma2 <- makeExperimentFrame1(c(12,13,27,27)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment)) ## 203, 204, 217, 218
ns3_ba1omicron1 <- makeExperimentFrame1(c(14,15,28,28)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
ns3_ba1omicron2 <- makeExperimentFrame1(c(14,15,29,29)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
```
```{r Importing the relevant data from our Nextseq4 and Nextseq7 submissions with intended 10nt indices}
### Next make a function for analyzing the enrichment of the virus in hygromycin antibiotic (thus selecting for infected cells)
index_key2 <- read.csv(file = "Keys/10ntR1_10ntR2.csv", header = T, stringsAsFactors = F) %>% mutate(primer1 = primer, primer2 = primer)
sample_key2 <- read.csv(file = "Keys/Barcode_receptor_samples.csv", header = T, stringsAsFactors = F)
sample_index_key2 <- merge(sample_key2[,c("gene","ortholog","mutant","protease","kozak","plasmid_template","primer1","primer2","concat")], index_key2[,c("primer2","index")], by = "primer2", all.x = T)
sample_index_key2 <- merge(sample_index_key2, index_key2[,c("primer1","index")], by = "primer1", all.x = T)
sample_index_key2$X <- paste(sample_index_key2$index.x,sample_index_key2$index.y, sep = "")
sample_index_key2$sequence <- sample_index_key2$X
## Current list of NGS data
myfiles = list.files(path="Data/Dbl_barcode_NS4", pattern="*.tsv", full.names=TRUE)
myfiles_df <- data.frame("number" = seq(1,length(myfiles)), "index" = myfiles)
## Now defining the function to analyze the enrichement with the NGS data
list_of_indexes <- c(3,3,4,4) ## Delete whenever. Only for troubleshooting.
makeExperimentFrame2 <- function(list_of_indexes){
## Deal with the unselected data first
rep1 <- read.delim(myfiles[list_of_indexes[1]], sep = "\t") %>% mutate(log10_count = log10(count))
# First filter is to only look at actual designer barcodes
rep1_filtered1 <- rep1 %>% filter(X %in% sample_index_key2$X)
# Second filter will be to ignore barcodes with counts so low they are unlikely real
rep1_filtered2 <- rep1_filtered1 %>% filter(log10_count > (mean(log10_count) - sd(log10_count) * 2))
## Repeat the process for the second replicate
rep2 <- read.delim(myfiles[list_of_indexes[2]], sep = "\t") %>% mutate(log10_count = log10(count))
rep2_filtered1 <- rep2 %>% filter(X %in% sample_index_key2$X)
rep2_filtered2 <- rep2_filtered1 %>% filter(log10_count > (mean(log10_count) - sd(log10_count) * 2))
unsel <- merge(rep1_filtered2, rep2_filtered2, by = "X", all = T)
unsel[is.na(unsel)] <- 0
unsel$rep1_freq <- unsel$count.x / sum(unsel$count.x)
unsel$rep2_freq <- unsel$count.y / sum(unsel$count.y)
unsel$u_freq <- 10^((log10(unsel$rep1_freq) + log10(unsel$rep2_freq))/2)
## Deal with the HygroR data next
hygro <- merge(read.delim(myfiles[list_of_indexes[3]], sep = "\t"), read.delim(myfiles[list_of_indexes[4]], sep = "\t"), by = "X", all = T)
## Combine the data; this should also take care of the filtering, since the unsel was already filtered
combined_frame <- merge(unsel[,c("X","u_freq")], hygro[,c("X","count.x","count.y")], by = "X", all.x = T)
combined_frame$sel_freq1 <- combined_frame$count.x / sum(combined_frame$count.x, na.rm = T)
combined_frame$sel_freq2 <- combined_frame$count.y / sum(combined_frame$count.y, na.rm = T)
combined_frame$h_freq <- 10^((log10(combined_frame$sel_freq1) + log10(combined_frame$sel_freq2))/2)
return_frame <- combined_frame[,c("X","u_freq","h_freq")]
## Do some additional analysis before returning the data frame
return_frame$h_enrichment <- return_frame$h_freq / return_frame$u_freq
colnames(return_frame) <- c("sequence","u_freq","h_freq","h_enrichment")
return_frame2_troubleshooting <- merge(return_frame, sample_index_key2[,c("gene","ortholog","mutant","protease","kozak","plasmid_template","concat","sequence")], by = "sequence", all = T)
return_frame2 <- merge(return_frame, sample_index_key2[,c("gene","ortholog","mutant","protease","kozak","plasmid_template","concat","sequence")], by = "sequence", all.x = T)
return(return_frame2)
}
```
```{r Looking at correlations of the uninfected cells with library v1.0 in Nextseq4}
i0274 <- read.delim(file = "Data/Dbl_barcode_NS4/I0274_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0276 <- read.delim(file = "Data/Dbl_barcode_NS4/I0276_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0278 <- read.delim(file = "Data/Dbl_barcode_NS4/I0278_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0280 <- read.delim(file = "Data/Dbl_barcode_NS4/I0280_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0282 <- read.delim(file = "Data/Dbl_barcode_NS4/I0282_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0284 <- read.delim(file = "Data/Dbl_barcode_NS4/I0284_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0287 <- read.delim(file = "Data/Dbl_barcode_NS4/I0287_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0289 <- read.delim(file = "Data/Dbl_barcode_NS4/I0289_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0291 <- read.delim(file = "Data/Dbl_barcode_NS4/I0291_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0293 <- read.delim(file = "Data/Dbl_barcode_NS4/I0293_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0295 <- read.delim(file = "Data/Dbl_barcode_NS4/I0295_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0297 <- read.delim(file = "Data/Dbl_barcode_NS4/I0297_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0299 <- read.delim(file = "Data/Dbl_barcode_NS4/I0299_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0305 <- read.delim(file = "Data/Dbl_barcode_NS4/I0305_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0308 <- read.delim(file = "Data/Dbl_barcode_NS4/I0308_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
i0310 <- read.delim(file = "Data/Dbl_barcode_NS4/I0310_lib.tsv", sep = "\t", header = T, stringsAsFactors = F)
unsel_ns4 <- merge(merge(merge(merge(merge(merge(merge(merge(merge(merge(merge(merge(merge(merge(merge(i0274, i0276, by = "X", all = T), i0278, by = "X", all = T), i0280, by = "X", all = T), i0282, by = "X", all = T), i0284, by = "X", all = T), i0287, by = "X", all = T), i0289, by = "X", all = T), i0291, by = "X", all = T), i0293, by = "X", all = T), i0295, by = "X", all = T), i0297, by = "X", all = T), i0299, by = "X", all = T), i0305, by = "X", all = T), i0308, by = "X", all = T), i0310, by = "X", all = T)
colnames(unsel_ns4) <- c("X","u1","u2","u3","u4","u5","u6","u7","u8","u9","u10","u11","u12","u13","u14","u15","u16")
unsel_ns4_filtered <- unsel_ns4 %>% filter(X %in% sample_index_key2$X)
unsel_ns4_filtered_freq <- unsel_ns4_filtered
unsel_ns4_filtered_freq[is.na(unsel_ns4_filtered)] <- 0
for(x in 2:ncol(unsel_ns4_filtered_freq)){
for(y in 1:nrow(unsel_ns4_filtered_freq)){
unsel_ns4_filtered_freq[y,x] <- unsel_ns4_filtered_freq[y,x] / sum(unsel_ns4_filtered_freq[,x])
}
}
unsel_ns4_filtered_freq_melted <- melt(unsel_ns4_filtered_freq, id = "X")
unsel_mean = data.frame("X" = unsel_ns4_filtered_freq$X, "freq" = rowMeans(unsel_ns4_filtered_freq[,2:17]))
unsel_mean_filtered <- unsel_mean %>% filter(freq > 1e-4)
unsel_mean_filtered$count <- unsel_mean_filtered$freq * 1e12
write.table(file = "Data/Dbl_barcode_NS4/zCombined_unsel.tsv", unsel_mean_filtered[,c("X","count")], sep = "\t", quote = F, row.names = F)
### Combining ALL negative control sequencing
ns3_negs_filtered$seq9 <- ns3_negs_filtered$X
ns4_negs_filtered_seq9 <- unsel_ns4_filtered_freq
ns4_negs_filtered_seq9$seq9 <- paste0(substr(ns4_negs_filtered_seq9$X,1,5),substr(ns4_negs_filtered_seq9$X,7,10),"N",substr(ns4_negs_filtered_seq9$X,11,19))
ns34_negs_filtered <- merge(ns3_negs_filtered, ns4_negs_filtered_seq9, by = "seq9", all = T)
ns34_negs_filtered[is.na(ns34_negs_filtered)] <- 0
ns34_negs_filtered <- ns34_negs_filtered[,colnames(ns34_negs_filtered)[!(colnames(ns34_negs_filtered) %in% c("X.x","X.y"))]]
## Do all pairwise correlations of unselected cells
unsel_correlation_vector <- c()
for(x in 2:ncol(ns34_negs_filtered)){
for(y in 2:ncol(ns34_negs_filtered)){
unsel_correlation_vector <- c(unsel_correlation_vector, (cor(ns34_negs_filtered[,x],ns34_negs_filtered[,y])))
}
}
## Do all pairwise correlations of unselected cells for ns3
ns3_unsel_correlation_vector <- c()
for(x in 2:18){
for(y in 2:18){
ns3_unsel_correlation_vector <- c(ns3_unsel_correlation_vector, (cor(ns34_negs_filtered[,x],ns34_negs_filtered[,y])))
}
}
## Do all pairwise correlations of unselected cells for ns4
ns4_unsel_correlation_vector <- c()
for(x in 19:34){
for(y in 19:34){
ns4_unsel_correlation_vector <- c(ns4_unsel_correlation_vector, (cor(ns34_negs_filtered[,x],ns34_negs_filtered[,y])))
}
}
combined_unsel_correlation_df <- rbind(data.frame("grouping" = "All_pairwise", "value" = unsel_correlation_vector),
data.frame("grouping" = "Set_1_pairwise", "value" = ns3_unsel_correlation_vector),
data.frame("grouping" = "Set_2_pairwise", "value" = ns4_unsel_correlation_vector))
combined_unsel_correlation_df$grouping <- factor(combined_unsel_correlation_df$grouping, levels = rev(c("All_pairwise", "Set_1_pairwise", "Set_2_pairwise")))
Comprehensive_neg_cntrl_correlations <- ggplot() + theme(legend.position = "top") +
labs(x = "Pearson's r^2", y = "Count") +
scale_x_continuous(limits = c(0.4,1.02)) +
geom_histogram(data = combined_unsel_correlation_df, aes(x = value^2, fill = grouping), color = "black", binwidth = 0.02, alpha = 0.8) +
facet_grid(rows = vars(grouping), scales = "free_y") +
NULL; Comprehensive_neg_cntrl_correlations
ggsave(file = "Plots/Comprehensive_neg_cntrl_correlations.pdf", Comprehensive_neg_cntrl_correlations, height = 3.75, width = 2.5)
```
```{r Calculating the enrichment scores in Nextseq 4}
myfiles = list.files(path="Data/Dbl_barcode_NS4", pattern="*.tsv", full.names=TRUE)
myfiles_df <- data.frame("number" = seq(1,length(myfiles)), "index" = myfiles)
ns4_g928a <- makeExperimentFrame2(c(1,1,2,2)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
ns4_g928b <- makeExperimentFrame2(c(9,9,10,10)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
ns4_g928c <- makeExperimentFrame2(c(16,16,17,17)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
ns4_g928d <- makeExperimentFrame2(c(26,26,27,27)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
```
```{r Calculating the enrichment scores in Nextseq 7}
myfiles = list.files(path="Data/Dbl_barcode_NS7", pattern="*.tsv", full.names=TRUE)
myfiles_df <- data.frame("number" = seq(1,length(myfiles)), "index" = myfiles)
ns7_g928a1 <- makeExperimentFrame2(c(1,1,2,2)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
ns7_g928a2 <- makeExperimentFrame2(c(8,8,9,9)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
ns7_g928a3 <- makeExperimentFrame2(c(14,14,15,15)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
ns7_alpha1 <- makeExperimentFrame2(c(1,1,3,3)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
ns7_alpha2 <- makeExperimentFrame2(c(8,8,10,10)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
ns7_alpha3 <- makeExperimentFrame2(c(14,14,16,16)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
ns7_delta1 <- makeExperimentFrame2(c(1,1,4,4)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
ns7_delta2 <- makeExperimentFrame2(c(8,8,11,11)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
ns7_delta3 <- makeExperimentFrame2(c(14,14,17,17)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
ns7_ba1omicron1 <- makeExperimentFrame2(c(1,1,5,5)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
ns7_ba1omicron2 <- makeExperimentFrame2(c(8,8,12,12)) %>% filter(h_enrichment != "Inf") %>% arrange(desc(h_enrichment))
```
```{r Combine all data to make a processed file I can upload to GEO}
ns3_g740d1$seq9 <- ns3_g740d1$sequence
ns3_g740d2$seq9 <- ns3_g740d2$sequence
ns3_alpha1$seq9 <- ns3_g740d2$sequence
ns3_alpha2$seq9 <- ns3_alpha2$sequence
ns3_beta1$seq9 <- ns3_beta1$sequence
ns3_beta2$seq9 <- ns3_beta2$sequence
ns3_delta1$seq9 <- ns3_delta1$sequence
ns3_delta2$seq9 <- ns3_delta2$sequence
ns3_gamma1$seq9 <- ns3_gamma1$sequence
ns3_gamma2$seq9 <- ns3_gamma2$sequence
ns3_ba1omicron1$seq9 <- ns3_ba1omicron1$sequence
ns3_ba1omicron2$seq9 <- ns3_ba1omicron2$sequence
ns4_g928a$seq9 <- paste0(substr(ns4_g928a$sequence,1,5),substr(ns4_g928a$sequence,7,10),"N",substr(ns4_g928a$sequence,11,19))
ns4_g928b$seq9 <- paste0(substr(ns4_g928b$sequence,1,5),substr(ns4_g928b$sequence,7,10),"N",substr(ns4_g928b$sequence,11,19))
ns4_g928c$seq9 <- paste0(substr(ns4_g928c$sequence,1,5),substr(ns4_g928c$sequence,7,10),"N",substr(ns4_g928c$sequence,11,19))
ns4_g928d$seq9 <- paste0(substr(ns4_g928d$sequence,1,5),substr(ns4_g928d$sequence,7,10),"N",substr(ns4_g928d$sequence,11,19))
ns7_g928a1$seq9 <- paste0(substr(ns7_g928a1$sequence,1,5),substr(ns7_g928a1$sequence,7,10),"N",substr(ns7_g928a1$sequence,11,19))
ns7_g928a2$seq9 <- paste0(substr(ns7_g928a2$sequence,1,5),substr(ns7_g928a2$sequence,7,10),"N",substr(ns7_g928a2$sequence,11,19))
ns7_g928a3$seq9 <- paste0(substr(ns7_g928a3$sequence,1,5),substr(ns7_g928a3$sequence,7,10),"N",substr(ns7_g928a3$sequence,11,19))
ns7_alpha1$seq9 <- paste0(substr(ns7_alpha1$sequence,1,5),substr(ns7_alpha1$sequence,7,10),"N",substr(ns7_alpha1$sequence,11,19))
ns7_alpha2$seq9 <- paste0(substr(ns7_alpha2$sequence,1,5),substr(ns7_alpha2$sequence,7,10),"N",substr(ns7_alpha2$sequence,11,19))
ns7_alpha3$seq9 <- paste0(substr(ns7_alpha3$sequence,1,5),substr(ns7_alpha3$sequence,7,10),"N",substr(ns7_alpha3$sequence,11,19))
ns7_delta1$seq9 <- paste0(substr(ns7_delta1$sequence,1,5),substr(ns7_delta1$sequence,7,10),"N",substr(ns7_delta1$sequence,11,19))
ns7_delta2$seq9 <- paste0(substr(ns7_delta2$sequence,1,5),substr(ns7_delta2$sequence,7,10),"N",substr(ns7_delta2$sequence,11,19))
ns7_delta3$seq9 <- paste0(substr(ns7_delta3$sequence,1,5),substr(ns7_delta3$sequence,7,10),"N",substr(ns7_delta3$sequence,11,19))
ns7_ba1omicron1$seq9 <- paste0(substr(ns7_ba1omicron1$sequence,1,5),substr(ns7_ba1omicron1$sequence,7,10),"N",substr(ns7_ba1omicron1$sequence,11,19))
ns7_ba1omicron2$seq9 <- paste0(substr(ns7_ba1omicron2$sequence,1,5),substr(ns7_ba1omicron2$sequence,7,10),"N",substr(ns7_ba1omicron2$sequence,11,19))
for_geo <- merge(ns3_g740d1[,c("gene","ortholog","mutant","protease","kozak","plasmid_template","concat","seq9")], ns7_g928a1[,c("sequence","seq9")], by = "seq9", all = T)
## Adding the 8 replicates for D614G
for_geo <- merge(for_geo, ns3_g740d1[,c("seq9","h_enrichment")], by = "seq9", all = T)
for_geo <- merge(for_geo, ns3_g740d2[,c("seq9","h_enrichment")], by = "seq9", all = T)
for_geo <- merge(for_geo, ns4_g928a[,c("seq9","h_enrichment")], by = "seq9", all = T)
for_geo <- merge(for_geo, ns4_g928b[,c("seq9","h_enrichment")], by = "seq9", all = T)
for_geo <- merge(for_geo, ns4_g928c[,c("seq9","h_enrichment")], by = "seq9", all = T)
for_geo <- merge(for_geo, ns7_g928a1[,c("seq9","h_enrichment")], by = "seq9", all = T)
for_geo <- merge(for_geo, ns7_g928a2[,c("seq9","h_enrichment")], by = "seq9", all = T)
for_geo <- merge(for_geo, ns7_g928a3[,c("seq9","h_enrichment")], by = "seq9", all = T)
## Adding the 5 replicates for Alpha
for_geo <- merge(for_geo, ns3_alpha1[,c("seq9","h_enrichment")], by = "seq9", all = T)
for_geo <- merge(for_geo, ns3_alpha2[,c("seq9","h_enrichment")], by = "seq9", all = T)
for_geo <- merge(for_geo, ns7_alpha1[,c("seq9","h_enrichment")], by = "seq9", all = T)
for_geo <- merge(for_geo, ns7_alpha2[,c("seq9","h_enrichment")], by = "seq9", all = T)
for_geo <- merge(for_geo, ns7_alpha3[,c("seq9","h_enrichment")], by = "seq9", all = T)
## Adding the 2 replicates for Beta
for_geo <- merge(for_geo, ns3_beta1[,c("seq9","h_enrichment")], by = "seq9", all = T)
for_geo <- merge(for_geo, ns3_beta2[,c("seq9","h_enrichment")], by = "seq9", all = T)
## Adding the 2 replicates for Gamma
for_geo <- merge(for_geo, ns3_gamma1[,c("seq9","h_enrichment")], by = "seq9", all = T)
for_geo <- merge(for_geo, ns3_gamma2[,c("seq9","h_enrichment")], by = "seq9", all = T)
## Adding the 5 replicates for Delta
for_geo <- merge(for_geo, ns3_delta1[,c("seq9","h_enrichment")], by = "seq9", all = T)
for_geo <- merge(for_geo, ns3_delta2[,c("seq9","h_enrichment")], by = "seq9", all = T)
for_geo <- merge(for_geo, ns7_delta1[,c("seq9","h_enrichment")], by = "seq9", all = T)
for_geo <- merge(for_geo, ns7_delta2[,c("seq9","h_enrichment")], by = "seq9", all = T)
for_geo <- merge(for_geo, ns7_delta3[,c("seq9","h_enrichment")], by = "seq9", all = T)
## Adding the 4 replicates for Omicron BA1
for_geo <- merge(for_geo, ns3_ba1omicron1[,c("seq9","h_enrichment")], by = "seq9", all = T)
for_geo <- merge(for_geo, ns3_ba1omicron2[,c("seq9","h_enrichment")], by = "seq9", all = T)
for_geo <- merge(for_geo, ns7_ba1omicron1[,c("seq9","h_enrichment")], by = "seq9", all = T)
for_geo <- merge(for_geo, ns7_ba1omicron2[,c("seq9","h_enrichment")], by = "seq9", all = T)
colnames(for_geo) <- c("sequence","gene","ortholog","mutant","protease","kozak","plasmid_template","concat","seq9",
"d614g_1","d614g_2","d614g_3","d614g_4","d614g_5","d614g_6","d614g_7","d614g_8",
"alpha_1","alpha_2","alpha_3","alpha_4","alpha_5",
"beta_1","beta_2",
"gamma_1","gammaa_2",
"delta_1","delta_2","delta_3","delta_4","delta_5",
"ba1_1","ba1_2","ba1_3","ba1_4")
write.csv(file = "Output_tables/Processed_enrichment_scores.csv",for_geo,row.names = F, quote = FALSE)
```
```{r Making an example scatter plot of how certain samples become enriched following selection with the D614G dataset}
d614g_enrichment_example <- merge(merge(merge(merge(merge(merge(merge(merge(merge(ns7_g928a1[,c("plasmid_template","u_freq")], ns7_g928a2[,c("plasmid_template","u_freq")], by = "plasmid_template"), ns7_g928a3[,c("plasmid_template","u_freq")], by = "plasmid_template"), ns4_g928a[,c("plasmid_template","u_freq")], by = "plasmid_template"), ns4_g928b[,c("plasmid_template","u_freq")], by = "plasmid_template"), ns4_g928b[,c("plasmid_template","h_freq")], by = "plasmid_template"), ns4_g928a[,c("plasmid_template","h_freq")], by = "plasmid_template"), ns7_g928a1[,c("plasmid_template","h_freq")], by = "plasmid_template"), ns7_g928a2[,c("plasmid_template","h_freq")], by = "plasmid_template"), ns7_g928a3[,c("plasmid_template","h_freq","ortholog","protease","mutant","kozak")], by = "plasmid_template")
colnames(d614g_enrichment_example)[2:11] <- c("u1","u2","u3","u4","u5","h1","h2","h3","h4","h5")
d614g_enrichment_example$u_freq <- 10^rowMeans(log10(d614g_enrichment_example[,seq(2,6)]))
d614g_enrichment_example$h_freq <- 10^rowMeans(log10(d614g_enrichment_example[,seq(7,10)]))
d614g_enrichment_example2 <- d614g_enrichment_example %>% filter(ortholog %in% c("H.sapiens","Control") & protease == "none" | ortholog %in% c("R.pearsonii", "R.alcyone"))
d614g_enrichment_example2$identifier <- paste0(d614g_enrichment_example2$ortholog," ",d614g_enrichment_example2$mutant," ",d614g_enrichment_example2$kozak)
d614g_enrichment_example3 <- d614g_enrichment_example2 %>% filter(identifier %in% c("H.sapiens WT high","Control dEcto high","H.sapiens WT low", "R.pearsonii WT high", "R.alcyone WT high"))
example_of_enrichment_scatterplot <- ggplot() +
labs(x = "Frequency of plasmid before selection", y = "Frequency of plasmid\nafter selection") +
scale_x_log10() + scale_y_log10() +
geom_abline(slope = 1, linetype = 2, alpha = 0.3) +
geom_segment(data = d614g_enrichment_example3, aes(x = u_freq, xend = u_freq, y = u_freq, yend = h_freq), linetype = 1, alpha = 0.3) +
geom_point(data = d614g_enrichment_example2, aes(x = u_freq, y = h_freq), alpha = 0.2) +
geom_point(data = d614g_enrichment_example3, aes(x = u_freq, y = h_freq), alpha = 0.5) +
geom_text_repel(data = d614g_enrichment_example3, aes(x = u_freq, y = h_freq, label = identifier), segment.color = "orange", min.segment.length = 0, color = "red", size = 2)
example_of_enrichment_scatterplot
ggsave(file = "Plots/example_of_enrichment_scatterplot.pdf", example_of_enrichment_scatterplot, height = 1.75, width = 3)
```
```{r Merging replicate scores for D614G, Alpha, Beta, Gamma, Delta, and Omicron BA1}
s2d614g <- merge(merge(merge(merge(merge(merge(merge(merge(ns3_g740d1[,c("plasmid_template","h_enrichment")],
ns3_g740d2[,c("plasmid_template","h_enrichment")], by = "plasmid_template", all = T),
ns4_g928a[,c("plasmid_template","h_enrichment")], by = "plasmid_template", all = T),
ns4_g928b[,c("plasmid_template","h_enrichment")], by = "plasmid_template", all = T),
ns4_g928c[,c("plasmid_template","h_enrichment")], by = "plasmid_template", all = T),
ns4_g928d[,c("plasmid_template","h_enrichment")], by = "plasmid_template", all = T),
ns7_g928a1[,c("plasmid_template","h_enrichment")], by = "plasmid_template", all = T),
ns7_g928a2[,c("plasmid_template","h_enrichment")], by = "plasmid_template", all = T),
ns7_g928a3[,c("plasmid_template","h_enrichment")], by = "plasmid_template", all = T)
for(x in 2:ncol(s2d614g)){s2d614g[is.na(s2d614g[,x]),x] <- min(s2d614g[,x], na.rm = T)}
s2d614g[,2:ncol(s2d614g)] <- log10(s2d614g[,2:ncol(s2d614g)])
s2d614g$mean_log10 <- rowMeans(s2d614g[,2:ncol(s2d614g)], na.rm = T)
s2d614g$sd_log10 <- apply(s2d614g[,2:(ncol(s2d614g)-1)], 1, sd, na.rm=TRUE)
s2d614g$geomean <- 10^s2d614g$mean_log10
s2alpha <- merge(merge(merge(merge(ns3_alpha1[,c("plasmid_template","h_enrichment")],
ns3_alpha2[,c("plasmid_template","h_enrichment")], by = "plasmid_template", all = T),
ns7_alpha1[,c("plasmid_template","h_enrichment")], by = "plasmid_template", all = T),
ns7_alpha2[,c("plasmid_template","h_enrichment")], by = "plasmid_template", all = T),
ns7_alpha3[,c("plasmid_template","h_enrichment")], by = "plasmid_template", all = T)
for(x in 2:ncol(s2alpha)){s2alpha[is.na(s2alpha[,x]),x] <- min(s2alpha[,x], na.rm = T)}
s2alpha[,2:ncol(s2alpha)] <- log10(s2alpha[,2:ncol(s2alpha)])
s2alpha$mean_log10 <- rowMeans(s2alpha[,2:ncol(s2alpha)], na.rm = T)
s2alpha$sd_log10 <- apply(s2alpha[,2:(ncol(s2alpha)-1)], 1, sd, na.rm=TRUE)
s2alpha$geomean <- 10^s2alpha$mean_log10
s2beta <- merge(ns3_beta1[,c("plasmid_template","h_enrichment")],
ns3_beta2[,c("plasmid_template","h_enrichment")], by = "plasmid_template", all = T)
for(x in 2:ncol(s2beta)){s2beta[is.na(s2beta[,x]),x] <- min(s2beta[,x], na.rm = T)}
s2beta[,2:ncol(s2beta)] <- log10(s2beta[,2:ncol(s2beta)])
s2beta$mean_log10 <- rowMeans(s2beta[,2:ncol(s2beta)], na.rm = T)
s2beta$sd_log10 <- apply(s2beta[,2:(ncol(s2beta)-1)], 1, sd, na.rm=TRUE)
s2beta$geomean <- 10^s2beta$mean_log10
s2gamma <- merge(ns3_gamma1[,c("plasmid_template","h_enrichment")],
ns3_gamma2[,c("plasmid_template","h_enrichment")], by = "plasmid_template", all = T)
for(x in 2:ncol(s2gamma)){s2gamma[is.na(s2gamma[,x]),x] <- min(s2gamma[,x], na.rm = T)}
s2gamma[,2:ncol(s2gamma)] <- log10(s2gamma[,2:ncol(s2gamma)])
s2gamma$mean_log10 <- rowMeans(s2gamma[,2:ncol(s2gamma)], na.rm = T)
s2gamma$sd_log10 <- apply(s2gamma[,2:(ncol(s2gamma)-1)], 1, sd, na.rm=TRUE)
s2gamma$geomean <- 10^s2gamma$mean_log10
s2delta <- merge(merge(merge(merge(ns3_delta1[,c("plasmid_template","h_enrichment")],
ns3_delta2[,c("plasmid_template","h_enrichment")], by = "plasmid_template", all = T),
ns7_delta1[,c("plasmid_template","h_enrichment")], by = "plasmid_template", all = T),
ns7_delta2[,c("plasmid_template","h_enrichment")], by = "plasmid_template", all = T),
ns7_delta3[,c("plasmid_template","h_enrichment")], by = "plasmid_template", all = T)
for(x in 2:ncol(s2delta)){s2delta[is.na(s2delta[,x]),x] <- min(s2delta[,x], na.rm = T)}
s2delta[,2:ncol(s2delta)] <- log10(s2delta[,2:ncol(s2delta)])
s2delta$mean_log10 <- rowMeans(s2delta[,2:ncol(s2delta)], na.rm = T)
s2delta$sd_log10 <- apply(s2delta[,2:(ncol(s2delta)-1)], 1, sd, na.rm=TRUE)
s2delta$geomean <- 10^s2delta$mean_log10
s2ba1omicron <- merge(merge(merge(ns3_ba1omicron1[,c("plasmid_template","h_enrichment")],
ns3_ba1omicron2[,c("plasmid_template","h_enrichment")], by = "plasmid_template", all = T),
ns7_ba1omicron1[,c("plasmid_template","h_enrichment")], by = "plasmid_template", all = T),
ns7_ba1omicron2[,c("plasmid_template","h_enrichment")], by = "plasmid_template", all = T)
for(x in 2:ncol(s2ba1omicron)){s2ba1omicron[is.na(s2ba1omicron[,x]),x] <- min(s2ba1omicron[,x], na.rm = T)}
s2ba1omicron[,2:ncol(s2ba1omicron)] <- log10(s2ba1omicron[,2:ncol(s2ba1omicron)])
s2ba1omicron$mean_log10 <- rowMeans(s2ba1omicron[,2:ncol(s2ba1omicron)], na.rm = T)
s2ba1omicron$sd_log10 <- apply(s2ba1omicron[,2:(ncol(s2ba1omicron)-1)], 1, sd, na.rm=TRUE)
s2ba1omicron$geomean <- 10^s2ba1omicron$mean_log10
## Combining all of the above data for each variant into a singular data frame
combined <- merge(merge(merge(merge(merge(s2d614g[,c("plasmid_template","geomean","sd_log10")],
s2alpha[,c("plasmid_template","geomean","sd_log10")], by = "plasmid_template", all = T),
s2beta[,c("plasmid_template","geomean","sd_log10")], by = "plasmid_template", all = T),
s2gamma[,c("plasmid_template","geomean","sd_log10")], by = "plasmid_template", all = T),
s2delta[,c("plasmid_template","geomean","sd_log10")], by = "plasmid_template", all = T),
s2ba1omicron[,c("plasmid_template","geomean","sd_log10")], by = "plasmid_template", all = T)
colnames(combined) <- c("plasmid_template","D614G","sd_d614g","Alpha","sd_alpha","Beta","sd_beta","Gamma","sd_gamma","Delta","sd_delta","BA1","sd_ba1")
write.csv(file = "Output_tables/Supplementary_table_1.csv", combined, row.names = F)
## Remove the E329K variant from the analysis because it was in the plasmid library at abnormally low levels
combined2 <- merge(combined, ns3_alpha1[,5:10], by = "plasmid_template", all = T) %>% filter(plasmid_template != "G879B_AttB_[koz-mut]ACE2[E329K]-IRES-mCherry-H2A-P2A-PuroR")
combined2$label <- ""
for(x in 1:nrow(combined2)){
if(combined2$ortholog[x] == "H.sapiens" & combined2$kozak[x] == "high"){combined2$label[x] <- combined2$ortholog[x]}
if(combined2$ortholog[x] == "H.sapiens" & combined2$kozak[x] == "low"){combined2$label[x] <- combined2$mutant[x]} else{combined2$label[x] <- combined2$ortholog[x]}}
combined3 <- combined2
```
## Make an overall graph that shows the extent of the infection data we are considering here
```{r Showing how human ACE2 abunadnce level affects infection in the multiplex assay}
kozak_protease <- combined2 %>% filter(ortholog == "H.sapiens" | ortholog == "H.sapiens(rep1)" | ortholog == "H.sapiens(rep2)") %>% filter(mutant == "WT")
for(x in 1:nrow(kozak_protease)){
kozak_protease$identifier[x] <- strsplit(kozak_protease$plasmid_template[x],"_")[[1]][1]
}
## Compare high and low Kozak
lowhigh_reps <- kozak_protease %>% filter(protease == "none")
lowhigh_reps_t <- data.frame(t(lowhigh_reps[,c("identifier","D614G","Alpha","Beta","Gamma","Delta","BA1")]))
colnames(lowhigh_reps_t) <- lowhigh_reps_t[1,]
lowhigh_reps_t <- lowhigh_reps_t[-1,]
lowhigh_reps_t$G755A <- as.numeric(lowhigh_reps_t$G755A)
lowhigh_reps_t$G752A <- as.numeric(lowhigh_reps_t$G752A)
lowhigh_reps_t$high_low_infection_ratio <- lowhigh_reps_t$G752A / lowhigh_reps_t$G755A
lowhigh_reps_t$label <- rownames(lowhigh_reps_t)
lowhigh_reps_t$label <- factor(lowhigh_reps_t$label, levels = c("D614G", "Alpha", "Beta","Gamma","Delta","BA1"))
ace2_high_low_plot <- ggplot() +
scale_y_log10(limits = c(0.3, 20)) +
labs(y = "Fold increase\nto infection", x = NULL) +
theme(axis.text.x = element_blank(), panel.grid.major.x = element_blank(), axis.ticks.x = element_blank()) +
geom_point(data = lowhigh_reps_t, aes(x = 0, y = high_low_infection_ratio, color = label), alpha = 0.4) +
geom_point(data = lowhigh_reps_t, aes(x = 0, y = 10^mean(log10(high_low_infection_ratio))), alpha = 0.4, shape = 95, color = "red", size = 8)
ace2_high_low_plot
ggsave(file = "Plots/ace2_high_low_plot.pdf", ace2_high_low_plot, height = 0.9, width = 2)
```
```{r Seeing how adding TMPRSS2 alters infection with human ACE2 at high abundance levels}
## Now let's look at the effect of TMPRSS2 on the high ACE2 expressor cells
high_protease <- kozak_protease %>% filter(identifier %in% c("G828A","G752A"))
high_protease_t <- data.frame(t(high_protease[,c("identifier","D614G","Alpha","Beta","Gamma","Delta","BA1")]))
colnames(high_protease_t) <- high_protease_t[1,]
high_protease_t <- high_protease_t[-1,]
high_protease_t$G828A <- as.numeric(high_protease_t$G828A)
high_protease_t$G752A <- as.numeric(high_protease_t$G752A)
high_protease_t$tmprss2_infection_ratio <- high_protease_t$G828A / high_protease_t$G752A
high_protease_t$label <- rownames(high_protease_t)
high_protease_t$label <- factor(high_protease_t$label, levels = c("D614G", "Alpha", "Beta","Gamma","Delta","BA1"))
ace2_tmprss2_plot <- ggplot() +
scale_y_log10(limits = c(0.3, 20)) +
labs(y = "Fold increase\nto infection", x = NULL) +
theme(axis.text.x = element_blank(), panel.grid.major.x = element_blank(), axis.ticks.x = element_blank()) +
geom_point(data = high_protease_t, aes(x = 0, y = tmprss2_infection_ratio, color = label), alpha = 0.4) +
geom_point(data = high_protease_t, aes(x = 0, y = 10^mean(log10(tmprss2_infection_ratio))), alpha = 0.4, shape = 95, color = "red", size = 8)
ace2_tmprss2_plot
ggsave(file = "Plots/ace2_tmprss2_plot.pdf", ace2_tmprss2_plot, height = 0.9, width = 2)
```
```{r Subsetted on the ortholog data at high abundance levels so they can be internally scaled}
tmprss2 <- combined2 %>% filter(protease == "TMPRSS2" & mutant == "WT" | kozak == "high" & mutant == "dEcto" | protease == "none" & kozak == "high")
## Values left unscaled
ortholog1 <- tmprss2[colnames(tmprss2)[(colnames(tmprss2) %in% c("ortholog","D614G","Alpha","Beta","Gamma","Delta","BA1"))]]
ortholog1_melt <- melt(ortholog1, id = "ortholog")
factor_levels_for_large_heatmap <- c("Control", "H.sapiens", "H.sapiens(rep1)", "H.sapiens(rep2)", "M.musculus", "S.scrofa", "M.javanica", "R.landeri", "R.alcyone", "R.ferrumequinum", "R.shameli", "R.affinis", "R.sinicus_215", "R.sinicus_275", "R.sinicus_200", "R.sinicus_472", "R.pearsonii")
ortholog1_melt$ortholog <- factor(ortholog1_melt$ortholog, levels = factor_levels_for_large_heatmap)
ortholog1_melt$variable <- factor(ortholog1_melt$variable, levels = c("D614G","Alpha","Beta","Gamma","Delta","BA1"))
orthologs_unscaled <- ggplot() + labs(x = NULL, y = NULL) +
scale_fill_gradient(low = "white", high = "red") +
theme(axis.text.x = element_text(hjust = 1, vjust = 1, angle = 45)) +
geom_tile(data = ortholog1_melt, aes(x = ortholog, y = variable, fill = value))
orthologs_unscaled
ggsave(file = "Plots/orthologs_unscaled.pdf", orthologs_unscaled, height = 3, width = 5)
## Scaled to dEcto and Human High Kozak with TMPRSS2
tmprss2b <- tmprss2
for(x in colnames(tmprss2)[(colnames(tmprss2) %in% c("D614G","Alpha","Beta","Gamma","Delta","BA1"))]){
temp_high <- mean(c(tmprss2b[ tmprss2b$plasmid_template == "G828A_AttB_ACE2-2A-TMPRSS2_IRES_mCherry-H2A-P2A-PuroR" ,x],tmprss2b[ tmprss2b$plasmid_template == "G852C_AttB_ACE2-2A-TMPRSS2_IRES_miRFP670-H2A-P2A-PuroR" ,x]))#max(tmprss2b[,x], na.rm = T)
temp_low <- tmprss2b[ tmprss2b$plasmid_template == "G758A_AttB_ACE2[dEcto]-IRES-mCherry-H2A-P2A-PuroR" ,x]
tmprss2b[,x] <- (tmprss2b[,x] - temp_low) / (temp_high - temp_low)
}
ortholog2 <- tmprss2b[colnames(tmprss2b)[(colnames(tmprss2b) %in% c("ortholog","D614G","Alpha","Beta","Gamma","Delta","BA1"))]]
ortholog2_melt <- melt(ortholog2, id = "ortholog")
ortholog2_melt$ortholog <- factor(ortholog2_melt$ortholog, levels = factor_levels_for_large_heatmap)
ortholog2_melt$variable <- factor(ortholog2_melt$variable, levels = c("D614G","Alpha","Beta","Gamma","Delta","BA1"))
orthologs2_s2variants <- ggplot() +
labs(x = NULL, y = NULL) +
scale_fill_gradient(low = "white", high = "red") +
theme(axis.text.x = element_text(hjust = 1, vjust = 1, angle = 45)) +
geom_tile(data = ortholog2_melt, aes(x = ortholog, y = variable, fill = value)); orthologs2_s2variants
ggsave(file = "Plots/orthologs2_s2variants.pdf", orthologs2_s2variants, height = 3, width = 5)
```
```{r Subsetting on the variants of human ACE2 with low abundance so these can be internally scaled}
low_kozak <- combined2 %>% filter(kozak == "low" | mutant == "dEcto")
## Normal unscaled
low_kozak1 <- low_kozak
low_kozak1 <- low_kozak[colnames(low_kozak)[(colnames(low_kozak) %in% c("mutant","D614G","Alpha","Beta","Gamma","Delta","BA1"))]]
low_kozak1_melt <- melt(low_kozak1, id = "mutant")
#low_kozak1_melt$variable <- factor(low_kozak1_melt$variable, levels = c(""))
low_kozak1_melt$mutant <- factor(low_kozak1_melt$mutant, levels = c("WT", "dEcto", "I21N", "E23K", "K26E", "K31D", "E35K", "D38H", "G326E", "E329K", "G352V", "K353D", "D355N"))
low_kozak1_ace2mutants <- ggplot() + labs(x = NULL, y = NULL) + theme(axis.text.x = element_text(hjust = 1, vjust = 1, angle = 45)) +
scale_fill_gradient(low = "white", high = "red") +
geom_tile(data = low_kozak1_melt, aes(x = mutant, y = variable, fill = value))
low_kozak1_ace2mutants
ggsave(file = "Plots/low_kozak1_ace2mutants.pdf", low_kozak1_ace2mutants, height = 1.25, width = 4)
## Scaled to dEcto and Human Low Kozak
low_kozak2 <- low_kozak
for(x in c(colnames(low_kozak)[(colnames(low_kozak) %in% c("D614G","Alpha","Beta","Gamma","Delta","BA1"))])){
temp_high <- low_kozak2[ low_kozak2$plasmid_template == "G755A_AttB_[koz-mut]ACE2-IRES-mCherry-H2A-P2A-PuroR" ,x]
temp_low <- low_kozak2[ low_kozak2$plasmid_template == "G758A_AttB_ACE2[dEcto]-IRES-mCherry-H2A-P2A-PuroR" ,x]
low_kozak2[,x] <- (low_kozak2[,x] - temp_low) / (temp_high - temp_low)
}
low_kozak2 <- low_kozak2[,c(colnames(low_kozak)[(colnames(low_kozak) %in% c("mutant","D614G","Alpha","Beta","Gamma","Delta","BA1"))])]
low_kozak2_melt <- melt(low_kozak2, id = "mutant")
low_kozak2_melt$variable <- factor(low_kozak2_melt$variable, levels = c("D614G","Alpha","Beta","Gamma","Delta","BA1"))
low_kozak2_melt$mutant <- factor(low_kozak2_melt$mutant, levels = c("WT", "dEcto", "I21N", "E23K", "K26E", "K31D", "E35K", "D38H", "G326E", "E329K", "G352V", "K353D", "D355N"))
low_kozak2_ace2mutants <- ggplot() + labs(x = NULL, y = NULL) + theme(axis.text.x = element_text(hjust = 1, vjust = 1, angle = 45)) +
scale_fill_gradient(low = "white", high = "red", limits = c()) +
geom_tile(data = low_kozak2_melt, aes(x = mutant, y = variable, fill = value))
low_kozak2_ace2mutants
ggsave(file = "Plots/low_kozak2_ace2mutants.pdf", low_kozak2_ace2mutants, height = 1.1, width = 3.1)
low_kozak2_melt$mutant <- factor(low_kozak2_melt$mutant, levels = rev(c("WT", "dEcto", "I21N", "E23K", "K26E", "K31D", "E35K", "D38H", "G326E", "E329K", "G352V", "K353D", "D355N")))
low_kozak2_ace2mutants_s2variants_flip <- ggplot() + labs(x = NULL, y = NULL) + theme(axis.text.x = element_text(hjust = 1, vjust = 1, angle = 45), legend.position = "top") +
scale_fill_gradient(low = "white", high = "red") +
geom_tile(data = low_kozak2_melt, aes(x = variable, y = mutant, fill = value))
low_kozak2_ace2mutants_s2variants_flip
ggsave(file = "Plots/low_kozak2_ace2mutants_s2variants_flip.pdf", low_kozak2_ace2mutants_s2variants_flip, height = 3, width = 2.5)
```
```{r REVISION - To show reproducibility of the low Kozak human mutant sample values}
s2d614g_hmuts <- merge(s2d614g, sample_key1[,c("ortholog","mutant","plasmid_template","kozak")])
colnames(s2d614g_hmuts)[2:10] <- c("r1","r2","r3","r4","r5","r6","r7","r8","r9")
s2d614g_hmuts2 <- s2d614g_hmuts %>% filter(ortholog %in% c("H.sapiens","Control"))
s2d614g_hmuts2$label <- paste0(s2d614g_hmuts2$kozak,"_",s2d614g_hmuts2$mutant)
s2d614g_hmuts2_melt <- melt(s2d614g_hmuts2, "id" = "label") %>% filter(variable %in% c("r1","r2","r3","r4","r5","r6","r7","r8","r9")) %>% filter(label != "high_D355N" & label != "high_WT")
s2d614g_hmuts2_melt$value <- as.numeric(s2d614g_hmuts2_melt$value)
s2d614g_hmuts2_melt_median <- s2d614g_hmuts2_melt %>% group_by(label) %>% summarize(median = median(value)) %>% arrange(desc(median))
s2d614g_hmuts2_melt$label <- factor(s2d614g_hmuts2_melt$label, levels = s2d614g_hmuts2_melt_median$label)
ggplot() + theme(axis.text.x = element_text(angle = -90, hjust = 0, vjust = 0.5), panel.grid.major.x = element_blank()) +
geom_boxplot(data = s2d614g_hmuts2_melt, aes(x = label, y = value), coef=0, outlier.alpha = 0) +
geom_quasirandom(data = s2d614g_hmuts2_melt, aes(x = label, y = value), color = "red", alpha = 0.3) +
geom_point(data = s2d614g_hmuts2_melt_median, aes(x = label, y = median), shape = 95, size = 8) +
labs(x = NULL, y = "Log10 enrichment") +
NULL
s2ba1omicron_hmuts <- merge(s2ba1omicron, sample_key1[,c("ortholog","mutant","plasmid_template","kozak")])
colnames(s2ba1omicron_hmuts)[2:5] <- c("r1","r2","r3","r4")
s2ba1omicron_hmuts2 <- s2ba1omicron_hmuts %>% filter(ortholog %in% c("H.sapiens","Control"))
s2ba1omicron_hmuts2$label <- paste0(s2ba1omicron_hmuts2$kozak,"_",s2ba1omicron_hmuts2$mutant)
s2ba1omicron_hmuts2_melt <- melt(s2ba1omicron_hmuts2, "id" = "label") %>% filter(variable %in% c("r1","r2","r3","r4","r5","r6","r7","r8","r9")) %>% filter(label != "low_E329K" & label != "high_D355N" & label != "high_WT")
s2ba1omicron_hmuts2_melt$value <- as.numeric(s2ba1omicron_hmuts2_melt$value)
s2ba1omicron_hmuts2_melt_median <- s2ba1omicron_hmuts2_melt %>% group_by(label) %>% summarize(median = median(value)) %>% arrange(desc(median))
s2ba1omicron_hmuts2_melt$label <- factor(s2ba1omicron_hmuts2_melt$label, levels = s2ba1omicron_hmuts2_melt_median$label)
ggplot() + theme(axis.text.x = element_text(angle = -90, hjust = 0, vjust = 0.5), panel.grid.major.x = element_blank()) +
geom_boxplot(data = s2ba1omicron_hmuts2_melt, aes(x = label, y = value), coef=0, outlier.alpha = 0) +
geom_quasirandom(data = s2ba1omicron_hmuts2_melt, aes(x = label, y = value), color = "red", alpha = 0.3) +
geom_point(data = s2ba1omicron_hmuts2_melt_median, aes(x = label, y = median), shape = 95, size = 8) +
labs(x = NULL, y = "Log10 enrichment") +
NULL
## Getting ratios
d614g_dEcto_wt <- merge(s2d614g_hmuts2_melt %>% filter(label == "high_dEcto"),s2d614g_hmuts2_melt %>% filter(label == "low_WT"), by = "variable") %>% mutate(ratio = value.x - value.y) %>% mutate(virus = "D614G")
ba1_dEcto_wt <- merge(s2ba1omicron_hmuts2_melt %>% filter(label == "high_dEcto"),s2ba1omicron_hmuts2_melt %>% filter(label == "low_WT"), by = "variable") %>% mutate(ratio = value.x - value.y) %>% mutate(virus = "Omicron BA1")
d614g_ba1_dEcto_wt <- rbind(d614g_dEcto_wt[,c("label.x","virus","variable","ratio")], ba1_dEcto_wt[,c("label.x","virus","variable","ratio")])
d614g_k31d_wt <- merge(s2d614g_hmuts2_melt %>% filter(label == "low_K31D"),s2d614g_hmuts2_melt %>% filter(label == "low_WT"), by = "variable") %>% mutate(ratio = value.x - value.y) %>% mutate(virus = "D614G")
ba1_k31d_wt <- merge(s2ba1omicron_hmuts2_melt %>% filter(label == "low_K31D"),s2ba1omicron_hmuts2_melt %>% filter(label == "low_WT"), by = "variable") %>% mutate(ratio = value.x - value.y) %>% mutate(virus = "Omicron BA1")
d614g_ba1_k31d_wt <- rbind(d614g_k31d_wt[,c("label.x","virus","variable","ratio")], ba1_k31d_wt[,c("label.x","virus","variable","ratio")])
d614g_d38h_wt <- merge(s2d614g_hmuts2_melt %>% filter(label == "low_D38H"),s2d614g_hmuts2_melt %>% filter(label == "low_WT"), by = "variable") %>% mutate(ratio = value.x - value.y) %>% mutate(virus = "D614G")
ba1_d38h_wt <- merge(s2ba1omicron_hmuts2_melt %>% filter(label == "low_D38H"),s2ba1omicron_hmuts2_melt %>% filter(label == "low_WT"), by = "variable") %>% mutate(ratio = value.x - value.y) %>% mutate(virus = "Omicron BA1")
d614g_ba1_d38h_wt <- rbind(d614g_d38h_wt[,c("label.x","virus","variable","ratio")], ba1_d38h_wt[,c("label.x","virus","variable","ratio")])
d614g_e35k_wt <- merge(s2d614g_hmuts2_melt %>% filter(label == "low_E35K"),s2d614g_hmuts2_melt %>% filter(label == "low_WT"), by = "variable") %>% mutate(ratio = value.x - value.y) %>% mutate(virus = "D614G")
ba1_e35k_wt <- merge(s2ba1omicron_hmuts2_melt %>% filter(label == "low_E35K"),s2ba1omicron_hmuts2_melt %>% filter(label == "low_WT"), by = "variable") %>% mutate(ratio = value.x - value.y) %>% mutate(virus = "Omicron BA1")
d614g_ba1_e35k_wt <- rbind(d614g_e35k_wt[,c("label.x","virus","variable","ratio")], ba1_e35k_wt[,c("label.x","virus","variable","ratio")])
d614g_e329k_wt <- merge(s2d614g_hmuts2_melt %>% filter(label == "low_E329K"),s2d614g_hmuts2_melt %>% filter(label == "low_WT"), by = "variable") %>% mutate(ratio = value.x - value.y) %>% mutate(virus = "D614G")
ba1_e329k_wt <- merge(s2ba1omicron_hmuts2_melt %>% filter(label == "low_E329K"),s2ba1omicron_hmuts2_melt %>% filter(label == "low_WT"), by = "variable") %>% mutate(ratio = value.x - value.y) %>% mutate(virus = "Omicron BA1")
d614g_ba1_e329k_wt <- rbind(d614g_e329k_wt[,c("label.x","virus","variable","ratio")], ba1_e329k_wt[,c("label.x","virus","variable","ratio")])
combined_ratios <- rbind(d614g_ba1_k31d_wt, d614g_ba1_d38h_wt, d614g_ba1_e35k_wt, d614g_ba1_e329k_wt) %>% mutate(linear_ratio = 10^ratio) #%>% filter(!(virus == "Omicron BA1" & variable == "r4" & label.x %in% c("low_E35K","low_D38H","low_E329K")))
combined_ratios$label.x <- factor(combined_ratios$label.x, levels = c("low_K31D","low_E35K","low_D38H","low_E329K"))
combined_ratios_ave <- combined_ratios %>% group_by(label.x, virus) %>% summarize(geomean_ratio = 10^(mean(ratio)), mean_ratio = mean(linear_ratio))
Revision_variant_WT_ratios_plot <- ggplot() +
theme(panel.grid.major.x = element_blank(), legend.position = "bottom", axis.text.x = element_text(hjust = 1, vjust = 1, angle = 45)) +
geom_point(data = combined_ratios, aes(x = label.x, y = linear_ratio, color = virus), position = position_dodge(width = 0.5), alpha = 0.4) +
geom_point(data = combined_ratios_ave, aes(x = label.x, y = mean_ratio, color = virus), position = position_dodge(width = 0.5), shape = 95, size = 8) +
labs(x = NULL, y = "Variant to WT ACE2\ninfection ratio") +
NULL; Revision_variant_WT_ratios_plot
ggsave(file = "Plots/Revision_variant_WT_ratios_plot.pdf", Revision_variant_WT_ratios_plot, height = 2.5, width = 3)
```
```{r REVISION - Bootstrapping of the K31D difference between D614G and Omicron}
## Bootstrap test
bootstrap_n <- 1000
label_vector <- c("low_K31D")
d614g_geomean_vector <- c()
ba1_geomean_vector <- c()
for(x in 1:bootstrap_n){
for(y in 1:length(label_vector)){
temp_d614g_vector <- (combined_ratios %>% filter(virus == "D614G" & label.x == label_vector[y]))[,"ratio"]
temp_ba1_vector <- (combined_ratios %>% filter(virus == "Omicron BA1" & label.x == label_vector[y]))[,"ratio"]
temp_d614g_value <- mean(sample(temp_d614g_vector,length(temp_d614g_vector),replace = T))
d614g_geomean_vector <- c(d614g_geomean_vector,temp_d614g_value)
temp_ba1_value <- mean(sample(temp_ba1_vector,length(temp_ba1_vector),replace = T))
ba1_geomean_vector <- c(ba1_geomean_vector,temp_ba1_value)
}
}
bootstrap_results_df <- data.frame("d614g" = d614g_geomean_vector, "ba1" = ba1_geomean_vector)
bootstrap_results_df$ba1_larger <- (bootstrap_results_df$ba1 - bootstrap_results_df$d614g) > 0
sum(bootstrap_results_df) / nrow(bootstrap_results_df)
bootstrap_results_df_melt <- melt(bootstrap_results_df[,c("d614g","ba1")])
bootstrap_results_df_melt$variable <- as.character(bootstrap_results_df_melt$variable)
bootstrap_results_df_melt[bootstrap_results_df_melt$variable == "d614g","variable"] <- "D614G"
bootstrap_results_df_melt[bootstrap_results_df_melt$variable == "ba1","variable"] <- "Omicron BA1"
Revision_D614G_BA1_K31D_plot <- ggplot() + theme(panel.grid.major.x = element_blank()) +
geom_violin(data = bootstrap_results_df_melt, aes(x = variable, y = value)) +
geom_point(data = d614g_ba1_k31d_wt, aes(x = virus, y = ratio), position = position_dodge(width = 0.5)) +
labs(x = NULL, y = "K31D to WT ratio") +
NULL; Revision_D614G_BA1_K31D_plot
ggsave(file = "Plots/Revision_D614G_BA1_K31D_plot.pdf", Revision_D614G_BA1_K31D_plot, height = 2.5, width = 2)
```
```{r REVISION - To show reproducibility of the low Kozak human mutant sample values}
## Probability that the D614G and Omicron BA1 versions of each sample come from the same population
s2d614g_hmuts2_melt$virus <- "D614G"
s2ba1omicron_hmuts2_melt$virus <- "Omicron_BA1"
d614g_omicron_comparison <- rbind(s2d614g_hmuts2_melt, s2ba1omicron_hmuts2_melt)
ggplot() + theme(axis.text.x = element_text(angle = -90, hjust = 0, vjust = 0.5), panel.grid.major.x = element_blank()) +
#geom_boxplot(data = s2ba1omicron_hmuts2_melt, aes(x = label, y = value), coef=0, outlier.alpha = 0) +
geom_quasirandom(data = d614g_omicron_comparison, aes(x = label, y = value, color = virus), alpha = 0.8) +
#geom_point(data = d614g_omicron_comparison, aes(x = label, y = median), shape = 95, size = 8) +
labs(x = NULL, y = "Log10 enrichment") +
NULL
```
```{r REVISION - Looking at how variable some of the ortholog infection values are}
s2d614g_orthologs <- s2d614g_hmuts %>% filter(!(ortholog %in% c("H.sapiens")))
s2d614g_orthologs_melt <- melt(s2d614g_orthologs) %>% filter(variable %in% c("r1","r2","r3","r4","r5","r6","r7","r8","r9"))
s2d614g_orthologs_melt_ave <- s2d614g_orthologs_melt %>% group_by(ortholog) %>% summarize(meanvalue = mean(value))
Revision_D614G_orthologs_plot <- ggplot() + theme(axis.text.x = element_text(hjust = 0, vjust = 0.5, angle = -90), panel.grid.major.x = element_blank()) +
labs(x = NULL , y = "Log10 enrichment ratio") +
geom_quasirandom(data = s2d614g_orthologs_melt, aes(x = ortholog, y = value), alpha = 0.3) +
geom_point(data = s2d614g_orthologs_melt_ave, aes(x = ortholog, y = meanvalue), size = 8, shape = 95) +
NULL; Revision_D614G_orthologs_plot
ggsave(file = "Plots/Revision_D614G_orthologs_plot.pdf", Revision_D614G_orthologs_plot, height = 2.5, width = 4)
```
```{r Making a combined heatmap with both orthologs and variants to demonstrate the full scale of enrichment scores captured in this dataset}
not_ortholog_not_lowkozak <- combined2 %>% filter(kozak == "high" & protease == "none")
combined_ortholog_variant <- rbind((ortholog1_melt %>% mutate(sample = ortholog))[,c("sample","variable","value")],
(low_kozak1_melt %>% mutate(sample = mutant))[,c("sample","variable","value")]) %>% filter(variable %in% c("D614G","Alpha","Beta","Gamma","Delta","BA1"))
combined_ortholog_variant$variable <- factor(combined_ortholog_variant$variable, levels = c("D614G","Alpha","Beta","Gamma","Delta","BA1"))
combined_ortholog_variant$sample <- factor(combined_ortholog_variant$sample, levels = rev(c("Control", "H.sapiens", "H.sapiens(rep1)", "H.sapiens(rep2)", "M.musculus", "S.scrofa", "M.javanica", "R.landeri", "R.alcyone", "R.ferrumequinum", "R.shameli", "R.affinis", "R.sinicus_215", "R.sinicus_275", "R.sinicus_200", "R.sinicus_472", "R.pearsonii", "WT", "dEcto", "I21N", "E23K", "K26E", "K31D", "E35K", "D38H", "G326E", "E329K", "G352V", "K353D", "D355N")))
combined_ortholog_variant_plot <- ggplot() + labs(x = NULL, y = NULL) + theme(axis.text.x = element_text(hjust = 1, vjust = 1, angle = 45), legend.position = "top") +
scale_fill_gradient(low = "white", high = "red", na.value = "white") + #limits=c(-0.25,0.75),
geom_tile(data = combined_ortholog_variant, aes(x = variable, y = sample, fill = value))
combined_ortholog_variant_plot
ggsave(file = "Plots/combined_ortholog_variant_plot.pdf", combined_ortholog_variant_plot, height = 4, width = 2)
```
```{r Comparing out multiplex assay scores to the traditional infection assay results from our 2021 Plos Pathogens article}
human_ace2_variants <- read.delim(file = "Data/Other_papers/2021_Shukla_PlosPathog/journal.ppat.1009715.s008.tsv", sep = "\t")
human_ace2_variants2 <- human_ace2_variants %>% group_by(cell_label) %>% summarize(mean_infection = mean(scaled_infection)) #10^mean(log_scaled_infection))
human_ace2_variants2$mutant <- NA
for(x in 3:nrow(human_ace2_variants2)){
human_ace2_variants2$mutant[x] <- strsplit(human_ace2_variants2$cell_label[x],"-")[[1]][2]
}
human_ace2_variants2$mutant[1] <- "dEcto"
human_ace2_variants2$mutant[2] <- "WT"
low_kozak1_s2variants <- low_kozak1_melt %>% filter(variable == "D614G")
human_ace2_variants3 <- merge(human_ace2_variants2,low_kozak1_s2variants[,c("mutant","value")])
human_ace2_variants3$value <- 10^human_ace2_variants3$value / 10^human_ace2_variants3[human_ace2_variants3$mutant == "WT","value"]
Variant_validation_graph <- ggplot() + labs(x = "Flow cytometry infectivity\nmeasurement from published study", y = "Sequencing-based\ninfectivity measurement\nfrom current study") +
scale_x_log10(breaks = c(0.1,0.5,1,3)) +
scale_y_log10(breaks = c(0.1,0.5,1,3)) +
geom_point(data = human_ace2_variants3, aes(x = mean_infection, y = value), alpha = 0.5) +
geom_text_repel(data = human_ace2_variants3, aes(x = mean_infection, y = value, label = mutant), color = "red", alpha = 0.8, size = 1.5, segment.color = "orange", segment.alpha = 0.5)
Variant_validation_graph
ggsave(file = "Plots/Variant_validation_graph.pdf", Variant_validation_graph, height = 1.75, width = 2)
```
```{r Comparing out multiplex assay scores to the somewhat traditional infection assay results from our 2022 Plos Biology article}
ortholog_2color_data <- read.delim(file = "Data/Other_papers/2022_Roelle_PlosBiol/Fig5.csv", sep = ",")
ortholog_2color_data_flow <- ortholog_2color_data %>% filter(type == "flow_cytometry" & virus_label == "SARS-CoV-2 RBD") %>% mutate(ortholog = cell_label)
ortholog_2color_data_micro <- ortholog_2color_data %>% filter(type == "microscopy" & cell_label == "SARS-CoV-2 RBD") %>% mutate(ortholog = virus_label)
ortholog_2color_data_flow$norm_geomean <- ortholog_2color_data_flow$geomean / ortholog_2color_data_flow[ortholog_2color_data_flow$ortholog == "H.sapiens","geomean"]
ortholog_2color_data_micro$norm_geomean <- ortholog_2color_data_micro$geomean / ortholog_2color_data_micro[ortholog_2color_data_micro$ortholog == "H.sapiens","geomean"]
norm_ortholog_2color_data <- merge(ortholog_2color_data_flow[,c("ortholog","norm_geomean")], ortholog_2color_data_micro[,c("ortholog","norm_geomean")], by = "ortholog")
norm_ortholog_2color_data$norm_geomean <- rowMeans(norm_ortholog_2color_data[,c("norm_geomean.x","norm_geomean.y")])
norm_ortholog_2color_data[norm_ortholog_2color_data$ortholog == "R.sinicus200","ortholog"] <- "R.sinicus_200"
norm_ortholog_2color_data[norm_ortholog_2color_data$ortholog == "R.sinicus215","ortholog"] <- "R.sinicus_215"
norm_ortholog_2color_data[norm_ortholog_2color_data$ortholog == "R.sinicus472","ortholog"] <- "R.sinicus_472"
norm_ortholog_2color_data[norm_ortholog_2color_data$ortholog == "NULL (fs)","ortholog"] <- "Neg cntrl"
ortholog1[ortholog1$ortholog == "Control","ortholog"] <- "dEcto"
ortholog1_melt_s2_plosbiol <- merge(ortholog1[,c("ortholog","D614G")], norm_ortholog_2color_data[,c("ortholog","norm_geomean")], by = "ortholog", all = T)
ortholog1_melt_s2_plosbiol$D614G <- ortholog1_melt_s2_plosbiol$D614G / ortholog1_melt_s2_plosbiol[ortholog1_melt_s2_plosbiol$ortholog == "H.sapiens","D614G"]
Variant_validation_graph2 <- ggplot() + labs(x = "Flow cytometry infectivity\nmeasurement from published study", y = "Sequencing-based\ninfectivity measurement\nfrom current study") +
scale_x_log10(breaks = c(0.1,0.3,1,3)) +
scale_y_log10(breaks = c(0.1,0.3,1,3)) +
geom_point(data = ortholog1_melt_s2_plosbiol, aes(x = norm_geomean, y = D614G), alpha = 0.5) +
geom_text_repel(data = ortholog1_melt_s2_plosbiol, aes(x = norm_geomean, y = D614G, label = ortholog), color = "red", alpha = 0.8, size = 1.5, segment.color = "orange", segment.alpha = 0.5)
Variant_validation_graph2
ggsave(file = "Plots/Variant_validation_graph2.pdf", Variant_validation_graph2, height = 1.75, width = 2)
```
```{r Comparing correlations with human ACE2 variants}
ggplot() +
geom_point(data = low_kozak, aes(x = D614G, y = Alpha)) +
geom_text_repel(data = low_kozak, aes(x = D614G, y = Alpha, label = mutant), color = "red")
ggplot() +
geom_point(data = low_kozak, aes(x = D614G, y = Beta)) +
geom_text_repel(data = low_kozak, aes(x = D614G, y = Beta, label = mutant), color = "red")
ggplot() +
geom_point(data = low_kozak, aes(x = D614G, y = Gamma)) +
geom_text_repel(data = low_kozak, aes(x = D614G, y = Gamma, label = mutant), color = "red")
ggplot() +
geom_point(data = low_kozak, aes(x = D614G, y = Delta)) +
geom_text_repel(data = low_kozak, aes(x = D614G, y = Delta, label = mutant), color = "red")
D614G_Omicron_scatterplot <- ggplot() +
geom_point(data = low_kozak, aes(x = D614G, y = BA1), alpha = 0.5) +
geom_text_repel(data = low_kozak, aes(x = D614G, y = BA1, label = mutant), color = "red", size = 2, segment.color = "orange", segment.alpha = 0.5)
D614G_Omicron_scatterplot
ggsave(file = "Plots/D614G_Omicron_scatterplot.pdf", D614G_Omicron_scatterplot, height = 1.5, width = 1.7)
```
## The below section looks at all of the SARS-CoV-2 variant RBD co-structures with human ACE2
```{r D614G RBD-ACE2 contact maps}
pdb_7sxy_dist_frame <- read.csv(file = "Data/PDB_contact_maps/7sxy_ace2row_rbdcol_dist_matrix_min.csv")
pdb_7sxy_dist_frame$position <- as.numeric(rownames(pdb_7sxy_dist_frame))
pdb_7sxy_dist_frame_melt <- melt(pdb_7sxy_dist_frame, id = "position")
pdb_7sxy_dist_frame_melt$rbd_position <-as.numeric(substr(pdb_7sxy_dist_frame_melt$variable,2,5)) + 329
pdb_7sxy_dist_frame_melt$ace2_position <- as.numeric(pdb_7sxy_dist_frame_melt$position) + 18
pdb_7sxy_dist_ace2_positionlist <- as.numeric(unique(pdb_7sxy_dist_frame_melt$ace2_position)) ## For interpretation, need to add 18 later since actually starts at residue 19
pdb_7sxy_dist_rbd_positionlist <- as.numeric(unique(pdb_7sxy_dist_frame_melt$position)) ## For interpretation, need to add 316 later since actually starts at residue 331
pdb_7sxy_dist_frame_melt$ace2_rbd <- paste(pdb_7sxy_dist_frame_melt$ace2_pos, pdb_7sxy_dist_frame_melt$rbd_pos, sep = "_")
pdb_6lzg_dist_frame <- read.csv(file = "Data/PDB_contact_maps/6lzg_ace2row_rbdcol_dist_matrix_min.csv")
pdb_6lzg_dist_frame$position <- as.numeric(rownames(pdb_6lzg_dist_frame))
pdb_6lzg_dist_frame_melt <- melt(pdb_6lzg_dist_frame, id = "position")
pdb_6lzg_dist_frame_melt$rbd_position <-as.numeric(substr(pdb_6lzg_dist_frame_melt$variable,2,5)) + 332
pdb_6lzg_dist_frame_melt$ace2_position <- as.numeric(pdb_6lzg_dist_frame_melt$position) + 18
pdb_6lzg_dist_ace2_positionlist <- as.numeric(unique(pdb_6lzg_dist_frame_melt$ace2_position)) ## For interpretation, need to add 18 later since actually starts at residue 19