-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSupplementary_analysis.Rmd
More file actions
1710 lines (1505 loc) · 69.5 KB
/
Supplementary_analysis.Rmd
File metadata and controls
1710 lines (1505 loc) · 69.5 KB
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: "Supplementary_analysis"
author: "Tao Wu"
date: "`r Sys.Date()`"
output:
rmdformats::readthedown:
highlight: kate
lightbox: false
toc_depth: 3
mathjax: true
---
```{r Supplementary_analyses-setup, include=FALSE}
options(max.print = "75")
knitr::opts_chunk$set(echo = TRUE, comment = "#>", eval = TRUE, collapse = TRUE,cache = FALSE)
knitr::opts_knit$set(width = 75)
```
```{r lib4,echo=TRUE,eval=TRUE,include=FALSE,message=FALSE}
library(dplyr)
library(tidyr)
library(NeoEnrichment)
library(ggplot2)
library(ggcharts)
library(stringr)
library(maftools)
library(ComplexHeatmap)
library(readr)
library(gt)
library(ezcox)
```
## Sample statistics and clinical features
Number of the patient with CCF information and number of patient with at least one neoantigenic mutation and subclonal mutation (CCF<0.6) are shown for each cancer type and number of the patient with mRNA expression information and number of patient with at least one neoantigenic mutation and accompanied mRNA expression information are shown for each cancer type:
```{r}
###sample statistics
all_mut_ccf <- readRDS("../data/all_mut_ccf_tpm.rds")
all_mut_ccf <- all_mut_ccf %>%
rename(ccf=ccf_hat) %>%
mutate(neo=ifelse(neo=="neo","yes","no"))
samples_has_subclonal <- all_mut_ccf %>% filter(ccf<0.6) %>% select(sample) %>%
distinct(sample)
all_mut_ccf %>%
group_by(sample) %>%
summarise(c_n=sum(neo=="yes"),c_m=sum(neo=="no")) %>%
mutate(type=ifelse(sample %in% samples_has_subclonal$sample,"yes","no")) -> sample_summ
sample_summ$cancer <- get_cancer_type(sample_summ$sample)
sample_summ %>%
group_by(cancer) %>%
summarise(sample_counts=n(),
sample_with_neoantigen_counts=sum(c_n>=1 & c_m >=1 & type=="yes")) -> cancer_summ
cancer_summ <- cancer_summ %>% arrange(sample_counts)
cancer_summ$cancer <- factor(cancer_summ$cancer,levels = cancer_summ$cancer)
cancer_summ %>%
dplyr::rename(`All samples`=sample_counts,
`Samples with >= 1 neoantigen and have subclonal mutations`=sample_with_neoantigen_counts) %>%
pivot_longer(cols = c("All samples","Samples with >= 1 neoantigen and have subclonal mutations"),
names_to="type",
values_to="counts") -> cancer_summ_longer
p1 <- pyramid_chart(data = cancer_summ_longer, x = cancer, y = counts, group = type)
all_mut_exp <- readRDS("../data/all_mut_tpm_not_filter.rds")
all_mut_exp %>%
group_by(sample) %>%
summarise(n_a=sum(neo=="not_neo"),n_c=sum(neo=="neo")) -> sample_summ
sample_summ$cancer <- get_cancer_type(sample_summ$sample)
sample_summ %>%
group_by(cancer) %>%
summarise(sample_counts=n(),
sample_with_neoantigen_counts=sum(n_a>=1 & n_c >=1)) -> cancer_summ
cancer_summ <- cancer_summ %>% arrange(sample_counts)
cancer_summ$cancer <- factor(cancer_summ$cancer,levels = cancer_summ$cancer)
cancer_summ %>%
dplyr::rename(`All samples`=sample_counts,
`Samples with >= 1 neoantigen`=sample_with_neoantigen_counts) %>%
pivot_longer(cols = c("All samples","Samples with >= 1 neoantigen"),
names_to="type",
values_to="counts") -> cancer_summ_longer
p2 <- pyramid_chart(data = cancer_summ_longer, x = cancer, y = counts, group = type)
p1
p2
```
We also calculated the significant sample in each cancer type:
```{r}
pancancer_ccf <- readRDS("../data/neo_nes_ccf06_1_remove_driver_samples_addp.rds") %>%
mutate(es_type=ifelse(es<0 & p <0.05,"sig_neg","others"))
pancancer_exp <- readRDS("../data/es_exp_filter_driver.rds") %>%
mutate(es_type=ifelse(es<0 & p_value <0.05,"sig_neg","others"))
pancancer_ccf$cancer <- get_cancer_type(pancancer_ccf$sample)
pancancer_exp$cancer <- get_cancer_type(pancancer_exp$sample)
get_plot <- function(dt,total_sig_sample){
sig <- dt %>%
filter(es_type=="sig_neg") %>%
dplyr::group_by(cancer) %>%
summarise(counts=n()) %>%
arrange(counts) %>%
mutate(cancer=factor(cancer,levels = cancer)) %>%
mutate(`Sample proportion`= counts/total_sig_sample) %>%
mutate(label=paste("frac(",counts,",",total_sig_sample,")",sep = ""))
p1 <- ggplot(data=sig,aes(x=cancer,y=`Sample proportion`))+
geom_bar(mapping = aes(x=cancer,y=`Sample proportion`),stat = "identity")+
theme_classic()+
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1))+
scale_y_continuous(expand = expansion(mult = c(0, .1)))+##remove blank in the bottom
theme(axis.title.x=element_blank())+
geom_text(aes(label=label), position=position_dodge(width=0.9), vjust=-0.25,size=2,parse=TRUE)
return(p1)
}
get_plot(pancancer_ccf,sum(pancancer_ccf$es_type=="sig_neg"))
get_plot(pancancer_exp,sum(pancancer_exp$es_type=="sig_neg"))
```
Pan-cancer sample distribution in pie plot:
```{r}
pancancer_ccf <- pancancer_ccf %>%
mutate(es_type2=ifelse(es<0 & p<0.05,"ES < 0 & P < 0.05","Others"))
pancancer_exp <- pancancer_exp %>%
mutate(es_type2=ifelse(es<0 & p_value<0.05,"ES < 0 & P < 0.05","Others"))
ccf_es <- pancancer_ccf$es
ccf_es1 <- pancancer_ccf$es_type2
par(mfrow=c(4,1))
op <- par(mar = rep(0, 4))
plot_pie(ccf_es,expression = "ccf_es<0",c("ES (CCF) < 0","ES (CCF) >= 0"))
plot_pie(ccf_es1,expression = "ccf_es1=='ES < 0 & P < 0.05'",c("ES (CCF) < 0 & P < 0.05","Others"))
exp_es <- pancancer_exp$es
exp_es1 <- pancancer_exp$es_type2
plot_pie(exp_es,expression = "exp_es<0",c("ES (EXP) < 0","ES (EXP) >= 0"))
plot_pie(exp_es1,expression = "exp_es1=='ES < 0 & P < 0.05'",c("ES (EXP) < 0 & P < 0.05","Others"))
```
The immune-thearpy dataset sample distribution and clinical parameters:
```{r eval=FALSE}
all_sample_exp_ccf <- readRDS("../data/Immunotherapy/all_mut_ccf_ici.rds")
ccf <- all_sample_exp_ccf %>% filter(!is.na(cancer_cell_frac))
exp <- all_sample_exp_ccf %>% filter(!is.na(exp))
all_sample <- union(names(table(ccf$sample)),names(table(exp$sample)))
both <- intersect(names(table(ccf$sample)),names(table(exp$sample)))
WES <- setdiff(names(table(ccf$sample)),names(table(exp$sample)))
RNA <- setdiff(names(table(exp$sample)),names(table(ccf$sample)))
all_clinical <- readRDS("../data/Immunotherapy/all_clinical.rds")
response <- all_clinical %>% filter(response2=="response")
no_response <- all_clinical %>% filter(response2!="response")
willy_tre <- read_csv("../data/Immunotherapy/willy_clinical.csv") %>%
select(`Patient ID`,Treatment,Gender,Age) %>%
rename(sample=`Patient ID`) %>% mutate(sample=paste("willy_",sample,sep = "")) %>% na.omit()
##nadeem Nivolumab
nadeem_tre <- data.frame(sample=all_sample[grepl("nadeem_",all_sample)],Treatment="Nivolumab",
Gender=NA,Age=NA,stringsAsFactors = F)
liu_clinical <- readRDS("../data/Immunotherapy/liu_clinical.rds") %>%
select(X,Tx,`gender..Male.1..Female.0.`) %>%
mutate(Gender=ifelse(`gender..Male.1..Female.0.`==1,"M","F")) %>%
select(-`gender..Male.1..Female.0.`) %>% mutate(Age=NA) %>%
rename(sample=X,Treatment=Tx) %>% mutate(sample=paste0("liu_",sample)) %>% filter(grepl("_Patient",sample))
all_tre <- bind_rows(list(willy_tre,nadeem_tre,liu_clinical))
saveRDS(all_tre,file = "../data/Immunotherapy/all_treatment.rds")
dt <- data.frame(sample=all_sample,
stringsAsFactors = F) %>%
mutate(`Data type`= case_when(
sample %in% both ~ "Both",
sample %in% WES ~ "WES",
sample %in% RNA ~ "RNA-Seq"
)) %>%
mutate(Response=ifelse(sample %in% response$sample,"Responder","Non-Responder")) %>%
mutate(cohort=gsub("_.*","",sample)) %>%
left_join(.,all_tre,by="sample")
dt <- dt %>% arrange(sample)
dt_cli <- left_join(dt,all_clinical,by="sample")
cohort_col <- RColorBrewer::brewer.pal(3,"Accent")
data_type_col <- RColorBrewer::brewer.pal(3,"Dark2")
Response_col <- RColorBrewer::brewer.pal(3,"Set1")[1:2]
Treatment_col <- RColorBrewer::brewer.pal(3,"Paired")
ha = HeatmapAnnotation(
Cohort=dt$cohort,
`Data type` = dt$`Data type`,
Response = dt$Response,
Treatment=dt$Treatment,
col = list(Cohort=c("liu"=cohort_col[1],"nadeem"=cohort_col[2],"willy"=cohort_col[3]),
`Data type` = c("WES" =data_type_col[1], "RNA-Seq" = data_type_col[2],"Both"=data_type_col[3]),
Response = c("Responder"=Response_col[1],"Non-Responder"=Response_col[2]),
Treatment=c("Nivolumab"=Treatment_col[1],"Pembrolizumab"=Treatment_col[2])),
annotation_name_side="left",height = unit(300, "cm"),width = unit(20, "cm")
)
lgd1 = Legend(labels = c("liu","nadeem","willy"), legend_gp = gpar(fill=c(cohort_col[1],cohort_col[2],cohort_col[3])),
title = "Cohort", ncol = 3)
lgd2 = Legend(labels = c("WES","RNA-Seq","Both"), legend_gp = gpar(fill=c(data_type_col[1],data_type_col[2],data_type_col[3])),
title = "Data type", ncol = 3)
lgd3 = Legend(labels = c("Responder","Non-Responder"), legend_gp = gpar(fill=c(Response_col[1],Response_col[2])),
title = "Response", ncol = 2)
lgd4 = Legend(labels = c("Nivolumab","Pembrolizumab"), legend_gp = gpar(fill=c(Treatment_col[1],Treatment_col[2],Treatment_col[3])),
title = "Treatment", ncol = 2)
draw(ha, test = T)
pd = packLegend(lgd1, lgd2,lgd3,lgd4)
draw(pd,x = unit(14, "cm"), y = unit(6, "cm"), just = c("left", "bottom"))
```
```{r eval=TRUE,warning=FALSE}
knitr::include_graphics("sample_statistics.png")
```
```{r eval=FALSE}
all_sample_exp_ccf <- left_join(all_sample_exp_ccf,dt_cli,by="sample")
all_sample_exp_ccf %>% group_by(sample) %>% summarise(TMB=log((n()/38)+1)) %>%
left_join(.,dt_cli,by="sample") %>% filter(!is.na(cohort)) -> all_tmb
all_tmb %>% group_by(cohort) %>% summarise(tmb_median=median(TMB),tmb_min=min(TMB),max_tmb=max(TMB))
all_sample_exp_ccf %>% filter(!is.na(cohort)) %>%
group_by(sample) %>% summarise(neo_counts=sum(neo=="neo")) %>%
left_join(.,dt_cli,by="sample")-> all_neo
all_neo %>% group_by(cohort) %>% summarise(median_neo=median(neo_counts))
########表格####
gt_input <- tibble(
cohort=c("Liu et.al \n (2019)","Hogo et.al \n (2016)","Riaz et.al \n (2017)"),
`Tumor type`=c("melanoma","melanoma","melanoma"),
Treatment=c("monotherapy","monotherapy","monotherapy"),
Strategy=c("WES RNA-seq","WES RNA-seq","WES RNA-seq"),
Patients=c(130,37,56),
`Number of men(%)`=c("77(59.2%)","26(70.3%)",NA),
`Number of women(%)`=c("53(40.8%)","11(29.7%)",NA),
`Median age, years`=c(NA,61,NA),
`Median survial time(OS,month)`=c(19.4,18.3,17.4),
`TMB median`=c(1.42,2.49,1.86),
`Neoantigen counts median`=c(28.5,77,52)
)
gt_tbl <- gt(data = gt_input)
gt_input %>%
gt(rowname_col = "cohort") %>%
cols_align(
align = "center"
) -> gt_tbl
gridExtra::grid.table(gt_input)
```
```{r eval=TRUE,warning=FALSE}
knitr::include_graphics("sample_table.png")
```
```{r}
#####oncoprint############
##liu
liu_mutations <- readRDS("../data/Immunotherapy/liu_mutations.rds")
liu_mutations <- liu_mutations %>% mutate(change=str_extract(cDNA_Change,"[A-Z]>[A-Z]")) %>%
mutate(Tumor_Seq_Allele2=gsub(">","",str_extract(change,">[A-Z]"))) %>%
mutate(Reference_Allele=gsub(">","",str_extract(change,"[A-Z]>"))) %>%
rename(Tumor_Sample_Barcode=Patient)
liu_clinical <- readRDS("../data/Immunotherapy/liu_clinical.rds") %>%
filter(grepl("Patient",X)) %>%
select(X,OS,dead) %>%
rename(Tumor_Sample_Barcode=X,Overall_Survival_time=OS,Overall_Survival_Status=dead)
liu <- read.maf(maf = liu_mutations,
clinicalData = liu_clinical,
verbose = FALSE)
oncoplot(maf = liu,top=10,draw_titv = TRUE,showTitle = FALSE,removeNonMutated=T)
##willy
files <- list.files("../data/Immunotherapy/willy/",full.names = T)
willy_maf <- merge_mafs(mafs = files)
oncoplot(maf = willy_maf,top=10,draw_titv = TRUE,showTitle = FALSE,removeNonMutated=T)
###nadeem
files <- list.files("../data/Immunotherapy/nadeem/",full.names = T)
nadeem_maf <- merge_mafs(mafs=files)
oncoplot(maf = nadeem_maf,top=10,draw_titv = TRUE,showTitle = FALSE,removeNonMutated=T)
```
## Robust of method
### Minimum number of non-neoantigenic mutations to calculate significant P
The calculated sample-level specific P values are dependent on the mutation rank, and also the number of total mutations and the number of antigenic mutations. So we done the simulation analysis to get the minimum number of antigenic and non-antigenic mutations to get confident quantification of ES. For each number of neoantigenic mutation, we put the neoantigenic mutations in the position of CCF interval or TPM expression with the smallest rank, and put the non-neoantigenic mutations in the position of CCF interval or TPM expression with the largest rank. Then we can get the minimum number of non-neoantigenic mutations to calculate significant p values in each number of neoantigenic mutation.
```{r eval=FALSE}
##CCF
set.seed(202202181)
neo_mut <- vector("list",10)
for (i in 1:10){
neo_c1 <- i
mut_c1 <- 0
j <- 1
dt <- data.frame(sample=rep("sim",neo_c1+mut_c1),
neo=c(rep("yes",neo_c1),rep("no",mut_c1)),
ccf=c(rep(0.005,neo_c1),rep(1,mut_c1)))
a <- NeoEnrichment::cal_nes_new_test(dt = dt,
sample_counts = 1000,
need_p = TRUE)
dt_current <- data.frame(neo_c=neo_c1,mut_c=mut_c1,es=a$es,p=a$p)
while (a$p >= 0.05){
mut_c1 <- mut_c1 + 1
j <- j + 1
dt <- data.frame(sample=rep("sim",neo_c1+mut_c1),
neo=c(rep("yes",neo_c1),rep("no",mut_c1)),
ccf=c(rep(0.005,neo_c1),rep(1,mut_c1)))
a <- NeoEnrichment::cal_nes_new_test(dt = dt,
sample_counts = 1000,
need_p = TRUE)
dt_current[j,] <- c(neo_c1,mut_c1,a$es,a$p)
print(dt_current)
}
neo_mut[[i]] <- dt_current
}
neo_mut <- bind_rows(neo_mut)
saveRDS(neo_mut,file = "../data/ccf_neo_mut_counts.rds")
###exp
neo_mut_exp <- vector("list",10)
for (i in 1:10){
neo_c1 <- i
mut_c1 <- 0
j <- 1
dt <- data.frame(sample=rep("sim",neo_c1+mut_c1),
neo=c(rep("neo",neo_c1),rep("not_neo",mut_c1))) %>% mutate(exp=row_number())
a <- NeoEnrichment::cales_t(data = dt,barcode = "sim",type = "II",
calp = TRUE,sample_counts = 1000,
cal_type = "exp")
dt_current <- data.frame(neo_c=neo_c1,mut_c=mut_c1,es=a$es,p=a$p_value)
while (a$p_value >= 0.05){
mut_c1 <- mut_c1 + 1
j <- j + 1
dt <- data.frame(sample=rep("sim",neo_c1+mut_c1),
neo=c(rep("neo",neo_c1),rep("not_neo",mut_c1))) %>%
mutate(exp=row_number())
a <- NeoEnrichment::cales_t(data = dt,barcode = "sim",type = "II",
calp = TRUE,sample_counts = 1000,
cal_type = "exp")
dt_current[j,] <- c(neo_c1,mut_c1,a$es,a$p_value)
print(dt_current)
}
neo_mut_exp[[i]] <- dt_current
}
neo_mut_exp <- bind_rows(neo_mut_exp)
saveRDS(neo_mut_exp,file = "../data/exp_neo_mut_counts.rds")
```
```{r}
neo_mut_ccf <- readRDS("../data/ccf_neo_mut_counts.rds")
neo_mut_sig <- neo_mut_ccf %>% filter(p<0.05)
neo_mut_sig <- neo_mut_sig %>%
mutate(all_mut_counts=neo_c+mut_c)
p1 <- ggplot(data=neo_mut_sig,aes(x=neo_c,y=all_mut_counts))+
geom_bar(stat = "identity")+
theme_prism()+
labs(x="neoantigen counts",y="all mutation counts")+
scale_x_continuous(breaks=neo_mut_sig$neo_c, labels = neo_mut_sig$neo_c)
neo_mut_exp <- readRDS("../data/exp_neo_mut_counts.rds")
neo_mut_exp_sig <- neo_mut_exp %>% filter(p<0.05)
neo_mut_sig <- neo_mut_exp_sig %>%
mutate(all_mut_counts=neo_c+mut_c)
p2 <- ggplot(data=neo_mut_sig,aes(x=neo_c,y=all_mut_counts))+
geom_bar(stat = "identity")+
theme_prism()+
labs(x="neoantigen counts",y="all mutation counts")+
scale_x_continuous(breaks=neo_mut_sig$neo_c, labels = neo_mut_sig$neo_c)
p1/p2
```
For example, if a patient sample only have one neoantigenic mutations, then at least 20 total mutations are required for reliable quantification of the immunoediting signal. This is a bottom line requirement, and indicates that any samples with 1 neoantigenic mutation and less than 20 total mutations will not have the chance to have significant (P<0.05) immunoediting signal.
### Threshold for neoantigen prediction
We used the less stringent threshold: IC50 < 500 and %Rank < 2 and TPM > 1 (TPM cutoff only for calculating ESccf) to filter neoantigens. This increases the precent of antigenic mutatoins from 9% to 19% for dataset used to calculate ESccf and from 16% to 31% for dataset used to calculated ESrna:
```{r eval=FALSE}
files <- list.files("~/test/data/2021_03_31/")
re <- vector("list",100)
for (i in 1:100){
mut <- readRDS(paste("~/test/data/2021_03_31/",files[i],sep = ""))
neo <- mut %>%
filter(novelty == 1) %>%
filter(IC50 < 500 & bindlevel=="WB" & novelty==1 ) %>%
distinct(index,.keep_all = T)
mut <- mut %>%
distinct(index,.keep_all = T) %>%
mutate(neo = ifelse(index %in% neo$index , "neo","not_neo"))
re[[i]] <- mut
}
all_mut <- bind_rows(re)
all_mut <- all_mut %>%
select(sample,chr,position,ref,alt,neo,gene,exp)
all_mut <- all_mut %>%
mutate(gene=gsub("\\:.+","",gene))
saveRDS(all_mut,file = "../data/all_mut_rank2_IC50.rds")
##add tmp
tpm <- readRDS("~/useful_data/xena_RSEM_TPM/tpm_trans.rds")
tpm <- tpm[!duplicated(tpm$gene),]
all_mut$tpm_exp <- mapply(function(sample,gene){
tpm[tpm$gene==gene,substr(sample,1,15)]
},all_mut$sample,all_mut$gene)
all_mut1 <- all_mut %>%
filter(lengths(tpm_exp)!=0)
all_mut1$tpm_exp <- as.numeric(all_mut1$tpm_exp)
saveRDS(all_mut1,file = "data/all_mut_tpm_not_filter_Rank2_IC50.rds")##this file is used to calculte EXP-ES
all_mut1 <- all_mut1 %>%
mutate(neo2=ifelse(neo=="neo" & tpm_exp>1,"neo","not_neo"))
all_mut1 <- all_mut1 %>%
select(-neo,-exp) %>%
rename(neo=neo2)
saveRDS(all_mut1,file = "data/all_mut_tpm_Rank2_IC50.rds")
##add ccf
results <- readRDS("~/test/data/2021_04_05/all_mut_mis_ccf.rds")
all_mut_tpm <- readRDS("data/all_mut_tpm_Rank2_IC50.rds")
all_mut <- all_mut_tpm %>%
mutate(index=paste(sample,chr,position,ref,alt,sep = ":")) %>%
dplyr::rename(ref_allele=ref,alt_allele=alt)
all_mut_ccf <- inner_join(
all_mut,
results %>% select(-sample),
by="index"
)
all_mut_ccf <- all_mut_ccf[!duplicated(all_mut_ccf$index),]
saveRDS(all_mut_ccf,file = "data/all_mut_ccf_tpm_Rank2_IC50.rds")##This file is used to calculate CCF-ES
```
Caculate ESccf and ESrna:
```{r eval=FALSE}
##cal
all_mut_ccf <- readRDS("data/all_mut_ccf_tpm_Rank2_IC50.rds")
driver_mutations <- readRDS("~/Immunoediting/data/driver_mutations.rds")
all_mut_ccf <- all_mut_ccf %>%
rename(ccf=ccf_hat) %>%
mutate(neo=ifelse(neo=="neo","yes","no"))
samples_has_subclonal <- all_mut_ccf %>% filter(ccf<0.6) %>% select(sample) %>%
distinct(sample)
cal_nes_warp <- function(dt){
results_ccf <- vector("list",length = length(unique(dt$sample)))
names(results_ccf) <- unique(dt$sample)
cl <- makeCluster(getOption("cl.cores", 20),type="FORK")
results_ccf <- parSapply(cl=cl,names(results_ccf),
function(x){
data <- dt %>% filter(sample == x)
a <- NeoEnrichment::cal_nes_new_test(dt = data,
sample_counts = 1000,
need_p = FALSE)
return(a)
},simplify = FALSE)
stopCluster(cl)
results_ccf <- Filter(function(x){length(x)>1},results_ccf)
pancancer_nes_ccf <- bind_rows(results_ccf)
return(pancancer_nes_ccf)
}
all_mut_ccf <- all_mut_ccf %>%
mutate(gene_protein_change=paste(Hugo_Symbol,Protein_Change,sep = "-"))
driver_mutations <- driver_mutations %>%
mutate(gene_protein_change=paste(gene,protein_change,sep = "-"))
all_mut_ccf <- all_mut_ccf %>%
mutate(is_driver=ifelse(gene_protein_change %in% driver_mutations$gene_protein_change,"yes","no"))
sum(all_mut_ccf$is_driver=="yes" & all_mut_ccf$neo=="yes") / sum(all_mut_ccf$neo=="yes")##0.01388538
all_mut_ccf %>% group_by(sample) %>%
summarise(inter_gene=intersect(Hugo_Symbol[neo=="yes"],
Hugo_Symbol[is_driver=="yes"])) -> aaa##701 samples
all_mut_ccf <- all_mut_ccf %>%
mutate(sample_neo_index=paste(sample,neo,Hugo_Symbol,sep = ","))
aaa <- aaa %>% mutate(sample_neo_index=paste(sample,"yes",inter_gene,sep = ","))
all_mut_ccf %>%
mutate(in_aaa = ifelse(sample_neo_index %in% aaa$sample_neo_index,"yes","no")) %>%
group_by(sample) %>%
summarise(need_sample=ifelse(any(in_aaa=="yes"),"no","yes")) %>%
filter(need_sample=="yes") -> summ2
need_samples <- intersect(samples_has_subclonal$sample,summ2$sample)
all_mut_ccf %>%
filter(sample %in% need_samples) %>%
group_by(sample) %>%
summarise(c_n=sum(neo=="yes"),c_m=sum(neo=="no")) %>% filter(c_n>=1 & c_m >=1) -> summ
neo_missense <- all_mut_ccf %>% filter(sample %in% summ$sample)
neo_missense <- neo_missense %>% select(sample,neo,ccf) %>% filter(!is.na(ccf))
neo_nes <- cal_nes_warp(neo_missense)
median(neo_nes$es)##0.19的新抗原
saveRDS(neo_nes,file = "../data/neo_es_ccf_IC50_Rank2.rds")
###模拟
neo_nes <- readRDS("../data/neo_es_ccf_IC50_Rank2.rds")
all_mut_ccf <- readRDS("../data/all_mut_ccf_tpm_Rank2_IC50.rds")
all_mut_ccf <- all_mut_ccf %>%
rename(ccf=ccf_hat) %>%
mutate(neo=ifelse(neo=="neo","yes","no"))
neo_missense <- all_mut_ccf %>% filter(sample %in% neo_nes$sample)
neo_missense <- neo_missense %>% select(sample,neo,ccf) %>% filter(!is.na(ccf))
cal_nes_warp <- function(dt){
results_ccf <- vector("list",length = length(unique(dt$sample)))
names(results_ccf) <- unique(dt$sample)
cl <- makeCluster(getOption("cl.cores", 20),type="FORK")
results_ccf <- parSapply(cl=cl,names(results_ccf),
function(x){
data <- dt %>% filter(sample == x)
a <- NeoEnrichment::cal_nes_new_test(dt = data,
sample_counts = 1000,
need_p = FALSE)
return(a)
},simplify = FALSE)
stopCluster(cl)
results_ccf <- Filter(function(x){length(x)>1},results_ccf)
pancancer_nes_ccf <- bind_rows(results_ccf)
return(pancancer_nes_ccf)
}
res <- vector("list",2000)
for (i in 1:2000){
neo_missense_sim <- neo_missense %>%
group_by(sample) %>%
mutate(neo_sim=sample(neo,length(neo)))
neo_missense_sim <- neo_missense_sim %>%
select(-neo) %>%
rename(neo=neo_sim)
neo_nes_sim <- cal_nes_warp(neo_missense_sim)
neo_nes_sim$sim_num <- i
res[[i]] <- neo_nes_sim
print(paste0("Complete ",i," sim. "))
}
saveRDS(res,file = "../data/sim_2000_filter_driver_IC50_Rank2.rds")
sim_2000 <- readRDS("../data/sim_2000_filter_driver_IC50_Rank2.rds")
sim_2000 <- bind_rows(sim_2000)
sim_2000$cancer <- get_cancer_type(sim_2000$sample,
parallel = T,cores = 20)
saveRDS(sim_2000,file = "../../tmp/sim_2000_filter_driver_IC50_Rank2_all_ccf.rds")
##cal rna
all_mut_exp <- readRDS("~/tmp/all_mut_tpm_not_filter_Rank2_IC50.rds")
all_mut_exp <- all_mut_exp %>% select(sample,tpm_exp,neo,chr,position,gene) %>% rename(exp=tpm_exp)
all_mut_exp %>%
group_by(sample) %>%
summarise(n_a=sum(neo=="not_neo"),n_c=sum(neo=="neo")) %>%
filter(n_a>=1,n_c>=1) -> summ
pancancer_mutation <- readRDS("data/pancancer_mutation.rds") %>%
mutate(index=paste(Sample_ID,chrom,start,sep = ":")) %>%
select(index,Amino_Acid_Change)
all_mut_exp <- left_join(
all_mut_exp %>% mutate(index=paste(sample,chr,position,sep = ":")),
pancancer_mutation
)
all_mut_exp <- all_mut_exp %>%
mutate(gene_protein_change=paste(gene,Amino_Acid_Change,sep = "-"))
driver_mutations <- readRDS("~/Immunoediting/data/driver_mutations.rds")
driver_mutations <- driver_mutations %>%
mutate(gene_protein_change=paste(gene,protein_change,sep = "-"))
all_mut_exp <- all_mut_exp %>%
mutate(is_driver=ifelse(gene_protein_change %in% driver_mutations$gene_protein_change,"yes","no"))
sum(all_mut_exp$is_driver=="yes" & all_mut_exp$neo=="neo") / sum(all_mut_exp$neo=="neo")##0.01029878
all_mut_exp %>% group_by(sample) %>%
summarise(inter_gene=intersect(gene[neo=="neo"],
gene[is_driver=="yes"])) -> aaa##1949 samples
all_mut_exp <- all_mut_exp %>%
mutate(sample_neo_index=paste(sample,neo,gene,sep = ","))
aaa <- aaa %>% mutate(sample_neo_index=paste(sample,"neo",inter_gene,sep = ","))
all_mut_exp %>%
mutate(in_aaa = ifelse(sample_neo_index %in% aaa$sample_neo_index,"yes","no")) %>%
group_by(sample) %>%
summarise(need_sample=ifelse(any(in_aaa=="yes"),"no","yes")) %>%
filter(need_sample=="no") -> summ2
neo_exp <- all_mut_exp %>% filter(sample %in% summ$sample) %>%
filter(!(sample %in% summ2$sample))
neo_exp <- neo_exp %>%
select(sample,neo,exp)
cal_nes_warp <- function(dt){
results_ccf <- vector("list",length = length(unique(dt$sample)))
names(results_ccf) <- unique(dt$sample)
cl <- makeCluster(getOption("cl.cores", 20),type="FORK")
results_ccf <- parSapply(cl=cl,names(results_ccf),
function(x){
a <- NeoEnrichment::cales_t(data = dt,barcode = x,type = "II",
calp = TRUE,sample_counts = 1000,
cal_type = "exp")
#df <- data.frame(sample=x,es=a)
return(a)
},simplify = FALSE)
stopCluster(cl)
results_ccf <- Filter(function(x){length(x)>1},results_ccf)
pancancer_nes_ccf <- bind_rows(results_ccf)
return(pancancer_nes_ccf)
}
nes_exp <- cal_nes_warp(neo_exp)
saveRDS(nes_exp,file = "../data/nes_exp_Rank2_IC50.rds")
##sim
neo_nes <- readRDS("../data/nes_exp_Rank2_IC50.rds")
all_mut_exp <- readRDS("~/tmp/all_mut_tpm_not_filter_Rank2_IC50.rds")
all_mut_exp <- all_mut_exp %>%
select(sample,tpm_exp,neo) %>%
rename(exp=tpm_exp)
neo_missense <- all_mut_exp %>% filter(sample %in% neo_nes$sample)
neo_missense <- neo_missense %>% filter(!is.na(exp))
cal_nes_warp <- function(dt){
results_ccf <- vector("list",length = length(unique(dt$sample)))
names(results_ccf) <- unique(dt$sample)
cl <- makeCluster(getOption("cl.cores", 35),type="FORK")
results_ccf <- parSapply(cl=cl,names(results_ccf),
function(x){
a <- NeoEnrichment::cales_t(data = dt,barcode = x,type = "II",
calp = FALSE,sample_counts = 1000,
cal_type = "exp")
df <- data.frame(sample=x,es=a)
return(df)
},simplify = FALSE)
stopCluster(cl)
results_ccf <- Filter(function(x){length(x)>1},results_ccf)
pancancer_nes_ccf <- bind_rows(results_ccf)
return(pancancer_nes_ccf)
}
res <- vector("list",2000)
for (i in 1:2000){
neo_missense_sim <- neo_missense %>%
group_by(sample) %>%
mutate(neo_sim=sample(neo,length(neo))) %>%
ungroup()
neo_missense_sim <- neo_missense_sim %>%
select(-neo) %>%
rename(neo=neo_sim)
neo_nes_sim <- cal_nes_warp(neo_missense_sim)
neo_nes_sim$sim_num <- i
res[[i]] <- neo_nes_sim
print(paste0("Complete ",i," sim. "))
}
saveRDS(res,file = "../data/sim_2000_es_exp_Rank2_IC50.rds")
sim_2000 <- readRDS("../data/sim_2000_es_exp_Rank2_IC50.rds")
sim_2000 <- bind_rows(sim_2000)
sim_2000$cancer <- get_cancer_type(sim_2000$sample,
parallel = T,cores = 20)
saveRDS(sim_2000,file = "../../tmp/sim_2000_es_exp_Rank2_IC50_all.rds")
```
Then we can get the pan-cancer simulation p values:
```{r}
neo_nes <- readRDS("../data/neo_es_ccf_IC50_Rank2.rds")
sim_all <- readRDS("../../tmp/sim_2000_filter_driver_IC50_Rank2_all_ccf.rds")
neo_nes$cancer <- NeoEnrichment::get_cancer_type(neo_nes$sample)
neo_nes_summ <- neo_nes %>%
group_by(cancer) %>% summarise(median_es=median(es))
sim_all %>%
group_by(sim_num) %>%
summarise(median_es=median(es)) -> summ
p <- WVPlots::ShadedDensity(frame = summ,
xvar = "median_es",
threshold = median(neo_nes$es),
title = "",
tail = "left")
p$layers[[1]]$aes_params$colour <- "red"
p$layers[[1]]$aes_params$size <- 1
p$layers[[2]]$aes_params$fill <- "blue" #geom_ribbon
p$layers[[3]]$aes_params$colour <- "black"
p$layers[[3]]$aes_params$size <- 1
p1 <- p + labs(x="Simulation median es")+
theme_prism()
##rna
neo_nes <- readRDS("../data/nes_exp_Rank2_IC50.rds")
sim_all <- readRDS("../../tmp/sim_2000_es_exp_Rank2_IC50_all.rds")
neo_nes$cancer <- NeoEnrichment::get_cancer_type(neo_nes$sample)
neo_nes_summ <- neo_nes %>%
group_by(cancer) %>% summarise(median_es=median(es))
sim_all %>%
group_by(sim_num) %>%
summarise(median_es=median(es)) -> summ
p <- WVPlots::ShadedDensity(frame = summ,
xvar = "median_es",
threshold = median(neo_nes$es),
title = "",
tail = "left")
p$layers[[1]]$aes_params$colour <- "red"
p$layers[[1]]$aes_params$size <- 1
p$layers[[2]]$aes_params$fill <- "blue" #geom_ribbon
p$layers[[3]]$aes_params$colour <- "black"
p$layers[[3]]$aes_params$size <- 1
p2 <- p + labs(x="Simulation median es")+
theme_prism()
p1/p2
```
Under this new cutoff, a trend in ESCCF signal (ES=-0.013, P=0.054) can still be observed. The pan-cancer ESRNA signal (ES=-0.056, P<0.005) is still significant.
### Another method for neoantigen prediction
We also used MHCfurry implemented in pVACtools to predict neoantigen (cutoff settings: IC50<50 and %Rank <0.5 and TPM >1, and 16% of mutations are predicted as neoantigen), and calculted corresponding ESccf and ESrna. The shell script of predicting neoantigen using pVACseq can be found in `code/shell/pVACseq.sh`:
```{r eval=FALSE}
##process output
library(dplyr)
samples <- data.table::fread("/public/slst/home/wutao2/TCGA_pvacseq/out_files_names",data.table = F,header = F)
for (i in samples$V1){
dt <- data.table::fread(paste0("/public/slst/home/wutao2/TCGA_pvacseq/out_files/",i),
data.table = F)
dt <- dt %>% select(Chromosome,Start,Stop,Reference,
Variant,`Gene Name`,`HLA Allele`,
`MHCflurry MT Score`,`MHCflurry MT Percentile`,
`MHCnuggetsI MT Score`,`Sample Name`)
write.table(dt,file = paste0("/public/slst/home/wutao2/TCGA_pvacseq/out_reorganized/",i),
sep = "\t",col.names = F,row.names = F,quote = F)
}
##get neoantigen
library(dplyr)
files <- list.files("/public/slst/home/wutao2/TCGA_pvacseq/out_reorganized",full.names = T)
re <- vector("list",length(files))
for (i in 1:length(files)){
mut <- data.table::fread(files[i],data.table = F)
mut <- mut %>% mutate(
index = paste(V1,V2,V3,V4,V5,sep = ":")
)
neo_mhcfurry <- mut %>%
filter(V8<50 & V9 <0.5) %>%
distinct(index,.keep_all = T)
neo_mhcnuggets <- mut %>%
filter(V10 < 50) %>%
distinct(index,.keep_all = T)
mut <- mut %>%
distinct(index,.keep_all = T) %>%
mutate(neo_MHCfurry = ifelse(index %in% neo_mhcfurry$index , "neo","not_neo")) %>%
mutate(neo_MHCnuggets = ifelse(index %in% neo_mhcnuggets$index , "neo","not_neo"))
re[[i]] <- mut
}
all_mut <- bind_rows(re)
saveRDS(all_mut,file = "/public/slst/home/wutao2/TCGA_pvacseq/res/all_mut_neo.rds")
##add tpm and ccf
colnames(all_mut)[1:2] <- c("gene","sample")
##add tpm
tpm <- readRDS("~/data/tpm_trans.rds")
tpm <- tpm[!duplicated(tpm$gene),]
all_mut$tpm_exp <- mapply(function(sample,gene){
tpm[tpm$gene==gene,substr(sample,1,15)]
},all_mut$sample,all_mut$gene)
all_mut1 <- all_mut %>%
filter(lengths(tpm_exp)!=0)
all_mut1$tpm_exp <- as.numeric(all_mut1$tpm_exp)
all_mut1 <- all_mut1 %>%
tidyr::separate(col = index,sep = ":",into = c("chr","p","position","ref","alt"))
all_mut1 <- all_mut1 %>% select(-p)
saveRDS(all_mut1,file = "../data/another_methods/all_mut_neo_exp.rds")
results <- readRDS("../data/all_mut_mis_ccf.rds")
all_mut1 <- all_mut1 %>%
mutate(index=paste(sample,chr,position,ref,alt,sep = ":")) %>%
dplyr::rename(ref_allele=ref,alt_allele=alt)
all_mut_ccf <- inner_join(
all_mut1,
results %>% select(index,ccf_hat,Protein_Change),
by="index"
) %>% rename(ccf=ccf_hat) %>% distinct(index,.keep_all = T) %>% select(-index)
saveRDS(all_mut_ccf,file = "../data/another_methods/all_mut_neo_ccf.rds")
##cal ccf
##cal es
##mhcfurry
all_mut_ccf <- readRDS("../data/another_methods/all_mut_neo_ccf.rds")
all_mut_ccf <- all_mut_ccf %>%
mutate(neo=ifelse(neo_MHCfurry=="neo" & tpm_exp>1,"yes","no"))
all_mut_ccf <- all_mut_ccf %>%
mutate(gene_protein_change=paste(gene,Protein_Change,sep = "-"))
driver_mutations <- readRDS("../data/driver_mutations.rds")
driver_mutations <- driver_mutations %>%
mutate(gene_protein_change=paste(gene,protein_change,sep = "-"))
all_mut_ccf <- all_mut_ccf %>%
mutate(is_driver=ifelse(gene_protein_change %in% driver_mutations$gene_protein_change,"yes","no"))
sum(all_mut_ccf$is_driver=="yes" & all_mut_ccf$neo=="yes") / sum(all_mut_ccf$neo=="yes")## 0.0134365
all_mut_ccf %>% group_by(sample) %>%
summarise(inter_gene=intersect(gene[neo=="yes"],
gene[is_driver=="yes"])) -> aaa##1560 samples
all_mut_ccf <- all_mut_ccf %>%
mutate(sample_neo_index=paste(sample,neo,gene,sep = ","))
aaa <- aaa %>% mutate(sample_neo_index=paste(sample,"yes",inter_gene,sep = ","))
all_mut_ccf %>%
mutate(in_aaa = ifelse(sample_neo_index %in% aaa$sample_neo_index,"yes","no")) %>%
group_by(sample) %>%
summarise(need_sample=ifelse(any(in_aaa=="yes"),"no","yes")) %>%
filter(need_sample=="yes") -> summ2
samples_has_subclonal <- all_mut_ccf %>%
filter(ccf<0.6) %>%
select(sample) %>%
distinct(sample)
need_samples <- intersect(samples_has_subclonal$sample,summ2$sample)
all_mut_ccf %>%
filter(sample %in% need_samples) %>%
group_by(sample) %>%
summarise(c_n=sum(neo=="yes"),c_m=sum(neo=="no")) %>% filter(c_n>=1 & c_m >=1) -> summ
neo_missense <- all_mut_ccf %>% filter(sample %in% summ$sample)
neo_missense <- neo_missense %>% select(sample,neo,ccf) %>% filter(!is.na(ccf))
cal_nes_warp <- function(dt){
results_ccf <- vector("list",length = length(unique(dt$sample)))
names(results_ccf) <- unique(dt$sample)
cl <- makeCluster(getOption("cl.cores", 40),type="FORK")
results_ccf <- parSapply(cl=cl,names(results_ccf),
function(x){
data <- dt %>% filter(sample == x)
a <- NeoEnrichment::cal_nes_new_test(dt = data,
sample_counts = 1000,
need_p = FALSE)
return(a)
},simplify = FALSE)
stopCluster(cl)
results_ccf <- Filter(function(x){length(x)>1},results_ccf)
pancancer_nes_ccf <- bind_rows(results_ccf)
return(pancancer_nes_ccf)
}
neo_nes <- cal_nes_warp(neo_missense)
saveRDS(neo_nes,file = "../data/another_methods/es_ccf_mhcfurry_filter_driver.rds")
saveRDS(neo_missense,file = "../data/another_methods/mut_cal_ccf.rds")
##sim
res <- vector("list",2000)
for (i in 1:2000){
neo_missense_sim <- neo_missense %>%
group_by(sample) %>%
mutate(neo_sim=sample(neo,length(neo))) %>%
ungroup()
neo_missense_sim <- neo_missense_sim %>%
select(-neo) %>%
rename(neo=neo_sim)
neo_nes_sim <- cal_nes_warp(neo_missense_sim)
neo_nes_sim$sim_num <- i
res[[i]] <- neo_nes_sim
print(paste0("Complete ",i," sim. "))
}
saveRDS(res,file = "../data/sim_2000_es_ccf_mhcfurry.rds")
sim_2000 <- readRDS("../data/sim_2000_es_ccf_mhcfurry.rds")
sim_2000 <- bind_rows(sim_2000)
sim_2000$cancer <- get_cancer_type(sim_2000$sample,
parallel = T,cores = 20)
saveRDS(sim_2000,file = "../../tmp/sim_2000_filter_all_ccf_mhcfurry.rds")
##exp
all_mut_exp <- readRDS("../data/another_methods/all_mut_neo_exp.rds")
all_mut_exp <- all_mut_exp %>%
rename(neo=neo_MHCfurry) %>%
rename(exp=tpm_exp)
all_mut_exp %>%
group_by(sample) %>%
summarise(n_a=sum(neo=="not_neo"),n_c=sum(neo=="neo")) %>%
filter(n_a>=1,n_c>=1) -> summ
pancancer_mutation <- readRDS("../data/pancancer_mutation.rds") %>%
mutate(index=paste(Sample_ID,chrom,start,sep = ":")) %>%
select(index,Amino_Acid_Change)
all_mut_exp <- left_join(
all_mut_exp %>% mutate(index=paste(sample,chr,position,sep = ":")),
pancancer_mutation
)
all_mut_exp <- all_mut_exp %>%
mutate(gene_protein_change=paste(gene,Amino_Acid_Change,sep = "-"))
driver_mutations <- readRDS("../data/driver_mutations.rds")
driver_mutations <- driver_mutations %>%
mutate(gene_protein_change=paste(gene,protein_change,sep = "-"))
all_mut_exp <- all_mut_exp %>%
mutate(is_driver=ifelse(gene_protein_change %in% driver_mutations$gene_protein_change,"yes","no"))
sum(all_mut_exp$is_driver=="yes" & all_mut_exp$neo=="neo") / sum(all_mut_exp$neo=="neo")##0.006262794
all_mut_exp %>% group_by(sample) %>%
summarise(inter_gene=intersect(gene[neo=="neo"],
gene[is_driver=="yes"])) -> aaa##1707 samples
all_mut_exp <- all_mut_exp %>%
mutate(sample_neo_index=paste(sample,neo,gene,sep = ","))
aaa <- aaa %>% mutate(sample_neo_index=paste(sample,"neo",inter_gene,sep = ","))
all_mut_exp %>%
mutate(in_aaa = ifelse(sample_neo_index %in% aaa$sample_neo_index,"yes","no")) %>%
group_by(sample) %>%
summarise(need_sample=ifelse(any(in_aaa=="yes"),"no","yes")) %>%
filter(need_sample=="no") -> summ2
neo_exp <- all_mut_exp %>% filter(sample %in% summ$sample) %>%
filter(!(sample %in% summ2$sample))
neo_exp <- neo_exp %>%
select(sample,neo,exp)
cal_nes_warp <- function(dt){
results_ccf <- vector("list",length = length(unique(dt$sample)))
names(results_ccf) <- unique(dt$sample)
cl <- makeCluster(getOption("cl.cores", 20),type="FORK")
results_ccf <- parSapply(cl=cl,names(results_ccf),
function(x){
a <- NeoEnrichment::cales_t(data = dt,barcode = x,type = "II",
calp = FALSE,sample_counts = 1000,
cal_type = "exp")
df <- data.frame(sample=x,es=a)
return(df)
},simplify = FALSE)
stopCluster(cl)
results_ccf <- Filter(function(x){length(x)>1},results_ccf)
pancancer_nes_ccf <- bind_rows(results_ccf)
return(pancancer_nes_ccf)
}
nes_exp <- cal_nes_warp(neo_exp)
saveRDS(nes_exp,file = "../data/another_methods/es_exp_filter_driver_mhcfurry.rds")
saveRDS(neo_exp,file = "../data/another_methods/mut_call_exp_mhcfurry.rds")
##sim
neo_exp <- readRDS("../data/another_methods/mut_call_exp_mhcfurry.rds")
cal_nes_warp <- function(dt){
results_ccf <- vector("list",length = length(unique(dt$sample)))
names(results_ccf) <- unique(dt$sample)
cl <- makeCluster(getOption("cl.cores", 20),type="FORK")
results_ccf <- parSapply(cl=cl,names(results_ccf),
function(x){
a <- NeoEnrichment::cales_t(data = dt,barcode = x,type = "II",
calp = FALSE,sample_counts = 1000,
cal_type = "exp")
df <- data.frame(sample=x,es=a)
return(df)
},simplify = FALSE)
stopCluster(cl)
results_ccf <- Filter(function(x){length(x)>1},results_ccf)
pancancer_nes_ccf <- bind_rows(results_ccf)
return(pancancer_nes_ccf)
}
res <- vector("list",2000)
for (i in 1:2000){
neo_missense_sim <- neo_exp %>%
group_by(sample) %>%
mutate(neo_sim=sample(neo,length(neo))) %>%
ungroup()
neo_missense_sim <- neo_missense_sim %>%
select(-neo) %>%
rename(neo=neo_sim)
neo_nes_sim <- cal_nes_warp(neo_missense_sim)
neo_nes_sim$sim_num <- i
res[[i]] <- neo_nes_sim
print(paste0("Complete ",i," sim. "))
}
saveRDS(res,file = "data/sim_2000_filter_driver_exp_mhcfurry.rds")
sim2000 <- readRDS("data/sim_2000_filter_driver_exp_mhcfurry.rds")
sim2000 <- bind_rows(sim2000)
sim2000$cancer <- get_cancer_type(sim2000$sample,parallel = T,cores = 20)
saveRDS(sim2000,file = "../../tmp/sim_2000_filter_all_exp_mhcfurry.rds")
```
Then we can get the simulation p values for MHCfurry dataset:
```{r}
##ccf mhcfurry
neo_nes <- readRDS("../data/another_methods/es_ccf_mhcfurry_filter_driver.rds")
sim_all <- readRDS("../../tmp/sim_2000_filter_all_ccf_mhcfurry.rds")
sim_all %>%
group_by(cancer,sim_num) %>%
summarise(median_es=median(es)) -> summ2
neo_nes$cancer <- get_cancer_type(neo_nes$sample)
neo_nes_summ <- neo_nes %>%
group_by(cancer) %>% summarise(median_es=median(es))
sim_all %>%
group_by(sim_num) %>%
summarise(median_es=median(es)) -> summ
p <- WVPlots::ShadedDensity(frame = summ,
xvar = "median_es",