-
Notifications
You must be signed in to change notification settings - Fork 0
/
hla_binding_preferences.Rmd
1737 lines (1492 loc) · 60 KB
/
hla_binding_preferences.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: "Self and foreing protein presentation preferences of HLA alleles"
output: html_document
---
Setup
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
if (!startsWith(as.character(getRversion()), "3.6")) {
stop("R v3.6 required in order to execute this Rmd file")
}
library(tidyverse)
library(broom)
library(data.table)
library(limma) #bioc
library(topGO)
library(org.Hs.eg.db) #bioc
library(ontologyIndex)
library(ggbeeswarm)
library(ggplot2)
library(Biostrings) #bioc
library(ggrepel)
library(circlize)
library(multipanelfigure)
library(ggsci)
library(latex2exp)
library(ggdist)
library(ggpubr)
library(ComplexHeatmap)
library(rstatix)
library(ontologySimilarity)
library(gridExtra)
library(cowplot)
get_os <- function(){
sysinf <- Sys.info()
if (!is.null(sysinf)){
os <- sysinf['sysname']
if (os == 'Darwin')
os <- "osx"
} else { ## mystery machine
os <- .Platform$OS.type
if (grepl("^darwin", R.version$os))
os <- "osx"
if (grepl("linux-gnu", R.version$os))
os <- "linux"
}
tolower(os)
}
if (get_os() == "osx") {
read_gz <- function(x) fread(paste("gzcat", x))
} else {
read_gz <- function(x) fread(paste("zcat", x))
}
rename <- dplyr::rename
select <- dplyr::select
```
## 1. HLA ligand-enriched genes and their GO analysis
### Load and preprocess binding predictions
Read in netMHCpan binders
```{r}
data.pred.full <- read_gz("data/human_proteome_netmhcpan_summary.txt.gz")
data.pred.full %>%
group_by(hla, ligand.len) %>%
summarize(count = sum(count)) %>%
arrange(-count) %>%
head()
```
Select data for pilot analysis
```{r}
data.pred.full %>%
filter(ligand.len == 9, hla %in% c("HLA-A1101", "HLA-A0201",
"HLA-A0101", "HLA-A0301",
"HLA-B0702", "HLA-B2705",
"HLA-B0801", "HLA-B5701", # HIV
"HLA-C0702", "HLA-C1502", # SARS
"HLA-C0202", "HLA-C0801")) -> data.pred.sel
data.pred.sel %>%
group_by(hla) %>%
summarize(count = sum(count)) %>%
arrange(-count)
```
Get protein lengths and Entrez IDs
```{r}
human_prots <- readAAStringSet("data/UP000005640_9606.fasta") %>%
as.character
# ! this provides uniprot <> entrez conversions
meta.prot <- data.table(uniprot.id2 = str_split_fixed(names(human_prots), "[\\| ]", 4)[,3],
protein.len = nchar(human_prots)) %>%
mutate(name = str_split_fixed(uniprot.id2, "_", 2)[,1]) %>%
merge(fread("data/uniprot_to_entrez.txt"))
```
Compute base statistics - observed and expected number of presented peptides per gene. Expected number is an average across a given HLA
```{r}
data.pred.sel.s <- data.pred.sel %>%
as.data.frame %>%
merge(meta.prot) %>%
group_by(hla) %>%
mutate(P0 = sum(count) / sum(protein.len - ligand.len)) %>%
ungroup %>%
rowwise() %>%
mutate(odds = log2((count + 1) / (protein.len + 1 - ligand.len) / P0),
p.value = binom.test(count + 1, protein.len + 1 - ligand.len,
p = P0, alternative = "two.sided")$p.value) %>%
group_by(hla) %>%
mutate(p.value.adj = p.adjust(p.value, method = "BH")) %>%
ungroup
```
### Human proteins enriched and depleted in HLA ligands
```{r}
#! hla.gene column is not used further
data.pred.sel.s <- data.pred.sel.s %>%
mutate(hla.gene = substr(hla, 5, 5),
sel = ifelse(odds >= 1 & p.value.adj < 0.05, 1,
ifelse(odds <= -1 & p.value.adj < 0.05, -1,
0)),
protein.len.q = cut(protein.len, quantile(protein.len)))
```
Motifs of surveyed HLA alleles
```{r FigS1, fig.width=10, fig.height=12}
pfigs1 <- ggdraw() +
draw_image("motifs/FigS1/HLA-A0201.png", x = .5, y = 1.05, hjust = 1, vjust = 1, width = 0.5, height = .45) +
draw_image("motifs/FigS1/HLA-A1101.png", x = 1, y = 1.05, hjust = 1, vjust = 1, width = 0.5, height = .45) +
draw_image("motifs/FigS1/HLA-B0702.png", x = .5, y = .72, hjust = 1, vjust = 1, width = 0.5, height = .45) +
draw_image("motifs/FigS1/HLA-B2705.png", x = 1, y = .72, hjust = 1, vjust = 1, width = 0.5, height = .45) +
draw_image("motifs/FigS1/HLA-C0202.png", x = .5, y = .39, hjust = 1, vjust = 1, width = 0.5, height = .45) +
draw_image("motifs/FigS1/HLA-C1502.png", x = 1, y = .39, hjust = 1, vjust = 1, width = 0.5, height = .45) +
draw_plot_label(c("HLA-A0201", "HLA-A1101", "HLA-B0702", "HLA-B2705", "HLA-C0202", "HLA-C1502"),
x = c(.15, .65, .15, .65, .15, .65), y = c(1, 1, .67, .67, .34, .34))
pfigs1
pdf("figures/FigS1.pdf", height = 12, width = 10)
pfigs1
dev.off()
```
Plot over- and under-represented proteins according to HLA ligand frequency
```{r Fig2a, fig.width = 6, fig.height = 10}
#! excl_for_now may be excessive
excl_for_now <- c(
"HLA-A0301","HLA-A0101",
"HLA-B5701", "HLA-B0801",
"HLA-C0801", "HLA-C0702")
hla_incl_vert <- c("HLA-A0201", "HLA-A1101",
"HLA-B0702", "HLA-B2705",
"HLA-C0202", "HLA-C1502")
hla_incl <- c("HLA-A0201", "HLA-B0702", "HLA-C0202",
"HLA-A1101", "HLA-B2705", "HLA-C1502")
pfig2a <- data.pred.sel.s %>%
filter(!(hla %in% excl_for_now)) %>%
mutate(hla = factor(hla, levels = hla_incl_vert)) %>%
ggplot(aes(x = odds, y = pmin(-log10(p.value), 20), size = count,
color = sel %>% as.factor())) +
geom_point() +
geom_vline(xintercept = 0, linetype = "dashed", color = "grey") +
#geom_hline(yintercept = 3, linetype = "dashed", color = "grey") +
scale_size_continuous("Number of\npeptides", breaks = c(1, 10, 100, 1000)) +
scale_color_manual("Ligand -",
values = c("#56b4df", "#000000", "#e69d00"),
labels=c("Depleted", "No change", "Enriched")) +
scale_x_continuous(TeX("$log_{2}\\,\\left[\\frac{ligands_{obs}}{ligands_{exp}}\\right]$"), limits = c(-5, 5)) +
ylab(TeX("$-log_{10}\\~Pvalue_{adj}$")) +
facet_wrap(~hla, ncol = 2) + #facet_wrap(~hla, nrow = 2) +
theme_pubclean() +
theme(legend.position = "bottom",
legend.box = "vertical")
pfig2a
```
```{r TableS1}
pst1 <- data.pred.sel.s %>%
filter(hla %in% hla_incl,
sel == 1) %>%
group_by(hla) %>%
summarize(enriched.genes = length(unique(entrez.id))) %>%
merge(data.pred.sel.s %>%
filter(hla %in% hla_incl,
sel == -1) %>%
group_by(hla) %>%
summarize(depleted.genes = length(unique(entrez.id)))) %>%
merge(data.pred.sel %>%
group_by(hla) %>%
summarize(ligand.count = sum(count)) ) %>%
arrange(hla) %>%
setNames(., c("Allele", "Number of\n enriched genes",
"Number of\n depleted genes", "Ligand count"))
ggtexttable(pst1, rows = NULL,
theme = ttheme("classic"))
pst1
```
### Presentation preferences based on source human protein length
```{r}
data.pred.sel.s.len <- data.pred.sel.s %>%
filter(!(hla %in% excl_for_now)) %>%
group_by(hla, sel, protein.len.q) %>%
summarize(count = n()) %>%
group_by(hla, sel) %>%
mutate(total = sum(count)) %>%
mutate(p = count / total)
```
```{r FigS2}
pfigs2 <- data.pred.sel.s.len %>%
merge(expand.grid(hla = data.pred.sel.s.len$hla %>% unique,
sel = data.pred.sel.s.len$sel %>% unique,
protein.len.q = data.pred.sel.s.len$protein.len.q %>% unique), all = T) %>%
mutate(p = ifelse(is.na(p), 0, p)) %>%
mutate(hla = factor(hla, levels = hla_incl)) %>%
ggplot(aes(x = protein.len.q %>% as.integer,
y = p,
fill = sel %>% as.factor,
color = sel %>% as.factor)) +
geom_errorbar(aes(ymin = p, ymax = p + sqrt(p * (1-p) / total)),
position = "dodge") +
geom_bar(stat = "identity", position = "dodge") +
scale_fill_manual("",
values = c("#56b4df", "#000000", "#e69d00"),
labels=c("Depleted","No change","Enriched")) +
scale_color_manual("",
values = c("#56b4df", "#000000", "#e69d00"),
labels=c("Depleted","No change","Enriched")) +
xlab("Protein length quartile") + ylab("Fraction of proteins") +
facet_wrap(~hla, nrow = 2) +
theme_pubclean() +
theme(aspect = 1, legend.position = "bottom")
pfigs2
pdf("figures/FigS2.pdf", height = 4, width = 7)
pfigs2
dev.off()
```
### GO analysis
http://web.mit.edu/~r/current/arch/i386_linux26/lib/R/library/limma/html/goana.html
```{r}
get_annots <- function(.set1, .set2 = meta.prot$entrez.id,
.threshold = 0.01, .fun = goana) {
.set1 <- .set1 %>% unique
.set2 <- c(.set1, .set2) %>% unique
.fun(.set1, universe = .set2,
FDR = 1.01) %>% # we'll do our own FDR filtering
add_rownames("Term.ID") %>%
mutate(total.N = length(.set2),
total.DE = length(.set1),
fold = log2(DE / total.DE / N * total.N),
P.DE.adj = p.adjust(P.DE, method = "BH")) %>%
filter(P.DE.adj < .threshold) %>%
arrange(P.DE, -fold)
}
get_annots1 <- function(.sel, .hla, data = data.pred.sel.s,
.threshold = 0.01, .fun = goana) {
get_annots(data %>% filter(hla == .hla, sel == .sel) %>% .$entrez.id,
data %>% filter(hla == .hla, sel == 0) %>% .$entrez.id,
.threshold, .fun) %>%
mutate(hla = .hla, sel = .sel)
}
data.pred.sel.s %>%
select(hla, sel) %>%
unique %>%
filter(sel != 0) %>%
group_by(sel, hla) %>%
group_modify(~ get_annots(filter(data.pred.sel.s, hla == .y$hla, sel == .y$sel)$entrez.id,
filter(data.pred.sel.s, hla == .y$hla, sel == 0)$entrez.id)) -> go.enr.1
```
```{r Fig2b, fig.height=14, fig.width=10}
trunc_str <- function(x, len = 6) {
strsplit(x, " ") %>%
lapply(function(xx) {
if(length(xx) >= len) {
xx[len] <- "..."
return(paste0(xx[1:len], collapse = " "))
}
return(paste0(xx, collapse = " "))
}) %>% unlist
}
go.top.1 <- go.enr.1 %>%
group_by(sel, hla) %>%
filter(rank(P.DE.adj) <= 20) %>%
.$Term.ID %>% unique
pfig2b <- go.enr.1 %>%
filter(!(hla %in% excl_for_now),
Term.ID %in% go.top.1) %>%
mutate(Term = trunc_str(Term, 4),
direction = ifelse(sel > 0, "enriched", "depleted")) %>%
ggplot(aes(x = factor(hla, levels = hla_incl_vert),
y = fct_reorder2(paste(Ont, Term), fold, paste(sel, hla)))) +
geom_quasirandom(aes(size = fold, fill = direction), shape = 21, width = 0.2) +
#geom_text(aes(label = paste0(round(100 * DE / total.DE, 0), "%"))) +
scale_y_discrete("", position = "right") +
#scale_x_discrete("", position = "top") +
xlab("") +
scale_fill_manual("HLA ligand -", values = c("#56b4df", "#e69d00")) +
#scale_color_distiller("-log10 Padj", palette = "Reds", direction = 1) +
scale_size_continuous("GO term enrinchment\nfold, log2", breaks = c(1, 2 ,4)) +
theme_pubclean() +
theme(legend.position = "bottom",
legend.box = "vertical",
axis.text.x = element_text(angle = 90, vjust = 0.5),
axis.text.y = element_text(family = "mono", size = 8))
pfig2b
```
```{r Fig2, fig.height = 14, fig.width = 14}
pfig2 <- ggdraw() +
draw_plot(pfig2a, x = 0, y = 0, width = .42, height = 1) +
draw_plot(pfig2b, x = .43, y = -.1, width = .57, height = 1.1) +
draw_plot_label(label = c("A", "B"), size = 11,
x = c(0, .42), y = c(1, 1))
pfig2
pdf("figures/Fig2.pdf", height = 14, width = 14)
pfig2
dev.off()
```
### Amino acid composition of HLEPs
```{r Fig3a}
#function for calculation of amino acid composition of a protein
aa_freq_count <- function(prot.seq, id_name) {
as.character(prot.seq) %>%
strsplit(split="") %>% unlist() %>%
table() %>% as_tibble() %>%
rename(aminoacid = '.') %>%
filter(!aminoacid %in% c("X", "U")) %>%
mutate(freq = n / sum(n),
id = id_name) %>%
select(aminoacid, freq, id)
}
#amino acid composition of all proteins from human proteome
aa.freq.prots <- data.table(seq = human_prots,
uniprot.id2 = str_split_fixed(names(human_prots), "[\\| ]", 4)[,3]) %>%
apply(MARGIN = 1, FUN = function(x) {aa_freq_count(x[1], x[2])}) %>%
rbindlist() %>%
rename(uniprot.id2 = id)
#amino acid composition of proteins enriched or depleted for selected alleles
data.pred.sel.s.aafreq <- data.pred.sel.s %>%
filter(hla %in% hla_incl) %>%
select(uniprot.id2, hla, sel) %>%
distinct() %>%
merge(aa.freq.prots) %>%
group_by(hla, sel, aminoacid) %>%
summarise(freq.mean = mean(freq),
sem = sd(freq)/sqrt(n())) %>%
ungroup()
hla.anchor.res <- tibble(hla = c(rep("HLA-A0201", 2), "HLA-A1101", "HLA-B0702", "HLA-B2705", rep("HLA-C0202", 3), rep("HLA-C1502", 3)), aminoacid = c("L", "V", "K", "P", "R", "F", "Y", "L", "L", "I", "V"), anchor = 1)
data.pred.sel.s.aafreq <- data.pred.sel.s.aafreq %>%
merge(hla.anchor.res, all = T) %>%
mutate(anchor = replace_na(anchor, -1))
aa.levels <- c("L","F","I","M","V","W","Y","C","H","A","G","P","T","S","Q","N","D","E","R","K")
pfig3a <- data.pred.sel.s.aafreq %>%
mutate(sel = factor(sel, levels = c("-1", "0", "1"))) %>%
filter(sel != "-1") %>%
ggplot(aes(x = factor(aminoacid, levels = aa.levels), color = sel, group = sel)) +
geom_bar(aes(y = anchor), stat = "identity", fill = "grey", color = 'white', alpha = 0.2) +
geom_line(aes(y = freq.mean)) +
geom_errorbar(aes(ymin=freq.mean-1.96*sem, ymax=freq.mean+1.96*sem), width=.1) +
facet_wrap(~hla, ncol = 2, scales = "free_x") +
scale_color_manual("",
values = c("#000000", "#e69d00"),
labels=c("Human proteome", "HLA ligand-enriched\n proteins")) +
xlab("") + ylab("Frequency of amino acid") +
coord_cartesian(ylim = c(0.005,0.15)) +
theme_pubclean() +
theme(legend.position = "bottom",
legend.box = "vertical")
pfig3a
```
### Amino acid composition of proteins of GO terms depleted for all alleles but HLA-B0702
```{r Fig3b}
data(gene_GO_terms)
#Which genes correspond to particular GO terms
go_genes <- plyr::ldply(gene_GO_terms, rbind) %>%
melt(id=1, value.name = "Term.ID") %>%
select(uniprot.id2 = .id, Term.ID) %>%
filter(Term.ID != '')
#Which GO terms are depleted for most of alleles
go.enr.1 %>%
filter(hla %in% hla_incl) %>%
group_by(Term.ID) %>%
summarise(sel.sum = sum(sel),
alleles = paste0(substring(hla, 6,10), collapse = ' ')) %>%
arrange(sel.sum)
#Note that there is a group of 14 GO terms that are common for HLDPs of all alleles but HLA-B0702
go.depl <- go.enr.1 %>%
filter(hla %in% hla_incl,
hla != "HLA-B0702") %>%
group_by(Term.ID) %>%
summarise(sel.go = sum(sel)) %>%
filter(sel.go == min(sel.go))
pfig3b <- go.enr.1 %>%
ungroup() %>%
filter(Term.ID %in% go.depl$Term.ID) %>%
select(Ontology = Ont, Term) %>%
distinct() %>%
mutate(Term = str_wrap(Term, 40)) %>%
arrange(Ontology) %>%
ggtexttable(rows = NULL,
theme = ttheme("classic", base_size = 8, padding = unit(c(2, 2), "mm")))
go.depl.genes <- go.depl %>%
merge(go_genes) %>%
merge(data.pred.sel.s %>%
mutate(uniprot.id2 = str_split_fixed(uniprot.id2, "_", 4)[,1]) %>%
filter(hla %in% hla_incl,
hla != "HLA-B0702",
sel < 0) %>%
distinct(uniprot.id2))
go.depl.aafreq <- go.depl.genes %>%
merge(aa.freq.prots %>%
mutate(uniprot.id2 = str_split_fixed(uniprot.id2, "_", 4)[,1])) %>%
bind_rows(aa.freq.prots %>%
mutate(sel.go = 0)) %>%
group_by(sel.go, aminoacid) %>%
summarise(freq.mean = mean(freq),
sem = sd(freq)/sqrt(n()))
pfig3c <- go.depl.aafreq %>%
mutate(sel.go = factor(sel.go)) %>%
ggplot(aes(x = factor(aminoacid, levels = aa.levels), color = sel.go, group = sel.go)) +
geom_line(aes(y = freq.mean)) +
geom_errorbar(aes(ymin=freq.mean-1.96*sem, ymax=freq.mean+1.96*sem), width=.1) +
scale_color_manual("",
values = c("#56b4df", "#000000"),
labels=c("Proteins for GO terms depleted\n in all HLAs but HLA-B0702", "Human proteome")) +
xlab("") + ylab("Frequency of amino acid") +
coord_cartesian(ylim = c(0.005,0.15)) +
theme_pubclean() +
theme(legend.position = "bottom",
legend.box = "vertical")
pfig3c
```
```{r Fig3, fig.width=7, fig.height=8}
pfig3 <- ggdraw() +
draw_plot(pfig3a, x = 0, y = .43, width = 1, height = .57) +
draw_plot(pfig3b, x = .15, y = 0, width = .1, height = .4) +
draw_plot(pfig3c, x = .4, y = 0, width = .58, height = .4) +
draw_plot_label(label = c("A", "B", "C"), size = 11,
x = c(0, 0, .4), y = c(1, .42, .42))
pfig3
pdf("figures/Fig3.pdf", height = 8, width = 7)
pfig3
dev.off()
```
### Different amino acid composition of proteins of different length quartiles
```{r FigS6a}
aa.short.2 <- tibble(aminoacid = c("L","F","I","M","V","W","Y","C","H","A","G","P","T","S","Q","N","D","E","R","K"), short = c(rep("LFIMV",5), rep("other", 6), "P", rep("other", 4),"DE","DE","RK","RK"))
levels.anchors <- c("LFIMV", "RK", "DE", "P", "other")
aa.freq.prots.q <- aa.freq.prots %>%
merge(meta.prot %>%
select(uniprot.id2, protein.len) %>%
distinct() %>%
mutate(protein.len.q = cut(protein.len, quantile(protein.len))))
pfigs6a <- aa.freq.prots.q %>%
merge(aa.short.2, by.x = "aminoacid", by.y = "aminoacid") %>%
group_by(short, uniprot.id2, protein.len.q) %>%
summarise(freq = sum(freq)) %>%
group_by(short, protein.len.q) %>%
summarise(freq.mean = mean(freq),
sd = sd(freq),
sem = sd(freq)/sqrt(n())) %>%
drop_na() %>%
ggplot(aes(x = protein.len.q %>% as.integer,
group = protein.len.q,
y = freq.mean)) +
facet_wrap(~factor(short, levels = levels.anchors), scales = "free") +
geom_point() +
geom_errorbar(aes(ymin=freq.mean-1.96*sem, ymax=freq.mean+1.96*sem), width=.1) +
xlab("Protein length quartile") + ylab("Aggregated frequency of amino acids") +
theme_pubr()
pfigs6a
```
### Re-check GO differences with Seph data
```{r}
data.seph <- fread("data/seph_hla_ligands.txt") %>%
merge(meta.prot, by = "uniprot.id")
data.seph.ann <- data.seph %>%
group_by(hla, ligand.len) %>%
group_modify(~get_annots(.x$entrez.id, .threshold = 1.01))
```
```{r Fig4a}
go.enr.1 %>%
filter(hla %in% c("HLA-A0201", "HLA-A1101"),
sel == 1) %>%
group_by(hla) %>%
filter(rank(P.DE.adj) <= 20) %>%
mutate(fold.orig = fold, P.DE.adj.orig = P.DE.adj,
hla.orig = hla) %>%
ungroup %>%
select(Term.ID, Ont, Term, fold.orig, P.DE.adj.orig, hla.orig) %>%
unique %>%
merge(data.seph.ann) -> data.seph.ann.sel
pfig4a <- data.seph.ann.sel %>%
filter(Ont == "CC", ligand.len == 9) %>%
mutate(hla.orig = paste0(hla.orig, "-assoc. GO"),
p = DE / total.DE, psd = sqrt(p * (1 - p) / total.DE)) %>%
arrange(p) %>%
group_by(hla.orig, Term) %>%
mutate(p.norm = p / mean(p), psd.norm = psd / mean(p), delta = abs(p[1] - p[2])) %>%
#filter(Ont == "CC", Term == "ribosome" | Term == "membrane" | Term == "nucleosome") %>%
ggplot(aes(x = fct_reorder(Term, P.DE),
y = p.norm, color = hla)) +
geom_pointrange(aes(ymin = p.norm - psd.norm, ymax = p.norm + psd.norm), width = 0.2) +
geom_point(aes(y = p.norm, size = DE), width = 0.2) +
geom_line(aes(group = hla)) +
geom_hline(yintercept = 1, linetype = "dashed", color = "grey30", size = 0.5) +
scale_color_manual(name = "Experimental\n ligandome", values = c("#dfc27d", "#80cdc1")) +
facet_wrap(~hla.orig, scales = "free") + scale_size("Number of\nproteins", breaks = c(100, 500, 1000)) +
xlab("") + ylab("Fraction of presented proteins / \n mean for two HLAs") +
theme_pubr() +
theme(legend.position = "right", #c(0.1, 0.7),
axis.text.x = element_text(angle = -45, vjust = 0.5, hjust = 0))
pfig4a
```
---
## 2. Human proteins are differentially presented by HLA ligands of different lengths
### An example A11
A0101 - bias in depleted genes for
B0702 - another example, with bias in depleted/enriched
A0201 - no effect
B0801 - no effect
B2701 - no effect
```{r}
data.pred.len <- data.pred.full %>% # note some duplicates due to entrez id
filter(hla == "HLA-A1101") %>%
merge(meta.prot, by = "uniprot.id") %>%
group_by(hla, ligand.len) %>%
mutate(P0 = sum(count) / sum(protein.len - ligand.len)) %>%
ungroup %>%
rowwise() %>%
mutate(odds = log2((count + 1) / (protein.len + 1 - ligand.len) / P0),
p.value = binom.test(count + 1, protein.len + 1 - ligand.len,
p = P0, alternative = "two.sided")$p.value) %>%
group_by(hla, ligand.len) %>%
mutate(p.value.adj = p.adjust(p.value, method = "BH")) %>%
ungroup
#! hla.gene column isn't used further
data.pred.len <- data.pred.len %>%
mutate(hla.gene = substr(hla, 5, 5),
sel = ifelse(odds >= 1 & p.value.adj < 0.05, 1,
ifelse(odds <= -1 & p.value.adj < 0.05, -1,
0)),
protein.len.q = cut(protein.len, quantile(protein.len)))
```
```{r TableS2}
pst2 <- data.pred.len %>%
filter(sel == 1) %>%
group_by(hla, ligand.len) %>%
summarize(enriched.genes = length(unique(entrez.id))) %>%
merge(data.pred.len %>%
filter(sel == -1) %>%
group_by(hla, ligand.len) %>%
summarize(depleted.genes = length(unique(entrez.id)))) %>%
merge(data.pred.full %>%
filter(hla == "HLA-A1101") %>%
group_by(hla, ligand.len) %>%
summarize(ligand.count = sum(count)) ) %>%
select(-hla) %>%
arrange(ligand.len) %>%
setNames(., c("Ligand length", "Number of\n enriched genes",
"Number of\n depleted genes", "Ligand count"))
ggtexttable(pst2, rows = NULL,
theme = ttheme("classic"))
```
```{r FigS3}
pfigs3 <- data.pred.len %>%
ggplot(aes(x = odds, y = pmin(-log10(p.value), 20), size = count,
color = sel %>% as.factor())) +
geom_point() +
geom_vline(xintercept = 0, linetype = "dashed", color = "grey") +
#geom_hline(yintercept = 3, linetype = "dashed", color = "grey") +
scale_color_manual("",
values = c("#56b4df", "#000000", "#e69d00"),
labels=c("Depleted", "No change", "Enriched")) +
scale_x_continuous(TeX("$log_2 (observed / expected)$"), limits = c(-3, 3)) +
ylab(TeX("$-log_{10}(P-value)$")) +
scale_size_continuous("Number of\npeptides", breaks = c(1, 10, 100, 1000)) +
facet_wrap(~ligand.len, nrow = 2) +
theme_pubclean() +
theme(aspect = 1, legend.position = "right")
pfigs3
pdf("figures/FigS3.pdf", height = 4, width = 7)
pfigs3
dev.off()
data.pred.len.plen <- data.pred.len %>%
group_by(ligand.len, sel, protein.len.q) %>%
summarize(count = n()) %>%
group_by(ligand.len, sel) %>%
mutate(total = sum(count)) %>%
mutate(p = count / total) %>%
merge(expand.grid(sel = data.pred.len$sel %>% unique,
ligand.len = data.pred.len$ligand.len %>% unique,
protein.len.q = data.pred.len$protein.len.q %>% unique), all = T) %>%
mutate(p = ifelse(is.na(p), 0, p))
#! this figure is not included in the article
data.pred.len.plen %>%
ggplot(aes(x = protein.len.q %>% as.integer,
y = count / total,
fill = sel %>% as.factor,
color = sel %>% as.factor)) +
geom_errorbar(aes(ymin = p, ymax = p + sqrt(p * (1-p) / total)),
position = "dodge") +
geom_bar(stat = "identity", position = "dodge") +
scale_color_manual("Direction",
values = c("#56b4df", "#000000", "#e69d00"),
labels=c("Depleted","No change","Enriched")) +
scale_fill_manual("Direction",
values = c("#56b4df", "#000000", "#e69d00"),
labels=c("Depleted","No change","Enriched")) +
xlab("Protein length quartile") + ylab("Fraction of peptides") +
facet_wrap(~ligand.len, nrow = 2) +
theme_minimal()
get_annots2 <- function(.sel, .ligand.len, data = data.pred.len,
.threshold = 0.01, .fun = goana) {
get_annots(data %>% filter(ligand.len == .ligand.len, sel == .sel) %>% .$entrez.id,
data %>% filter(ligand.len == .ligand.len, sel == 0) %>% .$entrez.id,
.threshold, .fun) %>%
mutate(ligand.len = .ligand.len, sel = .sel)
}
expand.grid(sel = c(1,-1), ligand.len = data.pred.len$ligand.len %>% unique) %>%
rowwise %>%
do(get_annots2(.$sel, .$ligand.len)) -> go.enr.len
go.top.len <- go.enr.len %>%
group_by(sel, ligand.len) %>%
filter(rank(P.DE.adj) <= 20) %>%
.$Term.ID %>% unique
```
````{r FigS4, fig.height=14, fig.width=10}
pfigs4 <- go.enr.len %>%
filter(Term.ID %in% go.top.len) %>%
mutate(Term = trunc_str(Term),
direction = ifelse(sel > 0, "Ligand enriched", "Ligand depleted")) %>%
ggplot(aes(x = paste0(ligand.len, "-mer") %>% factor(levels = paste0(8:12, "-mer")),
y = fct_reorder2(paste(Ont, Term), fold, paste(sel, ligand.len)))) +
geom_quasirandom(aes(size = fold, fill = direction), shape = 21, width = 0.2) +
#geom_point(aes(size = fold, fill = direction), shape = 21) +
#geom_text(aes(label = paste0(round(100 * DE / total.DE, 0), "%"))) +
scale_y_discrete("", position = "right") + xlab("") +
scale_size_continuous("GO enr. fold (log2)", breaks = c(1, 2 ,4)) +
scale_fill_manual("", values = c("#56b4df", "#e69d00")) +
#scale_color_distiller("-log10 Padj", palette = "Reds", direction = 1) +
#scale_size_continuous(guide = F, breaks = c(1,2,4,6)) +
theme_minimal() +
theme(legend.position = "top",
axis.text.x = element_text(angle = 90, vjust = 0.5))
pfigs4
pdf("figures/FigS4.pdf", height = 14, width = 10)
pfigs4
dev.off()
```
### Re-check ligand length bias with Seph data
```{r}
go.enr.len %>%
mutate(hla = "HLA-A1101") %>%
filter(sel == 1) %>%
filter(Term.ID %in% go.top.len) %>%
group_by(Term.ID) %>%
mutate(max.fold.len = ligand.len[which(fold == max(fold))]) %>%
#group_by(hla, ligand.len) %>%
#filter(rank(P.DE.adj) <= 20) %>%
mutate(fold.orig = fold, P.DE.adj.orig = P.DE.adj,
DE.orig = DE, total.DE.orig = total.DE,
ligand.len.orig = ligand.len) %>%
ungroup %>%
select(Term.ID, Ont, Term,
DE.orig, total.DE.orig,
fold.orig, P.DE.adj.orig, hla, ligand.len.orig, max.fold.len) %>%
unique %>%
merge(data.seph.ann) -> data.seph.ann.len
```
```{r Fig4b, fig.width=7, fig.height=7}
pfig4b <- data.seph.ann.len %>%
filter(ligand.len == ligand.len.orig) %>%
filter(Ont == "CC") %>%
mutate(ligand.len = factor(paste0(ligand.len, "-mer"), levels = c("9-mer", "10-mer", "11-mer", "12-mer")),
max.fold.len = factor(paste0(max.fold.len, "-mer"), levels = c("9-mer", "10-mer", "11-mer", "12-mer"))) %>%
#filter(ligand.len %in% c(10, 11), ligand.len.orig %in% c(10, 11)) %>%
ggplot(aes(x = DE.orig / total.DE.orig, y = DE / total.DE)) +
geom_smooth(method = "lm", se = F, color = "grey30", linetype = "dashed", size = 0.5) +
geom_point(aes(color = max.fold.len %>% as.factor), size = 3) +
geom_text_repel(aes(label = Term), seed = 42, force = 5,
#nudge_x = 0.4,
#nudge_y = 0.01,
segment.alpha = 0.7) +
facet_wrap(~ligand.len, scales = "free") +
scale_color_manual(name = "Max enrichment for", values = c("#542788", "#998ec3", "#f1a340")) +
scale_x_continuous("Fraction of presented proteins (synthetic)", expand = c(0.1, 0.01)) +
scale_y_continuous("Fraction of presented proteins (experimental)", expand = c(0.1, 0.01)) +
theme_pubr() +
theme(legend.position = "bottom")
pfig4b
```
```{r Fig4, fig.width=8, fig.height=12}
pfig4 <- ggdraw() +
draw_plot(pfig4a, x = 0, y = .58, width = 1, height = .42) +
draw_plot(pfig4b, x = 0, y = 0, width = 1, height = .57) +
draw_plot_label(label = c("A", "B"), size = 11,
x = c(0, 0), y = c(1, .57))
pfig4
pdf("figures/Fig4.pdf", height = 12, width = 8)
pfig4
dev.off()
```
## 3. Analysis of the extended dataset of in silico ligandomes for 93 HLA alleles
```{r}
#allele list and their frequencies were taken from Sarkizova et al., Nature Biotechnology (2020)
#see netMHCpan_output_preproc.Rmd for details about anchor residue inference
hla.freq <- fread("data/HLA_freq.tsv")
hla_extended <- hla.freq$hla
pst3a <- hla.freq %>%
setNames(., c("Allele", "Frequency", "P2\n anchor", "P9\n anchor", "Anchor\n group")) %>%
filter(substring(Allele, 1, 5) == "HLA-A") %>%
ggtexttable(rows = NULL,
theme = ttheme("classic"))
pst3b <- hla.freq %>%
setNames(., c("Allele", "Frequency", "P2\n anchor", "P9\n anchor", "Anchor\n group")) %>%
filter(substring(Allele, 1, 5) == "HLA-B") %>%
ggtexttable(rows = NULL,
theme = ttheme("classic"))
pst3c <- hla.freq %>%
setNames(., c("Allele", "Frequency", "P2\n anchor", "P9\n anchor", "Anchor\n group")) %>%
filter(substring(Allele, 1, 5) == "HLA-C") %>%
ggtexttable(rows = NULL,
theme = ttheme("classic"))
```
```{r TableS3, fig.width=14, fig.height=12}
pst3 <- ggdraw() +
draw_plot(pst3a, x = -.3, y = .107, width = 1, height = 1) +
draw_plot(pst3b, x = 0, y = .007, width = 1, height = 1) +
draw_plot(pst3c, x = .3, y = .212, width = 1, height = 1)
pst3
pdf("figures/TableS3.pdf", height = 12, width = 14)
pst3
dev.off()
```
### Explore protein length bias for 93 HLA alleles
```{r FigS6abc}
data.pred.sel.s.all <- read_gz("data/genes_enr_extended.tsv.gz")
data.pred.sel.s.all.len <- data.pred.sel.s.all %>%
filter(hla %in% hla_extended) %>%
merge(aa.freq.prots.q %>%
select(uniprot.id2, protein.len.q) %>% distinct()) %>%
group_by(hla, sel, protein.len.q) %>%
summarize(count = n()) %>%
group_by(hla, sel) %>%
mutate(total = sum(count)) %>%
mutate(p = count / total) %>%
ungroup()
pfigs6b <- data.pred.sel.s.all.len %>%
filter(sel != 0) %>%
drop_na() %>%
ggplot(aes(x = protein.len.q %>% as.integer() %>% factor(), y = p, fill = factor(sel))) +
geom_boxplot(position = "dodge", outlier.shape = NaN) +
geom_quasirandom(size = .5, dodge.width = 0.75) +
xlab("Protein length quartile") + ylab("Fraction of HLE(D)Ps") +
scale_fill_manual("",
values = c("#56b4df", "#e69d00"),
labels=c("Depleted", "Enriched")) +
theme_pubclean()
pfigs6b
pfigs6c <- data.pred.sel.s.all.len %>%
select(hla, sel, p, protein.len.q) %>%
filter(sel == 1) %>%
group_by(hla, sel) %>%
filter(rank(p) == max(rank(p))) %>%
group_by(protein.len.q, sel) %>%
summarise(n = n(),
fraction = n() / length(unique(data.pred.sel.s.all.len$hla))) %>%
ggplot(aes(x = factor(protein.len.q %>% as.integer()), y = n)) +
geom_bar(stat = 'identity', fill = "#e69d00") +
theme_pubclean() +
xlab("Protein length quantile corresponding\n to maximum of HLEPs distribution") +
ylab("Number of alleles (out of 93)")
pfigs6c
```
```{r FigS6, fig.width=8, fig.height=10}
pfigs6 <- ggdraw() +
draw_plot(pfigs6a, x = .15, y = .65, width = .7, height = .35) +
draw_plot(pfigs6b, x = 0, y = .23, width = .6, height = .4) +
draw_plot(pfigs6c, x = .6, y = .23, width = .4, height = .35) +
draw_text("Alleles with maximum of HLEPs in Q1", x = .25, y = .18, fontface = "bold") +
draw_text("Alleles with maximum of HLEPs in Q4", x = .75, y = .18, fontface = "bold") +
draw_image("motifs/FigS6/A3001.png",
x = .02, y = 0, width = .15, height = .15) +
draw_image("motifs/FigS6/A3101.png",
x = .17, y = 0, width = .15, height = .15) +
draw_image("motifs/FigS6/A3303.png",
x = .32, y = 0, width = .15, height = .15) +
draw_image("motifs/FigS6/B4402.png",
x = .6, y = 0, width = .15, height = .15) +
draw_image("motifs/FigS6/B4403.png",
x = .75, y = 0, width = .15, height = .15) +
draw_text("HLA-A3001", x = .1, y = .14) +
draw_text("HLA-A3101", x = .25, y = .14) +
draw_text("HLA-A3303", x = .4, y = .14) +
draw_text("HLA-B4402", x = .68, y = .14) +
draw_text("HLA-B4403", x = .83, y = .14) +
draw_plot_label(label = c("A", "B", "C", "D", "E"), size = 11,
x = c(.1, 0, .6, 0, .5), y = c(1, .6, .6, .22, .22))
pfigs6
pdf("figures/FigS6.pdf", height = 10, width = 8)
pfigs6
dev.off()
```
### GO enrichment for 93 HLA alleles
```{r}
#GO enrichment analysis was performed analogously as in section 1
go.enr.all <- fread("data/GO_enr_extended.tsv")
```
Which terms are more frequenty depleted?
In which alleles they are not depleted?
```{r FigS5abc}
#GO terms depleted in majority of alleles
go.depl.all <- go.enr.all %>%
select(sel, hla, Term.ID, Term, Ont) %>%
merge(hla.freq) %>%
group_by(sel, Term.ID, Term, Ont) %>%
summarise(n.allele = n(),
frac.allele = n.allele / length(hla_extended)) %>%
ungroup() %>%
filter(sel == -1) %>%
slice_max(order_by = n.allele, n = 20)
pfigs5a <- go.depl.all %>%
mutate(Alleles = paste0(n.allele, " (", round(frac.allele * 100, 0),
"%)")) %>%
select(Ontology = Ont, Term, Alleles) %>%
ggtexttable(rows = NULL,
theme = ttheme("classic", base_size = 9, padding = unit(c(2, 2), "mm")))
#Alleles-exceptions
go.depl.all.except <- go.enr.all %>%
filter(hla %in% hla_extended,
Term.ID %in% go.depl.all$Term.ID) %>%
group_by(hla) %>%
summarise(n = n()) %>%
merge(hla.freq) %>%
filter(n < 0.33 * max(n)) %>%
arrange(n, -Frequency)
#Genes differentially depleted in alleles-exceptions and in other alleles
go.depl.all.genes <- data.pred.sel.s.all %>%
filter(hla %in% hla_extended) %>%
mutate(exception = ifelse(hla %in% go.depl.all.except$hla, "exceptions", "others")) %>%
select(uniprot.id2, hla, sel, exception) %>%
distinct() %>%
group_by(uniprot.id2, exception) %>%
summarise(sel.sum = sum(sel)) %>%
dcast(uniprot.id2 ~ exception) %>%
filter(exceptions >= 0,
others <= -0.5*length(hla_extended))
go.depl.all.genes.aafreq <- go.depl.all.genes %>%
mutate(sel.go = -1) %>%
merge(aa.freq.prots) %>%
bind_rows(aa.freq.prots %>%
mutate(sel.go = 0)) %>%
group_by(sel.go, aminoacid) %>%
summarise(freq.mean = mean(freq),
sem = sd(freq)/sqrt(n()))
pfigs5c <- go.depl.all.genes.aafreq %>%
mutate(sel.go = factor(sel.go)) %>%
ggplot(aes(x = factor(aminoacid, levels = aa.levels), color = sel.go, group = sel.go)) +
geom_line(aes(y = freq.mean)) +
geom_errorbar(aes(ymin=freq.mean-1.96*sem, ymax=freq.mean+1.96*sem), width=.1) +
scale_color_manual("",
values = c("#56b4df", "#000000"),
labels=c("Proteins for GO terms depleted\n in the majority of HLAs", "Human proteome")) +
xlab("") + ylab("Frequency of amino acid") +
coord_cartesian(ylim = c(0.005,0.15)) +
theme_pubclean() +
theme(legend.position = "bottom",