/
APOBEC_HNSCC_manuscript_analysis.Rmd
2509 lines (1761 loc) · 139 KB
/
APOBEC_HNSCC_manuscript_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: "Analysis for APOBEC-induced mutations and their cancer effect size in head and neck squamous cell carcinoma"
author: "Vincent L. Cannataro"
output:
github_document:
toc: true
---
This `R Markdown` script contains the main analysis from the manuscript "APOBEC-induced mutations and their cancer effect size
in head and neck squamous cell carcinoma", Cannataro VL et al.
# processing MAF file and splitting into HPV positive and negative
First, we import the VirusScan data from Cao et al. (see comment in code for complete citation), to be used for charactarizing HPV status.
```{r import virusscan data}
# import data from the VirusScan manuscript --- Cao, S., Wendl, M. C., Wyczalkowski, M. A., Wylie, K., Ye, K., Jayasinghe, R., … Ding, L. (2016). Divergent viral presentation among human tumors and adjacent normal tissues. Scientific Reports, 6(May), 28294. https://doi.org/10.1038/srep28294
virusscan.data <- read.table(file = "input_data/virusscan/vscan_counts.tsv",sep = "\t",header = T,stringsAsFactors = F)
```
Next, we load in custom functions used in the analysis, and the HNSC data in MAF format. We convert the data from the TCGA to hg19 coordinates.
```{r loading and splitting MAF file, message=FALSE, warning=FALSE}
# load in the MAF file from the NCI
HNSC.MAF <- read.csv("input_data/NCI/gdc_download_20180201_160847/1aa33f25-3893-4f37-a6a4-361c9785d07e/TCGA.HNSC.mutect.1aa33f25-3893-4f37-a6a4-361c9785d07e.DR-10.0.somatic.maf",skip=5,header = T,sep = "\t",stringsAsFactors = F)
# source custom functions
source("R/flip_function.R")
source("R/unique_tumor_addition.R")
source("R/hg39_to_hg19_converter.R")
source("R/DNP_remover.R")
source("R/tumor_allele_adder.R")
# convert the MAF to hg19 coordinates
HNSC.MAF <- hg38.to.hg19.converter(chain = "input_data/hg38Tohg19.chain",hg38_maf = HNSC.MAF)
# Processed data from Hedberg et al., 2016 (doi 10.1172/JCI82066) using https://github.com/Townsend-Lab-Yale/HNSCC_APOBEC/blob/master/process_yale_data.ipynb
Hedberg.2016 <- read.csv(file = "output_data/yale_filtered.maf",header = T,sep = "\t",stringsAsFactors = F)
as.character(unique(Hedberg.2016$Tumor_Sample_Barcode)) # Tumor names from Hedberg et al., 2016.
Hedberg.2016 <- Hedberg.2016[-which(Hedberg.2016$Tumor_Sample_Barcode %in% c("PY-19T","PY-1T","PY-14T","PY-13T","PY-7T")),] # filtering out tumors that are also within the TCGA data set
```
Then, we merge the data, add a unique tumor barcode, remove potential di-nucleotide variants that are labeled as single nucleotide variants, add a column to the MAF specifying the tumor allele, and add a column to the MAF with the HPV calls and Virusscan calls. Finally, we split the data frame into a HPV positive file and a HPV negative file.
For more information on preprocessing see https://github.com/Townsend-Lab-Yale/cancereffectsizeR/blob/master/user_guide/cancereffectsizeR_user_guide.md
```{r merging data}
source("R/merging_NCI_and_local_MAF_files.R")
HNSC.MAF <- merging_TCGA_and_local_MAFdata_function(NCI_data = HNSC.MAF,Local_data = Hedberg.2016)
# tail(HNSC.MAF)
HNSC.MAF <- unique.tumor.addition.function(MAF.file = HNSC.MAF,non.TCGA.characters.to.keep = 'all')
# remove potential DNP
HNSC.MAF <- DNP.remover(MAF = HNSC.MAF)
# add a column that is just the variant allele
HNSC.MAF <- tumor.allele.adder(MAF = HNSC.MAF)
HNSC.MAF$HPV_call <- NA
HNSC.MAF$Virusscan_counts <- NA
for(i in 1:length(unique(HNSC.MAF$Unique_patient_identifier))){
if(length(which(virusscan.data$patient_id==unique(HNSC.MAF$Unique_patient_identifier)[i]))>0){
HNSC.MAF$HPV_call[HNSC.MAF$Unique_patient_identifier==unique(HNSC.MAF$Unique_patient_identifier)[i]] <-
ifelse(virusscan.data$VScan_counts[which(virusscan.data$patient_id==unique(HNSC.MAF$Unique_patient_identifier)[i])]>100,
"HPV+",
"HPV−")
HNSC.MAF$Virusscan_counts[HNSC.MAF$Unique_patient_identifier==unique(HNSC.MAF$Unique_patient_identifier)[i]] <-
virusscan.data$VScan_counts[which(virusscan.data$patient_id==unique(HNSC.MAF$Unique_patient_identifier)[i])]
}
}
# assigning HPV status to PY tumors
HNSC.MAF$HPV_call[which(startsWith(x = HNSC.MAF$Unique_patient_identifier,prefix = "PY"))] <- "HPV−"
HNSC.MAF$HPV_call[which(HNSC.MAF$Unique_patient_identifier=="PY-16T")] <- "HPV+"
# assigning HPV status to tumors with our VirusScan results
# HNSC.MAF$HPV_call[which(HNSC.MAF$Unique_patient_identifier=="TCGA-QK-A6IF")] <- "HPV+"
our_VirusScan_results <- read.csv(file = "input_data/VirusScan_RPHM_on_24_additional_TCGA_patients.txt",header = T,sep = "\t",stringsAsFactors = F)
for(i in 1:nrow(our_VirusScan_results)){
if(length(which(HNSC.MAF$Unique_patient_identifier==our_VirusScan_results$patient_id[i]))>0){
HNSC.MAF$HPV_call[which(HNSC.MAF$Unique_patient_identifier==our_VirusScan_results$patient_id[i])] <-
ifelse(our_VirusScan_results$rphm[i]>100,"HPV+","HPV−")
HNSC.MAF$Virusscan_counts[which(HNSC.MAF$Unique_patient_identifier==our_VirusScan_results$patient_id[i])] <- our_VirusScan_results$rphm[i]
}
}
# results of two tumors that did not have RNA-seq data (we could not run Virusscan) but did have consistent results from
# p16 and ISH clinical data
HNSC.MAF$HPV_call[which(HNSC.MAF$Unique_patient_identifier=="TCGA-CN-A63Y")] <- "HPV+"
HNSC.MAF$HPV_call[which(HNSC.MAF$Unique_patient_identifier=="TCGA-IQ-A61L")] <- "HPV−"
HNSC.MAF.hpvpos <- HNSC.MAF[which(HNSC.MAF$HPV_call=="HPV+"),]
MAF_for_analysis <- HNSC.MAF.hpvpos
length(unique(HNSC.MAF.hpvpos$Unique_patient_identifier))
save(MAF_for_analysis, file="output_data/HNSC_HPVpos_MAF.RData")
HNSC.MAF.hpvneg <- HNSC.MAF[which(HNSC.MAF$HPV_call=="HPV−"),]
MAF_for_analysis <- HNSC.MAF.hpvneg
length(unique(HNSC.MAF.hpvneg$Unique_patient_identifier))
save(MAF_for_analysis, file="output_data/HNSC_HPVneg_MAF.RData")
MAF_for_analysis <- HNSC.MAF
length(unique(HNSC.MAF$Unique_patient_identifier))
save(MAF_for_analysis, file="output_data/HNSC_MAF.RData")
message("HPV positive tumor with TP53 mutation:")
HNSC.MAF.hpvpos$Unique_patient_identifier[which(HNSC.MAF.hpvpos$Hugo_Symbol=="TP53")]
HNSC.MAF.hpvpos[which(HNSC.MAF.hpvpos$Hugo_Symbol=="TP53"),"Unique_patient_identifier"]
# making a table for supplemental data.
HPV.classification <- data.frame(Tumor_name=unique(HNSC.MAF$Unique_patient_identifier),Classification=NA,VirusScan_count=NA)
for(i in 1:nrow(HPV.classification)){
HPV.classification$Classification[i] <- HNSC.MAF$HPV_call[which(HNSC.MAF$Unique_patient_identifier==HPV.classification$Tumor_name[i])[1]]
HPV.classification$VirusScan_count[i] <- HNSC.MAF$Virusscan_counts[which(HNSC.MAF$Unique_patient_identifier==HPV.classification$Tumor_name[i])[1]]
}
write.table(x = HPV.classification,file = "output_data/supp_T_1_HPV_classification.txt",quote = F,sep = "\t",row.names = F)
```
## Summary of preprocessing data
The number of tumors in the whole dataset: `r length(unique(HNSC.MAF$Unique_patient_identifier)) `
The number of tumors in the HPV+ dataset: `r length(unique(HNSC.MAF.hpvpos$Unique_patient_identifier)) `
The number of tumors in the HPV− dataset: `r length(unique(HNSC.MAF.hpvneg$Unique_patient_identifier))`
Tumors that are HPV+ and also have a mutation in TP53: `r HNSC.MAF.hpvpos$Unique_patient_identifier[which(HNSC.MAF.hpvpos$Hugo_Symbol=="TP53")]`
Tumors that are from TCGA and HPV+: `r length(unique(HNSC.MAF$Unique_patient_identifier[which(HNSC.MAF$HPV_call=="HPV+" & startsWith(x=HNSC.MAF$Unique_patient_identifier,prefix="TCGA"))])) `
Tumors that are from TCGA and HPV−: `r length(unique(HNSC.MAF$Unique_patient_identifier[which(HNSC.MAF$HPV_call=="HPV−" & startsWith(x=HNSC.MAF$Unique_patient_identifier,prefix="TCGA"))])) `
# Trinucleotide heatmaps
The SNV selection intensity pipeline was run on the HPV data. The pipeline may be found here: https://github.com/Townsend-Lab-Yale/cancereffectsizeR and the associated manuscript is here: https://doi.org/10.1101/229724
We ran the R package `cancereffectsizeR` on a cluster, and then exported the data locally to call into this analysis script.
```{r Figure trinuc context HPVpos, fig.height=2.5, fig.width=10}
library(ggplot2)
load("input_data/selection_from_cluster/HNSC_HPVpos_cancereffectsizeR/trinuc_data.RData")
HPV.pos.trinuc.mutation_data <- trinuc_data$trinuc.mutation_data
HPV.pos.trinuc.heatmap <- ggplot(data=HPV.pos.trinuc.mutation_data, aes(Downstream, Upstream)) +
geom_tile(aes(fill = proportion*100), colour = "white") + scale_fill_gradient(low = "white", high = "steelblue", name="Percent")
HPV.pos.trinuc.heatmap <- HPV.pos.trinuc.heatmap + facet_grid(.~section_labels, labeller = label_parsed)
HPV.pos.trinuc.heatmap <- HPV.pos.trinuc.heatmap + geom_text(aes(label = round(proportion, 4)*100),size=2)
HPV.pos.trinuc.heatmap <- HPV.pos.trinuc.heatmap + theme_bw() + theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.ticks = element_blank(),
strip.text=element_text(size=15),
axis.title.x = element_text(size=15),
axis.title.y = element_text(size=15),
axis.text.x = element_text(size=12),
axis.text.y=element_text(size=12),plot.title = element_text(hjust = 0.5),legend.position = "left")
HPV.pos.trinuc.heatmap
ggsave(paste("Figures/","HPVpos","_trinuc_heatmap.eps",sep=""),height = 1.5,width = 7,plot = HPV.pos.trinuc.heatmap,dpi=300,device=cairo_ps, fallback_resolution = 300)
```
```{r Figure trinuc context HPVneg, fig.height=2.5, fig.width=10}
load("input_data/selection_from_cluster/HNSC_HPVneg_cancereffectsizeR/trinuc_data.RData")
HPV.neg.trinuc.mutation_data <- trinuc_data$trinuc.mutation_data
HPV.neg.trinuc.heatmap <- ggplot(data=HPV.neg.trinuc.mutation_data, aes(Downstream, Upstream)) +
geom_tile(aes(fill = proportion*100), colour = "white") + scale_fill_gradient(low = "white", high = "steelblue", name="Percent")
HPV.neg.trinuc.heatmap <- HPV.neg.trinuc.heatmap + facet_grid(.~section_labels, labeller = label_parsed)
HPV.neg.trinuc.heatmap <- HPV.neg.trinuc.heatmap + geom_text(aes(label = round(proportion, 4)*100),size=2)
HPV.neg.trinuc.heatmap <- HPV.neg.trinuc.heatmap + theme_bw() + theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.ticks = element_blank(),
strip.text=element_text(size=15),
axis.title.x = element_text(size=15),
axis.title.y = element_text(size=15),
axis.text.x = element_text(size=12),
axis.text.y=element_text(size=12),plot.title = element_text(hjust = 0.5),legend.position = "left")
HPV.neg.trinuc.heatmap
ggsave(filename = paste("Figures/","HPVneg","_trinuc_heatmap.eps",sep=""),height = 1.5,width = 7,plot = HPV.neg.trinuc.heatmap,dpi = 300,device=cairo_ps, fallback_resolution = 300)
```
# Gene-level mutation rates
```{r mutation rate of HPV positive vs negative}
# HPV.neg.mut.rates
HPV.neg.mut.rates <- get(load("input_data/selection_from_cluster/HNSC_HPVneg_cancereffectsizeR/dndscv_mutrates.RData"))
HPV.pos.mut.rates <- get(load("input_data/selection_from_cluster/HNSC_HPVpos_cancereffectsizeR/dndscv_mutrates.RData"))
all.equal(names(HPV.neg.mut.rates),names(HPV.pos.mut.rates))
mutation_rates <- data.frame(gene=names(HPV.neg.mut.rates),positive_mut_rates=as.numeric(HPV.pos.mut.rates),negative_mut_rates=as.numeric(HPV.neg.mut.rates))
library(ggrepel)
mutation_rates_forsupp <- mutation_rates
colnames(mutation_rates_forsupp) <- c("Gene","HPV_positive_rates","HPV_negative_rates")
write.table(x = mutation_rates_forsupp,file = "output_data/supp_T_3_mutation_rates_table.txt",quote = F,row.names = F,sep="\t")
source("R/fancy_scientific_code.R")
mutation_rates_full_scatter <- ggplot(data = mutation_rates, aes(x=positive_mut_rates,y=negative_mut_rates)) +
geom_point(alpha=0.2,col="black",size=0.5) +
geom_smooth(method='lm',color="red") +
geom_point(data = subset(mutation_rates, gene %in% c("FBXW7","PIK3CA","MAPK1")),aes(x=positive_mut_rates,y=negative_mut_rates),size=3,col="blue") +
geom_text_repel(data = subset(mutation_rates, gene %in% c("FBXW7","PIK3CA","MAPK1")),aes(x=positive_mut_rates,y=negative_mut_rates,label=gene),size=5,col="blue",fontface="bold") +
labs(x="Mutation rate in HPV+ tumors",y="Mutation rate in HPV− tumors") +
coord_equal(ratio=1) +
theme_bw() +
geom_abline(slope=1, intercept=0) +
scale_x_continuous(labels=fancy_scientific) +
scale_y_continuous(labels=fancy_scientific) + theme(plot.margin = margin(r=.2,unit = "in"))
mutation_rates_reduced <- ggplot(data = mutation_rates, aes(x=positive_mut_rates,y=negative_mut_rates)) + geom_point(alpha=0.2,col="black",size=0.5) + geom_point(data = subset(mutation_rates, gene %in% c("FBXW7","PIK3CA","MAPK1")),aes(x=positive_mut_rates,y=negative_mut_rates),size=3,col="blue") + geom_text_repel(data = subset(mutation_rates, gene %in% c("FBXW7","PIK3CA","MAPK1")),aes(x=positive_mut_rates,y=negative_mut_rates,label=gene),size=6,col="blue",fontface="bold") +
labs(x="Mutation rate in HPV+ tumors",y="Mutation rate in HPV− tumors") + coord_equal(ratio=1,xlim=c(0,0.5e-5),ylim=c(0,0.5e-5)) + theme_bw() + geom_smooth(method='lm',formula=y~x,color="red") + geom_abline(slope=1, intercept=0) + scale_x_continuous(labels=fancy_scientific) + scale_y_continuous(labels=fancy_scientific)
mutation_rates_full_scatter
summary(lm(data = mutation_rates,formula = positive_mut_rates~negative_mut_rates))
ggsave(plot = mutation_rates_full_scatter,filename = "Figures/mutation_rates_full_scatter.eps",height = 3,width = 8,dpi=300,device=cairo_ps, fallback_resolution = 300)
ggsave(plot = mutation_rates_reduced,filename = "Figures/mutation_rates_reduced.eps",height = 2.5,width = 2.5,device=cairo_ps, fallback_resolution = 300)
```
# Calculating trinucleotide context with weights for each tumor
Here, we use the `deconstructSigs` package to calculate the mutational signature weight for all signatures in all tumors.
```{r trinuc with weights}
library(reshape2)
# load("output_data/HNSC_MAF.RData")
HNSC.MAF <- MAF_for_analysis
source("R/trinuc_signatures_w_weights_E2G.R")
trinuc.contexts <- trinuc.profile.function_withweights(input.MAF = HNSC.MAF,
signature.choice = "signatures.cosmic",
minimum.mutations.per.tumor=50,save.figs=F)
length(trinuc.contexts[[2]]) #number of tumors with >50 mutations
save(trinuc.contexts,file="output_data/trinuc_contexts_HNSC_MAF.RData")
```
# Loading selection output and merging with APOBEC and HPV status
```{r load selection output and merge with APOBEC and HPV status}
library(tidyverse)
load("input_data/selection_from_cluster/HNSC_HPVneg_cancereffectsizeR/HNSC_HPVneg_selection_output.RData")
HNSC.selection.for.supp.HPVneg <- selection.output$all_mutations
HNSC.selection.output.HPVneg <- as.tibble(selection.output$complete_mutation_data) %>%
select(Gene, starts_with("Nucleo"),
Chromosome, starts_with("Reference"),
starts_with("Alternative"), Tumor_origin,
Unique_patient_identifier, starts_with("Amino"), Codon_position, synonymous.mu, trinucs, Gamma_epistasis)
load("input_data/selection_from_cluster/HNSC_HPVpos_cancereffectsizeR/HNSC_HPVpos_selection_output.RData")
HNSC.selection.for.supp.HPVpos <- selection.output$all_mutations
HNSC.selection.output.HPVpos <- as.tibble(selection.output$complete_mutation_data) %>%
select(Gene, starts_with("Nucleo"),
Chromosome, starts_with("Reference"),
starts_with("Alternative"), Tumor_origin,
Unique_patient_identifier, starts_with("Amino"), Codon_position, synonymous.mu, trinucs, Gamma_epistasis)
HNSC.selection.output.HPVneg$HPV_call <- "HPV−"
HNSC.selection.output.HPVpos$HPV_call <- "HPV+"
HNSC.selection.for.supp.HPVneg$HPV_call <- "HPV−"
HNSC.selection.for.supp.HPVpos$HPV_call <- "HPV+"
HNSC.selection.for.supp.both <- rbind(HNSC.selection.for.supp.HPVneg,HNSC.selection.for.supp.HPVpos)
HNSC.selection.for.supp.both$Name_short <- NA
for(i in 1:nrow(HNSC.selection.for.supp.both)){
HNSC.selection.for.supp.both$Name_short[i] <- paste(HNSC.selection.for.supp.both$Gene[i]," ",ifelse(!is.na(HNSC.selection.for.supp.both$AA_Ref[i]),paste(HNSC.selection.for.supp.both$AA_Ref[i],HNSC.selection.for.supp.both$AA_Pos[i],HNSC.selection.for.supp.both$AA_Change[i],sep=""),paste(HNSC.selection.for.supp.both$Nuc_Ref[i],HNSC.selection.for.supp.both$Nucleotide_position[i],HNSC.selection.for.supp.both$Nuc_Change[i],"NCSNV")),sep="")
}
colnames(HNSC.selection.for.supp.both)
HNSC.selection.for.supp.both <- HNSC.selection.for.supp.both[which(HNSC.selection.for.supp.both$freq>1),c("Name_short","Gene","Nucleotide_position","Nuc_Ref","Nuc_Change","HPV_call","freq","mu","AA_Pos","AA_Ref","AA_Change","gamma_epistasis")]
colnames(HNSC.selection.for.supp.both) <- c("Mutation_name","Gene","Nucleotide_position","Nuc_Ref","Nuc_Change","HPV_call","Frequency","Mutation_rate","AA_Pos","AA_Ref","AA_Change","Selection_intensity")
# load("output_data/trinuc_contexts_HNSC_MAF.RData")
weights.df <- trinuc.contexts$signature.weights[[1]]$weights
for(i in 2:length(trinuc.contexts$signature.weights)){
weights.df <- rbind(weights.df,trinuc.contexts$signature.weights[[i]]$weights)
}
HNSC.selection.output.HPVneg$Sig_2 <- NA
HNSC.selection.output.HPVneg$Sig_13 <- NA
HNSC.selection.output.HPVpos$Sig_2 <- NA
HNSC.selection.output.HPVpos$Sig_13 <- NA
for(i in 1:length(unique(HNSC.selection.output.HPVneg$Unique_patient_identifier))){
if(length(which(rownames(weights.df) == unique(HNSC.selection.output.HPVneg$Unique_patient_identifier)[i]))>0){
HNSC.selection.output.HPVneg$Sig_2[which(HNSC.selection.output.HPVneg$Unique_patient_identifier == unique(HNSC.selection.output.HPVneg$Unique_patient_identifier)[i])] <- weights.df$Signature.2[which(rownames(weights.df) == unique(HNSC.selection.output.HPVneg$Unique_patient_identifier)[i])]
HNSC.selection.output.HPVneg$Sig_13[which(HNSC.selection.output.HPVneg$Unique_patient_identifier == unique(HNSC.selection.output.HPVneg$Unique_patient_identifier)[i])] <- weights.df$Signature.13[which(rownames(weights.df) == unique(HNSC.selection.output.HPVneg$Unique_patient_identifier)[i])]
}
}
for(i in 1:length(unique(HNSC.selection.output.HPVpos$Unique_patient_identifier))){
if(length(which(rownames(weights.df) == unique(HNSC.selection.output.HPVpos$Unique_patient_identifier)[i]))>0){
HNSC.selection.output.HPVpos$Sig_2[which(HNSC.selection.output.HPVpos$Unique_patient_identifier == unique(HNSC.selection.output.HPVpos$Unique_patient_identifier)[i])] <- weights.df$Signature.2[which(rownames(weights.df) == unique(HNSC.selection.output.HPVpos$Unique_patient_identifier)[i])]
HNSC.selection.output.HPVpos$Sig_13[which(HNSC.selection.output.HPVpos$Unique_patient_identifier == unique(HNSC.selection.output.HPVpos$Unique_patient_identifier)[i])] <- weights.df$Signature.13[which(rownames(weights.df) == unique(HNSC.selection.output.HPVpos$Unique_patient_identifier)[i])]
}
}
HNSC.selection.output.HPVneg <- mutate(.data = HNSC.selection.output.HPVneg, APOBEC_weight = Sig_2 + Sig_13)
HNSC.selection.output.HPVpos <- mutate(.data = HNSC.selection.output.HPVpos, APOBEC_weight = Sig_2 + Sig_13)
```
Given the trinucleotide context of the mutation, we assign whether it was TCW to TKW, or TCN to TKN.
```{r assigning TCW to TKW trinucleotide status}
# Assigning TCW --> TKW trinucleotide context
HNSC.selection.output.HPVneg$TCW_TKW <- NA
HNSC.selection.output.HPVneg$TCN_TKN <- NA
HNSC.selection.output.HPVpos$TCW_TKW <- NA
HNSC.selection.output.HPVpos$TCN_TKN <- NA
for(j in 1:nrow(HNSC.selection.output.HPVneg)){
if(is.na(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j])){
#need to make a call of the same nucleotide position and amino acid alternative, find which is NOT NA, and make this the new "j"
matches <- which(HNSC.selection.output.HPVneg$Nucleotide_chromosome_position == HNSC.selection.output.HPVneg$Nucleotide_chromosome_position[j] &
HNSC.selection.output.HPVneg$Alternative_Nucleotide == HNSC.selection.output.HPVneg$Alternative_Nucleotide[j])
new.j <- matches[which(!is.na(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[matches]))]
if(((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="TCA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="T") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="TGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="A")) |
((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="TCT" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="T") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="AGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="A")) |
((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="TCA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="G") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="TGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="C")) |
((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="TCT" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="G") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="AGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="C"))){
HNSC.selection.output.HPVneg$TCW_TKW[j] <- 1
}else{
HNSC.selection.output.HPVneg$TCW_TKW[j] <- 0
}
}else{
if(((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="TCA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="T") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="TGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="A")) |
((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="TCT" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="T") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="AGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="A")) |
((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="TCA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="G") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="TGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="C")) |
((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="TCT" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="G") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="AGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="C"))){
HNSC.selection.output.HPVneg$TCW_TKW[j] <- 1
}else{
HNSC.selection.output.HPVneg$TCW_TKW[j] <- 0
}
}
# Now, mutations that could be TCN --> TKN
if(is.na(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j])){
#need to make a call of the same nucleotide position and amino acid alternative, find which is NOT NA, and make this the new "j"
matches <- which(HNSC.selection.output.HPVneg$Nucleotide_chromosome_position == HNSC.selection.output.HPVneg$Nucleotide_chromosome_position[j] &
HNSC.selection.output.HPVneg$Alternative_Nucleotide == HNSC.selection.output.HPVneg$Alternative_Nucleotide[j])
new.j <- matches[which(!is.na(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[matches]))]
if(((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="TCA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="T") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="TGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="A")) |
((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="TCT" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="T") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="AGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="A")) |
((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="TCA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="G") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="TGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="C")) |
((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="TCT" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="G") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="AGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="C")) |
((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="TCC" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="T") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="GGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="A")) |
((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="TCG" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="T") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="CGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="A")) |
((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="TCC" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="G") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="GGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="C")) |
((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="TCG" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="G") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[new.j]=="CGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[new.j]=="C"))
){
HNSC.selection.output.HPVneg$TCN_TKN[j] <- 1
}else{
HNSC.selection.output.HPVneg$TCN_TKN[j] <- 0
}
}else{
if(((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="TCA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="T") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="TGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="A")) |
((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="TCT" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="T") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="AGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="A")) |
((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="TCA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="G") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="TGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="C")) |
((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="TCT" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="G") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="AGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="C"))|
((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="TCC" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="T") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="GGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="A")) |
((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="TCG" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="T") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="CGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="A")) |
((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="TCC" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="G") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="GGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="C")) |
((HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="TCG" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="G") |
(HNSC.selection.output.HPVneg$Nucleotide_trinuc_context[j]=="CGA" & HNSC.selection.output.HPVneg$Alternative_Nucleotide[j]=="C"))){
HNSC.selection.output.HPVneg$TCN_TKN[j] <- 1
}else{
HNSC.selection.output.HPVneg$TCN_TKN[j] <- 0
}
}
}
for(j in 1:nrow(HNSC.selection.output.HPVpos)){
if(is.na(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j])){
#need to make a call of the same nucleotide position and amino acid alternative, find which is NOT NA, and make this the new "j"
matches <- which(HNSC.selection.output.HPVpos$Nucleotide_chromosome_position == HNSC.selection.output.HPVpos$Nucleotide_chromosome_position[j] &
HNSC.selection.output.HPVpos$Alternative_Nucleotide == HNSC.selection.output.HPVpos$Alternative_Nucleotide[j])
new.j <- matches[which(!is.na(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[matches]))]
if(((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="TCA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="T") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="TGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="A")) |
((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="TCT" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="T") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="AGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="A")) |
((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="TCA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="G") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="TGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="C")) |
((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="TCT" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="G") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="AGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="C"))){
HNSC.selection.output.HPVpos$TCW_TKW[j] <- 1
}else{
HNSC.selection.output.HPVpos$TCW_TKW[j] <- 0
}
}else{
if(((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="TCA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="T") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="TGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="A")) |
((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="TCT" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="T") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="AGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="A")) |
((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="TCA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="G") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="TGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="C")) |
((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="TCT" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="G") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="AGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="C"))){
HNSC.selection.output.HPVpos$TCW_TKW[j] <- 1
}else{
HNSC.selection.output.HPVpos$TCW_TKW[j] <- 0
}
}
# Now, mutations that could be TCN --> TKN
if(is.na(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j])){
#need to make a call of the same nucleotide position and amino acid alternative, find which is NOT NA, and make this the new "j"
matches <- which(HNSC.selection.output.HPVpos$Nucleotide_chromosome_position == HNSC.selection.output.HPVpos$Nucleotide_chromosome_position[j] &
HNSC.selection.output.HPVpos$Alternative_Nucleotide == HNSC.selection.output.HPVpos$Alternative_Nucleotide[j])
new.j <- matches[which(!is.na(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[matches]))]
if(((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="TCA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="T") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="TGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="A")) |
((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="TCT" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="T") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="AGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="A")) |
((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="TCA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="G") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="TGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="C")) |
((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="TCT" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="G") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="AGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="C")) |
((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="TCC" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="T") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="GGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="A")) |
((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="TCG" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="T") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="CGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="A")) |
((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="TCC" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="G") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="GGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="C")) |
((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="TCG" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="G") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[new.j]=="CGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[new.j]=="C"))
){
HNSC.selection.output.HPVpos$TCN_TKN[j] <- 1
}else{
HNSC.selection.output.HPVpos$TCN_TKN[j] <- 0
}
}else{
if(((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="TCA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="T") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="TGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="A")) |
((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="TCT" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="T") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="AGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="A")) |
((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="TCA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="G") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="TGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="C")) |
((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="TCT" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="G") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="AGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="C"))|
((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="TCC" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="T") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="GGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="A")) |
((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="TCG" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="T") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="CGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="A")) |
((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="TCC" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="G") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="GGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="C")) |
((HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="TCG" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="G") |
(HNSC.selection.output.HPVpos$Nucleotide_trinuc_context[j]=="CGA" & HNSC.selection.output.HPVpos$Alternative_Nucleotide[j]=="C"))){
HNSC.selection.output.HPVpos$TCN_TKN[j] <- 1
}else{
HNSC.selection.output.HPVpos$TCN_TKN[j] <- 0
}
}
}
# creating new name for the mutation
HNSC.selection.output.HPVneg$Name <- NA
for(i in 1:nrow(HNSC.selection.output.HPVneg)){
HNSC.selection.output.HPVneg$Name[i] <- paste(HNSC.selection.output.HPVneg$Gene[i]," ",ifelse(!is.na(HNSC.selection.output.HPVneg$Amino_acid_reference[i]),paste(HNSC.selection.output.HPVneg$Amino_acid_reference[i],HNSC.selection.output.HPVneg$Amino_acid_position[i],HNSC.selection.output.HPVneg$Amino_acid_alternative[i]," ", HNSC.selection.output.HPVneg$Chromosome[i],"_",HNSC.selection.output.HPVneg$Nucleotide_chromosome_position[i],HNSC.selection.output.HPVneg$Alternative_Nucleotide[i],sep=""),paste(HNSC.selection.output.HPVneg$Reference_Nucleotide[i],HNSC.selection.output.HPVneg$Nucleotide_chromosome_position[i],HNSC.selection.output.HPVneg$Alternative_Nucleotide[i],"NCSNV")),sep="")
}
HNSC.selection.output.HPVpos$Name <- NA
for(i in 1:nrow(HNSC.selection.output.HPVpos)){
HNSC.selection.output.HPVpos$Name[i] <- paste(HNSC.selection.output.HPVpos$Gene[i]," ",ifelse(!is.na(HNSC.selection.output.HPVpos$Amino_acid_reference[i]),paste(HNSC.selection.output.HPVpos$Amino_acid_reference[i],HNSC.selection.output.HPVpos$Amino_acid_position[i],HNSC.selection.output.HPVpos$Amino_acid_alternative[i]," ", HNSC.selection.output.HPVpos$Chromosome[i],"_",HNSC.selection.output.HPVpos$Nucleotide_chromosome_position[i],HNSC.selection.output.HPVpos$Alternative_Nucleotide[i],sep=""),paste(HNSC.selection.output.HPVpos$Reference_Nucleotide[i],HNSC.selection.output.HPVpos$Nucleotide_chromosome_position[i],HNSC.selection.output.HPVpos$Alternative_Nucleotide[i],"NCSNV")),sep="")
}
HNSC.selection.output.HPVneg$Name_short <- NA
for(i in 1:nrow(HNSC.selection.output.HPVneg)){
HNSC.selection.output.HPVneg$Name_short[i] <- paste(HNSC.selection.output.HPVneg$Gene[i]," ",ifelse(!is.na(HNSC.selection.output.HPVneg$Amino_acid_reference[i]),paste(HNSC.selection.output.HPVneg$Amino_acid_reference[i],HNSC.selection.output.HPVneg$Amino_acid_position[i],HNSC.selection.output.HPVneg$Amino_acid_alternative[i],sep=""),paste(HNSC.selection.output.HPVneg$Reference_Nucleotide[i],HNSC.selection.output.HPVneg$Nucleotide_chromosome_position[i],HNSC.selection.output.HPVneg$Alternative_Nucleotide[i],"NCSNV")),sep="")
}
HNSC.selection.output.HPVpos$Name_short <- NA
for(i in 1:nrow(HNSC.selection.output.HPVpos)){
HNSC.selection.output.HPVpos$Name_short[i] <- paste(HNSC.selection.output.HPVpos$Gene[i]," ",ifelse(!is.na(HNSC.selection.output.HPVpos$Amino_acid_reference[i]),paste(HNSC.selection.output.HPVpos$Amino_acid_reference[i],HNSC.selection.output.HPVpos$Amino_acid_position[i],HNSC.selection.output.HPVpos$Amino_acid_alternative[i],sep=""),paste(HNSC.selection.output.HPVpos$Reference_Nucleotide[i],HNSC.selection.output.HPVpos$Nucleotide_chromosome_position[i],HNSC.selection.output.HPVpos$Alternative_Nucleotide[i],"NCSNV")),sep="")
}
# HNSC.selection.output
# save(HNSC.selection.output,file = "output_data/HNSC_selection_with_APOBEC.RData")
save(HNSC.selection.output.HPVneg,file = "output_data/HNSC_selection_with_APOBEC_HPVneg.RData")
save(HNSC.selection.output.HPVpos,file = "output_data/HNSC_selection_with_APOBEC_HPVpos.RData")
# HNSC.selection.output.recur <- subset(HNSC.selection.output, Nucleotide_change_tally>1)
HNSC.selection.output.HPVneg.recur <- subset(HNSC.selection.output.HPVneg, Nucleotide_change_tally>1)
HNSC.selection.output.HPVpos.recur <- subset(HNSC.selection.output.HPVpos, Nucleotide_change_tally>1)
# save(HNSC.selection.output.recur, file = "output_data/HNSC_selection_with_APOBEC_recur.RData")
save(HNSC.selection.output.HPVneg.recur, file = "output_data/HNSC_selection_with_APOBEC_HPVneg_recur.RData")
save(HNSC.selection.output.HPVpos.recur, file = "output_data/HNSC_selection_with_APOBEC_HPVpos_recur.RData")
```
```{r describing weights and tumors}
# adding HPV status to signature weights
trinuc.w.HPV <- weights.df
trinuc.w.HPV$HPV <- NA
for(i in 1:nrow(trinuc.w.HPV)){
trinuc.w.HPV$HPV[i] <- HNSC.MAF$HPV_call[which(HNSC.MAF$Unique_patient_identifier==rownames(weights.df)[i])[1]]
}
# Among tumors that had enough substitutions that we could calculate mutational signatures ...
length(which(trinuc.w.HPV$HPV=="HPV+")) # ...how many tumors are HPV+
length(which(trinuc.w.HPV$HPV=="HPV−")) # ...how many tumors are HPV-
length(which(is.na(trinuc.w.HPV$HPV))) # ... how many tumors had unknown HPV status
save(trinuc.w.HPV,file = "output_data/signature_weights_w_HPV.RData")
length(unique(HNSC.selection.output.HPVpos$Unique_patient_identifier[which(HNSC.selection.output.HPVpos$HPV_call=="HPV+" & HNSC.selection.output.HPVpos$APOBEC_weight > 0)])) # Out of all tumors, how many were HPV+ and had an APOBEC signature
length(which((trinuc.w.HPV$`Signature.2` > 0 | trinuc.w.HPV$`Signature.13`>0) & trinuc.w.HPV$HPV=="HPV+"))
length(which((trinuc.w.HPV$`Signature.2` > 0 | trinuc.w.HPV$`Signature.13`>0) & trinuc.w.HPV$HPV=="HPV−"))/length(which(trinuc.w.HPV$HPV=="HPV−")) # proportion of HPV- tumors with enough substitutions to measure signatures that have APOBEC signature
length(which((trinuc.w.HPV$`Signature.2` > 0 | trinuc.w.HPV$`Signature.13`>0) & trinuc.w.HPV$HPV=="HPV+"))/length(which(trinuc.w.HPV$HPV=="HPV+")) # proportion of HPV+ tumors with enough substitutions to measure signatures that have APOBEC signature
# mean weights
mean(trinuc.w.HPV$`Signature.2`[which(trinuc.w.HPV$HPV=="HPV+")])
mean(trinuc.w.HPV$`Signature.13`[which(trinuc.w.HPV$HPV=="HPV+")])
#
mean(trinuc.w.HPV$`Signature.2`[which(trinuc.w.HPV$HPV=="HPV−")])
mean(trinuc.w.HPV$`Signature.13`[which(trinuc.w.HPV$HPV=="HPV−")])
```
# Creating prevalence and mutation rate plots
First, we create a dataframe with the prevalence vs. prevalence data
```{r prevalence prevalence plot setup, eval=T, include=T}
recur.hpv.pos <- subset(HNSC.selection.output.HPVpos.recur, HPV_call=="HPV+")
recur.hpv.pos <- subset(recur.hpv.pos, Name_short %in% names(table(recur.hpv.pos$Name_short))[which(table(recur.hpv.pos$Name_short)>1)]) #just the recurrent mutations
hpv.pos.names <- unique(recur.hpv.pos$Name_short)
recur.hpv.neg <- subset(HNSC.selection.output.HPVneg.recur, HPV_call=="HPV−")
recur.hpv.neg <- subset(recur.hpv.neg, Name_short %in% names(table(recur.hpv.neg$Name_short))[which(table(recur.hpv.neg$Name_short)>1)]) #just the recurrent mutations
hpv.neg.names <- unique(recur.hpv.neg$Name_short)
intersect(hpv.pos.names,hpv.neg.names)
both.names <- union(hpv.neg.names,hpv.pos.names)
#make a dataframe with nrows == union of names, and columnes the number in each type of tumor and then the prevalence in each type
prevalence.df <- as.data.frame(matrix(data = NA, nrow = length(both.names), ncol=5))
colnames(prevalence.df) <- c("Name","tally_HPVpos","tally_HPVneg","prev_HPVpos","prev_HPVneg")
prevalence.df$Name <- both.names
prevalence.df$tally_HPVpos <- 0
prevalence.df$tally_HPVneg <- 0
for(i in 1:nrow(prevalence.df)){
if(length(which(hpv.pos.names == prevalence.df$Name[i]))>0){
prevalence.df$tally_HPVpos[i] <- length(which(recur.hpv.pos$Name_short == prevalence.df$Name[i]))
}
if(length(which(hpv.neg.names == prevalence.df$Name[i]))>0){
prevalence.df$tally_HPVneg[i] <- length(which(recur.hpv.neg$Name_short == prevalence.df$Name[i]))
}
}
prevalence.df$prev_HPVpos <- prevalence.df$tally_HPVpos/length(unique(HNSC.selection.output.HPVpos$Tumor_origin[which(HNSC.selection.output.HPVpos$HPV_call=="HPV+")]))
prevalence.df$prev_HPVneg <- prevalence.df$tally_HPVneg/length(unique(HNSC.selection.output.HPVneg$Tumor_origin[which(HNSC.selection.output.HPVneg$HPV_call=="HPV−")]))
```
Then, we create a plot with mutation rate
```{r prevalence and mutation rate plots, fig.height=1.2, fig.width=3.25}
library(ggrepel)
common.text.size <- 6
library(cowplot)
# getting them to match up!
prev_plot <- ggplot(data = prevalence.df) +
geom_point(aes(y = prev_HPVneg, x = prev_HPVpos),alpha=0.5,size=1.5,color="red") +
geom_text_repel(data = subset(prevalence.df, (prev_HPVneg>0.025 | prev_HPVpos>0.04) | (prev_HPVneg>0.0 & prev_HPVpos>0)),aes(y = prev_HPVneg, x = prev_HPVpos,label=Name),box.padding =0.6,size=common.text.size*(5/14),color="black",segment.alpha = 0.3) +
theme_classic() +
expand_limits(x = 0, y = c(0,max(prevalence.df$prev_HPVneg)+.005)) +
geom_segment(aes(x = 0, xend =max(prevalence.df$prev_HPVneg)+.005, y = 0, yend =max(prevalence.df$prev_HPVneg)+.005),linetype="dashed") +
scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0)) +
labs(y=bquote("Prevalence in "~HPV^{"−"}~ "\n tumors"), x=bquote("Prevalence in "~HPV^{"+"}~ "tumors")) + theme(axis.text=element_text(size=common.text.size), axis.title=element_text(size=common.text.size,face="bold"),plot.margin = margin(r=.2,t=.0,l=.1,b=0.1,unit = "in")) +
# coord_equal() +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
theme(axis.title.x = element_text(margin = margin(t = -.2, r = 0, b = 0, l = 0))) #+ geom_label(aes(x = prev_HPVneg, y = prev_HPVpos, label=Name))
prev_plot
prev_plot_gridoff <- ggplot_gtable(ggplot_build(prev_plot))
prev_plot_gridoff$layout$clip[prev_plot_gridoff$layout$name == "panel"] <- "off"
library(grid)
library(gridExtra)
prev_plot_grob <- arrangeGrob(prev_plot_gridoff)
ggsave(filename = "Figures/prevalence_plot.eps",plot = prev_plot_grob,height = 1.2,width = 3.25,dpi = 300,device=cairo_ps, fallback_resolution = 300)
mutation_rates_full_scatter <- ggplot(data = mutation_rates, aes(x=positive_mut_rates,y=negative_mut_rates)) +
geom_point(alpha=0.2,col="red",size=0.5) +
geom_smooth(method='lm',color="red",size=.5,fullrange=T) +
# geom_text_repel(data=subset(mutation_rates, positive_mut_rates > 5e-5 | negative_mut_rates > 3e-5 ), aes(label=gene),size=3) +
geom_point(data = subset(mutation_rates, gene %in% c("FBXW7","PIK3CA","MAPK1")),aes(x=positive_mut_rates,y=negative_mut_rates),size=1.5,col="black") +
geom_text_repel(data = subset(mutation_rates, gene %in% c("FBXW7","PIK3CA","MAPK1")),aes(x=positive_mut_rates,y=negative_mut_rates,label=gene),size=common.text.size*(5/14),segment.alpha = 1,col="black",box.padding = 0.6) +
labs(y=bquote("Mutation rate in "~HPV^{"−"}~ "\n tumors"), x=bquote("Mutation rate in "~HPV^{"+"}~ "tumors")) +
# coord_equal() +
# theme_classic() +
expand_limits(x = 0, y = c(0,max(mutation_rates$negative_mut_rates)+1e-6)) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
geom_segment(aes(x = 0, xend =max(mutation_rates$negative_mut_rates)+1e-6, y = 0, yend =max(mutation_rates$negative_mut_rates)+1e-6),linetype="dashed") +
# geom_abline(slope=1, intercept=0,linetype = "dashed") +
scale_x_continuous(labels=fancy_scientific,expand = c(0, 0)) +
scale_y_continuous(labels=fancy_scientific,expand = c(0, 0)) + theme(axis.text=element_text(size=common.text.size),
axis.title=element_text(size=common.text.size,face="bold"),
plot.margin = margin(r=.2,t=.0,b=.0,l=.1,unit = "in")) + theme(axis.title.x = element_text(margin = margin(t = -.2, r = 0, b = 0, l = 0)))
mutation_rates_full_scatter
mutation_rates_gridoff <- ggplot_gtable(ggplot_build(mutation_rates_full_scatter))
mutation_rates_gridoff$layout$clip[mutation_rates_gridoff$layout$name == "panel"] <- "off"
mutation_rates_plot_grob <- arrangeGrob(mutation_rates_gridoff)
ggsave(plot = mutation_rates_plot_grob,filename = "Figures/mutation_rates_full_scatter.eps",height = 1.2,width = 3.25,dpi=300,device=cairo_ps, fallback_resolution = 300)
library(cowplot)
combined.plot.prev.and.muts <- plot_grid(prev_plot,mutation_rates_full_scatter,nrow = 2,align='v')
ggsave(plot = combined.plot.prev.and.muts,filename = "Figures/selection_and_mutrates_combined.eps",height = 1.2*2,width = 3.25,dpi=300,device=cairo_ps, fallback_resolution = 300)
HPV.neg.trinuc.heatmap <- ggplot(data=HPV.neg.trinuc.mutation_data, aes(Downstream, Upstream)) +
geom_tile(aes(fill = proportion*100), colour = "white") + scale_fill_gradient(low = "white", high = "steelblue", name="Percent") + facet_grid(.~section_labels, labeller = label_parsed) + #geom_text(aes(label = round(proportion, 4)*100),size=.8) +
theme_bw() + theme(panel.grid.major = element_blank(),plot.margin = margin(r=0,t=5,b=.0,l=0),
panel.grid.minor = element_blank(),
axis.ticks = element_blank(),
strip.text=element_text(size=common.text.size),
axis.title.x = element_text(size=common.text.size),
axis.title.y = element_text(size=common.text.size),
axis.text.x = element_text(size=common.text.size,margin=margin(t=0)),
legend.text = element_text(size=common.text.size,margin=margin(l=-2)),
legend.title = element_text(size=common.text.size),
axis.text.y=element_text(size=common.text.size,margin=margin(r=0)),
plot.title = element_text(hjust = 0.5),
legend.position = "right") +
guides(fill = guide_colorbar(barwidth = .5, barheight = 2)) +
theme(strip.text.x = element_text(margin = margin(0.4,0,0.4,0))) +
theme(legend.margin=margin(t = 0,r=0,b=0,l=-7),legend.box.margin=margin(0,0,0,0)) +
theme(panel.spacing = unit(.1, "lines")) +
theme(axis.title.x = element_text(margin = margin(t = -.2, r = 0, b = 0, l = 0)))
HPV.pos.trinuc.heatmap <- ggplot(data=HPV.pos.trinuc.mutation_data, aes(Downstream, Upstream)) +
geom_tile(aes(fill = proportion*100), colour = "white") + scale_fill_gradient(low = "white", high = "steelblue", name="Percent",labels=c(13,10,7,4,1),breaks=c(13,10,7,4,1)) + facet_grid(.~section_labels, labeller = label_parsed) + #geom_text(aes(label = round(proportion, 4)*100),size=.8) +
theme_bw() + theme(panel.grid.major = element_blank(),plot.margin = margin(r=0,t=5,b=.0,l=0),
panel.grid.minor = element_blank(),
axis.ticks = element_blank(),
strip.text=element_text(size=common.text.size),
axis.title.x = element_text(size=common.text.size),
axis.title.y = element_text(size=common.text.size),
axis.text.x = element_text(size=common.text.size,margin=margin(t=0)),
legend.text = element_text(size=common.text.size,margin=margin(l=-2)),
legend.title = element_text(size=common.text.size),
axis.text.y=element_text(size=common.text.size,margin=margin(r=0)),
plot.title = element_text(hjust = 0.5),
legend.position = "right") +
guides(fill = guide_colorbar(barwidth = .5, barheight = 2)) +
theme(strip.text.x = element_text(margin = margin(0.4,0,0.4,0))) +
theme(legend.margin=margin(t = 0,r=0,b=0,l=-7),legend.box.margin=margin(0,0,0,0)) +
theme(panel.spacing = unit(.1, "lines")) +
theme(axis.title.x = element_text(margin = margin(t = -.2, r = 0, b = 0, l = 0)))
# HPV.pos.trinuc.heatmap
combined.plot.prev.and.muts.heat <- plot_grid(prev_plot_gridoff,mutation_rates_gridoff,HPV.neg.trinuc.heatmap,HPV.pos.trinuc.heatmap,nrow = 4,align='v',axis='l',rel_heights = c(1,1,.4,.4),labels = "AUTO",label_size = 6)
ggsave(plot = combined.plot.prev.and.muts.heat,filename = "Figures/selection_and_mutrates_heat_combined.eps",height = 1*4,width = 3.25,dpi=300,device=cairo_ps, fallback_resolution = 300)
```
# Selection and tornado plots
First, we create a plot of the selection intensity of shared variants among HPV positive vs HPV negative tumors.
```{r gamma gamma plot, eval=T}
# just analyzing recurrent variants
load("input_data/selection_from_cluster/HNSC_HPVpos_cancereffectsizeR/HNSC_HPVpos_selection_output.RData")
HPV.pos.selectionoutput <- selection.output
HPV.pos.selection_minrecur <- subset(HPV.pos.selectionoutput$all_mutations, freq>1)
load("input_data/selection_from_cluster/HNSC_HPVneg_cancereffectsizeR/HNSC_HPVneg_selection_output.RData")
HPV.neg.selectionoutput <- selection.output
HPV.neg.selection_minrecur <- subset(HPV.neg.selectionoutput$all_mutations, freq>1)
# adding consistent variant names
HPV.pos.selection_minrecur$Name_short <- NA
for(i in 1:nrow(HPV.pos.selection_minrecur)){
HPV.pos.selection_minrecur$Name_short[i] <- paste(HPV.pos.selection_minrecur$Gene[i]," ",ifelse(!is.na(HPV.pos.selection_minrecur$AA_Ref[i]),paste(HPV.pos.selection_minrecur$AA_Ref[i],HPV.pos.selection_minrecur$AA_Pos[i],HPV.pos.selection_minrecur$AA_Change[i],sep=""),paste(HPV.pos.selection_minrecur$Nuc_Ref[i],HPV.pos.selection_minrecur$Nucleotide_position[i],HPV.pos.selection_minrecur$Nuc_Change[i],"NCSNV")),sep="")
}
HPV.neg.selection_minrecur$Name_short <- NA
for(i in 1:nrow(HPV.neg.selection_minrecur)){
HPV.neg.selection_minrecur$Name_short[i] <- paste(HPV.neg.selection_minrecur$Gene[i]," ",ifelse(!is.na(HPV.neg.selection_minrecur$AA_Ref[i]),paste(HPV.neg.selection_minrecur$AA_Ref[i],HPV.neg.selection_minrecur$AA_Pos[i],HPV.neg.selection_minrecur$AA_Change[i],sep=""),paste(HPV.neg.selection_minrecur$Nuc_Ref[i],HPV.neg.selection_minrecur$Nucleotide_position[i],HPV.neg.selection_minrecur$Nuc_Change[i],"NCSNV")),sep="")
}
# adding selection intensity (gamma) data to new data frame
gamma.df <- cbind(prevalence.df,NA,NA)
colnames(gamma.df)[6:7] <- c("gamma_HPVpos","gamma_HPVneg")
for(i in 1:nrow(gamma.df)){
if(length(which(HPV.pos.selection_minrecur$Name_short == gamma.df$Name[i]))>0){
gamma.df$gamma_HPVpos[i] <- HPV.pos.selection_minrecur$gamma_epistasis[which(HPV.pos.selection_minrecur$Name_short == gamma.df$Name[i])][1]
}
if(length(which(HPV.neg.selection_minrecur$Name_short == gamma.df$Name[i]))>0){
gamma.df$gamma_HPVneg[i] <- HPV.neg.selection_minrecur$gamma_epistasis[which(HPV.neg.selection_minrecur$Name_short == gamma.df$Name[i])][1]
}
}
# The following function was found at
# https://groups.google.com/forum/#!topic/ggplot2/a_xhMoQyxZ4 - Thanks Brian Diggs!
# And discussed and edited here: https://stackoverflow.com/a/24241954/8376488 - Thanks Jack Aidley!
fancy_scientific <- function(l) {
# turn in to character string in scientific notation
l <- format(l, scientific = TRUE)
l <- gsub("0e\\+00","0",l)
# quote the part before the exponent to keep all the digits
l <- gsub("^(.*)e", "'\\1'e", l)
# turn the 'e+' into plotmath format
l <- gsub("e", "%*%10^", l)
# return this as an expression
parse(text=l)
}
library(ggrepel)
gamma_plot <- ggplot(data = gamma.df) + geom_point(aes(x = gamma_HPVneg, y = gamma_HPVpos),alpha=0.5,size=2) + geom_text_repel(aes(x = gamma_HPVneg, y = gamma_HPVpos,label=Name),box.padding = 0.8,size=common.text.size*(5/14),color="darkred",fontface="bold") + theme_bw() + labs(x=bquote("Selection intensity in "~HPV^{"−"}~ "tumors"), y=bquote("Selection intensity in "~HPV^{"+"}~ "tumors")) + theme(axis.text=element_text(size=common.text.size), axis.title=element_text(size=common.text.size,face="bold")) + scale_y_log10(labels = fancy_scientific) + scale_x_log10(labels = fancy_scientific) + coord_equal() #+ coord_equal(xlim = c(0,),ylim = c(0,))
gamma_plot
ggsave(filename = "Figures/gamma_gamma_plot.eps",plot = gamma_plot,height = 2,width = 2,dpi=300,device=cairo_ps, fallback_resolution = 300)
```
Next, we create "tornado plots" of the variants with the top selection intensity among both HPV positive and HPV negative tumors.
First, we preprocess the data for the plots.
We start with the HPV negative data ...
```{r processing HPV neg for tornado plots}
### Figures for manuscript
# Selection plots with the same colors
# load in the HPV neg, load in the HPV pos, find all unique genes and generate color palette
# This will be sorted by selection, not frequency.
# Negative
load("input_data/selection_from_cluster/HNSC_HPVneg_cancereffectsizeR/HNSC_HPVneg_selection_output.RData")
selection.subset.neg <- selection.output$all_mutations[which(selection.output$all_mutations$freq>1),]
selection.subset.neg <- selection.subset.neg[which(!is.na(selection.subset.neg$Gene)),]
selection.subset.neg <- selection.subset.neg[order(-selection.subset.neg$gamma_epistasis),]
if(nrow(selection.subset.neg)>25){
selection.subset.neg.ordered <- selection.subset.neg[1:25,] #
}else{
selection.subset.neg.ordered <- selection.subset.neg
}
selection.subset.neg.ordered <- selection.subset.neg.ordered[order(selection.subset.neg.ordered$gamma_epistasis),]
selection.subset.neg.ordered$Name <- NA
for(i in 1:nrow(selection.subset.neg.ordered)){
selection.subset.neg.ordered$Name[i] <- paste(selection.subset.neg.ordered$Gene[i]," ",ifelse(!is.na(selection.subset.neg.ordered$AA_Ref[i]),paste(selection.subset.neg.ordered$AA_Ref[i],selection.subset.neg.ordered$AA_Pos[i],selection.subset.neg.ordered$AA_Change[i],sep=""),"NCSNV"))
}
length(unique(selection.subset.neg.ordered$Name))
if(length(which(selection.subset.neg.ordered$Name=="TP53 NCSNV"))>1){
selection.subset.neg.ordered$Name[which(selection.subset.neg.ordered$Name=="TP53 NCSNV")] <- paste("TP53 NCSNV",letters[length((which(selection.subset.neg.ordered$Name=="TP53 NCSNV"))):1],sep="")
}
selection.subset.neg.ordered$Name <- factor(selection.subset.neg.ordered$Name, levels=selection.subset.neg.ordered$Name)
```
... and then process the HPV positive data.
```{r processing HPV pos for tornado plots}
# Positive
load("input_data/selection_from_cluster/HNSC_HPVpos_cancereffectsizeR/HNSC_HPVpos_selection_output.RData")
selection.subset.pos <- selection.output$all_mutations[which(selection.output$all_mutations$freq>1),]
selection.subset.pos <- selection.subset.pos[which(!is.na(selection.subset.pos$Gene)),]
selection.subset.pos <- selection.subset.pos[order(-selection.subset.pos$gamma_epistasis),]
if(nrow(selection.subset.pos)>25){
selection.subset.pos.ordered <- selection.subset.pos[1:25,] #
}else{
selection.subset.pos.ordered <- selection.subset.pos
}
selection.subset.pos.ordered <- selection.subset.pos.ordered[order(selection.subset.pos.ordered$gamma_epistasis),]
selection.subset.pos.ordered$Name <- NA
for(i in 1:nrow(selection.subset.pos.ordered)){
selection.subset.pos.ordered$Name[i] <- paste(selection.subset.pos.ordered$Gene[i]," ",ifelse(!is.na(selection.subset.pos.ordered$AA_Ref[i]),paste(selection.subset.pos.ordered$AA_Ref[i],selection.subset.pos.ordered$AA_Pos[i],selection.subset.pos.ordered$AA_Change[i],sep=""),"NCSNV"))
}
selection.subset.pos.ordered$Name <- factor(selection.subset.pos.ordered$Name, levels=selection.subset.pos.ordered$Name)
```
Before making the plots, we assign colors to each unique gene name among both plots.
```{r finding colors used for unique genes in combined build}
##Find colors used for unique genes in combined build.
source("R/fancy_scientific_code.R")
selection.subset.combined.ordered <- rbind(selection.subset.neg.ordered,selection.subset.pos.ordered)
unique.genes <- unique(selection.subset.combined.ordered$Gene)
#Make a dataframe of just the unique genes
selection.subset.combined.ordered.unique <- as.data.frame(matrix(nrow=0,ncol=ncol(selection.subset.combined.ordered)))
colnames(selection.subset.combined.ordered.unique) <- colnames(selection.subset.combined.ordered)
for(i in 1:length(unique.genes)){
selection.subset.combined.ordered.unique <- rbind(selection.subset.combined.ordered.unique,selection.subset.combined.ordered[which(selection.subset.combined.ordered$Gene==unique.genes[i])[1],])
}
#from http://stackoverflow.com/questions/18265941/two-horizontal-bar-charts-with-shared-axis-in-ggplot2-similar-to-population-pyr
library('grid')
library('gridExtra')
g.mid <- ggplot(selection.subset.combined.ordered.unique,aes(x=1,y=Name)) +
geom_text(aes(label=Name),size=7) +
# geom_segment(aes(x=0.94,xend=0.96,yend=Name)) +
# geom_segment(aes(x=1.04,xend=1.065,yend=Name)) +
ggtitle("") +
ylab(NULL) +
scale_x_continuous(expand=c(0,0),limits=c(0.94,1.065)) + ggtitle("HNSCC HPV+") +
theme(axis.title=element_blank(),
panel.grid=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
panel.background=element_blank(),