-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiSTEP_analysis.Rmd
7092 lines (6340 loc) · 294 KB
/
MultiSTEP_analysis.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: "MultiSTEP FIX project analysis"
author: "Nicholas Popp"
date: "`r Sys.Date()`"
output: pdf_document
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(echo = TRUE)
options(readr.show_col_types = FALSE)
```
```{r install and load libraries}
## install and load required packages
## knitr 1.41 for making files
if (!require(knitr)) install.packages('knitr')
library(knitr)
## here 1.2.0 for directory management
if (!require(here)) install.packages('here')
library(here)
## broom 1.2.0 for tidy fitting
if (!require(broom)) install.packages('broom')
library(broom)
## furrr for parallelizing
if (!require(furrr)) install.packages('furrr')
library(furrr)
## hash for creating hash table
if (!require(hash)) install.packages('hash')
library(hash)
## scales 1.1.1 for scientific notation
if (!require(scales)) install.packages('scales')
library(scales)
## tidyverse 1.3.1 for ggplot, dplyr, data manipulation
## absolutely required
if (!require(tidyverse)) install.packages('tidyverse')
library(tidyverse)
## paletteer 1.4.0 for color palettes
if (!require(paletteer)) install.packages('paletteer')
library(paletteer)
## ggpubr 0.4.0 for correlation stats
if (!require(ggpubr)) install.packages('ggpubr')
library(ggpubr)
## ggrastr 1.0.0 for reducing plot size when >1000 points
if (!require(ggrastr)) install.packages('ggrastr')
library(ggrastr)
## janitor 2.1.2 for cleaning data
if (!require(janitor)) install.packages('janitor')
library(janitor)
## ggridges 0.5.4 for stacked density plots
if (!require(ggridges)) install.packages('ggridges')
library(ggridges)
## patchwork 1.1.1 for aligning multi-panel plots
if (!require(patchwork)) install.packages('patchwork')
library(patchwork)
## colorspace 2.1-0 for color manipulation
if (!require(colorspace)) install.packages('colorspace')
library(colorspace)
## ggrepel 0.9.1 to label points easily
if (!require(ggrepel)) install.packages('ggrepel')
library(ggrepel)
## tidymodels 1.0.0 for classification models
if (!require(tidymodels)) install.packages('tidymodels')
library(tidymodels)
## themis 1.0.0 for dealing with unbalanced class data
if (!require(themis)) install.packages('themis')
library(themis)
## ggpattern 1.0.1 for striped fills
if (!require(ggpattern)) install.packages('ggpattern')
library(ggpattern)
## ggalluvial 1.1.1 for alluvial plots
if (!require(ggalluvial)) install.packages('ggalluvial')
library(ggalluvial)
## devtools 1.1.1 for installing from github
if (!require(devtools)) install.packages('devtools')
library(devtools)
## ggsankey 0.0.99999 for sankey plots
if (!require(ggsankey)) install.github('davidsjoberg/ggsankey')
library(ggsankey)
## ggpubr 0.5.0 for statistics
if (!require(ggpubr)) install.packages('ggpubr')
library(ggpubr)
## mcp 0.3.4 for changepoint analysis
## requires download of JAGS to work (https://sourceforge.net/projects/mcmc-jags/)
if (!require(mcp)) install.packages('mcp')
library(mcp)
## HDInterval 0.2.4 for changepoint analysis
if (!require(HDInterval)) install.packages('HDInterval')
library(HDInterval)
```
```{r Rmd file setup}
## make sure working directories are correct
## the analysis file should be one directory above all input files
i_am("MultiSTEP_analysis.Rmd")
###############################################################################
## set seed for reproducible plots (randomization)
set.seed(627)
```
```{r plot setup}
## set plot theming, including font size to 6pt
theme_set(theme_bw(base_size = 6) +
theme(text = element_text(size = 6, color = "black"),
strip.background = element_blank(),
strip.text = element_text(size = 6, color = "black"),
plot.tag = element_text(size = 6, color = "black"),
plot.caption = element_text(size = 6, color = "black"),
plot.title = element_text(size = 6, hjust = 0.5, vjust = 1, color = "black"),
legend.text = element_text(size = 6, color = "black"),
axis.text = element_text(size = 6, color = "black"),
axis.ticks = element_line(color = "black"),
panel.border = element_rect(color = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "right",
legend.justification = "center"))
```
```{r function setup}
## create beautiful heatmaps
heatmap_plot <- function(...) {
ggplot(data = ...,
aes(x = position,
y = fct_rev(var_aa),
fill = average_score2)) +
## setup to use color to plot missing data
geom_tile(data = . %>%
filter(is.na(average_score2)),
aes(color = ""),
fill = "grey50") +
## plot non-NA data with grey stroke
geom_tile(data = . %>%
filter(is_wt != "WT"),
color = "grey20") +
## fill in WT positions white (WT score, by definition)
geom_tile(data = . %>%
filter(is_wt == "WT"),
fill = "white", color = "grey20") +
## identify WT with point in tile
geom_point(data = . %>%
filter(is_wt == "WT"),
aes(shape = ""),
size = 0.2, color = "black") +
## adjust fill colors (blue = low, red = high, white = WT)
scale_fill_distiller(palette = "RdBu", direction = -1,
limits = c(0, 2),
labels = c("0", "0.5", "1", "1.5", "2")) +
scale_color_manual(values = NA) +
## scale y axis to remove excess space
scale_y_discrete(expand = c(0, 0),
guide = guide_axis(n.dodge = 2)) +
## add labels
labs(x = "Position",
y = "Substituted amino acid") +
## adjust plot features
theme(panel.border = element_rect(fill = NA, color = "black"),
axis.text.y = element_text(hjust = 0.5))
}
###############################################################################
## function to read out all matching Clinvar files in subdirectories
read_clinvar_path <- function(path){
## read in tsv file
read_tsv(path, col_names = TRUE,
col_select = c("Type", "Name", "#AlleleID", "ReviewStatus",
"ClinicalSignificance", "GeneSymbol")) %>%
## create path name variable
mutate(source_path = path) %>%
## convert path to year
extract(col = source_path,
into = "year",
regex = ".*_([0-9]+)-.*")
}
###############################################################################
## function to read out all matching Clinvar files in subdirectories
read_flow_path <- function(path){
## read in csv file
read_csv(path, col_names = TRUE) %>%
## create path name variable
mutate(source_path = path)
}
###############################################################################
## function to compare DNA and protein strings to identify variants
## use in conjunction with rowwise() and mutate() on a dataframe of sequences
## to call variants from sequence
variant_caller <- function(nt1, nt2) {
## create temp length count
temp_length <- str_length(nt1) - str_length(nt2)
## count insertions
if (temp_length < 0) {
## take absolute value of length to prevent negative numbers in table
temp_length <- abs(temp_length)
## output insertions with nt length
diff_aa <- paste0("insertion: length ", temp_length, " nt")
diff_nt <- paste0("insertion: length ", temp_length, " nt")
diff_codon <- paste0("insertion: length ", temp_length, " nt")
## count deletions, not including 3 nt deletions
} else if (temp_length > 0 & temp_length != 3) {
## output deletions with nt length
diff_aa <- paste0("deletion: length ", temp_length, " nt")
diff_nt <- paste0("deletion: length ", temp_length, " nt")
diff_codon <- paste0("deletion: length ", temp_length, " nt")
## correct length and codon deletion analysis
} else {
## turn strings into vector of NT
nt1vec <- unlist(strsplit(nt1, ""))
nt2vec <- unlist(strsplit(nt2, ""))
## combine strings into 3 NT codons
nt1codvec <- paste0(nt1vec[c(TRUE, FALSE, FALSE)],
nt1vec[c(FALSE, TRUE, FALSE)],
nt1vec[c(FALSE, FALSE, TRUE)])
nt2codvec <- paste0(nt2vec[c(TRUE, FALSE, FALSE)],
nt2vec[c(FALSE, TRUE, FALSE)],
nt2vec[c(FALSE, FALSE, TRUE)])
## convert WT to aa strings
aa1vec <- unlist(mget(nt1codvec, hash_codon_table@.xData))
aa2vec <- unlist(mget(nt2codvec, hash_codon_table@.xData))
## deletion analysis to find position
if (temp_length == 3){
## append NNN to end to create same length vector
nt2codvec_temp <- append(nt2codvec, "NNN")
## compare as vector, find first missing position
missing_pos <- (1:length(nt1codvec))[nt1codvec != nt2codvec_temp][1]
## add "NNN" at first missing position and re-compare
## append adds after position, so have to subtract 1
nt2codvec_NNN <- append(nt2codvec, "NNN", after = missing_pos - 1)
## find new missing first position
new_missing_pos <- (1:length(nt1codvec))[nt1codvec != nt2codvec_NNN]
## compare missing positions
match_missing <- missing_pos == new_missing_pos
## check for codon deletions + substitutions
if (length(match_missing) > 1){
## assign values for complex deletions
diff_aa <- paste0("complex deletion: length ", temp_length, " nt")
diff_nt <- paste0("complex deletion: length ", temp_length, " nt")
diff_codon <- paste0("complex deletion: length ", temp_length, " nt")
## if codon deletion is in frame, will only be same position and return TRUE
## if FALSE, deletion is out of frame
} else if (match_missing == TRUE) {
## create list of different amino acids, collapse with , separator
diff_aa <- paste0(aa1vec[new_missing_pos], new_missing_pos, "del",
collapse = ", ")
## create list of different nucleotides, collapse with , separator
diff_nt <- paste0("codon deletion: length ", temp_length, " nt")
## create list of different codons, collapse with , separator
diff_codon <- paste0(nt1codvec[new_missing_pos], new_missing_pos, "del")
} else {
## report deletion with nt length
diff_aa <- paste0("frameshift deletion: length ", temp_length, " nt")
diff_nt <- paste0("frameshift deletion: length ", temp_length, " nt")
diff_codon <- paste0("frameshift deletion: length ", temp_length, " nt")
}
} else {
## compare nucleotides and amino acids
var_nt <- (1:length(nt1vec))[nt1vec != nt2vec]
var_aa <- (1:length(aa1vec))[aa1vec != aa2vec]
var_codon <- (1:length(nt1codvec))[nt1codvec != nt2codvec]
## if no difference in length of amino acids or nucleotides, label WT
if (length(var_nt) == 0) {
## label as WT
diff_aa <- "WT"
diff_nt <- "WT"
diff_codon <- "WT"
## else, make list of variants at nucleotide and amino acid level
} else {
## divide nt position by 3 to make aa position
## use ceiling to create a round number and prevent dividing errors
ceiling_nt <- ceiling(var_nt / 3)
## only retain unique aa position values
ceiling_nt <- unique(ceiling_nt)
## create list of different amino acids, collapse with , separator
diff_aa <- paste0(aa1vec[ceiling_nt], ceiling_nt, aa2vec[ceiling_nt],
collapse = ", ")
## create list of different nucleotides, collapse with , separator
diff_nt <- paste0(nt1vec[var_nt], var_nt, nt2vec[var_nt],
collapse = ", ")
## create list of different codons
diff_codon <- paste0(nt1codvec[var_codon], var_codon, nt2codvec[var_codon],
collapse = ", ")
}
}
}
## concatenate different nt and aa together
diff_all <- c(diff_aa, diff_nt, diff_codon)
## add list names for unnesting later
names(diff_all) <- c("diff_aa", "diff_nt", "diff_codon")
## return list
return(diff_all)
}
###############################################################################
## function to call pathogenicity according to ACMG criteria (Richards, 2015)
## call this function within mutate() when modifying a dataframe
reclassify_vars <- function(very_strong = "very_strong",
strong = "strong",
moderate = "moderate",
supporting = "supporting") {
## determine resulting classification
case_when(
## pathogenic
very_strong == 1 & strong >= 1 ~ "P",
very_strong == 1 & moderate >= 2 ~ "P",
very_strong == 1 & moderate == 1 & supporting == 1 ~ "P",
very_strong == 1 & supporting >= 2 ~ "P",
strong >= 2 ~ "P",
strong == 1 & moderate >= 3 ~ "P",
strong == 1 & moderate == 2 & supporting >= 2 ~ "P",
strong == 1 & moderate == 1 & supporting >= 4 ~ "P",
## likely pathogenic
very_strong == 1 & moderate == 1 ~ "LP",
strong == 1 & moderate > 0 & moderate <= 2 ~ "LP",
strong == 1 & supporting >= 2 ~ "LP",
moderate >= 3 ~ "LP",
moderate == 2 & supporting >= 2 ~ "LP",
moderate == 1 & supporting >= 4 ~ "LP",
## VUS (all other combinations)
TRUE ~ "VUS")
}
## find distance between query position and list of feature positions
find_distance <- function(x, y){
## retain position
position <- x
## find closest feature position
closest <- y[which.min(abs(x - y))]
## calculate distance between query and feature
distance <- abs(x - closest)
## return all three as a string vector
return(paste(position, closest, distance))
}
```
```{r reference information}
## WT gene sequence in nucleotides (does not include engineered linker/tag/TMD)
wt_FIX_nt <- "ATGCAGCGCGTGAACATGATCATGGCAGAATCACCAGGCCTCATCACCATCTGCCTTTTAGGATATCTACTCAGTGCTGAATGTACAGTTTTTCTTGATCATGAAAACGCCAACAAAATTCTGAATCGGCCAAAGAGGTATAATTCAGGTAAATTGGAAGAGTTTGTTCAAGGGAACCTTGAGAGAGAATGTATGGAAGAAAAGTGTAGTTTTGAAGAAGCACGAGAAGTTTTTGAAAACACTGAAAGAACAACTGAATTTTGGAAGCAGTATGTTGATGGAGATCAGTGTGAGTCCAATCCATGTTTAAATGGCGGCAGTTGCAAGGATGACATTAATTCCTATGAATGTTGGTGTCCCTTTGGATTTGAAGGAAAGAACTGTGAATTAGATGTAACATGTAACATTAAGAATGGCAGATGCGAGCAGTTTTGTAAAAATAGTGCTGATAACAAGGTGGTTTGCTCCTGTACTGAGGGATATCGACTTGCAGAAAACCAGAAGTCCTGTGAACCAGCAGTGCCATTTCCATGTGGAAGAGTTTCTGTTTCACAAACTTCTAAGCTCACCCGTGCTGAGACTGTTTTTCCTGATGTGGACTATGTAAATTCTACTGAAGCTGAAACCATTTTGGATAACATCACTCAAAGCACCCAATCATTTAATGACTTCACTCGGGTTGTTGGTGGAGAAGATGCCAAACCAGGTCAATTCCCTTGGCAGGTTGTTTTGAATGGTAAAGTTGATGCATTCTGTGGAGGCTCTATCGTTAATGAAAAATGGATTGTAACTGCTGCCCACTGTGTTGAAACTGGTGTTAAAATTACAGTTGTCGCAGGTGAACATAATATTGAGGAGACAGAACATACAGAGCAAAAGCGAAATGTGATTCGAATTATTCCTCACCACAACTACAATGCAGCTATTAATAAGTACAACCATGACATTGCCCTTCTGGAACTGGACGAACCCTTAGTGCTAAACAGCTACGTTACACCTATTTGCATTGCTGACAAGGAATACACGAACATCTTCCTCAAATTTGGATCTGGCTATGTAAGTGGCTGGGGAAGAGTCTTCCACAAAGGGAGATCAGCTTTAGTTCTTCAGTACCTTAGAGTTCCACTTGTTGACCGAGCCACATGTCTTCGATCTACAAAGTTCACCATCTATAACAACATGTTCTGTGCTGGCTTCCATGAAGGAGGTAGAGATTCATGTCAAGGAGATAGTGGGGGACCCCATGTTACTGAAGTGGAAGGGACCAGTTTCTTAACTGGAATTATTAGCTGGGGTGAAGAGTGTGCAATGAAAGGCAAATATGGAATATATACCAAGGTATCCCGGTATGTCAACTGGATTAAGGAAAAAACAAAGCTCACT"
## WT gene sequence in amino acids (does not include engineered linker/tag/TMD)
wt_FIX <- "MQRVNMIMAESPGLITICLLGYLLSAECTVFLDHENANKILNRPKRYNSGKLEEFVQGNLERECMEEKCSFEEAREVFENTERTTEFWKQYVDGDQCESNPCLNGGSCKDDINSYECWCPFGFEGKNCELDVTCNIKNGRCEQFCKNSADNKVVCSCTEGYRLAENQKSCEPAVPFPCGRVSVSQTSKLTRAETVFPDVDYVNSTEAETILDNITQSTQSFNDFTRVVGGEDAKPGQFPWQVVLNGKVDAFCGGSIVNEKWIVTAAHCVETGVKITVVAGEHNIEETEHTEQKRNVIRIIPHHNYNAAINKYNHDIALLELDEPLVLNSYVTPICIADKEYTNIFLKFGSGYVSGWGRVFHKGRSALVLQYLRVPLVDRATCLRSTKFTIYNNMFCAGFHEGGRDSCQGDSGGPHVTEVEGTSFLTGIISWGEECAMKGKYGIYTKVSRYVNWIKEKTKLT"
###############################################################################
## convert WT FIX sequence to dataframe to use as dictionary
wt_FIX_aa <- tibble(wt_aa =
unlist(str_extract_all(wt_FIX, boundary("character"))),
position = seq(1, nchar(wt_FIX), by = 1))
## convert WT sequence dataframe to hash table for faster lookup
hash_wt_FIX <- hash(keys = wt_FIX_aa$position,
values = wt_FIX_aa$wt_aa)
###############################################################################
## import codon conversion table
codon_table <- read_csv(here("inputs", "codon_table", "codon_table.csv"))
## convert codon table to hash table for faster lookup
hash_codon_table <- hash(keys = codon_table$codon,
values = codon_table$aa)
###############################################################################
## import amino acid abbreviation table
aa_table <- read_csv(here("inputs", "codon_table", "aa_conversion.csv"))
## convert amino acid abbreviation table to hash table for faster lookup
## one letter to three letter abbreviation
hash_aa1_to_aa3 <- hash(keys = aa_table$aa1,
values = aa_table$aa3)
## convert amino acid abbreviation table to hash table for faster lookup
## three letter to one letter abbreviation
hash_aa3_to_aa1 <- hash(keys = aa_table$aa3,
values = aa_table$aa1)
###############################################################################
## read in protein domain table for FIX
domains <- read_csv(here("inputs", "protein_information", "domains.csv")) %>%
## make domain names a factor so they plot in default order
mutate(domain = factor(domain, levels = c("Signal peptide", "Propeptide",
"Gla", "EGF1", "EGF2",
"Activation peptide",
"Serine protease")),
domain_short = factor(domain_short, levels = c("SP", "PP", "Gla",
"EGF1", "EGF2", "AP",
"SPD")))
###############################################################################
## create antibody table for easy labeling
antibody_table <- tibble(antibody = c("001", "3570", "102", "124", "strep"),
antibody_nonnum = c("ab001", "ab3570", "ab102", "ab124", "abstrep"),
antibody_label = c("Carboxylation-sensitive FIX-specific antibody",
"Carboxylation-sensitive Gla-motif antibody",
"Heavy chain antibody",
"Light chain antibody",
"Strep II tag antibody")) %>%
## make two-line version for some plots
mutate(antibody_label2 = gsub("sensitive ", "sensitive\n", antibody_label))
###############################################################################
## define positions within library tiles
tile1 <- seq(from = 1, to = 164, by = 1)
tile2 <- seq(from = 146, to = 318, by = 1)
tile3 <- seq(from = 299, to = 461, by = 1)
## define tile overlapping positions, if any
overlap12 <- intersect(x = tile1, y = tile2)
overlap23 <- intersect(x = tile2, y = tile3)
###############################################################################
## create easy reference variables for RefSeq/Ensembl/UniProt accessions for FIX
refseq_cDNA <- "NM_000133.4"
refseq_protein <- "NP_000124.1"
refseq_gDNA <- "NC_000023.11"
ensembl_transcript_id <- "ENST00000218099"
ensembl_protein_id <- "ENSP00000218099"
uniprot_id <- "P00740"
```
```{r analyze PacBio sequencing data}
## import PacBio data
all_barcodes <- read_table(here("inputs", "pacbio",
"round1-2_FIX_allbc_noCterm_barcode_variant_map_cutoff3.txt"),
col_names = c("barcode", "sequence"))
###############################################################################
## call variants
all_barcodes_varcalled <- all_barcodes %>%
## variant_caller() requires rowwise(), not sure why
rowwise() %>%
## annotate variants
mutate(var = list(variant_caller(nt1 = wt_FIX_nt, nt2 = sequence))) %>%
## unlist variants for aa and nt
unnest_wider(col = var) %>%
## alter stop codon from * to X for easier analysis later
mutate(diff_aa = gsub("\\*", "X", diff_aa)) %>%
## remove extraneous columns
select(-sequence)
###############################################################################
## catalog variant types
all_barcodes_varcalled_type <- all_barcodes_varcalled %>%
## count variants
mutate(var_count = case_when(str_count(diff_aa, ":") > 0 ~ 0,
diff_aa == "WT" ~ 0,
diff_aa == "not seen" ~ 0,
TRUE ~ str_count(diff_aa, ",") + 1),
## split single variants into WT aa, variant aa, and position
wt_aa = case_when(var_count == 1 ~ str_sub(diff_aa, start = 1L, end = 1L),
diff_aa == "WT" ~ "WT",
TRUE ~ "XXX"),
var_aa = case_when(var_count == 1 & grepl("del", diff_aa) == TRUE ~
str_sub(diff_aa, start = -3L, end = -1L),
var_count == 1 & grepl("del", diff_aa) == FALSE ~
str_sub(diff_aa, start = -1L, end = -1L),
diff_aa == "WT" ~ "WT",
TRUE ~ "YYY"),
position = case_when(var_count == 1 ~ as.numeric(str_extract(diff_aa, "[0-9]+")),
diff_aa == "WT" ~ 0,
TRUE ~ 0),
## aggregate >5 variants
var_count = case_when(var_count > 5 ~ "6+",
TRUE ~ as.character(var_count)),
## classify variants
var_type = case_when(diff_aa == "not seen" ~ "not seen or filtered",
diff_aa == "WT" ~ "0 - WT",
str_count(diff_aa, ":") > 0 ~ "indel",
var_count == "1" & var_aa == "del" ~ "1 - codon deletion",
var_count == "1" & wt_aa == var_aa ~ "1 - synonymous",
var_count == "1" & var_aa == "X" ~ "1 - nonsense",
var_count == "1" ~ "1 - missense",
TRUE ~ var_count))
###############################################################################
## isolate only single variant barcodes
all_barcodes_varcalled_single <- all_barcodes_varcalled_type %>%
## filter to include only specified round and single variants
filter(grepl("1 - ", var_type) == TRUE | diff_aa == "WT") %>%
filter(grepl("del", var_type) != TRUE) %>%
## remove unnecessary columns
select(barcode, diff_aa, diff_nt, diff_codon) %>%
## change position of WT as 0, extract position otherwise
mutate(position = case_when(diff_aa == "WT" ~ 0,
TRUE ~ as.numeric(str_extract(diff_aa, "[0-9]+"))),
## identify WT and variant amino acids, replace WT as NA
wt_aa = case_when(diff_aa != "WT" ~ str_sub(diff_aa, start = 1L, end = 1L),
TRUE ~ NA_character_),
var_aa = case_when(diff_aa != "WT" ~ str_sub(diff_aa, start = -1L, end = -1L),
TRUE ~ NA_character_))
###############################################################################
## write barcode map to csv
write_csv(all_barcodes_varcalled_single,
here("outputs", "barcode_map",
"MultiSTEP_F9_barcode_variant_map_singlevars.csv"))
###############################################################################
## calculate statistics on unique values in PacBio libraries
pacbio_variants <- all_barcodes_varcalled_type %>%
group_by(var_type) %>%
summarise(across(.cols = c(contains("diff"), "barcode"),
.fns = n_distinct,
.names = "n_{.col}")) %>%
adorn_totals(where = c("row", "col"))
## calculate number of single codon variants in FIX scored by PacBio
pacbio_num_codon_variants <- pacbio_variants %>%
## keep only single codon variants not including indels
filter(grepl("1", var_type)) %>%
filter(!grepl("deletion", var_type)) %>%
## revert to non-tabyl dataframe
untabyl() %>%
## get totals
adorn_totals("row")
```
```{r analyzing Human Protein Atlas data}
## read in all genes in Human Protein Atlas
HPA_all <- read_tsv(here("inputs", "human_protein_atlas",
"proteinatlas_f7d77999.tsv")) %>%
## clean names
clean_names() %>%
## pull out localization, FDA approved drugs, and human disease association
mutate(localization = case_when(grepl("Predicted secreted",
protein_class) == TRUE ~ "Secreted",
grepl("Predicted membrane",
protein_class) == TRUE ~ "Membrane",
TRUE ~ "Intracellular"))
###############################################################################
## count genes by localization
HPA_secreted <- HPA_all %>%
count(localization) %>%
## calculate boundaries for donut plot
mutate(frac = round(n / sum(n), digits = 3),
ymax = cumsum(frac),
ymin = lag(ymax, default = 0),
mid = ymax - 0.5*frac)
###############################################################################
## Fig. 1a: donut plot of genes by localization
secreted_plot <- ggplot() +
## create background boxes with fill and grey border
geom_rect(data = HPA_secreted,
aes(xmin = 5, xmax = 6.5,
ymin = ymin, ymax = ymax,
fill = localization), color = "black") +
## make circular
coord_polar(theta = "y") +
## add labels with both number and percent of genes in cellular compartment
geom_text(data = HPA_secreted,
aes(label = paste0(comma(n), "\n", round(frac * 100, digits = 0), "%"),
x = 5.75, y = mid),
vjust = 0.5, hjust = 0.5, size = 6 / .pt) +
## rescale x axis and fill colors
scale_x_continuous(limits = c(3, 6.5)) +
scale_fill_manual(
values = lighten(as.list(paletteer_d("PNWColors::Sunset")[c(5, 3, 1)]),
amount = 0.2)) +
## remove all axes
theme_void(base_size = 6) +
## alter figure legend position, size, and colors
guides(fill = guide_legend(override.aes = list(size = 0.1, color = NA))) +
theme(legend.position.inside = c(0.5, 0.5),
legend.title = element_blank(),
legend.text = element_text(size = 6),
legend.key.size = unit(0.7, "lines"))
## save Fig. 1a
ggsave(here("outputs", "main_fig_panels", "1a_secreted_proteins_HPA.pdf"),
plot = secreted_plot, device = cairo_pdf,
height = 50, width = 50, units = "mm")
###############################################################################
## create list of secreted genes for later use with ClinVar
secreted_gene_list <- HPA_all %>%
filter(localization == "Secreted") %>%
select(gene)
```
```{r Clinvar secreted data}
## import yearly ClinVar data from December 2016 to June 2023
## and only include single nucleotide variants that pass filters
all_clinvar <- list.files(path = here("inputs", "ClinVar", "by_year"),
pattern = "*.txt",
recursive = TRUE) %>%
## then read each in using read_clinvar_path, which adds a path column
## that can be used to isolate the year
map_df(~read_clinvar_path(here("inputs", "ClinVar", "by_year", .))) %>%
## remove duplicates (hg37 and hg38)
distinct() %>%
## keep only single variants
filter(Type == "single nucleotide variant") %>%
## split Name into transcript and protein variant
extract(col = Name, into = c("Transcript", "protein_variant"),
regex = "(.*) \\((.*)\\)") %>%
## drop missing protein variants
drop_na(protein_variant) %>%
## remove synonymous, nonsense
filter(!grepl("Ter|=", protein_variant)) %>%
## remove variants without assertions
filter(!grepl("no assertion|no interpretation|-", ReviewStatus)) %>%
## keep only B/LB/VUS/LP/P
filter(!grepl(";|,|risk|not|other|drug|Affects|association",
ClinicalSignificance)) %>%
## convert classifications
mutate(ClinicalSignificance =
case_when(grepl("Conflicting", ClinicalSignificance) ~ "VUS",
grepl("Uncertain", ClinicalSignificance) ~ "VUS",
grepl("Benign/", ClinicalSignificance) ~ "Likely benign",
grepl("Pathogenic/", ClinicalSignificance) ~ "Likely pathogenic",
TRUE ~ ClinicalSignificance)) %>%
## keep only necessary columns
select(GeneSymbol, year, ClinicalSignificance)
###############################################################################
## count secreted gene variants by classification in each year
clinvar_secreted <- all_clinvar %>%
## remove nonsecreted genes
inner_join(secreted_gene_list, by = c("GeneSymbol" = "gene")) %>%
## count
count(year, ClinicalSignificance) %>%
## divide by thousands
mutate(nthousands = n / 1000)
###############################################################################
## Fig. 1b - ClinVar variants for secreted proteins, annual
secreted_clinvar_plot <- ggplot(clinvar_secreted,
aes(x = year,
y = nthousands,
group = ClinicalSignificance,
color = ClinicalSignificance)) +
## line graph
geom_line(linewidth = 0.5) +
## points
geom_point(size = 0.5) +
## rescale colors, x and y axes
scale_color_manual(values = c('Pathogenic' = 'firebrick3',
'Likely pathogenic' = 'coral',
'Benign' = 'royalblue3',
'Likely benign' = 'steelblue1',
'VUS' = 'grey50')) +
scale_x_discrete(expand = c(0.05, 0)) +
scale_y_continuous(expand = c(0, 0),
limits = c(-1, 91),
breaks = seq(0, 90, by = 30)) +
## alter legend position, size, color, location
guides(color = guide_legend(override.aes = list(size = 0.5,
linewidth = 0.5))) +
theme(legend.key.width = unit(3, 'mm'),
legend.key.height = unit(3, "mm"),
legend.key = element_rect(fill = NA, color = NA),
legend.title = element_blank(),
legend.position = c(0, 1),
legend.justification = c(0, 1),
legend.background = element_rect(fill = NA, color = NA),
## change axis text to be angled for horizontal space compression
axis.text.x = element_text(angle = 45, hjust = 1)) +
## add axis labels
labs(x = "Year",
y = "Secreted missense variants\n(thousands)")
## save Fig. 1b
ggsave(here("outputs", "main_fig_panels", "1b_secreted_clinvar.pdf"),
plot = secreted_clinvar_plot, device = cairo_pdf,
height = 43, width = 43, units = "mm")
```
```{r MultiSTEP construct comparison}
## import MultiSTEP construct experiment
construct_pilot <- list.files(path = here("inputs", "flow",
"strep_linkers",
"scale"),
pattern = "*.csv",
recursive = TRUE) %>%
map_df(~read_flow_path(here("inputs", "flow",
"strep_linkers",
"scale", .))) %>%
## clean names
clean_names() %>%
## rename Flowjo default variable names
rename(abstrep = fitc_a,
bfp = bv_450_a,
mcherry = pe_texas_red_a) %>%
## extract source path column to usable variables
extract(col = source_path, into = c("construct"),
regex = ".*100_(.*)_00[0-9]_.*") %>%
## adjust so that no negative values remain and
## add small pseudocount for log plotting to prevent log(0) errors
mutate(adj_abstrep = abstrep + abs(min(abstrep)) + 0.01,
## change names and order
construct = case_when(construct == "poly_G384A" ~ "Unrecombined",
construct == "WT" ~ "MultiSTEP:\nL1-Strep",
TRUE ~ "MultiSTEP:\nL1-Strep-L2"),
construct = factor(construct,
levels = c("Unrecombined",
"MultiSTEP:\nL1-Strep",
"MultiSTEP:\nL1-Strep-L2")))
###############################################################################
## Fig. S2b - pilot constructs
construct_plot <- construct_pilot %>%
ggplot(aes(x = adj_abstrep,
y = construct)) +
## add density distributions from flow cytometry
geom_density_ridges(aes(fill = construct,
color = construct,
height = after_stat(ndensity)),
show.legend = FALSE, alpha = 0.7, bandwidth = 1/64,
scale = 1) +
## adjust fill, x and y axes
scale_x_log10(limits = c(9.95, 1.05e4),
breaks = trans_breaks("log10", function(x) 10^x, n = 4),
labels = trans_format("log10", math_format(10^.x))) +
scale_y_discrete(limits = rev) +
scale_fill_viridis_d(option = "C", end = 0.8) +
scale_color_viridis_d(option = "C", end = 0.8) +
## add labels
labs(x = "Strep II tag-Alexa-488") +
## adjust grid lines, remove y axis title
theme(panel.grid.major.y = element_line(color = "grey40"),
axis.title.y = element_blank())
## save Fig. S1g
ggsave(here("outputs", "supp_fig_panels", "S1g_constructs.pdf"),
plot = construct_plot, device = cairo_pdf,
height = 42, width = 40, units = "mm")
```
```{r heavy chain pilot experiment}
## import heavy chain pilot data with known variants
pilot_102 <- list.files(path = here("inputs", "flow",
"pilot_variants_102",
"scale"),
pattern = "*.csv",
recursive = TRUE) %>%
map_df(~read_flow_path(here("inputs", "flow",
"pilot_variants_102",
"scale", .))) %>%
## clean names
clean_names() %>%
## rename Flowjo default variable names
rename(ab102 = alexa_fluor_647_a,
abstrep = alexa_fluor_488_a,
bfp = pacific_blue_a,
mcherry = m_cherry_a) %>%
## extract source path column to usable variables
extract(col = source_path, into = c("variant", "fluor"),
regex = ".*-([A-z]+[0-9]{0,3}[A-Z]?)_.*_(.*)\\+.csv") %>%
## adjust so that no negative values remain and
## add small pseudocount for log plotting to prevent log(0) errors
mutate(adj_ab102 = ab102 + abs(min(ab102)) + 0.01,
## change names and order
variant = case_when(variant == "control" ~ "Unrecombined",
TRUE ~ variant),
variant = factor(variant,
levels = c("Unrecombined", "WT", "C28Y",
"A37T", "S220T")))
###############################################################################
## Fig. 1e - pilot heavy chain
pilot_102_plot <- pilot_102 %>%
ggplot(aes(x = adj_ab102,
y = variant)) +
## add density distributions from flow cytometry
geom_density_ridges(aes(fill = variant,
color = variant,
height = after_stat(ndensity)),
show.legend = FALSE,
scale = 1, alpha = 0.7, bandwidth = 1/64) +
## adjust fill, x and y axes
scale_x_log10(limits = c(9.95, 1.05e6),
breaks = trans_breaks("log10", function(x) 10^x, n = 4),
labels = trans_format("log10", math_format(10^.x))) +
scale_y_discrete(limits = rev) +
scale_fill_viridis_d(option = "C", end = 0.8) +
scale_color_viridis_d(option = "C", end = 0.8) +
## add labels
labs(x = "Heavy chain-Alexa-647") +
## adjust grid lines, remove y axis title
theme(panel.grid.major.y = element_line(color = "grey40"),
axis.title.y = element_blank())
## save Fig. 1e
ggsave(here("outputs", "main_fig_panels", "1e_heavy_chain.pdf"),
plot = pilot_102_plot, device = cairo_pdf,
height = 45, width = 55, units = "mm")
```
```{r light chain pilot experiment}
## import light chain pilot data with known variants
pilot_124 <- list.files(path = here("inputs", "flow",
"pilot_variants_124",
"scale"),
pattern = "*.csv",
recursive = TRUE) %>%
map_df(~read_flow_path(here("inputs", "flow",
"pilot_variants_124",
"scale", .))) %>%
## clean names
clean_names() %>%
## rename Flowjo default variable names
rename(ab124 = alexa_647_a,
abstrep = gfp_a,
bfp = bfp_a,
mcherry = m_cherry_yg_a) %>%
## extract source path column to useable variables
extract(col = source_path, into = c("variant", "fluor"),
regex = ".*scale_Rep_.*_([A-z]+[0-9]{0,3}[A-Z]?)_rep.*_(.*)\\+.csv") %>%
## adjust so that no negative values remain and
## add small pseudocount for log plotting to prevent log(0) errors
mutate(adj_ab124 = ab124 + abs(min(ab124)) + 0.01,
adj_abstrep = abstrep + abs(min(abstrep)) + 0.01,
## change names and order
variant = case_when(variant == "neg" ~ "Unrecombined",
TRUE ~ variant),
variant = factor(variant,
levels = c("Unrecombined", "WT", "C28Y",
"A37T", "S220T")))
###############################################################################
## Fig. 1f - pilot light chain
pilot_124_plot <- pilot_124 %>%
ggplot(aes(x = adj_ab124,
y = variant)) +
## add density distributions from flow cytometry
geom_density_ridges(aes(fill = variant,
color = variant,
height = after_stat(ndensity)),
show.legend = FALSE,
scale = 1, alpha = 0.7, bandwidth = 1/64) +
## adjust fill, x and y axes
scale_x_log10(limits = c(9.95, 1.05e6),
breaks = trans_breaks("log10", function(x) 10^x, n = 4),
labels = trans_format("log10", math_format(10^.x))) +
scale_y_discrete(limits = rev) +
scale_fill_viridis_d(option = "C", end = 0.8) +
scale_color_viridis_d(option = "C", end = 0.8) +
## add labels
labs(x = "Light chain-Alexa-647") +
## adjust grid lines, remove y axis title
theme(panel.grid.major.y = element_line(color = "grey40"),
axis.title.y = element_blank())
## save Fig. 1f
ggsave(here("outputs", "main_fig_panels", "1f_light_chain.pdf"),
plot = pilot_124_plot, device = cairo_pdf,
height = 45, width = 55, units = "mm")
```
```{r strep tag pilot experiment}
## import light chain pilot data with known variants
pilot_strep <- list.files(path = here("inputs", "flow",
"pilot_variants_strep",
"scale"),
pattern = "*.csv",
recursive = TRUE) %>%
map_df(~read_flow_path(here("inputs", "flow",
"pilot_variants_strep",
"scale", .))) %>%
## clean names
clean_names() %>%
## rename Flowjo default variable names
rename(abstrep = alexa_fluor_647_a,
bfp = pacific_blue_a,
mcherry = m_cherry_a) %>%
## extract source path column to useable variables
extract(col = source_path, into = c("variant", "fluor"),
regex = ".*_293F_([A-z]+[0-9]{0,3}[A-Z]?)_rep.*_(.*)\\+.csv") %>%
## adjust so that no negative values remain and
## add small pseudocount for log plotting to prevent log(0) errors
mutate(adj_abstrep = abstrep + abs(min(abstrep)) + 0.01,
## change names and order
variant = case_when(variant == "neg" ~ "Unrecombined",
TRUE ~ variant),
variant = factor(variant,