-
Notifications
You must be signed in to change notification settings - Fork 4
/
tx100Lung_compath_final.R
1567 lines (1384 loc) · 80.7 KB
/
tx100Lung_compath_final.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
#### ### #### ###
###Geospatial immune variability illuminates differential evolution of lung adenocarcinoma##
##ALL stat analyses and figures##
## permanently available at: https://github.com/qalid7/tx100_compath
#### ### #### ### 20200310
#R version notes
#############
#mostly developed on R 3.5.1, but also tested on R 3.6.3 on 20200329
#for latest R if you struggle with ComplexHeatmap, do this:
#R version 3.6.3
#if (!requireNamespace("BiocManager", quietly=TRUE))
# install.packages("BiocManager")
#BiocManager::install("ComplexHeatmap")
#############
#libraries
#############
library("survival")
library("survminer")
library(tidyverse)
library(ggpubr)
library(gridExtra)
library(RColorBrewer)
library("ggsci")
library(dplyr)
library(ComplexHeatmap)
library(ggcorrplot)
library(corrplot)
library(gridExtra)
library(RColorBrewer)
library(reshape2)
library(ggstatsplot)
library(circlize)
library(psych)
#############
#Functions
#############
ggcorrplotModified <- function (corr, method = c("square", "circle"), type = c("full",
"lower", "upper"), ggtheme = ggplot2::theme_minimal, title = "",
show.legend = TRUE, legend.title = "Corr", show.diag = FALSE,
colors = c("blue", "white", "red"), outline.color = "gray",
hc.order = FALSE, hc.method = "complete", lab = FALSE, lab_col = "black",
lab_size = 4, p.mat = NULL, sig.level = 0.05, insig = c("pch",
"blank"), pch = 4, pch.col = "black", pch.cex = 5, tl.cex = 12,
tl.col = "black", tl.srt = 45, lab.notsig="")
{
type <- match.arg(type)
method <- match.arg(method)
insig <- match.arg(insig)
if (!is.matrix(corr) & !is.data.frame(corr))
stop("Need a matrix or data frame!")
corr <- as.matrix(corr)
if (hc.order) {
ord <- ggcorrplot:::.hc_cormat_order(corr)
corr <- corr[ord, ord]
if (!is.null(p.mat))
p.mat <- p.mat[ord, ord]
}
if (type == "lower") {
corr <- ggcorrplot:::.get_lower_tri(corr, show.diag)
p.mat <- ggcorrplot:::.get_lower_tri(p.mat, show.diag)
}
else if (type == "upper") {
corr <- ggcorrplot:::.get_upper_tri(corr, show.diag)
p.mat <- ggcorrplot:::.get_upper_tri(p.mat, show.diag)
}
corr <- reshape2::melt(corr, na.rm = TRUE)
corr$pvalue <- rep(NA, nrow(corr))
corr$signif <- rep(NA, nrow(corr))
if (!is.null(p.mat)) {
p.mat <- reshape2::melt(p.mat, na.rm = TRUE)
corr$coef <- corr$value
corr$pvalue <- p.mat$value
corr$signif <- as.numeric(p.mat$value <= sig.level)
p.mat <- subset(p.mat, p.mat$value > sig.level)
if (insig == "blank")
corr$value <- corr$value * corr$signif
}
corr$abs_corr <- abs(corr$value) * 10
p <- ggplot2::ggplot(corr, ggplot2::aes_string("Var1", "Var2",
fill = "value"))
if (method == "square")
p <- p + ggplot2::geom_tile(color = outline.color)
else if (method == "circle") {
p <- p + ggplot2::geom_point(color = outline.color, shape = 21,
ggplot2::aes_string(size = "abs_corr")) + ggplot2::scale_size(range = c(4,
10)) + ggplot2::guides(size = FALSE)
}
p <- p + ggplot2::scale_fill_gradient2(low = colors[1], high = colors[3],
mid = colors[2], midpoint = 0, limit = c(-1, 1), space = "Lab",
name = legend.title) + ggtheme() + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = tl.srt,
vjust = 1, size = tl.cex, hjust = 1), axis.text.y = ggplot2::element_text(size = tl.cex)) +
ggplot2::coord_fixed()
label <- as.character(round(corr[, "value"], 2))
label[label=="0"] <- lab.notsig
if (lab)
p <- p + ggplot2::geom_text(ggplot2::aes_string("Var1",
"Var2", label = "label"), color = lab_col, size = lab_size)
if (!is.null(p.mat) & insig == "pch") {
p <- p + ggplot2::geom_point(data = p.mat, ggplot2::aes_string("Var1",
"Var2"), shape = pch, size = pch.cex, color = pch.col)
}
if (title != "")
p <- p + ggplot2::ggtitle(title)
if (!show.legend)
p <- p + ggplot2::theme(legend.position = "none")
p <- p + ggcorrplot:::.no_panel()
p
}
#############
#Data
#############
setwd("/Users/kjabbar/Dropbox (ICR)/yuanlab/Manuscripts/Lung Tx1/code_data/")
load("./data/data_10.RData")
##
#TRACERx 100 cohort
#1# - regional: tx100 multiregion cohort (n=275 for 85 patients). includes main dig. path. scores e.g. lym$ and immune class.
#ASCAT and VAF: DNA-based tumor purity. cd8.score.danaher: Danaher et al RNA-seq signature of CD8+. orig_immune_cluster: Rosenthal et al RNA-seq based immune classification.
#pathology TILs: pathology TIL scoring using the Salgado et al method (n=260 regions).
#2# - diagnsotic: tx100 diagnostic cohort from both HE, IHC slides (n=100 for 100 patients).
#Stromal.TIL: pathology scores on the first 100 slides.
#3# - tx: combined tx100 regional and diagnsotic cohort at patient level (n=85, patients with a regional sample).
#both regional and disgnostic scores combined together with key genomic scores.
#4# - tx_surv15May2018: original tx100 survival data from 15 May 2018 - just kept here for the record.
#5# - txclin_supp: provided to make the Supp Extended Data Fig 1 heatmap.
##Other items
#6# - tx_genomic_pairdist: tx phenotype-based pairwise genomic dist.
#7# - tx_genomic_pairdist_extended: tx phenotype-based pairwise genomic dist, ALL regions - to validate class. schemes.
#8# - regional_immune_schemes: 4 more region-specific immune schemes.
#9# - txluad_domClon_pairdist: tx phenotype-based pairwise phy. analysis.
#10# - stromal_tumor_cellAvgDist: tx regional min and max dist between a tumor and a stromal cell for all 275 tumor regions.
#11# - reg_tils_immune: deconvulted immune cells onto the HE TIL classes for the same registered sections.
#12# - reg_eval: manual evaluation of HE-IHC registered sections.
##
##
#LATTICe-A cohort
#13# - lattice_80: manual estimations for fraction of lym and path. TILs, and corresponding automated scores (n=80 patients LATTICe-A cohort).
#14# - latticea_bioai: list contains 3 DFs for TTF1, CD45, SMA. Rows correspond to image patches from cores and cols show the IHC/HE cell counts by deep learning.
#15# - lattice: entire LATTICe-A cohort (n=970 patients), all summarised patient level data.
#16# - lt: entire LATTICe-A immune data for all 4,324 H&E samples.
##
## data from Rosenthal et al 2019 (Nature):
#17# - tx_rosenthal_RNA_danaher: RNA-seq Danaher et al immune signatures for 142 tracerx regions with histology/deep learning-based immune class.
#18# - tx_rosenthal_RNA_clusters: the original RNA-seq clusters from Rosetnhal et al 2019. Provided seprately for S5b.
#############
#### ### #### ### #### ### #### ###
#Figures
#### ### #### ### #### ### #### ###
#1g-h and S2 g: biological-AI correlations
#############
ggscatter(latticea_bioai$TTF1, x = "tumour_norm", y = "ttf1_norm", add = "reg.line", xlab = "H&E-based cancer cell / 100um",
ylab = "TTF1+ cell / 100um",
color = "#00ff00",
conf.int = TRUE, size = 2,
add.params = list(color = "grey50", fill = "azure3"),
cor.coef = TRUE, cor.method = "spearman")
ggscatter(latticea_bioai$CD3, x = "lym_norm", y = "cd3_norm", add = "reg.line", xlab = "H&E-based lymphocyte cell / 100um",
ylab = "CD45+ cell / 100um",
color = "#0000ff",
conf.int = TRUE, size = 2,
add.params = list(color = "grey50", fill = "azure3"),
cor.coef = TRUE, cor.method = "spearman")
ggscatter(latticea_bioai$SMA, x = "stromal_norm", y = "sma_norm", add = "reg.line", xlab = "H&E-based stromal cell / 100um",
ylab = "SMA cell / 100um",
color = "goldenrod",
conf.int = TRUE, size = 2,
add.params = list(color = "grey50", fill = "azure3"),
cor.coef = TRUE, cor.method = "spearman")
#############
#2a: regions specific immune variability in tx
#############
r2=regional
r2$Histology[r2$Histology=="Other"] <- "Z"
r2 = r2[order(r2$lymphocytes_per, decreasing = F),]
r2 = r2[order(r2$Histology, decreasing = F),]
pDotplot = ggdotchart(r2, x = "PublicationID", y = "lymphocytes_per",
color = "immuneClass_2",
group = "PublicationID",
sort.by.groups = TRUE,
palette = c("blue2", "red2", "#f4d5d5"),
#sorting = "descending",
#rotate = TRUE,
#add = "segments",
add.params = list(color = "lightgray", size = 0.8),
dot.size = 3,
#label = min(regionalT$lymphocytes_per),
#y.text.col = TRUE,
ggtheme = theme_pubr())
#and the heatmap
txS8=tx
txS8$Histology[txS8$Histology=="Other"] <- "Z"
txS8 = txS8[order(txS8$lymphocytes_per_min, decreasing = F),]
txS8 = txS8[order(txS8$Histology, decreasing = F),]
txS8$DFS_yes[txS8$DFS_censor_variable==1] <- txS8$DFS_time_days
txS8$DFS_no[txS8$DFS_censor_variable==0] <- txS8$DFS_time_days
Heatmap(txS8$cd8_per, name = "CD8", width = unit(2.85, "mm"),
cluster_rows = F, cluster_columns = F, gap = unit(2, "mm"),
col = colorRamp2(c(0, 17), c("#F2E2E2", "#8E0000")))+
Heatmap(txS8$cd4_per, name = "CD4", width = unit(2.85, "mm"),
cluster_rows = F, cluster_columns = F, gap = unit(2, "mm"),
col = colorRamp2(c(0, 28), c("#E3F0E2", "#067C00")))+
Heatmap(txS8$foxp3_per, name = "FOXP3", width = unit(2.85, "mm"),
cluster_rows = F, cluster_columns = F, gap = unit(2, "mm"),
col = colorRamp2(c(0, 21), c("#F9E2F2", "#CC008E")))
#############
#2c-d: deep learning vs Danaher immune signatures from Rosenthal et al 2019
#############
r = tx_rosenthal_RNA_danaher
Heatmap(scale(r[, c(3)]), name = "comb", row_split = r$immuneClass_2, row_gap = unit(2, "mm"), border = F,
col = colorRamp2(c(-4.2, 0, 6), c("#4DBBD5B2", "white", "red2")), cluster_columns = FALSE,
show_row_dend = F, show_column_dend = F, row_labels = F, show_row_names = F, cluster_row_slices = F, show_heatmap_legend = F,
column_names_rot = 45)+
Heatmap(scale(r[, c(5:18)]), name = "comb", row_split = r$immuneClass_2, row_gap = unit(2, "mm"), border = F,
col = colorRamp2(c(-4.2, 0, 6), c("#4DBBD5B2", "white", "red2")), column_title = "RNA-seq immune cell signatures", cluster_columns = FALSE,
show_row_dend = F, show_column_dend = F, row_labels = F, show_row_names = F, cluster_row_slices = F, show_heatmap_legend = F,
column_names_rot = 45)
#hot-cold comparisons:
rC = r[! r$immuneClass_2 =="intermediate" ,]
rC$sample = paste0(rC$PublicationID, "_", rC$region)
rC = rC[order(rC$immuneClass_2) ,]
rC$Name = rep("tx_all")
rC = rC[, c(19:20, 4, 5:18)]
df2<-melt(rC,id.var=c("sample","immuneClass_2", "Name"))
p <- ggplot(df2, aes(variable, value,fill=immuneClass_2), color = c("blue2", "red2"))
p + geom_boxplot()+scale_fill_manual(values = c("blue2", "red2"))+
theme(axis.text.x = element_text(angle = 45, hjust = 1))+
xlab("Immune signature") + ylab("Estimated infiltration (Danaher et al)")
#below for the stats. sign. for above merged panel
comList <- list( c("cold", "hot"))
p1=ggboxplot(rC, x = "immuneClass_2",
y = "cd8", color = "immuneClass_2", ylab = "CD8",
add = "jitter", border = "white",palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))+theme(axis.title.x=element_blank())
p2=ggboxplot(rC, x = "immuneClass_2",
y = "cd4", color = "immuneClass_2", ylab = "CD4",
add = "jitter", border = "white",palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))+theme(axis.title.x=element_blank())
p3=ggboxplot(rC, x = "immuneClass_2",
y = "bcell", color = "immuneClass_2", ylab = "B cell",
add = "jitter", border = "white",palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))+theme(axis.title.x=element_blank())
p4=ggboxplot(rC, x = "immuneClass_2",
y = "cd45", color = "immuneClass_2", ylab = "CD45",
add = "jitter", border = "white",palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))+theme(axis.title.x=element_blank())
p5=ggboxplot(rC, x = "immuneClass_2",
y = "cyto", color = "immuneClass_2", ylab = "Cyto",
add = "jitter", border = "white",palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))+theme(axis.title.x=element_blank())
p6=ggboxplot(rC, x = "immuneClass_2",
y = "dend", color = "immuneClass_2", ylab = "Dendritic",
add = "jitter", border = "white",palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))+theme(axis.title.x=element_blank())
p7=ggboxplot(rC, x = "immuneClass_2",
y = "cd8.exhausted", color = "immuneClass_2", ylab = "CD8 exhausted",
add = "jitter", border = "white",palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))+theme(axis.title.x=element_blank())
p8=ggboxplot(rC, x = "immuneClass_2",
y = "macrophage", color = "immuneClass_2", ylab = "Macrophage",
add = "jitter", border = "white",palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))+theme(axis.title.x=element_blank())
p9=ggboxplot(rC, x = "immuneClass_2",
y = "neutrophil", color = "immuneClass_2", ylab = "Neutrophil",
add = "jitter", border = "white",palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))+theme(axis.title.x=element_blank())
p10=ggboxplot(rC, x = "immuneClass_2",
y = "nkcd56dim", color = "immuneClass_2", ylab = "NK CD56",
add = "jitter", border = "white",palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))+theme(axis.title.x=element_blank())
p11=ggboxplot(rC, x = "immuneClass_2",
y = "nk", color = "immuneClass_2", ylab = "NK",
add = "jitter", border = "white",palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))+theme(axis.title.x=element_blank())
p12=ggboxplot(rC, x = "immuneClass_2",
y = "tcells", color = "immuneClass_2", ylab = "T cells",
add = "jitter", border = "white",palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))+theme(axis.title.x=element_blank())
p13=ggboxplot(rC, x = "immuneClass_2",
y = "th1", color = "immuneClass_2", ylab = "TH1",
add = "jitter", border = "white",palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))+theme(axis.title.x=element_blank())
p14=ggboxplot(rC, x = "immuneClass_2",
y = "treg", color = "immuneClass_2", ylab = "Treg",
add = "jitter", border = "white",palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))+theme(axis.title.x=element_blank())
#p-value correction to be annotated on the figure
p = c(5.8e-5, 1.5e-6, 9.4e-9, 3.4e-5, 0.00014, 0.018, 1.4e-5,
0.007, 0.0029, 6.6e-6, 4e-4, 2.9e-6, 3.3e-6, 9.1e-7)
p.adjust(p, method = "BH")
#grid.arrange(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, ncol=7)
#############
#3a-b and S5a: phenotype-based pairwise genomic dist and phy. analysis
#############
#mutations summary from Jamal-Hanjani, NEJM 2017
#then pairwise dist. for subclonal mutations for every hot-hot, cold-cold pair
comList <- list( c("hot_hot", "cold_cold"))
ggboxplot(tx_genomic_pairdist[tx_genomic_pairdist$Histology=="LUAD",], x = "immuneClass2", y = "geneticDist",
color = "immuneClass2", palette = c("blue", "red2"),
add = "jitter", border = "white")+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))
ggboxplot(tx_genomic_pairdist[tx_genomic_pairdist$Histology=="LUSC",], x = "immuneClass2", y = "geneticDist",
color = "immuneClass2", palette = c("blue", "red2"),
add = "jitter", border = "white")+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))
#distance using phy. tree for pairs in LUAD tumors
#this is checked manually from the file: all.pyclone_trees.20161220.RData, using these data:
#trees$LTX0050$manual_tree
#trees$LTX0050$manual_mean_pyclone_ccf
#trees$LTX0050$manual_edgelength
comList <- list( c("hot_hot", "cold_cold"))
ggboxplot(txluad_domClon_pairdist, x = "immuneClass2", y = "phyDist2", color = "immuneClass2", palette = c("red2", "blue"), ylab = "Dist. of dominant clones to the MRCA (phylogenetics)",
add = "jitter", border = "white")+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))+theme(axis.title.x=element_blank())
#reported in the caption, phyDist is when the dominant clone closest
#to the most recent common ancestor of each tree was considered
ggboxplot(txluad_domClon_pairdist, x = "immuneClass2", y = "phyDist", color = "immuneClass2", palette = c("red2", "blue"), ylab = "Dist. of dominant clones to the MRCA (phylogenetics)",
add = "jitter", border = "white")+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))+theme(axis.title.x=element_blank())
#not in the ms but just to confirm method a (from MJH Supp mutations data) and method b (Nicky's trees) are the same!
ggboxplot(txluad_domClon_pairdist, x = "immuneClass2", y = "geneticDist", color = "immuneClass2", palette = c("red2", "blue"), ylab = "Genomic distance",
add = "jitter", border = "white")+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))+theme(axis.title.x=element_blank())
#############
#3d,f and S5c, d, e, f, g, h: survival analysis using the number of cold regions in TRACERx
#############
#many tests in this section, the ones are in the final paper are clearly labeled to the panel
txH2LUADLUSC <- tx[ which(tx$Histology=="LUAD"
| tx$Histology == "LUSC"), ]
txH2LUADLUSC$Histology = as.factor(as.character(txH2LUADLUSC$Histology))
txH2LUADLUSC$sex = as.factor(as.character(txH2LUADLUSC$sex))
txH2LUADLUSC$coldP3 = as.factor(as.character(txH2LUADLUSC$coldP3))
txH2LUADLUSC$pathologyTNM2 = as.factor(as.character(txH2LUADLUSC$pathologyTNM2))
#with clonal neo local quartile for the available 79 luad lusc patients:
#quantile(txH2LUADLUSC$ClonalNeo[txH2LUADLUSC$Histology=="LUSC"])
txH2LUADLUSC$ClonalNeoUQ[txH2LUADLUSC$Histology=="LUAD" & txH2LUADLUSC$ClonalNeo >= 189]<- "UQ.high"
txH2LUADLUSC$ClonalNeoUQ[txH2LUADLUSC$Histology=="LUAD" & txH2LUADLUSC$ClonalNeo < 189]<- "cUQ.low"
txH2LUADLUSC$ClonalNeoUQ[txH2LUADLUSC$Histology=="LUSC" & txH2LUADLUSC$ClonalNeo >= 206.25]<- "UQ.high"
txH2LUADLUSC$ClonalNeoUQ[txH2LUADLUSC$Histology=="LUSC" & txH2LUADLUSC$ClonalNeo < 206.25]<- "cUQ.low"
txH2LUADLUSC$ClonalNeoUQ <- as.factor(as.character(txH2LUADLUSC$ClonalNeoUQ))
#first test, without the genomic score
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~coldP3+age+sex+pack_years_calculated+Histology+pathologyTNM2+Adjuvant.therapy, data = txH2LUADLUSC)
ggforest(fit, data=txH2LUADLUSC)
#Fig 3d#
#KM
fit <- survfit(Surv(DFS_time_days, DFS_censor_variable)~rCold<=1, data = txH2LUADLUSC)
ggsurvplot(fit, data = txH2LUADLUSC, conf.int = FALSE,
pval = TRUE, pval.size = 5, pval.coord = c(0.2, 0.1),
linetype = "solid",
#surv.median.line = "hv",
legend = "none", legend.title = "", title = "LUAD+LUSC",
legend.labs = c("High", "Low"),
surv.plot.height = 0.7, palette = c("#81391b", "#ef5123"),
risk.table = TRUE,
risk.table.col = "black", break.time.by = 200,
tables.height = 0.25,
tables.theme = theme_cleantable(),
tables.y.text = TRUE, risk.table.title = "Number at Risk",
tables.x.text = "", xlim = c(0, 1400),
xlab = "Days to Death or Recurrence", ylab = "Disease-free Survival")
#Fig 3f#
#including total number of regions
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~coldP3+age+sex+pack_years_calculated+Histology+pathologyTNM2+Adjuvant.therapy+ClonalNeoUQ+nTotalRegions, data = txH2LUADLUSC)
ggforest(fit, data=txH2LUADLUSC)
#Fig S5c#
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~coldP3+age+sex+pack_years_calculated+Histology+pathologyTNM2+Adjuvant.therapy+ClonalNeoUQ, data = txH2LUADLUSC)
ggforest(fit, data=txH2LUADLUSC)
#also "alluded to" in text, univariate as cont.:
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~rCold, data = txH2LUADLUSC)
ggforest(fit, data=txH2LUADLUSC)
#or at the median again:
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~coldP3, data = txH2LUADLUSC)
ggforest(fit, data=txH2LUADLUSC)
#as continuous, keeping it simple with main clin data
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~rCold+age+sex+pack_years_calculated+Histology+pathologyTNM2+Adjuvant.therapy, data = txH2LUADLUSC)
ggforest(fit, data=txH2LUADLUSC)
#Fig S5f#
#as continuous, testing independce against other scores
#correcting for Histology (by adding +Histology) in each fit doesn't make a big difference
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~rCold+subclonalCNA, data = txH2LUADLUSC)
ggforest(fit, data=txH2LUADLUSC)
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~rCold+mean_ASCAT.purity, data = txH2LUADLUSC)
ggforest(fit, data=txH2LUADLUSC)
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~rCold+tumour_per_mean, data = txH2LUADLUSC)
ggforest(fit, data=txH2LUADLUSC)
#Fig S5g#
#the original test including other histology patients (only 6 more), cant do this with ClonalNeo UQ
fit <- survfit(Surv(DFS_time_days, DFS_censor_variable)~rCold<=1, data = tx)
ggsurvplot(fit, data = tx, conf.int = FALSE,
pval = TRUE, pval.size = 5, pval.coord = c(0.2, 0.1),
linetype = "solid",
#surv.median.line = "hv",
legend = "none", legend.title = "", title = "ALL",
legend.labs = c("High", "Low"),
surv.plot.height = 0.7, palette = c("#81391b", "#ef5123"),
risk.table = TRUE,
risk.table.col = "black", break.time.by = 200,
tables.height = 0.25,
tables.theme = theme_cleantable(),
tables.y.text = TRUE, risk.table.title = "Number at Risk",
tables.x.text = "", xlim = c(0, 1400),
xlab = "Days to Death or Recurrence", ylab = "Disease-free Survival")
txS = tx
txS$Histology = as.factor(as.character(txS$Histology))
txS$sex = as.factor(as.character(txS$sex))
txS$coldP3 = as.factor(as.character(txS$coldP3))
txS$pathologyTNM2 = as.factor(as.character(txS$pathologyTNM2))
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~coldP3+age+sex+pack_years_calculated+Histology+pathologyTNM2+Adjuvant.therapy, data = txS)
ggforest(fit, data=txS)
#Fig S5e#
#lastly HR comparison panel
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~rCold, data = txH2LUADLUSC)
ggforest(fit, data=txH2LUADLUSC)
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~coldP3, data = txH2LUADLUSC)
ggforest(fit, data=txH2LUADLUSC)
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~coldProp, data = txH2LUADLUSC)
ggforest(fit, data=txH2LUADLUSC)
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~rHot, data = txH2LUADLUSC)
ggforest(fit, data=txH2LUADLUSC)
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~lymphocytes_per, data = txH2LUADLUSC)
ggforest(fit, data=txH2LUADLUSC)
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~lymphocytes_per_min, data = txH2LUADLUSC)
ggforest(fit, data=txH2LUADLUSC)
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~lymphocytes_per_mean, data = txH2LUADLUSC)
ggforest(fit, data=txH2LUADLUSC)
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~lymphocytes_per_sd, data = txH2LUADLUSC)
ggforest(fit, data=txH2LUADLUSC)
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~cd8_per, data = txH2LUADLUSC)
ggforest(fit, data=txH2LUADLUSC)
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~cd4_per, data = txH2LUADLUSC)
ggforest(fit, data=txH2LUADLUSC)
txH2LUADLUSC$cd8foxp3_Ratio = txH2LUADLUSC$cd8_per/txH2LUADLUSC$foxp3_per
txH2LUADLUSC$cd4foxp3_Ratio = txH2LUADLUSC$cd4_per/txH2LUADLUSC$foxp3_per
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~cd8foxp3_Ratio, data = txH2LUADLUSC)
ggforest(fit, data=txH2LUADLUSC)
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~cd4foxp3_Ratio, data = txH2LUADLUSC)
ggforest(fit, data=txH2LUADLUSC)
summaryPs <- data.frame(
Measure = c("9N cold regions", "99>1 cold regions", "99 N cold regions/total",
"8N hot regions",
"7Diagnostic lymphocyte%", "6Regional lymphocyte% (min)", "5Regional lymphocyte% (mean)",
"55Regional lymphocyte% (SD)",
"4CD8+%", "3CD4+FOXP3-%", "2CD8+%/CD4+FOXP3+%", "1CD4+FOXP3-%/CD4+FOXP3+%"),
PVal = c(0.003, 0.005, 0.098,
0.795,
0.05, 0.058, 0.125,
0.855,
0.631, 0.517, 0.713, 0.804),
lower95 = c(1.1, 1.3, 0.87,
0.75,
0.86, 0.94, 0.94,
0.93,
0.89, 0.91, 0.7, 0.86),
upper95 = c(1.8, 5.3, 5.3,
1.2,
1, 1,1,
1.1,
1.1, 1, 1.3, 1.2),
hr = c(1.4, 2.7, 2.2,
0.97,
0.93, 0.97, 0.97,
1,
0.98, 0.98, 0.95, 1))
summaryPs$PVal_log10 <- -log10(summaryPs$PVal)
summaryPs$PvalAdjust <- p.adjust(summaryPs$PVal, method = "BH")
summaryPs$PvalAdjust_log10 <- -log10(summaryPs$PvalAdjust)
ggplot(data=summaryPs,aes(x=hr,y=Measure))+
geom_point(aes(size=PVal_log10), colour="#CB6728", fill="#CB6728", shape=21)+
geom_errorbarh(aes(xmin=lower95,xmax=upper95), height=0)+
geom_vline(xintercept=1,linetype="longdash", colour="grey70")+
scale_size_continuous(breaks=c(5000,10000,15000))+theme_bw()+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
axis.ticks.y = element_blank(),
axis.line.x = element_blank()) + labs(x = "Hazard ratio", y = "Immune feature")
#adjust p-vals
ggplot(data=summaryPs,aes(x=hr,y=Measure))+
geom_point(aes(size=PvalAdjust_log10), colour="#CB6728", fill="#CB6728", shape=21)+
geom_errorbarh(aes(xmin=lower95,xmax=upper95), height=0)+
geom_vline(xintercept=1,linetype="longdash", colour="grey70")+
scale_size_continuous(breaks=c(5000,10000,15000))+theme_bw()+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
axis.ticks.y = element_blank(),
axis.line.x = element_blank()) + labs(x = "Hazard ratio", y = "Immune feature")
#############
#S5b: survival analysis using the number of immune cold region but with the RNA-seq-based classification (Rosenthal et al)
#############
#PS we don't use the overall patient level immune classification in Rosenthal et al 2019
#because that involves "salvaged" immune status from pathology TILs
#this is strict to N cold regions, using RNA clusters, not histology
#why a seprate RNA df? because there might be some regions in "regional" that have RNA, but no histology
#we want the max number of tumors here which is 64 according to Rosenthal et al 2019
r = tx_rosenthal_RNA_clusters[, c(1, 2)] %>%
group_by(PublicationID, orig_immune_cluster) %>%
tally()
txRNA = dcast(r, PublicationID ~ orig_immune_cluster)
txRNA[is.na(txRNA)] <- 0
names(txRNA)[2] <- "rRNA_high"
names(txRNA)[3] <- "rRNA_low"
nat = merge(txRNA, tx_surv15May2018)
median(nat$rRNA_low)
nat$coldRNAp3[nat$rRNA_low>1] <- ">1"
nat$coldRNAp3[nat$rRNA_low<=1] <- "<=1"
nat$coldRNAp3 = as.factor(as.character(nat$coldRNAp3))
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~rRNA_low, data = nat)
u1 = ggforest(fit, data=nat)
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~coldRNAp3, data = nat)
u3 = ggforest(fit, data=nat)
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~rRNA_high, data = nat)
u2 = ggforest(fit, data=nat)
grid.arrange(u1, u3, u2, ncol=1)
#############
#3e,g and S5c, d, e: survival using the number of cold regions in LATTICe-A (validation cohort)
#############
#reported in text, N cold as cont.
tmp_model <- coxph(Surv(time_to_rfs, rfs_status == '1') ~ cold , data=lattice)
ggforest(tmp_model, data = NULL, main = "", fontsize = 0.7, refLabel = "", noDigits = 2)
summary(tmp_model)
tmp <- lattice
tmp$coldP3 = as.factor(as.character(tmp$coldP3))
tmp$gender = as.factor(as.character(tmp$gender))
tmp$Adjuvant.therapy = as.factor(as.character(tmp$Adjuvant.therapy))
tmp$stage = as.factor(as.character(tmp$stage))
levels(tmp$stage)[levels(tmp$stage)=="IIIA"] <- "III"
levels(tmp$stage)[levels(tmp$stage)=="IIIB"] <- "III"
tmplatt=tmp
tmplatt = tmplatt[!is.na(tmplatt$age_surgery) & !is.na(tmplatt$gender) &
!is.na(tmplatt$pack_years) & !is.na(tmplatt$stage) &
!is.na(tmplatt$Adjuvant.therapy) & !is.na(tmplatt$time_to_rfs) &
!is.na(tmplatt$rfs_status),]
#a simple test with the r cold on its own
tmp_model <- coxph(Surv(time_to_rfs, rfs_status == '1') ~ coldP3 + age_surgery + gender + pack_years + stage + Adjuvant.therapy, data=tmplatt)
ggforest(tmp_model, data = NULL, main = "", fontsize = 0.7, refLabel = "", noDigits = 2)
#Fig 3e#
#KM
fit <- survfit(Surv(time_to_rfs, rfs_status)~cold<=1, data = lattice)
ggsurvplot(fit, data = lattice, conf.int = FALSE,
pval = TRUE, pval.size = 5, pval.coord = c(0.2, 0.1),
linetype = "solid",
#surv.median.line = "hv",
legend = "none", legend.title = "", #title = "N cold regions (median) <= 1",
legend.labs = c("High", "Low"),
surv.plot.height = 0.7, palette = c("#81391b", "#ef5123"),
risk.table = TRUE,
risk.table.col = "black", break.time.by = 1000,
tables.height = 0.25,
tables.theme = theme_cleantable(),
tables.y.text = TRUE, risk.table.title = "Number at Risk",
tables.x.text = "", xlim = c(0, 6345),
xlab = "Days to Death or Recurrence", ylab = "Disease-free Survival")
surv_pvalue(fit)
#Fig 3g#
tmp_model <- coxph(Surv(time_to_rfs, rfs_status == '1') ~ coldP3 + age_surgery + gender + pack_years + stage + Adjuvant.therapy + nTotalRegions, data=tmplatt)
ggforest(tmp_model, data = NULL, main = "", fontsize = 0.7, refLabel = "", noDigits = 2)
#Fig 3g# - caption info: n=827
tmp_model <- coxph(Surv(time_to_rfs, rfs_status == '1') ~ coldP3 + age_surgery + gender + pack_years + stage + Adjuvant.therapy + nTotalRegions, data=tmp)
ggforest(tmp_model, data = NULL, main = "", fontsize = 0.7, refLabel = "", noDigits = 2)
#Fig S5c#
tmp_model <- coxph(Surv(time_to_rfs, rfs_status == '1') ~ coldP3 + age_surgery + gender + pack_years + stage + Adjuvant.therapy , data=tmplatt)
ggforest(tmp_model, data = NULL, main = "", fontsize = 0.7, refLabel = "", noDigits = 2)
#Fig S5d# with tumor size instead of total regions
tmp2 = tmplatt[!is.na(tmplatt$largest_tumour_size),]
tmp_model <- coxph(Surv(time_to_rfs, rfs_status == '1') ~ coldP3 + age_surgery + gender + pack_years + stage + Adjuvant.therapy + largest_tumour_size, data=tmp2)
ggforest(tmp_model, data = NULL, main = "", fontsize = 0.7, refLabel = "", noDigits = 2)
#Fig S5d# caption info: n=815
tmp3 = tmp
tmp3 = tmp[!is.na(tmp$age_surgery) & !is.na(tmp$gender) & !is.na(tmp$largest_tumour_size) &
!is.na(tmp$stage) &
!is.na(tmp$Adjuvant.therapy) & !is.na(tmp$time_to_rfs) &
!is.na(tmp$rfs_status),]
tmp_model <- coxph(Surv(time_to_rfs, rfs_status == '1') ~ coldP3 + age_surgery + gender + pack_years + stage + Adjuvant.therapy + largest_tumour_size, data=tmp3)
ggforest(tmp_model, data = NULL, main = "", fontsize = 0.7, refLabel = "", noDigits = 2)
#Fig S5e#
#head to head, image-immune features:
rU2 = lt %>%
group_by(ACA_ID) %>%
summarise(lymphocytes_per_mean = mean(lymphocytes_per),
lymphocytes_per_min = min(lymphocytes_per),
lymphocytes_per_sd = sd(lymphocytes_per))
lattice_lym = NULL
lattice_lym = merge(lattice, rU2)
fit <- coxph(Surv(time_to_rfs, rfs_status)~cold, data = lattice_lym)
ggforest(fit, data=lattice_lym)
summary(fit)
fit <- coxph(Surv(time_to_rfs, rfs_status)~col
dP3, data = lattice_lym)
ggforest(fit, data=lattice_lym)
summary(fit)
lattice_lym$coldProp = lattice_lym$cold/lattice_lym$nTotalRegions
fit <- coxph(Surv(time_to_rfs, rfs_status)~cold+coldProp, data = lattice_lym)
ggforest(fit, data=lattice_lym)
fit <- coxph(Surv(time_to_rfs, rfs_status)~cold+hot, data = lattice_lym)
ggforest(fit, data=lattice_lym)
fit <- coxph(Surv(time_to_rfs, rfs_status)~cold+lymphocytes_per_min, data = lattice_lym)
ggforest(fit, data=lattice_lym)
fit <- coxph(Surv(time_to_rfs, rfs_status)~cold+lymphocytes_per_mean, data = lattice_lym)
ggforest(fit, data=lattice_lym)
fit <- coxph(Surv(time_to_rfs, rfs_status)~cold+lymphocytes_per_sd, data = lattice_lym)
ggforest(fit, data=lattice_lym)
summaryPs <- data.frame(
Measure = c("9N cold regions", "99>1 cold regions", "99 N cold regions/total","8N hot regions",
"6Regional lymphocyte% (min)", "5Regional lymphocyte% (mean)", "55Regional lymphocyte% (SD)"),
PVal = c(4.83e-07, 2.18e-05, 0.54, 0.233,
0.459, 0.647, 0.732),
lower95 = c(1.1, 1.2, 0.97, 0.98,
0.97, 0.97, 0.97),
upper95 = c(1.2, 1.7, 1.3, 1.1,
1, 1, 1),
hr = c(1.1, 1.5, 0.99, 1,
0.99, 0.99, 1))
summaryPs$PVal_log10 <- -log10(summaryPs$PVal)
summaryPs$PvalAdjust <- p.adjust(summaryPs$PVal, method = "BH")
summaryPs$PvalAdjust_log10 <- -log10(summaryPs$PVal)
#change HR for the number of cold regions/total number of regions in LATTICe-A is adjusted from
#0.88[0.57-1.3] to 0.95[0.95-1.2].
#not adjusted
ggplot(data=summaryPs,aes(x=hr,y=Measure))+
geom_point(aes(size=PVal_log10), colour="#CB6728", fill="#CB6728", shape=21)+
geom_errorbarh(aes(xmin=lower95,xmax=upper95), height=0)+
geom_vline(xintercept=1,linetype="longdash", colour="grey70")+
scale_size_continuous(breaks=c(5000,10000,15000))+theme_bw()+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
axis.ticks.y = element_blank(),
axis.line.x = element_blank()) + labs(x = "Hazard ratio", y = "Immune feature")
#adjusted p-vals
ggplot(data=summaryPs,aes(x=hr,y=Measure))+
geom_point(aes(size=PvalAdjust_log10), colour="#CB6728", fill="#CB6728", shape=21)+
geom_errorbarh(aes(xmin=lower95,xmax=upper95), height=0)+
geom_vline(xintercept=1,linetype="longdash", colour="grey70")+
scale_size_continuous(breaks=c(5000,10000,15000))+theme_bw()+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
axis.ticks.y = element_blank(),
axis.line.x = element_blank()) + labs(x = "Hazard ratio", y = "Immune feature")
#############
#S6: validation of immune phenotype classification over 4 new schemes
#############
#below numbers derived simply from:
reg = regional[, c("PublicationID", "region", "lymphocytes_per")]
median(reg$lymphocytes_per)+sd(reg$lymphocytes_per)/4 # or /2, /3, /6
median(reg$lymphocytes_per)-sd(reg$lymphocytes_per)/4 # or /2, /3, /6
#schemes visualisation
ggdensity(regional, x = "lymphocytes_per",
add = "median", rug = T)+
geom_vline(xintercept = 20.42028, linetype="dotted",
color = "gray", size=0.9)+
geom_vline(xintercept = 32.15778, linetype="dotted",
color = "gray", size=0.9)+
geom_vline(xintercept = 23.35466, linetype="dotted",
color = "gray", size=0.9)+
geom_vline(xintercept = 29.2234, linetype="dotted",
color = "gray", size=0.9)+
geom_vline(xintercept = 22.37653, linetype="dotted",
color = "gray", size=0.9)+
geom_vline(xintercept = 30.20153, linetype="dotted",
color = "gray", size=0.9)+
geom_vline(xintercept = 24.33278, linetype="dotted",
color = "gray", size=0.9)+
geom_vline(xintercept = 28.24528, linetype="dotted",
color = "gray", size=0.9)
#test survival in each threshold
txH2LUADLUSC <- tx[ which(tx$Histology=="LUAD"
| tx$Histology == "LUSC"), ]
txH2LUADLUSC = txH2LUADLUSC[, -c(14:16)]
txH2LUADLUSC$Histology = as.factor(as.character(txH2LUADLUSC$Histology))
txH2LUADLUSC$sex = as.factor(as.character(txH2LUADLUSC$sex))
txH2LUADLUSC$coldP3 = as.factor(as.character(txH2LUADLUSC$coldP3))
txH2LUADLUSC$pathologyTNM2 = as.factor(as.character(txH2LUADLUSC$pathologyTNM2))
#with clonal neo local quartile for the available 79 luad lusc patients:
#quantile(txH2LUADLUSC$ClonalNeo[txH2LUADLUSC$Histology=="LUSC"])
txH2LUADLUSC$ClonalNeoUQ[txH2LUADLUSC$Histology=="LUAD" & txH2LUADLUSC$ClonalNeo >= 189]<- "UQ.high"
txH2LUADLUSC$ClonalNeoUQ[txH2LUADLUSC$Histology=="LUAD" & txH2LUADLUSC$ClonalNeo < 189]<- "cUQ.low"
txH2LUADLUSC$ClonalNeoUQ[txH2LUADLUSC$Histology=="LUSC" & txH2LUADLUSC$ClonalNeo >= 206.25]<- "UQ.high"
txH2LUADLUSC$ClonalNeoUQ[txH2LUADLUSC$Histology=="LUSC" & txH2LUADLUSC$ClonalNeo < 206.25]<- "cUQ.low"
txH2LUADLUSC$ClonalNeoUQ <- as.factor(as.character(txH2LUADLUSC$ClonalNeoUQ))
reg$imC[reg$lymphocytes_per >=median(reg$lymphocytes_per)] <- "hot"
reg$imC[reg$lymphocytes_per <median(reg$lymphocytes_per)] <- "cold"
reg$imC2 = reg$imC
reg$imC2[reg$lymphocytes_per >= (median(reg$lymphocytes_per)-sd(reg$lymphocytes_per)/2) &
reg$lymphocytes_per <= (median(reg$lymphocytes_per)+sd(reg$lymphocytes_per)/2)] <- "intermediate"
reg$imC3 = reg$imC
reg$imC3[reg$lymphocytes_per >= (median(reg$lymphocytes_per)-sd(reg$lymphocytes_per)/3) &
reg$lymphocytes_per <= (median(reg$lymphocytes_per)+sd(reg$lymphocytes_per)/3)] <- "intermediate"
reg$imC6 = reg$imC
reg$imC6[reg$lymphocytes_per >= (median(reg$lymphocytes_per)-sd(reg$lymphocytes_per)/6) &
reg$lymphocytes_per <= (median(reg$lymphocytes_per)+sd(reg$lymphocytes_per)/6)] <- "intermediate"
regS0 <- reg %>% group_by(PublicationID, imC) %>%
dplyr::summarise(count=n())
regS0 = dcast(regS0, PublicationID ~ imC)
names(regS0) <- c("PublicationID", "rCold", "rHot")
regS0[is.na(regS0)] <- 0
tx0 = merge(txH2LUADLUSC, regS0, by = "PublicationID")
regS2 <- reg %>% group_by(PublicationID, imC2) %>%
dplyr::summarise(count=n())
regS2 = dcast(regS2, PublicationID ~ imC2)
names(regS2) <- c("PublicationID", "rCold", "rHot", "rIntermediate")
regS2[is.na(regS2)] <- 0
tx2 = merge(txH2LUADLUSC, regS2, by = "PublicationID")
regS3 <- reg %>% group_by(PublicationID, imC3) %>%
dplyr::summarise(count=n())
regS3 = dcast(regS3, PublicationID ~ imC3)
names(regS3) <- c("PublicationID", "rCold", "rHot", "rIntermediate")
regS3[is.na(regS3)] <- 0
tx3 = merge(txH2LUADLUSC, regS3, by = "PublicationID")
regS6 <- reg %>% group_by(PublicationID, imC6) %>%
dplyr::summarise(count=n())
regS6 = dcast(regS6, PublicationID ~ imC6)
names(regS6) <- c("PublicationID", "rCold", "rHot", "rIntermediate")
regS6[is.na(regS6)] <- 0
tx6 = merge(txH2LUADLUSC, regS6, by = "PublicationID")
tx0$coldP[tx0$rCold>median(tx0$rCold)] <- "med.High"
tx0$coldP[tx0$rCold<=median(tx0$rCold)] <- "Low"
tx2$coldP[tx2$rCold>median(tx2$rCold)] <- "med.High"
tx2$coldP[tx2$rCold<=median(tx2$rCold)] <- "Low"
tx3$coldP[tx3$rCold>median(tx3$rCold)] <- "med.High"
tx3$coldP[tx3$rCold<=median(tx3$rCold)] <- "Low"
tx6$coldP[tx6$rCold>median(tx6$rCold)] <- "med.High"
tx6$coldP[tx6$rCold<=median(tx6$rCold)] <- "Low"
tx0$coldP = as.factor(as.character(tx0$coldP))
tx2$coldP = as.factor(as.character(tx2$coldP))
tx3$coldP = as.factor(as.character(tx3$coldP))
tx6$coldP = as.factor(as.character(tx6$coldP))
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~coldP+age+sex+pack_years_calculated+Histology+pathologyTNM2+Adjuvant.therapy+ClonalNeoUQ+nTotalRegions, data = tx0)
a=ggforest(fit, data=tx0, main = "Threshold: No intermediate zone")
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~coldP+age+sex+pack_years_calculated+Histology+pathologyTNM2+Adjuvant.therapy+ClonalNeoUQ+nTotalRegions, data = tx2)
b=ggforest(fit, data=tx2, main = "Threshold: s.d./2")
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~coldP+age+sex+pack_years_calculated+Histology+pathologyTNM2+Adjuvant.therapy+ClonalNeoUQ+nTotalRegions, data = tx3)
c=ggforest(fit, data=tx3, main = "Threshold: s.d./3")
fit <- coxph(Surv(DFS_time_days, DFS_censor_variable)~coldP+age+sex+pack_years_calculated+Histology+pathologyTNM2+Adjuvant.therapy+ClonalNeoUQ+nTotalRegions, data = tx6)
d=ggforest(fit, data=tx6, main = "Threshold: s.d./6")
grid.arrange(a,c,b,d, ncol=2)
#cd8 danaher differnce in hot vs cold regions using all thresholds
comList <- list( c("cold", "hot"))
ggboxplot(regional[! regional$immuneClass_2=="intermediate" ,], x = "immuneClass_2", y = "cd8.score.danaher", color = "immuneClass_2",
add = "jitter", border = "white", palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))
reg2 = merge(reg, regional[, c("PublicationID", "region", "cd8.score.danaher"), ], by = c("PublicationID", "region"), all.x = T)
ggboxplot(reg2[! reg2$imC=="intermediate" ,], x = "imC", y = "cd8.score.danaher", color = "imC",
add = "jitter", border = "white", palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))
ggboxplot(reg2[! reg2$imC2=="intermediate" ,], x = "imC2", y = "cd8.score.danaher", color = "imC2",
add = "jitter", border = "white", palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))
ggboxplot(reg2[! reg2$imC3=="intermediate" ,], x = "imC3", y = "cd8.score.danaher", color = "imC3",
add = "jitter", border = "white", palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))
ggboxplot(reg2[! reg2$imC6=="intermediate" ,], x = "imC6", y = "cd8.score.danaher", color = "imC6",
add = "jitter", border = "white", palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))
##NOTE
#using R ver 3.6.3 the p-value for the SD/2 vs cd8.danaher was 1.5e-06 instead 3.7e-06
##
#now using the the same new 4 schemes, we test the pairwise genetic dist.
#we changed the immune classification 4 times, will the gentics dist in LUAD remain sign.?
#here we've the 4 classifications/schemes ready in a df: regional_immune_schemes
#just done exactly like the above code for survival tests
#imC: no intermediate zone
#imC2: SD/2 for the intermediate zone
#imC3: SD/3 for the intermediate zone
#imC6: SD/6 for the intermediate zone
#and all possible pairwise genetic dist. calculated in: tx_genomic_pairdist_extended
#2 dfs together we can reproduce S6 genetic dist. tests
#this immune_scheme_sub
#no immune class, we will add the 4 schemes in manually
tx_genomic_pairdist_extended$immune_scheme_sub <- NA
#start
for (i in 1:nrow(tx_genomic_pairdist_extended)){
x=substring(tx_genomic_pairdist_extended$rsCRUK[[i]], 1,11)
y=paste0(substring(tx_genomic_pairdist_extended$rsCRUK[[i]], 1,9), substring(tx_genomic_pairdist_extended$rsCRUK[[i]], 12,13))
tx_genomic_pairdist_extended$immune_scheme_sub[[i]] <- paste0(regional_immune_schemes$imC[regional_immune_schemes$regionCRUK %in% x],
"_", regional_immune_schemes$imC[regional_immune_schemes$regionCRUK %in% y])
} ###change here imC, imC2, imC3, imC6###
tx_genomic_pairdist_extended_ch = tx_genomic_pairdist_extended[tx_genomic_pairdist_extended$immune_scheme_sub=="hot_hot" | tx_genomic_pairdist_extended$immune_scheme_sub=="cold_cold" ,]
tx_genomic_pairdist_extended_ch$PublicationID = substring(tx_genomic_pairdist_extended_ch$rsCRUK, 1,8)
tx_genomic_pairdist_extended_ch <- tx_genomic_pairdist_extended_ch[order(tx_genomic_pairdist_extended_ch$immune_scheme_sub),]
comList <- list( c("hot_hot", "cold_cold"))
p1<-ggboxplot(tx_genomic_pairdist_extended_ch[tx_genomic_pairdist_extended_ch$histology_group=="Adenocarcinoma",], x = "immune_scheme_sub", y = "geneticDist",
color = "immune_scheme_sub", palette = c("blue", "red2"), title = "LUAD",
add = "jitter", border = "white")+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))
p2<-ggboxplot(tx_genomic_pairdist_extended_ch[tx_genomic_pairdist_extended_ch$histology_group=="Squamous cell carcinoma",], x = "immune_scheme_sub", y = "geneticDist",
color = "immune_scheme_sub", palette = c("blue", "red2"), title = "LUSC",
add = "jitter", border = "white")+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))
grid.arrange(p1,p2, nrow=1)
#check n
#table(tx_genomic_pairdist_extended_ch$histology_group, tx_genomic_pairdist_extended_ch$immune_scheme_sub)
tx_genomic_pairdist_extended_ch = NULL
### end of figure
#panel d:
#distribution of lym% in tx and LATTICe-A for histology subtypes
ggdensity(regional, x = "lymphocytes_per", color = "Histology", palette = c("#98AED6", "#682A45", "black"),
add = "mean", rug = TRUE) +
theme(legend.position="none")
ggdensity(lt, x = "lymphocytes_per", color = "#98AED6",
add = "mean", rug = TRUE) +
theme(legend.position="none")
comList <- list( c("LUAD", "LUSC"))
ggboxplot(regional, x = "Histology", y = "lymphocytes_per", color = "Histology", title = "TRACERx (n=275)",
add = "jitter", border = "white")+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))+
scale_color_manual(values=c("#98AED6", "#682A45", "black"))
#############
#4b-c and S7: cancer-stromal cell-cell fractal dimension analysis
#############
#FD vs immune class in tx
comList = list(c("cold", "hot"))
ggboxplot(regional[regional$Histology=="LUAD" & ! regional$immuneClass_2=="intermediate",],
x = "immuneClass_2", y = "fd", color = "immuneClass_2", ylab = "Fractal dimension",
add = "jitter", border = "white",palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))
ggboxplot(regional[regional$Histology=="LUSC"& ! regional$immuneClass_2=="intermediate",],
x = "immuneClass_2", y = "fd", color = "immuneClass_2", ylab = "Fractal dimension",
add = "jitter", border = "white",palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))
#now FD for all vs immmune class
comList = list(c("cold", "hot"))
ggboxplot(regional[! regional$immuneClass_2=="intermediate",],
x = "immuneClass_2", y = "fd", color = "immuneClass_2", ylab = "Fractal dimension",
add = "jitter", border = "white",palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))
#now test stromal% instead of FD in both classes
ggboxplot(regional[! regional$immuneClass_2=="intermediate",],
x = "immuneClass_2", y = "fibroblasts_per", color = "immuneClass_2", ylab = "Stromal%",
add = "jitter", border = "white",palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))
ggboxplot(regional[regional$Histology=="LUAD" & ! regional$immuneClass_2=="intermediate",],
x = "immuneClass_2", y = "fibroblasts_per", color = "immuneClass_2", ylab = "Stromal%",
add = "jitter", border = "white",palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))
ggboxplot(regional[regional$Histology=="LUSC"& ! regional$immuneClass_2=="intermediate",],
x = "immuneClass_2", y = "fibroblasts_per", color = "immuneClass_2", ylab = "Stromal%",
add = "jitter", border = "white",palette = c("blue2", "red2"))+
stat_compare_means(comparisons = comList, method = "wilcox")+
theme(legend.position="") + theme(text = element_text(size=18))
#effect size reported in main text
r = regional[! regional$immuneClass_2=="intermediate",]
r$imc = as.factor(as.character(r$immuneClass_2))
cohen.d(r$fd, r$imc)
cohen.d(r$fibroblasts_per, r$imc)
#FD vs LOHHLA - at region level
r1 = regional[!is.na(regional$LOHHLAloss.A) | !is.na(regional$LOHHLAloss.B) |
!is.na(regional$LOHHLAloss.C),]
r1$LOHHLAloss_any = NULL
r1$LOHHLAloss_any[r1$LOHHLAloss.A == T | r1$LOHHLAloss.B == T