-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathORACLE 2 code.R
2988 lines (2353 loc) · 151 KB
/
ORACLE 2 code.R
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
#
## Loading packages
#
library(tidyverse)
library(DESeq2)
library(survminer)
library(survival)
library(nlme)
library(ggalluvial)
library(ggrepel)
library(corrplot)
library(ComplexHeatmap)
library(circlize)
library(gridExtra)
library(forestplot)
library(biomaRt)
library(fst)
library(stringr)
library(org.Hs.eg.db)
library(DescTools)
library(scales)
#
## Calculation of ORACLE risk-score
#
#Filter and normalised count data
#gene expression at least 1 TPM in at least 20% of samples, variance stabilising tranformation
TRACERx_count <- read.csv("2022-11-06_tx421_count.csv",row.names = 1)
TRACERx_TPM <- read.csv("2022-11-06_tx421_TPM.csv", row.names = 1)
#
n_TPM <- 1
tmp <- TRACERx_TPM > n_TPM # at least n TPM
tumour_sample_n <- ncol(TRACERx_TPM)
tpm_threshold <- 0.2*tumour_sample_n #in at least n% of samples
#keep genes
keep <- rowSums(tmp) >= tpm_threshold
TRACERx_filt_count <- TRACERx_count[keep,]
#prepare DESeq Dataset
coldata<-data.frame(sample = colnames(TRACERx_filt_count),row.names = colnames(TRACERx_filt_count))
TRACERx_filt_count <- round(TRACERx_filt_count)
dds <- DESeqDataSetFromMatrix(countData = TRACERx_filt_count,
colData = coldata,
design = ~1)
#vst normalisation
vsd <- vst(dds, blind=TRUE, fitType="mean")
vsd <- assay(vsd)
#calculate ORACLE risk score
Supp_Table_5_ORACLE <- read.csv("Supp_Table_5_ORACLE.csv")
Tx421_full_riskscore <- data.frame(sample_name = colnames(vsd) , ORACLE_riskscore = colSums(vsd[Supp_Table_5_ORACLE$Gene.Symbol,]*Supp_Table_5_ORACLE$Model.Coefficient) )
#
## Batch correction
#
#Perform batch correction for risk scores
cutoff <- read.csv("2018-11-07_oracle_de.novo_cut.off.csv")
cutoff <- cutoff$RiskScore[1]
#Tx100 risk scores
tracerx_oracle_rs <- read.csv("data_20230810\\tracerx_oracle_rs_md.csv")
tracerx_oracle_rs$sample_name <- gsub("-",tracerx_oracle_rs$sample_name, replacement = ".")
#compare between Tx100 and Tx421
compare.df <- left_join(Tx421_full_riskscore,tracerx_oracle_rs[,c("sample_name","RiskScore")])
compare.df <- compare.df[which(!is.na(compare.df$RiskScore)),]
colnames(compare.df)[2:3] <- c("Tx421","Tx100")
#plot non-corrected riskscore with Tx100
md <- lm(data = compare.df, Tx100~Tx421)
r <- summary(md)
ggplot(compare.df,aes(Tx421,Tx100)) + geom_point() + geom_smooth(method = "lm",se=F) +
ylab("2019 Risk Score") + xlab("2023 Risk Score") + ggtitle(paste0("n_TPM=",n_TPM, ", n_sample=",85)) +
scale_y_continuous(expand = c(0,0),limits = c(8,12)) +
scale_x_continuous(expand = c(0,0),limits = c(8,12)) +
geom_hline(yintercept = cutoff,lty="dashed") + geom_vline(xintercept = cutoff,lty="dashed") +
geom_text(aes(x=8.8, y=11.5, label = paste0("R-sq=",signif(r$r.squared,digits = 3), "\np=",signif(r$coefficients[2,4],digits = 2)))) +
geom_text(aes(x=8.8, y=11.1, label = paste0("Y=",signif(r$coefficient[2,1],digits = 3), "X",signif(r$coefficients[1,1],digits = 3)))) +
theme(panel.background = element_blank(),panel.border = element_rect(colour = "black", fill=NA, size=1))
#corrected riskscore
Tx421_full_riskscore$ORACLE_riskscore <- Tx421_full_riskscore$ORACLE_riskscore * r$coefficients[2,1] + r$coefficients[1,1]
#
## RNA signature risk-scores
#
#Obtain count data on full list of genes
TRACERx_count <- read.csv("2022-11-06_tx421_count.csv",row.names = 1)
#prepare DESeq Dataset
coldata<-data.frame(sample = colnames(TRACERx_count),row.names = colnames(TRACERx_count))
TRACERx_count <- round(TRACERx_count)
dds <- DESeqDataSetFromMatrix(countData = TRACERx_count,
colData = coldata,
design = ~1)
#vst normalisation
vsd <- vst(dds, blind=TRUE, fitType="mean")
vsd <- assay(vsd)
#import signatures
Li_JAMA <- read.csv("Li_JAMA_2017.csv")
Wang <- read.csv("Wang_Front_Immuno_2022.csv")
Zhao<-read.csv("Zhao_LC_2020.csv")
Song <- read.csv("Song_Sci Rep_2022.csv")
Jin <- read.csv("Jin_J Immunol Res_2022.csv")
LiFeng <- read.csv("FengLi_Sci Rep_2022.csv")
#Li et al. JAMA Oncol 2017
mat <- vsd[which( rownames(vsd) %in% c(Li_JAMA$IRG1,Li_JAMA$IRG2) ), ] %>% as.data.frame()
Li_JAMA$gene_pair <- paste(Li_JAMA$IRG1,Li_JAMA$IRG2,sep="_")
IRGP_score <- matrix(nrow = length(Li_JAMA$gene_pair), ncol = ncol(mat),
dimnames = list(Li_JAMA$gene_pair, colnames(mat))) %>% as.data.frame
IRG1 <- NA
IRG2 <- NA
for(i in 1:ncol(IRGP_score)){
for(k in 1:nrow(Li_JAMA)){
IRG1 <- mat[which(rownames(mat) == Li_JAMA$IRG1[k]),i];
IRG2 <- mat[which(rownames(mat) == Li_JAMA$IRG2[k]),i];
IRGP_score[k,i] <- ifelse(IRG1 < IRG2,1,0)
}
}
Li_riskscore <- data.frame(Li_RS = colSums(IRGP_score[Li_JAMA$gene_pair,] * Li_JAMA$Coef), sample_name = colnames(IRGP_score))
#Wang et al. Front Immunol 2022
mat <- vsd[which( rownames(vsd) %in% Wang$Gene ), ] %>% as.data.frame()
Wang_riskscore <- data.frame(Wang_RS = colSums(mat[Wang$Gene,] * Wang$Coefficient), sample_name = colnames(mat))
#Zhao et al. Lung cancer 2020
mat <- vsd[which( rownames(vsd) %in% Zhao$Gene ), ] %>% as.data.frame()
Zhao_riskscore <- data.frame(Zhao_RS = colSums(mat[Zhao$Gene,] * Zhao$Coefficient), sample_name = colnames(mat))
#Song et al. Sci Rep 2022
mat <- vsd[which( rownames(vsd) %in% Song$Genes ), ] %>% as.data.frame()
Song_riskscore <- data.frame(Song_RS = colSums(mat[Song$Genes,] * Song$coef), sample_name = colnames(mat))
#Jin et al. J Immunol Res 2022
mat <- vsd[which( rownames(vsd) %in% Jin$Gene ), ] %>% as.data.frame()
Jin_riskscore <- data.frame(Jin_RS = colSums(mat[Jin$Gene,] * Jin$beta), sample_name = colnames(mat))
#Feng Li et al. Sci Rep 2022
mat <- vsd[which( rownames(vsd) %in% LiFeng$Gene ), ] %>% as.data.frame()
LiFeng_riskscore <- data.frame(LiFeng_RS = colSums(mat[LiFeng$Gene,] * LiFeng$beta), sample_name = colnames(mat))
#
Tx421_full_riskscore <- left_join(Tx421_full_riskscore, Li_riskscore, by = "sample_name")
Tx421_full_riskscore <- left_join(Tx421_full_riskscore, Wang_riskscore, by = "sample_name")
Tx421_full_riskscore <- left_join(Tx421_full_riskscore, Zhao_riskscore, by = "sample_name")
Tx421_full_riskscore <- left_join(Tx421_full_riskscore, Song_riskscore, by = "sample_name")
Tx421_full_riskscore <- left_join(Tx421_full_riskscore, Jin_riskscore, by = "sample_name")
Tx421_full_riskscore <- left_join(Tx421_full_riskscore, LiFeng_riskscore, by = "sample_name")
Tx421_full_riskscore$sample_name <- gsub("[.]",Tx421_full_riskscore$sample_name, replacement = "-")
#filter for LUAD cohort and join with anonymous id - CRUK ID
Tx421_clinicopatho <- read.csv("Tx421_merged_clinicopathological_data_20220726.nooutcome.csv")
Tx421_LUAD <- Tx421_clinicopatho[which(Tx421_clinicopatho$Histology_per_region == "Invasive adenocarcinoma"),]
Tx421_LUAD$sample_name[which(Tx421_LUAD$sample_name == "LTX0615_SU_T1-R5")] <- "LTX0615_SU_T2-R5" #This is a mislabelled tumour which belong to T2 cluster
Tx421_LUAD <- Tx421_LUAD[which(grepl("SU_T1", Tx421_LUAD$sample_name)),] #select primary tumour
Tx421_riskscore <- left_join(Tx421_LUAD[,c("sample_name","cruk_id","sample_name_cruk","tumour_id_mphase_cruk")], Tx421_full_riskscore, by = "sample_name")
Tx421_riskscore <- Tx421_riskscore[which(!is.na(Tx421_riskscore$ORACLE_riskscore)),]
#
## isolate TRACERx validation cohort
#
#separate region info
Tx421_riskscore$RegionalID <- apply(Tx421_riskscore, 1, FUN = function(x){ strsplit(x[1], split = "-")[[1]][2] })
#assign ORACLE risk-class
Tx421_riskscore$bin <- ifelse(Tx421_riskscore$ORACLE_riskscore > cutoff,"High","Low")
risk_class <- table(Tx421_riskscore$cruk_id,Tx421_riskscore$bin)
risk_class <- data.frame(High=as.matrix(risk_class)[,"High"], Low=as.matrix(risk_class)[,"Low"])
risk_class$ORACLE_class <- NA
risk_class$ORACLE_class <- ifelse(risk_class$High > 0, paste(risk_class$ORACLE_class, "High", sep=""), risk_class$ORACLE_class)
risk_class$ORACLE_class <- ifelse(risk_class$Low > 0, paste(risk_class$ORACLE_class, "Low", sep=""), risk_class$ORACLE_class)
risk_class$ORACLE_class <- gsub(x=risk_class$ORACLE_class, pattern="NA", replacement="")
risk_class$ORACLE_class <- gsub(x=risk_class$ORACLE_class, pattern="HighLow", replacement="Discordant")
risk_class$cruk_id <- rownames(risk_class)
Tx421_riskscore <- left_join(Tx421_riskscore,risk_class,by = "cruk_id")
#prepare TRACERx321 validation cohort - excluding patients used in Biswas et al. 2019
tracerx_oracle_rs <- read.csv("C:\\Users\\cola2318\\Dropbox\\UCL RA data\\Tx421\\github\\tracerx_oracle_rs.csv")
Tx100 <- unique(tracerx_oracle_rs$PublicationID)
Tx321_riskscore <- Tx421_riskscore[which(!Tx421_riskscore$cruk_id %in% Tx100),]
#
## load data
#
### Figure 1
#Tx validation cohort risk-scores
Tx321_riskscore <- read.csv("20230727_TRACERx321_riskscores.csv")
#2019 cutoff
cutoff <- read.csv("2018-11-07_oracle_de.novo_cut.off.csv")
cutoff <- cutoff$RiskScore[1]
#load four metrics result
TSB_metric1 <- read.csv("Discordant_perc.csv")
TSB_metric2 <- read.csv("Cluster_concordance_AUC.csv")
TSB_metric3 <- read.csv("ExpVar_byHouseham.csv")
TSB_metric4 <- read.csv("LeastBiopsy_TSB.csv")
### Figure 2
#Tx risk-score
Tx321_riskscore <- read.csv("20230727_TRACERx321_riskscores.csv")
#Tx clinical data
TRACERx_clinical <- readRDS("all_patient_df_20221109.RDS")
all_tumour_df_20220209 <- readRDS("all_tumour_df_20220209.RDS")
all_tumour_df_20220209$tumour_id_mphase_cruk <- apply(all_tumour_df_20220209, 1 , FUN = function(x){ if(grepl("Cluster", x[12])) {x[12] <- gsub(".*-", x[12], replacement = paste0(x[4] , "_"))} else {x[12] <- x[4]} } )
#overall survival data
Tx321_Survdata <- left_join(Tx321_riskscore, TRACERx_clinical[,c("cruk_id","cens_os","os_time")], by = "cruk_id")
#join clinicopathological
Tx321_Survdata <- left_join(Tx321_Survdata, all_tumour_df_20220209[,c("tumour_id_mphase_cruk","age","sex","pack_years_calculated","pTNMStage_v8","adjuvant_treatment_YN","IASLC_LUAD_grade")], by = "tumour_id_mphase_cruk")
Tx321_Survdata$pTNMStage_v8[which(grepl("CRUK0704",Tx321_Survdata$tumour_id_mphase_cruk))] <- "2b" #collision tumour
#censor survival at 5 years
Tx321_Survdata$os_time <- Tx321_Survdata$os_time/365
Tx321_Survdata$cens_os[which(Tx321_Survdata$os_time >5)]<-0
Tx321_Survdata$os_time[which(Tx321_Survdata$os_time>5)] <- 5
#survival data for each patient
Tx321_tumour_Survdata <- Tx321_Survdata[which(!duplicated(Tx321_Survdata$cruk_id)),]
Tx321_tumour_Survdata$ORACLE_class <- factor(Tx321_tumour_Survdata$ORACLE_class, levels = c("Low","Discordant","High"))
#calculate ORACLE mean score
tmp <- aggregate(Tx321_Survdata$ORACLE_riskscore, by = list(cruk_id = Tx321_Survdata$cruk_id), mean)
colnames(tmp)[2] <- "ORACLE_mean"
Tx321_tumour_Survdata <- left_join(Tx321_tumour_Survdata, tmp, by = "cruk_id")
#factor levels
Tx321_tumour_Survdata$sex <- factor(Tx321_tumour_Survdata$sex , levels = c("Male","Female"))
Tx321_tumour_Survdata$adjuvant_treatment_YN <- factor(Tx321_tumour_Survdata$adjuvant_treatment_YN , levels = c("No adjuvant","Adjuvant"))
Tx321_tumour_Survdata$TNM_combine <- NA
Tx321_tumour_Survdata$TNM_combine[which(grepl("1",Tx321_tumour_Survdata$pTNMStage_v8 ))] <- "I"
Tx321_tumour_Survdata$TNM_combine[which(grepl("2",Tx321_tumour_Survdata$pTNMStage_v8 ))] <- "II"
Tx321_tumour_Survdata$TNM_combine[which(grepl("3",Tx321_tumour_Survdata$pTNMStage_v8 ))] <- "III"
Tx321_tumour_Survdata$TNM_combine <- factor(Tx321_tumour_Survdata$TNM_combine, levels = c("I","II","III"))
Tx321_tumour_Survdata$IASLC_LUAD_grade[which(Tx321_tumour_Survdata$IASLC_LUAD_grade == "Grade 1")] <- NA
Tx321_tumour_Survdata$IASLC_LUAD_grade <- factor(Tx321_tumour_Survdata$IASLC_LUAD_grade, levels = c("IMA","Grade 2","Grade 3"))
## 2C
#function for simulation - psuedo single biopsy cohort
create_surv <- function(signature){
#
RiskScore.df <- dplyr::select(sample.df, cruk_id, paste(signature,"RS",sep = "_"))
#sample 1 region per patient tumour
bootstrap.df <- aggregate(RiskScore.df[,paste(signature,"RS",sep = "_")] , by=list(cruk_id = RiskScore.df$cruk_id),FUN=function(x){sample(x,size=1,replace = T)})
colnames(bootstrap.df)[2] <- "Boot_RS"
#join os_time, cens_os
surv.df <- left_join(sample.df,bootstrap.df,by="cruk_id")
#use original riskscore for patient tumour with only 1 region
surv.df[which(surv.df$cruk_id %in% names(which(table(surv.df$cruk_id)==1))),"Boot_RS"] <- surv.df[which(surv.df$cruk_id %in% names(which(table(surv.df$cruk_id)==1))),paste(signature,"RS",sep = "_")]
#
surv.df <- surv.df[which(!duplicated(surv.df$cruk_id)),c("cruk_id","Boot_RS")]
#TRACERx risk ROC cut-off
if(signature == "ORACLE"){
cutoff <- read.csv("2018-11-07_oracle_de.novo_cut.off.csv")
cutoff <- cutoff$RiskScore[1]
}
else{cutoff <- median(sample.df[,paste(signature,"RS",sep = "_")])}
#bootstrap data frame
surv.df$bin <- ifelse(surv.df[,"Boot_RS"] > cutoff, "High","Low")
surv.df <- left_join(surv.df,Tx321_tumour_Survdata[,c("cruk_id","os_time","cens_os")],by="cruk_id")
return(surv.df)
}
#function for survival association analysis - log-rank p, cox regression
bootsrap_surv <- function(survdf){
survdiff <- survdiff(Surv(survdf$os_time,survdf$cens_os)~survdf$bin)
logrank_p <- pchisq(survdiff$chisq,df=1,lower.tail = FALSE)
logrank_p <- signif(logrank_p,digits = 2)
#cox regression on bootstrap riskscore
cox <- coxph(Surv(os_time, cens_os)~Boot_RS, data = survdf)
cox_result <- summary(cox)
cox_result <- data.frame(HR=cox_result$coefficients[,2], lower_ci=cox_result$conf.int[,3], upper_ci=cox_result$conf.int[,4], P=cox_result$coefficients[,5])
result.df <- data.frame(log_rank_p = logrank_p,HR = cox_result$HR, cox_pval = cox_result$P, cox_lci = cox_result$lower_ci, cox_uci = cox_result$upper_ci)
return(result.df)
}
### Figure 3
## 3A-B
#lung-cancer-specific survival
Tx321_tumour_Survdata <- left_join(Tx321_tumour_Survdata, TRACERx_clinical[,c("cruk_id","cens_lung_specific","lung_specific_time")], by = "cruk_id")
#censor LCSS at 5 years
Tx321_tumour_Survdata$lung_specific_time <- Tx321_tumour_Survdata$lung_specific_time/365
Tx321_tumour_Survdata$cens_lung_specific[which(Tx321_tumour_Survdata$lung_specific_time >5)]<-0
Tx321_tumour_Survdata$lung_specific_time[which(Tx321_tumour_Survdata$lung_specific_time>5)] <- 5
## 3C
#Mascaux dataset
Mascaux <- read.delim("GSE33479.txt.gz", as.is=T, check.names=FALSE)
gene.annot <- read.delim("GPL6480-9577.txt", as.is=T, check.names=FALSE,skip=17)
patient.annot <- read.table("GSE33479_series_matrix.txt.gz", header = TRUE,fill = TRUE,skip=25)
#ORACLE genes
Supp_Table_5_ORACLE <- read.csv("Supp_Table_5_ORACLE.csv")
#remove non-matched probes
Mascaux <- Mascaux[,-c(124:127)]
Mascaux <- Mascaux[-which(is.na(Mascaux$ID_REF)),]
colnames(Mascaux)[1] <- "ID"
#match gene names to probes
Mascaux <- left_join(Mascaux,gene.annot[,c("ID","GENE_SYMBOL")], by="ID")
Mascaux <- Mascaux[-which(Mascaux$GENE_SYMBOL == ""),]
#paste patient ID
colnames(patient.annot) <- paste(patient.annot[15,], colnames(patient.annot),sep = "-")
#duplicated genes - max value
Mascaux_ORACLE <- Mascaux[which(Mascaux$GENE_SYMBOL %in% Supp_Table_5_ORACLE$Gene.Symbol),]
Mascaux_ORACLE <- aggregate(Mascaux_ORACLE[,-which(colnames(Mascaux_ORACLE) == "GENE_SYMBOL")],by=list(Gene = Mascaux_ORACLE$GENE_SYMBOL),max)
Mascaux_ORACLE <- column_to_rownames(Mascaux_ORACLE, var = "Gene")
Mascaux_ORACLE <- Mascaux_ORACLE[,-1]
## 3D
#load ORACLE clinical data - retreive recurrence samples
Tx421_riskscore <- read.csv("20230727_TRACERx421_riskscores.csv")
Tx421_clinicopatho <- read.csv("Tx421_merged_clinicopathological_data_20220726.nooutcome.csv")
TRACERx_clinical <- readRDS("all_patient_df_20221109.RDS")
#primary-metastasis phylogenies
seed.region <- read.table("seedingRegionInfo.txt",header = T,sep = "\t")
## 3E-F
#disease-free survival
Relapse_survdata <- dplyr::select(Tx321_riskscore, ORACLE_class, ORACLE_riskscore,cruk_id,tumour_id_mphase_cruk)
Relapse_survdata <- Relapse_survdata[which(!duplicated(Relapse_survdata$cruk_id)),]
Relapse_survdata <- left_join(Relapse_survdata, TRACERx_clinical[,c("cruk_id","dfs_time","cens_dfs","dfs_time_any_event","Relapse_cat_new","first_dfs_any_event")], by = "cruk_id")
Relapse_survdata <- left_join(Relapse_survdata, all_tumour_df_20220209[,c("tumour_id_mphase_cruk","age","sex","pack_years_calculated","pTNMStage_v8","adjuvant_treatment_YN")], by = "tumour_id_mphase_cruk")
# For DFS, censor 4 patients who are currently marked as "recurrence" but uncertain whether the recurrence is from 1st primary or 2nd primary (if from 2nd primary, these cases should NOT be marked as recurrence in TRACERx protocol)
# "CRUK0512", "CRUK0373","CRUK0428","CRUK0511" : currently marked as recurrence, after 2nd primary cancer was confirmed
Relapse_survdata$cens_dfs[which(Relapse_survdata$cruk_id %in% c("CRUK0512","CRUK0373","CRUK0428","CRUK0511"))] <- 0
Relapse_survdata$dfs_time[which(Relapse_survdata$cruk_id %in% c("CRUK0512","CRUK0373","CRUK0428","CRUK0511"))] <- Relapse_survdata$dfs_time_any_event[which(Relapse_survdata$cruk_id %in% c("CRUK0512","CRUK0373","CRUK0428","CRUK0511"))]
#censor DFS at 5 years
Relapse_survdata$dfs_time_any_event <- Relapse_survdata$dfs_time_any_event/365
Relapse_survdata$dfs_time <- Relapse_survdata$dfs_time/365
Relapse_survdata$cens_dfs[which(Relapse_survdata$dfs_time >5)]<-0
Relapse_survdata$dfs_time[which(Relapse_survdata$dfs_time>5)] <- 5
#calculate ORACLE mean risk-score
tmp <- aggregate(Relapse_survdata$ORACLE_riskscore, by = list(cruk_id = Relapse_survdata$cruk_id), mean)
colnames(tmp)[2] <- "ORACLE_mean"
Relapse_survdata <- left_join(Relapse_survdata, tmp, by = "cruk_id")
### Figure 4
#CCLE test result
IC50_results <- read.csv("CCLE_result_table_20230308.csv",row.names = 1)
### Figure 5
#TRACERx clinicopathological risk factors + genetic evolutionary metrics
Features.df <- read.csv("Source Data ED8A.csv",check.names = F)
#TRACERx evolutionary biomarkers
Tx_biomarkers <- read.csv("Source Data Fig5B.csv")
#function for glm test
biomarker.glm <- function(FU_time){
tmp <- dplyr::select(Tx_biomarker_avail, cruk_id,SCNA_ITH,STAS,ctDNA_status,subclonal_wgd, RecentSubclExpansionScore ,ORACLE_scaled,cens_os,os_time)
#censor any patient exceed FU time
tmp$cens_os[which(tmp$os_time >FU_time)]<-0
tmp$os_time[which(tmp$os_time>FU_time)] <- FU_time
#removed censored patients within the FU time
if(FU_time > 1){
tmp <- tmp[-which(tmp$os_time < FU_time & tmp$cens_os==0),]
}
#Create glm result data frame for all biomarker combinations
colnames(tmp)[2:7] <- c("SCNA_ITH","STAS","ctDNA","S_WGD","RSE","ORACLE")
glm.result.df <- data.frame(variable = c("SCNA_ITH","STAS","ctDNA","S_WGD","RSE","ORACLE"),Explained_var = NA)
#
for(i in 1:nrow(glm.result.df)){
mod <- glm(data=tmp,as.formula(paste0("cens_os ~",glm.result.df$variable[i])) )
glm.result.df$Explained_var[i] <- PseudoR2(mod)*100
}
glm_time <- glm.result.df
glm_time$OS_time <- FU_time
glm_time$event <- paste0(glm_time$OS_time,"(" ,table(tmp$cens_os)["1"],")")
return(glm_time)
}
### Extended Data Fig 2
all_tumour_df_20220209 <- readRDS("all_tumour_df_20220209.RDS")
all_tumour_df_20220209$tumour_id_mphase_cruk <- apply(all_tumour_df_20220209, 1 , FUN = function(x){ if(grepl("Cluster", x[12])) {x[12] <- gsub(".*-", x[12], replacement = paste0(x[4] , "_"))} else {x[12] <- x[4]} } )
### Extended Data Fig 3
#load signature genes
Li_JAMA <- read.csv("Li_JAMA_2017.csv")
Wang <- read.csv("Wang_Front_Immuno_2022.csv")
Zhao<-read.csv("Zhao_LC_2020.csv")
Song <- read.csv("Song_Sci Rep_2022.csv")
Jin <- read.csv("Jin_J Immunol Res_2022.csv")
LiFeng <- read.csv("FengLi_Sci Rep_2022.csv")
#load LUAD sample expression matrix
LUAD_vsd <- read.csv("tracerx_primaryLUAD_vsd.csv", row.names = 1)
#prepare expression matrix for each signature
mat1 <- LUAD_vsd[Supp_Table_5_ORACLE$Gene.Symbol,] #ORACLE
mat2 <- LUAD_vsd[which(rownames(LUAD_vsd) %in% c(Li_JAMA$IRG1,Li_JAMA$IRG2)), ] #Li
mat3 <- LUAD_vsd[which(rownames(LUAD_vsd) %in% Wang$Gene), ] #Wang
mat4 <- LUAD_vsd[which(rownames(LUAD_vsd) %in% Zhao$Gene), ] #Zhao
mat5 <- LUAD_vsd[which(rownames(LUAD_vsd) %in% Song$Genes), ] #Song
mat6 <- LUAD_vsd[which(rownames(LUAD_vsd) %in% Jin$Gene), ] #Jin
mat7 <- LUAD_vsd[which(rownames(LUAD_vsd) %in% LiFeng$Gene), ] #Feng Li
#function for calculating concordant rate in the same cluster
clusterSigs <- function(mat,k){
#hclust
tmp <- scale(t(mat),center = TRUE)
clust <- hclust(dist(tmp,method = "manhattan"),method = "ward.D2")
#cut into k clusters
clust_data <- data.frame(cluster=cutree(clust,k), sample_name = names(cutree(clust,k)))
#paste IDs to cluster
clust_data$Shorter_ID <- gsub("_.*",rownames(clust_data),replacement = "")
for(i in 1:nrow(clust_data)){
clust_data$cluster[i] <- paste(clust_data$Shorter_ID[i],clust_data$cluster[i],sep = "-")
}
#assign concordant or discordant cluster
clust_data$result <- NA
for(i in 1:nrow(clust_data)){
if(length(clust_data$cluster[which(clust_data$Shorter_ID==clust_data$Shorter_ID[i])]%>%unique()) == 1){
clust_data$result[i] <- "Concordant"
}
else {clust_data$result[i] <- "Discordant"}
}
#calculate percentage
clust_data_summary <- clust_data[-which(duplicated(clust_data$Shorter_ID)),]
return(100*table(clust_data_summary$result)["Concordant"]/nrow(clust_data_summary))
}
#function to create df for samples fall in which cluster group when cut into k clusters
clusterdf <- function(mat, ht, k){
tmp <- scale(t(mat),center = TRUE,scale = T)
df <- data.frame(sample_name=NA,clust=NA)
#from 1 to k cluster
for(i in 1:k){
a <- data.frame(sample_name = colnames(t(tmp))[column_order(draw(ht))[[i]]], clust=i)
df <- rbind(df,a)
}
df <- df[-1,]
df$cruk_id <- gsub("_.*",df$sample,replacement = "")
rownames(df) <- df$sample
df <- dplyr::select(df,clust)
return(df)
}
#function to create heatmap
clust_heatmap <- function(mat){
tmp <- scale(t(mat),center = TRUE,scale = T)
##top heatmap
ht_gene <- Heatmap(t(tmp),
clustering_distance_columns = dist(tmp,method = "manhattan"),
clustering_method_columns = "ward.D2",
cluster_rows = FALSE,
name = "ht1",
row_dend_width = unit(15, "mm"),
row_names_gp = gpar(fontsize=7),column_names_gp = gpar(fontsize=2),
col = colorRamp2(seq(-3,3), viridis(7)),
show_row_names = TRUE,show_column_names = F,row_names_side = "left",
heatmap_legend_param = list(title = NULL, color_bar = "continuous")
)
##cluster number annotation
ht2 <- Heatmap(t(tmp),
clustering_distance_columns = dist(tmp,method = "manhattan"),
clustering_method_columns = "ward.D2",
cluster_rows = FALSE,
name = "ht2",
column_split = 2,
row_dend_width = unit(15, "mm"),
row_names_gp = gpar(fontsize=7),column_names_gp = gpar(fontsize=2),
col = colorRamp2(seq(-3,3), viridis(7)),
show_row_names = TRUE,show_column_names = F,row_names_side = "left",
heatmap_legend_param = list(title = NULL, color_bar = "continuous")
)
df2 <- clusterdf(mat, ht2,2)
df2 <- data.frame(cluster = df2[colnames(mat),])
rownames(df2) <- colnames(mat)
colors <- structure(colorRampPalette(brewer.pal(n=11, name="RdYlBu")[-c(1, 11)])(2), names = c(1:2))
ha2 <-HeatmapAnnotation("2" = df2[colnames(mat), ],height = unit(3,"cm"),border = T,show_legend = F,
show_annotation_name = T,col = list("2"=colors),annotation_name_side="left")
#
ht10 <- Heatmap(t(tmp),
clustering_distance_columns = dist(tmp,method = "manhattan"),
clustering_method_columns = "ward.D2",
cluster_rows = FALSE,
name = "ht10",
column_split = 10,
row_dend_width = unit(15, "mm"),
row_names_gp = gpar(fontsize=7),column_names_gp = gpar(fontsize=2),
col = colorRamp2(seq(-3,3), viridis(7)),
show_row_names = TRUE,show_column_names = F,row_names_side = "left",
heatmap_legend_param = list(title = NULL, color_bar = "continuous")
)
df10 <- clusterdf(mat, ht10,10)
df10 <- data.frame(cluster = df10[colnames(mat),])
rownames(df10) <- colnames(mat)
colors <- structure(colorRampPalette(brewer.pal(n=11, name="RdYlBu")[-c(1, 11)])(10), names = c(1:10))
ha10 <-HeatmapAnnotation("10" = df10[colnames(mat), ],height = unit(3,"cm"),border = T,
show_legend = F,show_annotation_name = T,col = list("10"=colors),annotation_name_side="left")
#
ht60 <- Heatmap(t(tmp),
clustering_distance_columns = dist(tmp,method = "manhattan"),
clustering_method_columns = "ward.D2",
cluster_rows = FALSE,
name = "ht60",
column_split = 60,
row_dend_width = unit(15, "mm"),
row_names_gp = gpar(fontsize=7),column_names_gp = gpar(fontsize=2),
col = colorRamp2(seq(-3,3), viridis(7)),
show_row_names = TRUE,show_column_names = F,row_names_side = "left",
heatmap_legend_param = list(title = NULL, color_bar = "continuous")
)
df60 <- clusterdf(mat, ht60,60)
df60 <- data.frame(cluster = df60[colnames(mat),])
rownames(df60) <- colnames(mat)
colors <- structure(colorRampPalette(brewer.pal(n=11, name="RdYlBu")[-c(1, 11)])(60), names = c(1:60))
ha60 <-HeatmapAnnotation("60" = df60[colnames(mat), ],height = unit(3,"cm"),border = T,
show_legend = F,show_annotation_name = T,col = list("60"=colors),annotation_name_side="left")
##patient heatmap
idx <- data.frame(sample_name = colnames(mat))
idx <- left_join(idx, Tx321_riskscore[,c("sample_name","cruk_id")], by ="sample_name")
idx$value <- "Y"
patient_ht <- as.data.frame(spread(idx,sample_name,value = value))
rownames(patient_ht) <- patient_ht$cruk_id
order <- data.frame(sample_name = colnames(mat)[column_order(draw(ht1))])
order <- left_join(order, Tx321_riskscore[,c("sample_name","cruk_id")], by ="sample_name")
patient_ht <- patient_ht[unique(order$cruk_id),-1]
ht_patient <- Heatmap(patient_ht,
cluster_columns = F,
cluster_rows = FALSE,
name = "ht3",
na_col = "white",
show_heatmap_legend = F,
row_names_gp = gpar(fontsize=5),
col = structure("black",names="Y"), row_order = unique(order$cruk_id),
show_row_names = TRUE,show_column_names = FALSE,row_names_side = "left",width = 1
)
#combine heatmap
ht_list <- ht1%v%ha2%v%ha10%v%ha60%v%ht3
ht_list
print(decorate_heatmap_body("ht1", {grid.rect(gp = gpar(fill = "transparent", col = "black", lwd = 0.75))});
decorate_heatmap_body("ht3", {grid.rect(gp = gpar(fill = "transparent", col = "black", lwd = 0.75))});
decorate_heatmap_body("ht3", {grid.rect(gp = gpar(fill = "transparent", col = "black", lwd = 0.75))});
decorate_heatmap_body("ht3", {for (i in 1:122){grid.lines(x=unit(c(1,0),"npc"),y=unit(c(i/122,i/122),"npc"), gp = gpar(lty="dotted", col="gray75", lwd=0.75))};grid.rect(gp = gpar(fill = "transparent", col = "black", lwd = 0.75))})
)
##pie chart for each cluster
df2$sample_name <- rownames(df2)
df2 <- left_join(df2, Tx321_riskscore[,c("sample_name","cruk_id")])
df2$group <- apply(df2,1,FUN = function(x){paste(x[3],x[1],sep = "-")})
#clust 2
df2$result <- NA
for(i in 1:nrow(df2)){
if(length(unique(df2$group[which(df2$cruk_id==df2$cruk_id[i])])) == 1){
df2$result[i] <- "Concordant"
}
else {df2$result[i] <- "Discordant"}
}
tmp <- df2[-which(duplicated(df2$cruk_id)),]
pie.df <- data.frame(class = c("Concordant","Discordant"),perc=c(length(which(tmp$result=="Concordant"))/nrow(tmp),length(which(tmp$result=="Discordant"))/nrow(tmp)))
ggplot(pie.df)+geom_col(aes(x=1,y=perc,fill=class))+coord_polar("y", start=0)+
scale_fill_manual(values = c("black","azure4"))+
theme_void() + theme(legend.position = "none")
#clust 10
df10$sample_name <- rownames(df10)
df10 <- left_join(df10, Tx321_riskscore[,c("sample_name","cruk_id")])
df10$group <- apply(df10,1,FUN = function(x){paste(x[3],x[1],sep = "-")})
#
df10$result <- NA
for(i in 1:nrow(df10)){
if(length(unique(df10$group[which(df10$cruk_id==df10$cruk_id[i])])) == 1){
df10$result[i] <- "Concordant"
}
else {df10$result[i] <- "Discordant"}
}
tmp2 <- df10[-which(duplicated(df10$cruk_id)),]
pie.df <- data.frame(class = c("Concordant","Discordant"),perc=c(length(which(tmp2$result=="Concordant"))/nrow(tmp2),length(which(tmp2$result=="Discordant"))/nrow(tmp2)))
ggplot(pie.df)+geom_col(aes(x=1,y=perc,fill=class))+coord_polar("y", start=0)+
scale_fill_manual(values = c("black","azure4"))+
theme_void() + theme(legend.position = "none")
#clust 60
df60$sample_name <- rownames(df60)
df60 <- left_join(df60, Tx321_riskscore[,c("sample_name","cruk_id")])
df60$group <- apply(df60,1,FUN = function(x){paste(x[3],x[1],sep = "-")})
#
df60$result <- NA
for(i in 1:nrow(df60)){
if(length(unique(df60$group[which(df60$cruk_id==df60$cruk_id[i])])) == 1){
df60$result[i] <- "Concordant"
}
else {df60$result[i] <- "Discordant"}
}
tmp3 <- df60[-which(duplicated(df60$cruk_id)),]
pie.df <- data.frame(class = c("Concordant","Discordant"),perc=c(length(which(tmp3$result=="Concordant"))/nrow(tmp3),length(which(tmp3$result=="Discordant"))/nrow(tmp3)))
ggplot(pie.df)+geom_col(aes(x=1,y=perc,fill=class))+coord_polar("y", start=0)+
scale_fill_manual(values = c("black","azure4"))+
theme_void() + theme(legend.position = "none")
##barplot
rownames(tmp) <- tmp$cruk_id
tmp <- tmp[rownames(patient_ht),]
tmp$order <- c(nrow(tmp):1)
ggplot(tmp)+geom_tile(aes(x=fct_reorder(cruk_id,order),y=1,fill=result))+coord_flip()+
scale_fill_manual(values = c("black","azure4"))+
theme_void() + theme(legend.position = "none")
rownames(tmp2) <- tmp2$cruk_id
tmp2 <- tmp2[rownames(patient_ht),]
tmp2$order <- c(nrow(tmp2):1)
ggplot(tmp2)+geom_tile(aes(x=fct_reorder(cruk_id,order),y=1,fill=result))+coord_flip()+
scale_fill_manual(values = c("black","azure4"))+
theme_void() + theme(legend.position = "none")
rownames(tmp3) <- tmp3$cruk_id
tmp3 <- tmp3[rownames(patient_ht),]
tmp3$order <- c(nrow(tmp3):1)
ggplot(tmp3)+geom_tile(aes(x=fct_reorder(cruk_id,order),y=1,fill=result))+coord_flip()+
scale_fill_manual(values = c("black","azure4"))+
theme_void() + theme(legend.position = "none")
}
### Extended Data Fig 4
## 4C-D
#function to calculate expression sd
ExpSD.df <- function(mat){
df <- as.data.frame(t(mat))
df$PatientID <- gsub("_.*",rownames(df),replacement = "")
#calculate mean expression
df_mean <- aggregate(df[,-ncol(df)],by=list(df$PatientID), FUN = function(x){ mean(x,na.rm=T)})
#calculate sd of expression
df_sd <- aggregate(df[,-ncol(df)],by=list(df$PatientID),FUN = function(x){ sd(x,na.rm=T)})
#remove single-region samples
df_sd <- df_sd[,which(!grepl("NA",colnames(df_sd)))]
#calculate average sd
rownames(df_sd) <- df_sd$Group.1
df_sd <- df_sd[,-1]
annot.df <- data.frame(mean_var = colSums(df_sd)/nrow(df_sd))
#descending order
annot.df <- arrange(annot.df,desc(mean_var))
df_sd <- df_sd[,rownames(annot.df)]
return(df_sd)
}
#function to calculate mean variation
MeanSD.df <- function(mat,sig){
df <- as.data.frame(t(mat))
df$PatientID <- gsub("_.*",rownames(df),replacement = "")
#calculate mean expression
df_mean <- aggregate(df[,-ncol(df)],by=list(df$PatientID), FUN = function(x){ mean(x,na.rm=T)})
#calculate sd of expression
df_sd <- aggregate(df[,-ncol(df)],by=list(df$PatientID),FUN = function(x){ sd(x,na.rm=T)})
#calculate sd of expression
df_sd <- df_sd[,which(!grepl("NA",colnames(df_sd)))]
#remove single-region samples
rownames(df_sd) <- df_sd$Group.1
df_sd <- df_sd[,-1]
#calculate average sd
annot.df <- data.frame(mean_var = colSums(df_sd)/nrow(df_sd))
annot.df <- arrange(annot.df,desc(mean_var))
annot.df$signature <- sig
return(annot.df)
}
### Extended Data Fig 5
#load microarray data
load("2019-04-17_microarray_expression.RData")
load("2019-04-17_microarray_survival.RData")
### Extended Data Fig 6
#GDSC IC50 data
LUAD_IC50 <- read.csv("C:\\Users\\cola2318\\Desktop\\UCL RA\\RA project\\CCLE\\LUAD_IC50_20220112.csv",row.names = 1)
df <- read_excel("C:\\Users\\cola2318\\Desktop\\UCL RA\\RA project\\CCLE\\LUAD_IC50_20220112.xlsx")
colnames(LUAD_IC50) <- colnames(df)[-1]
### Extended Data Fig 9
#load regional mutation data
Tx421_regionMut <- fst::read.fst("tx421_RegionMutTable.fst")
#load GISTIC results
HighLow_summary <- read.csv("20230620_concordant_oracle_highlow_cytoband_summary_wide.csv")
#filter for driver mutations
Tx421_regionMut <- Tx421_regionMut[which(Tx421_regionMut$PASS == "TRUE" & Tx421_regionMut$Is.present.region == "TRUE"),]
Tx421_regionMut <- Tx421_regionMut[which(Tx421_regionMut$DriverMut == "TRUE"),]
#fix names
Tx421_regionMut$RegionID <- gsub("_LN0",Tx421_regionMut$RegionID,replacement = "_LN")
Tx421_regionMut$RegionID <- gsub("_LN",Tx421_regionMut$RegionID,replacement = "_LN0")
Tx421_regionMut$RegionID <- gsub(":SU_T1.",Tx421_regionMut$RegionID,replacement = "_SU_T1-")
Tx421_regionMut$RegionID <- gsub(":SU_T2.",Tx421_regionMut$RegionID,replacement = "_SU_T2-")
Tx421_regionMut$RegionID <- gsub(":SU_LN",Tx421_regionMut$RegionID,replacement = "_SU_LN")
### Extended Data Fig 10
#load Uppsala LUSC
UPP_count_data <- read.delim("UPP LUSC\\GSE81089_readcounts_featurecounts.tsv.gz")
UPP_sample <- read.delim("UPP LUSC\\GSE81089_series_matrix.txt.gz",skip = 64)
#
## plot figures
#
### Figure 1
## 1B
#keep only multi-region samples
Tx321_samplingbias <- Tx321_riskscore[-which(Tx321_riskscore$High == 0 & Tx321_riskscore$Low == 1),]
Tx321_samplingbias <- Tx321_samplingbias[-which(Tx321_samplingbias$High == 1 & Tx321_samplingbias$Low == 0),]
#join stage info
Tx321_samplingbias$ORACLE_class <- factor(Tx321_samplingbias$ORACLE_class,levels = c("Low","Discordant","High"))
ggplot(Tx321_samplingbias,aes(x=fct_reorder(cruk_id, ORACLE_riskscore + as.numeric(ORACLE_class), .fun=mean), y = ORACLE_riskscore))+
geom_point(aes(col = ORACLE_class),alpha = 0.5,pch=16,size = 5)+
geom_hline(yintercept = cutoff,lty = "dotted")+
geom_line(col = "black",size=0.5)+
xlab("Patient ID")+
ylab("ORACLE Risk score")+
labs(color="Class")+
scale_y_continuous(breaks = seq(8.5,11.5,1),expand = c(0,0),limits = c(8.5,11.7))+
scale_x_discrete(expand = c(0.01,0.01)) +
scale_color_manual(values = c("#3B4992FF","azure4","#EE0000FF"))+
theme(legend.position = "none",panel.background = element_blank(),axis.text.x = element_blank(),axis.ticks.x = element_blank(),panel.border = element_rect(colour = "black", fill=NA, size=1))
## 1C
#dichotomise tumour region risk
Tx321_samplingbias$Li_bin <- ifelse(Tx321_samplingbias$Li_RS < median(Tx321_samplingbias$Li_RS), "Low","High")
Tx321_samplingbias$Wang_bin <- ifelse(Tx321_samplingbias$Wang_RS < median(Tx321_samplingbias$Wang_RS), "Low","High")
Tx321_samplingbias$Zhao_bin <- ifelse(Tx321_samplingbias$Zhao_RS < median(Tx321_samplingbias$Zhao_RS), "Low","High")
Tx321_samplingbias$Song_bin <- ifelse(Tx321_samplingbias$Song_RS < median(Tx321_samplingbias$Song_RS), "Low","High")
Tx321_samplingbias$Jin_bin <- ifelse(Tx321_samplingbias$Jin_RS < median(Tx321_samplingbias$Jin_RS), "Low","High")
Tx321_samplingbias$LiFeng_bin <- ifelse(Tx321_samplingbias$LiFeng_RS < median(Tx321_samplingbias$LiFeng_RS), "Low","High")
#assign patient risk-class for each signature
#Li JAMA Oncol 2017
tmp <- table(Tx321_samplingbias$cruk_id,Tx321_samplingbias$Li_bin)
tmp <- data.frame(High=as.matrix(tmp)[,"High"], Low=as.matrix(tmp)[,"Low"])
tmp$Li_class <- NA
tmp$Li_class <- ifelse(tmp$High > 0, paste(tmp$Li_class, "High", sep=""), tmp$Li_class)
tmp$Li_class <- ifelse(tmp$Low > 0, paste(tmp$Li_class, "Low", sep=""), tmp$Li_class)
tmp$Li_class <- gsub(x=tmp$Li_class, pattern="NA", replacement="")
tmp$Li_class <- gsub(x=tmp$Li_class, pattern="HighLow", replacement="Discordant")
tmp$cruk_id <- rownames(tmp)
tmp$Li_class <- factor(tmp$Li_class, levels = c("Low","Discordant","High"))
Tx321_samplingbias <- left_join(Tx321_samplingbias, tmp[,c("cruk_id","Li_class")], by = "cruk_id")
#Wang Front Immunol 2022
tmp <- table(Tx321_samplingbias$cruk_id,Tx321_samplingbias$Wang_bin)
tmp <- data.frame(High=as.matrix(tmp)[,"High"], Low=as.matrix(tmp)[,"Low"])
tmp$Wang_class <- NA
tmp$Wang_class <- ifelse(tmp$High > 0, paste(tmp$Wang_class, "High", sep=""), tmp$Wang_class)
tmp$Wang_class <- ifelse(tmp$Low > 0, paste(tmp$Wang_class, "Low", sep=""), tmp$Wang_class)
tmp$Wang_class <- gsub(x=tmp$Wang_class, pattern="NA", replacement="")
tmp$Wang_class <- gsub(x=tmp$Wang_class, pattern="HighLow", replacement="Discordant")
tmp$cruk_id <- rownames(tmp)
tmp$Wang_class <- factor(tmp$Wang_class, levels = c("Low","Discordant","High"))
Tx321_samplingbias <- left_join(Tx321_samplingbias, tmp[,c("cruk_id","Wang_class")], by = "cruk_id")
#Zhao Lung Cancer 2020
tmp <- table(Tx321_samplingbias$cruk_id,Tx321_samplingbias$Zhao_bin)
tmp <- data.frame(High=as.matrix(tmp)[,"High"], Low=as.matrix(tmp)[,"Low"])
tmp$Zhao_class <- NA
tmp$Zhao_class <- ifelse(tmp$High > 0, paste(tmp$Zhao_class, "High", sep=""), tmp$Zhao_class)
tmp$Zhao_class <- ifelse(tmp$Low > 0, paste(tmp$Zhao_class, "Low", sep=""), tmp$Zhao_class)
tmp$Zhao_class <- gsub(x=tmp$Zhao_class, pattern="NA", replacement="")
tmp$Zhao_class <- gsub(x=tmp$Zhao_class, pattern="HighLow", replacement="Discordant")
tmp$cruk_id <- rownames(tmp)
tmp$Zhao_class <- factor(tmp$Zhao_class, levels = c("Low","Discordant","High"))
Tx321_samplingbias <- left_join(Tx321_samplingbias, tmp[,c("cruk_id","Zhao_class")], by = "cruk_id")
#Song Sci Rep 2022
tmp <- table(Tx321_samplingbias$cruk_id,Tx321_samplingbias$Song_bin)
tmp <- data.frame(High=as.matrix(tmp)[,"High"], Low=as.matrix(tmp)[,"Low"])
tmp$Song_class <- NA
tmp$Song_class <- ifelse(tmp$High > 0, paste(tmp$Song_class, "High", sep=""), tmp$Song_class)
tmp$Song_class <- ifelse(tmp$Low > 0, paste(tmp$Song_class, "Low", sep=""), tmp$Song_class)
tmp$Song_class <- gsub(x=tmp$Song_class, pattern="NA", replacement="")
tmp$Song_class <- gsub(x=tmp$Song_class, pattern="HighLow", replacement="Discordant")
tmp$cruk_id <- rownames(tmp)
tmp$Song_class <- factor(tmp$Song_class, levels = c("Low","Discordant","High"))
Tx321_samplingbias <- left_join(Tx321_samplingbias, tmp[,c("cruk_id","Song_class")], by = "cruk_id")
#Jin J Immunol Res 2022
tmp <- table(Tx321_samplingbias$cruk_id,Tx321_samplingbias$Jin_bin)
tmp <- data.frame(High=as.matrix(tmp)[,"High"], Low=as.matrix(tmp)[,"Low"])
tmp$Jin_class <- NA
tmp$Jin_class <- ifelse(tmp$High > 0, paste(tmp$Jin_class, "High", sep=""), tmp$Jin_class)
tmp$Jin_class <- ifelse(tmp$Low > 0, paste(tmp$Jin_class, "Low", sep=""), tmp$Jin_class)
tmp$Jin_class <- gsub(x=tmp$Jin_class, pattern="NA", replacement="")
tmp$Jin_class <- gsub(x=tmp$Jin_class, pattern="HighLow", replacement="Discordant")
tmp$cruk_id <- rownames(tmp)
tmp$Jin_class <- factor(tmp$Jin_class, levels = c("Low","Discordant","High"))
Tx321_samplingbias <- left_join(Tx321_samplingbias, tmp[,c("cruk_id","Jin_class")], by = "cruk_id")
#Li Sci Rep 2022
tmp <- table(Tx321_samplingbias$cruk_id,Tx321_samplingbias$LiFeng_bin)
tmp <- data.frame(High=as.matrix(tmp)[,"High"], Low=as.matrix(tmp)[,"Low"])
tmp$LiFeng_class <- NA
tmp$LiFeng_class <- ifelse(tmp$High > 0, paste(tmp$LiFeng_class, "High", sep=""), tmp$LiFeng_class)
tmp$LiFeng_class <- ifelse(tmp$Low > 0, paste(tmp$LiFeng_class, "Low", sep=""), tmp$LiFeng_class)
tmp$LiFeng_class <- gsub(x=tmp$LiFeng_class, pattern="NA", replacement="")
tmp$LiFeng_class <- gsub(x=tmp$LiFeng_class, pattern="HighLow", replacement="Discordant")
tmp$cruk_id <- rownames(tmp)
tmp$LiFeng_class <- factor(tmp$LiFeng_class, levels = c("Low","Discordant","High"))
Tx321_samplingbias <- left_join(Tx321_samplingbias, tmp[,c("cruk_id","LiFeng_class")], by = "cruk_id")
#calculate risk-class frequency
TSB_summary <- Tx321_samplingbias[which(!duplicated(Tx321_samplingbias$cruk_id)),]
TSB <- rbind(table(TSB_summary$ORACLE_class)*100/nrow(TSB_summary),
table(TSB_summary$Li_class)*100/nrow(TSB_summary),
table(TSB_summary$Wang_class)*100/nrow(TSB_summary),
table(TSB_summary$Zhao_class)*100/nrow(TSB_summary),
table(TSB_summary$Song_class)*100/nrow(TSB_summary),
table(TSB_summary$Jin_class)*100/nrow(TSB_summary),
table(TSB_summary$LiFeng_class)*100/nrow(TSB_summary)) %>% as.data.frame()
#tidy up variable level
TSB$signature <- c("ORACLE","Li JAMA Oncol 2017","Wang Front Immunol 2022","Zhao Lung Cancer 2020","Song Sci Rep 2022","Jin J Immunol Res 2022","Li Sci Rep 2022")
TSB$signature <- factor(TSB$signature, levels = c("ORACLE" ,"Li JAMA Oncol 2017","Wang Front Immunol 2022","Zhao Lung Cancer 2020","Song Sci Rep 2022","Jin J Immunol Res 2022","Li Sci Rep 2022"))
TSB_melt <- melt(TSB)
TSB_melt$variable <- factor(TSB_melt$variable, levels = c("Low","High","Discordant"))
ggplot(TSB_melt, aes(x = "",y=value, fill=variable))+
geom_col(width = 1, col = "black")+
coord_polar("y", start=0)+
ylab("")+ xlab("")+
geom_text(aes(label = paste0(signif(value,digits = 2),"%")),position=position_stack(vjust=0.5),size=6)+
scale_fill_manual(values=c("#3B4992FF","#EE0000FF","azure4"))+
facet_grid(~signature) +
theme_void()+
theme(legend.position = "none")
## 1D
#tidy up
TSB_metric1 <- dplyr::select(TSB_metric1, signature, Discordant)
TSB_metric2 <- dplyr::select(TSB_metric2, signature, AUC)
TSB_metric3 <- aggregate(TSB_metric3$mean_var, by = list(signature = TSB_metric3$signature), median) # median variation across signature genes
#ranking by each metric
TSB_metric1 <- arrange(TSB_metric1, Discordant)
TSB_metric1$rank <- 1:nrow(TSB_metric1)
TSB_metric2 <- arrange(TSB_metric2, desc(AUC))
TSB_metric2$rank <- 1:nrow(TSB_metric2)
TSB_metric3 <- arrange(TSB_metric3, x)
TSB_metric3$rank <- 1:nrow(TSB_metric3)
TSB_metric4 <- arrange(TSB_metric4, biop_need)
TSB_metric4$rank <- 1:nrow(TSB_metric4)