/
paper.Rmd
2332 lines (2051 loc) · 69.1 KB
/
paper.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: "ADRB2 First Pass Analysis"
author: "Nathan Lubock"
output:
html_document:
df_print: paged
---
# Executive Summary
This document outlines our experimental platform for performing Deep Mutational Scan of the $\beta_2$ Adrenergic receptor, as well as a precursory analysis of our most recent experiments. Here we include details of how the assay works, and key results that emphasize the robustness and repeatability our assay.
```{r, init, echo=FALSE, message=FALSE, warning=FALSE}
# pretty plots!
library(gridExtra)
library(paletteer)
library(scales)
library(cowplot) # <- plot_grid
library(ggbeeswarm)
#library(ggrepel)
# clustering
library(factoextra)
library(uwot) # <- devtools::install_github("jlmelville/uwot")
library(dbscan)
# tidyverse
library(furrr); plan(multiprocess) # <- parallel map
library(corrr) # <- devtools::install_github("drsimonj/corrr")
library(stringr)
library(broom)
library(forcats)
library(magrittr)
library(tidyverse)
# setwd('~/Dropbox/Kosuri/ADRB2/')
# ---------------------------------------------------------------------
knitr::opts_chunk$set(fig.width = 16, fig.height = 9, dpi=300)
knitr::opts_chunk$set(fig.path = "./pipeline/")
knitr::opts_chunk$set(dev='png')
knitr::opts_chunk$set(warning=FALSE)
knitr::opts_chunk$set(echo=FALSE)
# see http://stackoverflow.com/q/36230790 to scroll output
# needs to be really big to prevent wrapping from happening before the scroll bar comes up
options(width = 240)
# ---------------------------------------------------------------------
theme_pub <- function(base_size = 13, base_family = "") {
require(grid)
# based on https://github.com/noamross/noamtools/blob/master/R/theme_nr.R
# start with theme_bw and modify from there!
theme_bw(base_size = base_size, base_family = base_family) +# %+replace%
theme(
# grid lines
# panel.grid.major.x = element_line(colour="#ECECEC", size=0.5, linetype=1),
#panel.grid.major.y = element_line(colour="#ECECEC", size=0.5, linetype=1),
panel.grid.major.x = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
panel.background = element_blank(),
# axis options
axis.ticks.y = element_blank(),
axis.title.x = element_text(size=rel(2.25), vjust=0.25),
axis.title.y = element_text(size=rel(2.25), vjust=0.35),
axis.text = element_text(color="black", size=rel(1.5)),
# legend options
legend.title = element_blank(),
legend.key = element_rect(fill="white"),
legend.key.size = unit(1, "cm"),
legend.text = element_text(size=rel(2)),
# facet options
strip.text = element_text(size=rel(2)),
strip.background = element_blank(),
# title options
plot.title = element_text(size=rel(2.25), vjust=0.25, hjust=0.5)
)
}
# blank out grids for cowplot
theme_blank <- theme(
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
panel.grid.major.y = element_blank(),
panel.background = element_blank()
)
# set the theme and brewer color
theme_set(theme_pub())
```
Load up.
```{r, loading-main, message=FALSE, warning=FALSE}
# ancillary files
aa.types <- read_delim('ancillary/aa-class.txt', delim = ' ')
wt.key <- read_delim('ancillary/wt-key.txt', delim = ' ')
wt.aa <- tibble(
AA = system("tail -1 data/ADRB2_prot.fasta | fold -w1", intern=T),
Pos = seq(2,414)
) %>%
filter(Pos < 414) %>%
mutate(
Struct = case_when(
Pos %in% seq(1, 25) ~ 'N-term',
Pos %in% seq(26, 61) ~ 'TM1',
Pos %in% seq(62, 65) ~ 'IC1',
Pos %in% seq(66, 96) ~ 'TM2',
Pos %in% seq(97, 101) ~ 'EC1',
Pos %in% seq(102, 137) ~ 'TM3',
Pos %in% seq(138, 145) ~ 'IC2',
Pos %in% seq(146, 172) ~ 'TM4',
Pos %in% seq(173, 195) ~ 'EC2',
Pos %in% seq(196, 237) ~ 'TM5',
Pos %in% seq(238, 261) ~ 'IC3',
Pos %in% seq(262, 299) ~ 'TM6',
Pos %in% seq(300, 303) ~ 'EC3',
Pos %in% seq(304, 328) ~ 'TM7',
Pos %in% seq(329, 341) ~ 'H8',
Pos %in% seq(342, 413) ~ 'C-term',
TRUE ~ 'Other'
) %>%
factor(levels =c('N-term', 'TM1', 'IC1', 'TM2', 'EC1',
'TM3', 'IC2', 'TM4', 'EC2', 'TM5',
'IC3', 'TM6', 'EC3', 'TM7', 'H8', 'C-term'))
) %>%
inner_join(aa.types, by = 'AA')
numbering <- read_csv('./ancillary/b2-gpcrdb.csv', col_names = c('gpcr_db', 'bw', 'sb', 'b2')) %>%
mutate(
WT_AA = str_sub(b2,1,1),
Pos = as.numeric(str_sub(b2,2))
)
boundaries <- wt.aa %>%
group_by(Struct) %>%
summarise(Pos = max(Pos))
#-------------------------------------------------------------------------------
# Treatment data
bc.counts.3 <- read_delim(
'output/drug-3_idx-bcs-counts.txt.gz',
delim = ' ',
col_names = c('Index', 'Barcode', 'Count'),
col_types = 'cci'
) %>%
# add index information and reads per index
inner_join(
read_delim('data/drug-3_idx-key.txt', delim = ' '),
by = 'Index'
) %>%
select(-Index) %>%
mutate(Repeat = as.integer(Repeat))
bc.counts.7 <- read_delim(
'output/drug-7_cond-bcs-counts.txt.gz',
delim = ' ',
col_names = c('Condition', 'Repeat', 'Barcode', 'Count'),
col_types = 'cici'
) %>%
mutate(
Condition = case_when(
Condition == '150' ~ '0.150',
Condition == '625' ~ '0.625',
TRUE ~ Condition
),
Repeat = as.integer(Repeat)
)
bc.counts <- bind_rows(bc.counts.3, bc.counts.7) %>%
mutate(
Forsk_Expr = case_when(Condition %in% c('0', '0.150', '0.625', 'F') ~ 'F',
Condition %in% c('5', 'F_5') ~ 'F_5')
)
rm(bc.counts.3, bc.counts.7)
# write_csv(bc.counts, './pipeline/bc-counts.csv.gz')
#-------------------------------------------------------------------------------
# Barcode Mapping Data
single.mutants <-
read_delim(
'output/NextSeq_MiSeq.known-vars.txt.gz',
#'~/Downloads/NextSeq_MiSeq.known-vars.txt.gz',
delim = ' ',
col_names = c('Barcode', 'MapReads', 'Variant'),
col_types = 'cic'
) %>%
mutate(
Pos = as.integer(str_extract(Variant, '\\d+')) + 1, # account for Met
AA = str_extract(Variant, '\\D$')
)
#-------------------------------------------------------------------------------
# Neg controls
neg.controls <- read_tsv(
'./output/NextSeq_MiSeq.negs.txt.gz',
col_names = c('Barcode', 'MapReads', 'CIGAR', 'Loc', 'Class'),
col_types = 'cicic'
)
neg.controls %<>%
filter(Class == 'Indel') %>%
semi_join(single.mutants) %>%
select(Barcode) %>%
anti_join(neg.controls, .)
#-------------------------------------------------------------------------------
# synonymous mutants
synon <- read_delim(
'./output/NextSeq_MiSeq.synon.translate.txt',
delim = ' ',
col_names = c('Barcode', 'MapReads')
)
#-------------------------------------------------------------------------------
# Forskolin Cutoffs/pseudocounts
F_Max <- 10
F_Min <- 0.2
reads <- bc.counts %>%
count(Condition, Repeat, wt=Count) %>%
rename(Reads = n) %>%
mutate(Pseudo = 1 * Reads / min(Reads)) # <---- tune pc here
exprs <- bc.counts %>%
select(Condition, Repeat) %>%
distinct() %>%
filter(!Condition %in% c('F', 'F_5')) %>%
arrange(Condition, Repeat)
```
# Experimental Design
We first synthesized all ~8,000 missense variants of the $\beta_2$ Adrenergic receptor. We then cloned these variants upstream of a cyclic AMP (cAMP) responsive luciferase reporter that contains a unique DNA "barcode" sequence of the 3' untranslated region of the reporter (Figure labels: minP - minimal promoter, Luc - luciferase, BC - barcode). This barcode uniquely identifies the variant cloned upstream and allows us to measure that variant's function by RNA-seq. We then integrated the entire variant-reporter cassette at single copy in a defined loci on the HEK293T genome. This ensures that a variant's activity is linked only to its associated genetic reporter.
In this experiment, we incubated our heterogeneous cell line containing multiple redundant copies of all ~8,000 variants with 0, 0.15, 0.625, and 5 $\mu$M isoproterenol in two biological replicates. We then isolated and sequenced the RNA corresponding to our barcodes. In order to estimate the copy number of each variant, we also incubated our cell line with forskolin to induce expression of our reporter without activating our $\beta_2$ mutants. We could then use the ratio of barcode abundance in the isoproterenol and forskolin conditions as a measurement of fitness.
```{r, test, fig.width=10.8, fig.height=8.43}
knitr::include_graphics('./ancillary/MultiplexedSchemeADRB2.png')
```
# Preprocessing
## Repeatability
Let's see how well our measurements correspond at the barcode level.
```{r, bc-corrs}
# enable parallel correlation testing
cor.help <- function(df) {
df %>%
spread(Repeat, Norm) %$%
cor.test(`1`, `2`, na.action = 'complete.obs') %>%
tidy()
}
bc.counts %>%
inner_join(reads) %>%
mutate(Norm = log10(Count / (Reads / 1e6))) %>%
select(Barcode, Condition, Repeat, Norm) %>%
group_by(Condition) %>%
nest() %>%
mutate(Cor = future_map(data, cor.help)) %>%
select(-data) %>%
unnest() %>%
arrange(Condition)
bc.corr.plot <- bc.counts %>%
filter(Condition == '0.625') %>%
inner_join(reads) %>%
mutate(Norm = Count / (Reads / 1e6)) %>%
select(Barcode, Norm, Repeat) %>%
spread(Repeat, Norm) %>%
sample_n(500000) %>%
ggplot(aes(x=`1`, y=`2`)) +
geom_abline() +
geom_hex(bins=100, aes(fill=log10(..count..))) +
scale_fill_paletteer_c(viridis, plasma) +
scale_x_log10(
labels=comma,
limits=c(NA,100)
) +
scale_y_log10(
labels=comma,
limits=c(NA,100)
) +
annotation_logticks() +
labs(
x = 'Repeat 1 (RPM)',
y = 'Repeat 2 (RPM)',
title = 'Barcodes'
) +
theme(legend.position = 'none')
bc.corr.plot
```
## Experimental Changes
We can also track the effect of experimental modulation
```{r, corr-over-time}
bc.counts.2 <- read_delim(
'output/drug-2_idx-bcs-counts.txt.gz',
delim = ' ',
col_names = c('Index', 'Barcode', 'Count'),
col_types = 'cci'
) %>%
# add index information and reads per index
inner_join(
read_delim('data/drug-2_idx-key.txt', delim = ' '),
by = 'Index'
) %>%
select(-Index) %>%
mutate(
Repeat = as.integer(Repeat),
Day = 1L
) %>%
filter(Condition == '0.625')
bc.counts.6 <- read_delim(
'output/drug-6_cond-bcs-counts.txt.gz',
delim = ' ',
col_names = c('Condition', 'Repeat', 'Barcode', 'Count'),
col_types = 'cici'
) %>%
mutate(
Condition = case_when(
Condition == '150' ~ '0.150',
Condition == '625' ~ '0.625',
TRUE ~ Condition
),
Repeat = as.integer(Repeat),
Day = 2L
) %>%
filter(Condition == '0.625')
days.625 <- bc.counts %>%
filter(Condition == '0.625') %>%
select(-Forsk_Expr) %>%
mutate(Day = 3L) %>%
bind_rows(bc.counts.2) %>%
bind_rows(bc.counts.6)
rm(bc.counts.2, bc.counts.6)
# normalize counts
days.625 %<>%
count(Day, Repeat, wt=Count) %>%
rename(Reads = n) %>%
inner_join(days.625) %>%
mutate(Norm = log10(Count / (Reads / 1e6)))
# corr calc
days.625 %>%
select(Day, Repeat, Barcode, Norm) %>%
group_by(Day) %>%
nest() %>%
mutate(Cor = future_map(data, cor.help)) %>%
select(-data) %>%
unnest()
#12:6
days.625 %>%
select(Day, Repeat, Barcode, Norm) %>%
group_by(Day) %>%
nest() %>%
mutate(foo = map(data, ~spread(.x, Repeat, Norm) %>% sample_n(500000))) %>%
select(-data) %>%
unnest() %>%
ggplot(aes(x=`1`, y=`2`)) +
geom_abline() +
geom_hex(bins=100, aes(fill=log10(..count..))) +
scale_fill_paletteer_c(viridis, plasma) +
scale_x_log10(
labels=comma,
limits=c(NA,10)
) +
scale_y_log10(
labels=comma,
limits=c(NA,10)
) +
annotation_logticks() +
facet_wrap(~ Day, nrow=1) +
labs(
x = 'Repeat 1 (RPM)',
y = 'Repeat 2 (RPM)'
)
rm(days.625)
```
## Forskolin Normalization
Before we aggregate our barcodes together into variants (see Appendix) to, we must first normalize to their copy number by using forskolin as a proxy. At this stage, the concept of a repeat breaks down (due to some experimental considerations). However, we do keep experiments performed on different days separate.
We will set a minimum read cutoff in our forskolin condition to ensure that variants that we pseudocount in the drug conditions will be real. Plotting the distributions of read counts per barcocde for our forskolin conditions, we have
```{r, forsk-reads}
f.cutoffs.int <- reads %>%
filter(Condition %in% c('F', 'F_5')) %>%
mutate(Cutoff = F_Min) %>%
mutate(Count = round(Cutoff * (Reads/1e6)))
bc.counts %>%
filter(Condition %in% c('F', 'F_5')) %>%
mutate(Count = if_else(Count > 30, 30L, Count)) %>%
ggplot(aes(x=Count)) +
geom_histogram(binwidth = 1) +
geom_vline(
data=f.cutoffs.int,
aes(xintercept=Count),
color='red'
)+
facet_grid(Repeat ~ Condition) +
scale_x_continuous(
breaks=seq(0,30),
labels=c(seq(0,29), '30+')
) +
scale_y_log10() +
annotation_logticks(sides = 'l')
rm(f.cutoffs.int)
```
In addition, we will average the result together, drop any barcodes that are not present in both repeats, and that the mean value pass the read filter. For the drug conditions, we will set any missing value to a pseudocount. (This will take a while ~10-15 mins depending on how many cores are avalible)
```{r, forsk-ratio}
# dplyr grinds to a halt if there are a ton of groups (e.g. millions of bcs)
# amazingly, it's faster to spread the data and manually calc the average
avg.help <- function(df) {
df %>%
select(Forsk_Expr, Barcode, Repeat, F_Norm) %>%
spread(Repeat, F_Norm) %>%
mutate(Avg = (`1` + `2`) / 2) %>%
filter(!is.na(Avg)) %>%
select(Barcode, Forsk_Expr, F_Norm = Avg)
}
forsk <- bc.counts %>%
filter(Condition %in% c('F', 'F_5')) %>%
inner_join(reads, by = c('Condition', 'Repeat')) %>%
mutate(F_Norm = Count / Reads) %>%
group_by(Condition) %>%
nest() %>%
mutate(foo = future_map(data, avg.help)) %>%
select(-data) %>%
unnest() %>%
select(-Condition)
forsk.ratio.raw <- bc.counts %>%
filter(!Condition %in% c('F', 'F_5')) %>%
group_by(Condition, Repeat, Forsk_Expr) %>%
nest() %>%
# add explicit 0's to bc's missing from forsk
# filter ensures we're joining the right forsk condition
mutate(
foo = future_map2(data, Forsk_Expr,
~right_join(.x, filter(forsk, Forsk_Expr == .y), by = 'Barcode')
)
) %>%
select(-data, -Forsk_Expr) %>%
unnest() %>%
replace_na(list(Count = 0L)) %>%
inner_join(reads) %>%
group_by(Condition, Repeat) %>%
mutate(
Is_Pseudo = if_else(Count == 0, T, F),
Norm = (Count + Pseudo) / (Reads + n()*Pseudo),
Ratio = Norm / F_Norm
) %>%
ungroup()
```
Now that we have normalized each barcode to its copy number, we will filter out the nosiest population
### Copy Number Filtering
We suspect that one of the largest sources of noise will come from variants that have a low cellular representation. Using forskolin as a proxy, we will plot the deviation from the mean variant value $Dist = \log_{10}(Ratio) - mean(\log_{10}(Ratio))$, where $Ratio = \frac{Count/Reads}{Count_{Forskolin}/Reads_{Forskolin}}$. To aid in visualization, we will plot the barcodes for 800 mutants.
```{r, mean-dev}
forsk.ratio.raw %>%
inner_join(single.mutants, by = 'Barcode') %>%
inner_join(
single.mutants %>%
select(Pos, AA) %>%
distinct() %>%
sample_n(800)
) %>%
group_by(Condition, Repeat, Pos, AA) %>%
mutate(
Mean = mean(log10(Ratio)),
Dist = log10(Ratio) - Mean
) %>%
ungroup() %>%
ggplot(aes(x=F_Norm * 1e6, y=Dist)) +
geom_hline(yintercept=0, color='black', linetype='dashed') +
geom_point(alpha=0.1, aes(color=Is_Pseudo)) +
geom_smooth(se=F, method='loess', aes(color=Is_Pseudo)) +
geom_smooth(se=F, method='loess', color='black') +
geom_vline(xintercept = F_Max, color = 'black', linetype='dashed') +
geom_vline(xintercept = F_Min, color = 'black', linetype='dashed') +
facet_grid(Repeat ~ Condition) +
scale_x_log10() +
scale_color_manual(values=c('#009B9E','#C75DAB')) +
annotation_logticks(sides='b') +
labs(
x = 'Forskolin Counts (Reads per Million)',
y = expression(log[10]~Distance~From~Mean)
) +
theme(legend.position = 'Bottom')
```
We see that barcodes with low copy-number tend to over-estimate the mean, while high copy-number variants under-estimate it. Thus, we will remove these variants from the population
```{r, forsk-filter}
forsk.ratio <- forsk.ratio.raw %>%
filter(
F_Norm * 1e6 > F_Min,
F_Norm * 1e6 < F_Max
)
# link to library and negative controls
single.mutant.expression <- forsk.ratio %>%
inner_join(single.mutants, by = 'Barcode')
# subtract 69 bp for the FLAG-tag, 1 to make numbering nice
negs <- neg.controls %>%
filter(Class == 'Indel') %>%
mutate(Pos = (Loc - 70) %/% 3) %>%
filter(Pos > 0) %>%
inner_join(forsk.ratio)
# write_csv(forsk.ratio.raw, './pipeline/forsk-ratio-raw.csv')
rm(forsk.ratio.raw)
rm(bc.counts)
rm(forsk)
```
## Forskolin Repeatability
What do the correlations look like at this stage?
```{r, forsk-corr}
forsk.ratio %>%
mutate(Ratio = log10(Ratio)) %>%
select(Barcode, Condition, Repeat, Ratio) %>%
spread(Repeat, Ratio) %>%
group_by(Condition) %>%
nest() %>%
mutate(Cor = map(data, ~tidy(cor.test(.x$`1`, .x$`2`, na.action='complete.obs')))) %>%
select(-data) %>%
unnest()
forsk.ratio %>%
filter(Condition == '0.625') %>%
select(Barcode, Ratio, Repeat) %>%
spread(Repeat, Ratio) %>%
ggplot(aes(x=`1`, y=`2`)) +
geom_abline() +
geom_point(alpha=0.01) +
scale_x_log10(labels=comma) +
scale_y_log10(labels=comma) +
annotation_logticks() +
labs(
x = 'Repeat 1 (AU)',
y = 'Repeat 2 (AU)'
)
```
## Variant Filtering
One possible source of noise could be coming from a lack of barcodes. We would assume that as the number of barcodes increase the CV should decrease
```{r, lib-dist}
lib.med <- single.mutant.expression %>%
group_by(Condition, Repeat, Pos, AA) %>%
summarise(
Median = median(Ratio),
MAD = mad(Ratio),
Mean = mean(Ratio),
SD = sd(Ratio),
CV = SD / Mean,
N = n()
) %>%
ungroup()
lib.med %>%
ggplot(aes(x=N, y=CV)) +
geom_point(alpha=0.01) +
facet_grid(Repeat~Condition) +
geom_smooth()
```
We see that this is not the case.
## Barcode vs Variant Correlation
```{r, corrs}
lib.med %>%
mutate(Mean = log10(Mean)) %>%
select(Condition, Repeat, Pos, AA, Mean) %>%
spread(Repeat, Mean) %>%
group_by(Condition) %>%
nest() %>%
mutate(Cor = map(data, ~tidy(cor.test(.x$`1`, .x$`2`, na.action='complete.obs')))) %>%
select(-data) %>%
unnest()
lib.corr.plot <- lib.med %>%
filter(Condition == '0.625') %>%
select(Pos, AA, Repeat, Mean) %>%
spread(Repeat, Mean) %>%
ggplot(aes(x=`1`, y=`2`)) +
geom_abline() +
geom_hex(bins=100, aes(fill=log10(..count..))) +
scale_x_log10(labels=comma) +
scale_y_log10(labels=comma) +
scale_fill_paletteer_c(viridis, plasma) +
annotation_logticks() +
labs(
x = 'Repeat 1 (AU)',
y = 'Repeat 2 (AU)',
title = 'Missense Variants'
) +
theme(legend.position = 'none')
# aspect 9:9
plot_grid(bc.corr.plot, lib.corr.plot, nrow=2)
```
## PositiveNegative Controls
### Negative Control Normalization
Next, we need to account for how our data is changing across conditions. Since we used chip-synthesized oligos to generate our library, we expect a large proportion of our library to be frameshifts. We can use these frameshifts as a sort of "spike-in" control if they do not respond to drug. Plotting our frameshifts by position, we have
```{r, neg-control-pos}
negs.med <- negs %>%
group_by(Condition, Repeat, Pos) %>%
summarise(
Median = median(Ratio),
MAD = mad(Ratio),
Mean = mean(Ratio),
SD = sd(Ratio),
CV = SD / Mean,
N = n(),
AA = 'Indel'
) %>%
ungroup()
negs.by.pos <- exprs %>%
inner_join(negs.med) %>%
mutate(
Condition = paste0(Condition, ' uM Iso'),
Condition = if_else(Condition == '0 uM Iso', '-Iso', Condition)
) %>%
ggplot(aes(x=Pos, y=Mean)) +
geom_point() +
geom_smooth(se=F) +
geom_vline(xintercept = 330, linetype = 'dashed') +
#scale_y_continuous(trans='log2') +
facet_grid(Repeat ~ Condition) +
labs(
y = 'Forskolin Ratio',
x = 'Position',
title = 'Effect of Indel per Codon'
)
#1600:900
negs.by.pos
```
We see that the effect is diminished shortly after the start of the unstructured C-terminus! Thus we will exclude these frameshifts from our negative control set.
### Positive vs. Negative Controls
Now that our positive and negative controls are normallized, we will plot the mean response for each condition.
```{r, wt-vs-negs}
# filter out negs < 330 (start of c-terminal tail)
negs.scale <- negs %>%
filter(Pos < 330) %>%
group_by(Condition, Repeat) %>%
summarise(
Scale_Median = median(Ratio),
Scale_Mean = mean(Ratio),
Scale_SD = sd(Ratio),
Scale_N = n()
) %>%
ungroup() %>%
mutate(Variant = 'Indel')
scalars <- synon %>%
inner_join(forsk.ratio) %>%
group_by(Condition, Repeat) %>%
summarise(
Scale_Median = median(Ratio),
Scale_Mean = mean(Ratio),
Scale_SD = sd(Ratio),
Scale_N = n(),
Variant = 'Synon'
) %>%
ungroup() %>%
bind_rows(negs.scale)
wt.vs.negs <- scalars %>%
ggplot(aes(x=as.numeric(Condition), y=Scale_Mean, color=Variant)) +
geom_point() +
stat_summary(fun.y = mean, geom = 'line', lwd = 1)
wt.vs.negs
```
We see that our frameshifts and WT reads are decreasing as a function of isoproterenol concentration. This is at ends with the expectation that frameshifts should not respond to isoproterenol stimulation. We hypothesize that both curves are decreasing as the drug concentration increases because more of the functionally retarded mutants will be activated, thereby "stealing" reads from fully active mutants. Thus, by normalizing to the mean negative control value (which should remain constant regardless of drug concentration) at each condition for each repeat we can account for the change in reads per variant.
```{r, negs-norm}
negs.norm <- scalars %>%
filter(Variant == 'Indel') %>%
select(Condition, Repeat, Select_Mean = Scale_Mean) %>%
inner_join(scalars) %>%
ggplot(aes(x=as.numeric(Condition), y=Scale_Mean/Select_Mean, color=Variant)) +
geom_point() +
stat_summary(fun.y = mean, geom = 'line', lwd = 1)
negs.norm
```
Normalizing to WT should also account for these changes and make our values easier to interpret in the process
```{r, wt-norm}
wt.norm <- scalars %>%
filter(Variant == 'Synon') %>%
select(Condition, Repeat, Select_Mean = Scale_Mean) %>%
inner_join(scalars) %>%
ggplot(aes(x=as.numeric(Condition), y=Scale_Mean/Select_Mean, color=Variant)) +
geom_point() +
stat_summary(fun.y = mean, geom = 'line', lwd = 1)
wt.norm
```
Interestingly, the negative controls do not remain flat after normalization. This implies that we have not fully accounted for the compositional effects in our library or that our synonymous mutants are problematic. Given what we know about how our synonymous mutants are detected, this is probably the case.
## Write out intermediate files
Since the first half of these calculations are quite expensive, we'll save an intermediate version of our data
```{r, for.eric}
# save intermediate data-frame
# write_csv(lib.med, './output/lib-med.csv.gz')
# write_csv(negs.med, './output/negs-med.csv.gz')
# write_csv(scalars, './output/scalars.csv')
# write_csv(exprs, './output/exprs.csv')
# do the class averaging here
class.norm.int <- single.mutant.expression %>%
filter(F_Norm * 1e6 < F_Max) %>%
inner_join(aa.types, by = 'AA') %>%
group_by(Condition, Repeat, Pos, Class) %>%
summarise(
Mean = mean(Ratio),
N = n()
) %>%
ungroup()
# write_csv(class.norm.int, './output/class-norm-int.csv.gz')
```
# Final DF
We will use the standard propegation of uncertainty formula to combine the SDs from our two repeats $\sigma = \frac{1}{2\sqrt{\frac{\sigma^2_1}{\mu^2_1} + \frac{\sigma^2_2}{\mu^2_1}}$
```{r, final-df}
# forsk.ratio.raw <- read_csv('./pipeline/forsk-ratio-raw.csv.gz', col_types = 'ccidciiddldd')
# lib.med <- read_csv('./output/lib-med.csv.gz', col_names = T, col_types = 'ciicdddddi')
# negs.med <- read_csv('./output/negs-med.csv.gz', col_names = T, col_types = 'ciidddddic')
# scalars <- read_csv('./output/scalars.csv', col_names = T, col_types = 'cidddic')
# class.norm.int <- read_csv('./output/class-norm-int.csv.gz', col_names = T, col_types = 'ciicdi')
# exprs <- read_csv('./output/exprs.csv', col_names = T, col_types = 'ci')
# aa.types <- read_delim('./ancillary/aa-class.txt', delim = ' ')
# numbering <- read_csv('./ancillary/b2-gpcrdb.csv', col_names = c('gpcr_db', 'bw', 'sb', 'b2')) %>%
# mutate(
# WT_AA = str_sub(b2,1,1),
# Pos = as.numeric(str_sub(b2,2))
# )
#---------------------------------------------------------------------------------
variants.norm.raw <- lib.med %>%
inner_join(scalars, by = c('Condition', 'Repeat')) %>%
filter(Variant == 'Indel') %>% #<--------------------
mutate(Norm = Mean / Scale_Mean)
################################################################################
# CHOOSE NORMALIZATION HERE
################################################################################
# group by amino acid class to get extra power
class.norm.raw <- class.norm.int %>%
inner_join(
scalars %>% filter(Variant == 'Indel'), # <--------------------
by = c('Condition', 'Repeat')
) %>%
mutate(Norm = Mean / Scale_Mean) %>%
select(Condition, Repeat, Pos, Class, Norm, N)
#-------------------------------------------------------------------------------
# Drop variants with high CV's and average repeats together
variants.norm <- variants.norm.raw %>%
# filter(CV < 1) %>%
group_by(Condition, Pos, AA) %>%
summarise(
Min = min(Norm),
Max = max(Norm),
Norm = mean(Norm),
N = mean(N),
Uncert = 0.5 * sqrt(sum(SD^2 / Scale_Mean^2)),
PCV = Uncert / Norm
) %>%
ungroup() %>%
inner_join(aa.types, by = 'AA') %>%
mutate(
Struct = case_when(
Pos %in% seq(1, 25) ~ 'N-term',
Pos %in% seq(26, 61) ~ 'TM1',
Pos %in% seq(62, 65) ~ 'IC1',
Pos %in% seq(66, 96) ~ 'TM2',
Pos %in% seq(97, 101) ~ 'EC1',
Pos %in% seq(102, 137) ~ 'TM3',
Pos %in% seq(138, 145) ~ 'IC2',
Pos %in% seq(146, 172) ~ 'TM4',
Pos %in% seq(173, 195) ~ 'EC2',
Pos %in% seq(196, 237) ~ 'TM5',
Pos %in% seq(238, 261) ~ 'IC3',
Pos %in% seq(262, 299) ~ 'TM6',
Pos %in% seq(300, 303) ~ 'EC3',
Pos %in% seq(304, 328) ~ 'TM7',
Pos %in% seq(329, 341) ~ 'H8',
Pos %in% seq(342, 413) ~ 'C-term',
TRUE ~ 'Other'
) %>%
factor(levels =c('N-term', 'TM1', 'IC1', 'TM2', 'EC1',
'TM3', 'IC2', 'TM4', 'EC2', 'TM5',
'IC3', 'TM6', 'EC3', 'TM7', 'H8', 'C-term'))
)
class.norm <- class.norm.raw %>%
# filter(CV < 1) %>%
group_by(Condition, Pos, Class) %>%
summarise(
Min = min(Norm),
Max = max(Norm),
SD = sd(Norm),
Norm = mean(Norm),
N = n()
) %>%
ungroup() %>%
mutate(
Struct = case_when(
Pos %in% seq(1, 25) ~ 'N-term',
Pos %in% seq(26, 61) ~ 'TM1',
Pos %in% seq(62, 65) ~ 'IC1',
Pos %in% seq(66, 96) ~ 'TM2',
Pos %in% seq(97, 101) ~ 'EC1',
Pos %in% seq(102, 137) ~ 'TM3',
Pos %in% seq(138, 145) ~ 'IC2',
Pos %in% seq(146, 172) ~ 'TM4',
Pos %in% seq(173, 195) ~ 'EC2',
Pos %in% seq(196, 237) ~ 'TM5',
Pos %in% seq(238, 261) ~ 'IC3',
Pos %in% seq(262, 299) ~ 'TM6',
Pos %in% seq(300, 303) ~ 'EC3',
Pos %in% seq(304, 328) ~ 'TM7',
Pos %in% seq(329, 341) ~ 'H8',
Pos %in% seq(342, 413) ~ 'C-term',
TRUE ~ 'Other'
) %>%
factor(levels =c('N-term', 'TM1', 'IC1', 'TM2', 'EC1',
'TM3', 'IC2', 'TM4', 'EC2', 'TM5',
'IC3', 'TM6', 'EC3', 'TM7', 'H8', 'C-term'))
)
```
## Frame Shifts and Mutational Tolerance
As the name would suggest, mutational tolerance is a given residue's ability to accept amino acid substitutions. For our purposes, we will bound activity between the frameshift and WT, and average the effects of all substitutions at a given position. This ensures that substitutions that result in better than WT activity or worse than the mean frameshift do not artificially bring the tolerance up or down.
```{r, frameshift-tolerance-track}
frameshifts <- negs.med %>%
mutate(AA = '(-)') %>%
inner_join(
scalars %>%
filter(Variant == 'Indel'),
by = c('Condition', 'Repeat')
) %>%
mutate(Norm = Mean / Scale_Mean) %>%
group_by(Condition, Pos, AA) %>%
summarise(Norm = mean(Norm)) %>%
ungroup()
# tolerance is just the average effect of each mutation at a give pos
tolerance <- variants.norm %>%
group_by(Condition, Pos) %>%
summarise(Tolerance = mean(Norm)) %>%
mutate(Rank = rank(Tolerance)) %>%
ungroup()
```
# Validation
## Variant Distributions
Now that we are normalizing to the mean synonymous variant, let's see what the distributions of effects look like (excluding C-terminus from the frameshfits)
```{r, norm-dist}
negs.vs.indel <- negs.med %>%
filter(Pos < 330) %>%
inner_join(scalars, by = c('Condition', 'Repeat')) %>%
filter(Variant == 'Indel') %>% # <--------------------
mutate(Norm = Mean / Scale_Mean) %>%
group_by(Condition, Pos, AA) %>%
summarise(Norm = mean(Norm)) %>%
ungroup() %>%
bind_rows(
variants.norm %>%
select(Condition, Pos, AA, Norm)
) %>%
mutate(
AA = if_else(AA == 'Indel', 'Frameshift', 'Missense'),
Condition = if_else(Condition == '0', '-Iso', paste(Condition, 'uM Iso'))
)
# ASPECT 9:9
negs.vs.indel %>%
ggplot(aes(x=Norm, color=AA)) +
geom_vline(xintercept = 1, linetype = 'dashed') +
geom_density(lwd=1.1) +
scale_x_continuous(
trans = 'log2',
breaks = c(0.5, 1, 2, 4),
labels = c(0.5, 1, 2, 4),
limits = c(2^-1.5, 2^2.5)
) +
facet_wrap(~ Condition, ncol=1) +
scale_color_manual(values = c('#ca0020', '#0571b0')) +
labs(
x = 'Activity',
y = 'Density'
) +
theme(legend.position = 'bottom')
# sig test
negs.vs.indel %>%
group_by(Condition) %>%
nest() %>%
mutate(foo = map(data, ~tidy(wilcox.test(Norm ~ AA, data=.x)))) %>%
select(-data) %>%
unnest()
```
## Negs by Position
Similar to before, we can plot the effect of frameshift relative to WT
```{r, negs-vs-wt}
# ASPECT 9:9
frameshifts %>%
mutate(
Condition = paste0(Condition, ' uM Iso'),
Condition = if_else(Condition == '0 uM Iso', '-Iso', Condition)
) %>%
ggplot(aes(x=Pos, y=Norm)) +
geom_point() +
geom_smooth(se=F) +
geom_vline(xintercept = 330, linetype = 'dashed') +
facet_wrap(~ Condition, ncol = 1) +
scale_y_continuous(trans='log2') +
labs(
y = 'Activity',
x = 'Position'
)
# sig test
frameshifts %>%
mutate(Group = if_else(Pos > 341, 'C-term', 'Other')) %>%
group_by(Condition) %>%
nest() %>%
mutate(
foo = map(data, ~tidy(wilcox.test(Norm ~ Group, data=.x)))
) %>%
select(-data) %>%
unnest() %>%
select(-method)
frameshifts %>%