-
Notifications
You must be signed in to change notification settings - Fork 1
/
95_Baseline_Genesets_ccrcc_Analyses.Rmd
1619 lines (1148 loc) · 45.2 KB
/
95_Baseline_Genesets_ccrcc_Analyses.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "CA209009 baseline Geneset scores and ccrcc group analysis"
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
# Clear the environment
rm(list = ls())
# Free up memory by forcing garbage collection
invisible(gc())
# Manually set the seed to an arbitrary number for consistency in reports
myseed <- 9
```
## Procedure
1. Open sdrf with scores and clusters assigned
1. Calculate all score association with Response (ROC)
1. Calculate publication score association with Response (ROC)
1. Objective response rate Table for PBRM1
1. Fisher exact for PBRM1 groups
1. Objective response rate Table for ccrcc
1. Fisher exact for ORR in ccrcc groups
1. Fisher exact for ORR ccrcc4 vs rest
1. Objective response rate Graph for ccrcc
1. PBRM1 mutant rate Table for ccrcc groups
1. Fisher exact for PBRM1 mutant rate in ccrcc groups
1. PBRM1 mutant rate Graph for ccrcc groups
1. Odds ratio for PBRM1 mutant vs WT
1. Odds ratio for ccrcc4 vs ccrcc1/2/3
1. Odds ratio for signature scores
1. Merge Odss ratios to single table
1. Forest plot of all Odds Ratios
1. Scatterplots and boxplots for comparisons of interest
1. Heatmap showing all clustered Signature scores versus waterfall plot
1. Heatmap showing publication clustered Signature scores versus waterfall plot
## Paths and Packages
```{r paths_packages}
# Provide paths
data_dir <- "./data/import"
results_dir <- "./results"
work_dir <- "./work"
## Load packages ##
#tidyverse bundles: ggplot2, dplyr, tidyr, readr, purrr and tibble
suppressPackageStartupMessages(library(tidyverse))
library(ComplexHeatmap)
library(circlize)
library(limma)
library(knitr)
library(ggpubr)
library(broom)
library(pROC)
library(plotROC)
```
```{r palettes}
ccrcc_colors = c("ccrcc1"= "black",
"ccrcc2"= "red",
"ccrcc3"= "grey",
"ccrcc4"= "goldenrod")
```
```{r functions}
source("./code/ggplot_theme_dj_prm.R")
#' Custom ggplot theme with bolded text for easier legibility
#Don Jackson
## contrastTable Functions by Scott Chasalow
contrastTable <- function(object, ...)
UseMethod("contrastTable")
contrastTable.coxph <- function(object, linmat, level = 0.95, df = 1, rnames =
dimnames(linmat)[[1]]) {
#
# DESCRIPTION:
# Computes point estimates and confidence intervals, and Wald
# test statistics and p-values, for specified contrasts (or
# more generally, linear combinations) of coefficients from a
# fitted Cox model (coxph object). Typically these contrasts
# will represent some sort of hazard ratio (HR).
#
# This is a method for the generic function contrastTable for
# objects inheriting from class "coxph".
#
# ARGUMENTS:
# object a coxph object
# linmat numeric matrix with one row per contrast and one column
# corresponding to each coefficient in object.
# level desired confidence level. Default is 0.95, giving 95%
# confidence intervals for the contrasts.
# df a vector of positive integers, giving the degrees of
# freedom for the chi-squared distribution used for computing
# the Wald test p-values. The default is 1. Must have length
# one, in which case that value is used for all tests, or
# length nrow(linmat). If you're unsure what value to use for
# a particular contrast, consult a statistician. If you ARE a
# statistician, consult a different statistician. Has no
# influence on HR point and interval estimates.
# rnames character vector giving names of the requested
# contrasts, used as rownames in the return value. Default is
# row names of linmat.
#
# VALUE:
# a numeric matrix with one row per contrast, and columns
# "HR", "logHR", "SE.logHR", "lo.logHR", "up.logHR", "level",
# "WaldStat", and "Pvalue".
#
###
# Argument checking
###
if (length(rnames) == 0) rnames <- character(0)
if (!is.matrix(linmat))
stop("linmat must be a matrix.")
ncon <- nrow(linmat)
if (ncon == 0) return(NULL)
b <- coef(object)
if (ncol(linmat) != length(b))
stop(paste("linmat must have", length(b), "columns."))
if (length(df) != 1 && length(df) != ncon)
stop(paste("df must have length 1 or ", ncon, ".", sep = ""))
if (length(level) != 1)
stop("level must have length 1.")
###
# Compute useful stuff
###
loghr <- linmat %*% b
hrest <- exp(loghr)
se.loghr <- sqrt(diag(linmat %*% object$var %*% t(linmat)))
qqq <- qnorm( 1 - ( (1 - level)/2 ) )
lo <- loghr - qqq * se.loghr
hi <- loghr + qqq * se.loghr
waldval <- loghr/se.loghr
pwald <- 1 - pchisq(waldval^2, df)
###
# Wrap it up pretty and go home
###
cnames <- c( "HR", "logHR", "SE.logHR", "lo.logHR", "up.logHR", "level",
"WaldStat", "Pvalue" )
level <- rep(level, ncon)
out <- c(hrest, loghr, se.loghr, lo, hi, level, waldval, pwald)
out <- array(out, c(ncon, round(length(out)/ncon)), list(rnames, cnames))
out
}
contrastTable.glm <- function(object, linmat, level = 0.95, df = 1, rnames =
dimnames(linmat)[[1]]) {
#
# DESCRIPTION:
#PRM:
#don't have a description for this
#As far as I can figure, this produces Odds ratios, not Hazard ratios
#Because the GLM is for a binary outcome (Response)
#Down in the chunk applying this function we ask for the OR for the difference (DIFF of Score) between the 25th percentile score and the 75th percentile score
#
###
# Argument checking
###
if (length(rnames) == 0) rnames <- character(0)
if (!is.matrix(linmat))
stop("linmat must be a matrix.")
ncon <- nrow(linmat)
if (ncon == 0) return(NULL)
b <- coef(object)
if (ncol(linmat) != length(b))
stop(paste("linmat must have", length(b), "columns."))
if (length(df) != 1 && length(df) != ncon)
stop(paste("df must have length 1 or ", ncon, ".", sep = ""))
if (length(level) != 1)
stop("level must have length 1.")
###
# Compute useful stuff
###
logor <- linmat %*% b
hrest <- exp(logor)
se.logor <- sqrt(diag(linmat %*% summary(object)$cov.scaled %*% t(linmat)))
qqq <- qnorm( 1 - ( (1 - level)/2 ) )
lo <- logor - qqq * se.logor
hi <- logor + qqq * se.logor
waldval <- logor/se.logor
pwald <- 1 - pchisq(waldval^2, df)
###
# Wrap it up pretty and go home
###
cnames <- c( "OR", "logOR", "SE.logOR", "lo.logOR", "up.logOR", "level",
"WaldStat", "Pvalue" )
level <- rep(level, ncon)
out <- c(hrest, logor, se.logor, lo, hi, level, waldval, pwald)
out <- array(out, c(ncon, round(length(out)/ncon)), list(rnames, cnames))
out
}
```
## Data Sources
```{r load_data}
#SDRF (Sample and Data Relationship Format) file with signature scores
scores_file <- paste0(results_dir, "/GEP_Table_BiopsyScreen_GEPSignatures_sdrf.txt")
sdrfScreen <- read_tsv(scores_file)
sdrfScreen$Response20pct <- as.factor(sdrfScreen$Response20pct)
sdrfScreen$individual <- as.factor(sdrfScreen$individual)
sdrfScreen$clinical.history <- as.factor(sdrfScreen$clinical.history)
```
SDRF (Sample and Data Relationship Format) file of Screen samples with signature scores:
+*`r scores_file`*
```{r load_pbrm1}
# Patient Annotation
clinicalData_file <- paste(data_dir, "CM9_Patient_Annotation.txt", sep = "/" )
clinicalData <- read_tsv(clinicalData_file)
clinicalData_pbrm1 <- clinicalData%>%
filter(!is.na(PBRM1),
Response20pct != "NE")
clinicalData_pbrm1$PBRM1_status <- NA
clinicalData_pbrm1$PBRM1_status <- "Mutant"
clinicalData_pbrm1$PBRM1_status[clinicalData_pbrm1$PBRM1 == "WT"] <- "WT"
clinicalData_pbrm1$PBRM1_status[clinicalData_pbrm1$PBRM1 == "Missense_Mutation"] <- "WT"
clinicalData_pbrm1$PBRM1_status <- factor(clinicalData_pbrm1$PBRM1_status,
levels = c("WT","Mutant" ))
```
Clinical data including PBRM1 status for all patients
+*`r clinicalData_file`*
Created factor(clinicalData_pbrm1$PBRM1_status, levels = c("WT","Mutant" )) where "WT" includes one missense mutant, and "Mutant" is treuncation mutations.
## ROC for All Signature scores
ROC analysis requires a binary response metric
+ Response20pct=="Not20pct" <- 0
+ Response20pct=="20pctDec" <- 1
```{r ROC_all, length = 8in, width = 7in}
sdrfScreen$OR_num <- NA
sdrfScreen$OR_num[which(sdrfScreen$Response20pct=="Not20pct")] <- 0
sdrfScreen$OR_num[which(sdrfScreen$Response20pct=="20pctDec")] <- 1
comp_sign <-c("ccrcc4.Score",
# "HIF1A.Score",
"Merck18.Score",
"CD3TCR.Score",
"IM150_Teff.Score",
"IM150_Angio.Score",
"Fuhrman.Score",
"Adenosine.Score",
"IM150_MyeloidInfl.Score",
# "Ad_Short.Score",
# "Ad_RNAseq.Score",
"ccrcc2.Score",
"BMS.Score",
"EMTstroma.Score",
"Javelin.Score")
df_comp <- NULL
df_data <- NULL
for(i in comp_sign){
df_comp <- rbind(df_comp, data.frame("BM"=i, "d"=sdrfScreen$OR_num, m=sdrfScreen[[i]]))
roc_marker <- roc(formula=sdrfScreen[["OR_num"]]~sdrfScreen[[i]],percent=TRUE,
direction = "<", #my addition to keep it AUC
# arguments for ci
ci=TRUE, boot.n=1000, ci.alpha=0.95, stratified=FALSE)
label <- paste0("N= ",nrow(sdrfScreen[which(!is.na(sdrfScreen[[i]])), ]), ", AUC: ", round(roc_marker$auc, 2),
"% (", round(roc_marker$ci[1], 2),"% -",round(roc_marker$ci[3], 2),"%)" )
#adding a separate column to allow sort by AUC
AUC <- round(roc_marker$auc, 2)
df_data<- rbind(df_data, data.frame("Biomarker"=i, "Stat"=label, "AUC" = AUC))
}
#ROC all on one plot
ROCall <- df_comp%>%
filter(BM != "BMS.Score")%>%
ggplot(aes(d = d, m = m, colour=BM)) +
geom_roc() +
style_roc(xlab = "1 - Specificity", ylab= "Sensitivity" ) +
coord_equal()+ggtitle("CM009 ROC Analysis")
# ROC facetted by Signature score
ROCfacet <- ggplot(df_comp, aes(d = d, m = m, color="black")) +
geom_roc() +
style_roc(xlab = "1 - Specificity", ylab= "Sensitivity" ) +
coord_equal() +
ggtitle("CM009 ROC Analyses") +
facet_wrap(~BM, nrow = 4, ncol = 3) +
theme(legend.position="bottom")
df_data <- df_data %>%
arrange(desc(AUC)) %>%
select(-AUC)
kable(df_data, title = "CM009 Signature analysis: AUCs")
print(ROCall)
print(ROCfacet)
```
\newpage
## ROC for Publication Signature scores
This uses only Signatures previously associated with nivolumab response.
Signature scores are continuous metric and ORR is evaluated by ROC.
ROC analysis requires a binary response metric
+ Response20pct=="Not20pct" <- 0
+ Response20pct=="20pctDec" <- 1
```{r ROC_pub, length = 8in, width = 7in}
sdrfScreen$OR_num <- NA
sdrfScreen$OR_num[which(sdrfScreen$Response20pct=="Not20pct")] <- 0
sdrfScreen$OR_num[which(sdrfScreen$Response20pct=="20pctDec")] <- 1
comp_sign <-c("Merck18.Score",
"CD3TCR.Score",
"IM150_Teff.Score",
"IM150_Angio.Score",
"Adenosine.Score",
"IM150_MyeloidInfl.Score",
"EMTstroma.Score",
"Javelin.Score")
df_comp <- NULL
df_data <- NULL
for(i in comp_sign){
df_comp <- rbind(df_comp, data.frame("BM"=i, "d"=sdrfScreen$OR_num, m=sdrfScreen[[i]]))
roc_marker <- roc(formula=sdrfScreen[["OR_num"]]~sdrfScreen[[i]],percent=TRUE,
direction = "<", #my addition to keep it AUC
# arguments for ci
ci=TRUE, boot.n=1000, ci.alpha=0.95, stratified=FALSE)
label <- paste0("N= ",nrow(sdrfScreen[which(!is.na(sdrfScreen[[i]])), ]), ", AUC: ", round(roc_marker$auc, 2),
"% (", round(roc_marker$ci[1], 2),"% -",round(roc_marker$ci[3], 2),"%)" )
#adding a separate column to allow sort by AUC
AUC <- round(roc_marker$auc, 2)
df_data<- rbind(df_data, data.frame("Biomarker"=i, "Stat"=label, "AUC" = AUC))
}
#ROC all on one plot
ROCall_pub <- df_comp%>%
filter(BM != "BMS.Score")%>%
ggplot(aes(d = d, m = m, colour=BM)) +
geom_roc() +
style_roc(xlab = "1 - Specificity", ylab= "Sensitivity" ) +
coord_equal()+
ggtitle("CM009 ROC Analysis")+
theme_dj(16)
# ROC facetted by Signature score
ROCfacet_pub <- ggplot(df_comp, aes(d = d, m = m, color="black")) +
geom_roc() +
style_roc(xlab = "1 - Specificity", ylab= "Sensitivity" ) +
coord_equal() +
ggtitle("CM009 Publication ROC Analyses") +
facet_wrap(~BM, nrow = 4, ncol = 3) +
theme(legend.position="bottom")
df_data <- df_data %>%
arrange(desc(AUC)) %>%
select(-AUC)
kable(df_data, title = "CM009 Publication Signature analysis: AUCs")
print(ROCall_pub)
print(ROCfacet_pub)
```
\newpage
## ORR for PBRM1 Groups
PBRM1 is a discrete category and ORR is evaluated by fisher exact test.
This analysis is run on the clinical dataset, where there are 48 patients with Objective response and PBRM1 status.
```{r pbrm1_ORR_table}
# calculate OR rate by pbrm1
groupcount3 <- clinicalData_pbrm1 %>% group_by(PBRM1_status) %>%
summarise(N_in_group = n())
orr_pcts5 <- clinicalData_pbrm1 %>% group_by(PBRM1_status, Response20pct) %>%
summarise(N = n())
orr_pcts6 <- orr_pcts5%>%
left_join(groupcount3,
by = c("PBRM1_status"))%>%
mutate(OR_Pct = round(100* N/N_in_group,2))%>%
filter(Response20pct=="20pctDec")
orr_pcts6$PBRM1_status <- factor(orr_pcts6$PBRM1_status,
levels = c("WT","Mutant" ))
kable(orr_pcts6, digits = 0,
caption = "CM9 48 patients: OR Percentage, By PBRM1")
```
```{r fisherexact_pbrm1}
table_pbrm1 <- orr_pcts6%>%
select(one_of(c("PBRM1_status","N", "N_in_group")))%>%
rename(R = N)%>%
mutate(NR = N_in_group - R)%>%
select(-N_in_group)
kable(table_pbrm1,
caption = "PBRM1 matrix for Fisher exact test")
fisher_pbrm1 <- table_pbrm1[,2:3]
foo <- fisher.test(fisher_pbrm1,
alternative = "two.sided")
pbrm1pval <- foo[["p.value"]]
```
The P value for the 2x2 matrix testing Objective response distribution in PBRM1 mutant versus WT is 0.011:
+ *`r pbrm1pval`*
\newpage
## ORR for ccrcc Groups
ccrcc is a discrete category and ORR is evaluated by fisher exact test.
```{r ccrcc_ORR_table}
# calculate OR rate by ccrcc
groupcount <- sdrfScreen %>% group_by(ccrccCluster) %>%
summarise(N_in_group = n())
orr_pcts <- sdrfScreen %>% group_by(ccrccCluster, Response20pct) %>%
summarise(N = n())
orr_pcts2 <- orr_pcts%>%
left_join(groupcount,
by = c("ccrccCluster"))%>%
mutate(OR_Pct = round(100* N/N_in_group,2))%>%
filter(Response20pct=="20pctDec")
#orr_pcts2$ccrcc <- gsub(".Score", "", orr_pcts2$ccrcc)
orr_pcts2$ccrccCluster <- factor(orr_pcts2$ccrccCluster ,
levels = c("ccrcc1",
"ccrcc2",
"ccrcc3",
"ccrcc4"))
kable(orr_pcts2, digits = 0,
caption = "CM9 56 baseline: OR Percentage, By ccrccCluster")
```
```{r fisherexact_ccrcc}
table_ccrcc <- orr_pcts2%>%
select(one_of(c("ccrccCluster","N", "N_in_group")))%>%
rename(R = N)%>%
mutate(NR = N_in_group - R)%>%
select(-N_in_group)
kable(table_ccrcc,
caption = "ccrcc matrix for Fisher exact test")
fisher_ccrcc <- table_ccrcc[,2:3]
foo <- fisher.test(fisher_ccrcc)
ccrccpval <- foo[["p.value"]]
```
The P value for the 4x2 matrix testing Objective response distribution in all ccrcc groups is 0.056:
+ *`r ccrccpval`*
```{r ccrcc4_ORR_table}
#compare ccrcc4 cluster members to rest
sdrfScreen$ccrcc4_binary <- NA
sdrfScreen$ccrcc4_binary <- "Notccrcc4"
sdrfScreen$ccrcc4_binary[sdrfScreen$ccrccCluster == "ccrcc4"] <- "ccrcc4"
sdrfScreen$ccrcc4_binary <- factor(sdrfScreen$ccrcc4_binary,
levels = c("Notccrcc4", "ccrcc4"))
# calculate OR rate by initial treatment
groupcount2 <- sdrfScreen %>% group_by(ccrcc4_binary) %>%
summarise(N_in_group = n())
orr_pcts3 <- sdrfScreen %>% group_by(ccrcc4_binary, Response20pct) %>%
summarise(N = n())
orr_pcts4 <- orr_pcts3%>%
left_join(groupcount2,
by = c("ccrcc4_binary"))%>%
mutate(OR_Pct = round(100* N/N_in_group,2))%>%
filter(Response20pct=="20pctDec")
#orr_pcts2$ccrcc <- gsub(".Score", "", orr_pcts2$ccrcc)
orr_pcts4$ccrcc4_binary <- factor(orr_pcts4$ccrcc4_binary ,
levels = c( "Notccrcc4",
"ccrcc4"))
kable(orr_pcts4, digits = 0,
caption = "CM9 56 baseline: OR Percentage, By ccrcc4_binary")
```
```{r fisherexact_ccrcc4}
table_ccrcc4 <- orr_pcts4%>%
select(one_of(c("ccrcc4_binary","N", "N_in_group")))%>%
rename(R = N)%>%
mutate(NR = N_in_group - R)%>%
select(-N_in_group)
kable(table_ccrcc4,
caption = "ccrcc4 matrix for Fisher exact test")
fisher_ccrcc4 <- table_ccrcc4[,2:3]
foo <- fisher.test(fisher_ccrcc4,
alternative = "two.sided")
ccrcc4pval <- foo[["p.value"]]
```
The P value for the 2x2 matrix testing Objective response distribution in ccrcc4 versus all other groups is 0.013:
+ *`r ccrcc4pval`*
## ORR graph by ccrcc Cluster
```{r ccrcc_OR_graph}
#Add the CR percent in case I figure out how to plot it on top
CRcount <- sdrfScreen %>% group_by(ccrccCluster, BOR) %>%
summarise(CR_in_group = n()) %>%
filter(BOR == "CR")
orr_graph <- orr_pcts2%>%
left_join(CRcount)%>%
mutate(CR_Pct = round(100* CR_in_group/N_in_group,2))
#add the 95% CI for the proportion
#https://stats.stackexchange.com/questions/207807/95-confidence-interval-for-proportions-in-r
#confidence interval for a proportion is given by:
#p_hat +/- z * sqrt(p_hat * (1-p_hat)/n)
# Set CI alpha level (1-alpha/2)*100%
alpha = 0.05
# Calculate the critical z-score
z = qnorm(1-alpha/2)
# Compute the CI
#p_hat + c(-1,1)*z*sqrt(p_hat*(1-p_hat)/n)
orr_graph <- orr_graph%>%
mutate(LCI = OR_Pct -1*z*sqrt(OR_Pct*(100-OR_Pct)/N_in_group))%>%
mutate(UCI = OR_Pct + 1*z*sqrt(OR_Pct*(100-OR_Pct)/N_in_group))
#Confidence interval cannot be <0
orr_graph$LCI[orr_graph$LCI <0] <-0
#Don't know how to plot the CR bars on top of the OR bars.
#This doesn't work, hangs, crashes
#likely because of facetting?
# ggplot(data=my_data,aes(x=Block))+
# geom_bar(aes(y=Start),stat="identity",position ="identity",alpha=.3,fill='lightblue',color='lightblue4') +
# geom_bar(aes(y=End),stat="identity",position ="identity",alpha=.8,fill='pink',color='red')
orr_by_ccrcc <- ggplot(orr_graph, aes(x = ccrccCluster, y = OR_Pct, fill = ccrccCluster)) +
geom_bar(stat = "identity") +
geom_errorbar( aes(x= ccrccCluster, ymin=LCI, ymax=UCI), width=0.05, colour="black", size=1)+
scale_fill_manual(values = ccrcc_colors) +
labs(title = "CM9: ORR in ccrccCluster",
subtitle = "Baseline, N=56",
x = "Groups from ccrccCluster",
y = "ORR, %",
color = "ORR") +
theme(legend.position = "bottom")+
geom_text(data = orr_graph,
aes(x = ccrccCluster, y = -10,
label = paste("N=",N_in_group)),
inherit.aes = FALSE, hjust = 0.5, vjust = 0,
size = 4) +
theme_dj(16)
orr_by_ccrcc
```
\newpage
## PBRM1 status for ccrcc Groups
```{r ccrcc_pbrm1_table}
sdrfScreen_pbrm1 <- sdrfScreen%>%
filter(!is.na(PBRM1))
sdrfScreen_pbrm1$PBRM1_status <- NA
sdrfScreen_pbrm1$PBRM1_status <- "Mutant"
sdrfScreen_pbrm1$PBRM1_status[sdrfScreen_pbrm1$PBRM1 == "WT"] <- "WT"
sdrfScreen_pbrm1$PBRM1_status[sdrfScreen_pbrm1$PBRM1 == "Missense_Mutation"] <- "WT"
sdrfScreen_pbrm1$PBRM1_status <- factor(sdrfScreen_pbrm1$PBRM1_status,
levels = c("WT","Mutant" ))
# calculate pbrm1 rate by ccrcc
groupcount4 <- sdrfScreen_pbrm1 %>% group_by(ccrccCluster) %>%
summarise(N_in_group = n())
pbrm_pcts <- sdrfScreen_pbrm1 %>% group_by(ccrccCluster, PBRM1_status) %>%
summarise(N = n())
pbrm_pcts2 <- pbrm_pcts%>%
left_join(groupcount4,
by = c("ccrccCluster"))%>%
mutate(PBRM1mutant_Pct = round(100* N/N_in_group,2))%>%
filter(PBRM1_status=="Mutant")
pbrm_pcts2$ccrccCluster <- factor(pbrm_pcts2$ccrccCluster ,
levels = c("ccrcc1",
"ccrcc2",
"ccrcc3",
"ccrcc4"))
kable(pbrm_pcts2, digits = 0,
caption = "CM9 33 baseline: PBRM1 Mutant Percentage, By ccrccCluster")
```
```{r fisherexact_ccrcc_pbrm1}
table_ccrcc_PBRM <- pbrm_pcts2%>%
select(one_of(c("ccrccCluster","N", "N_in_group")))%>%
rename(Mutant = N)%>%
mutate(WT = N_in_group - Mutant)%>%
select(-N_in_group)
kable(table_ccrcc_PBRM,
caption = "ccrcc_PBRM matrix for Fisher exact test")
fisher_ccrcc_PBRM <- table_ccrcc_PBRM[,2:3]
foo <- fisher.test(fisher_ccrcc_PBRM,
alternative = "two.sided")
ccrccPBRMpval <- foo[["p.value"]]
```
The P value for the 2x2 matrix testing PBRM1 distribution in ccrcc groups is 0.91:
+ *`r ccrccPBRMpval`*
## PBRM1 graph by ccrcc Cluster
```{r ccrcc_PBRM1_graph}
#add the 95% CI for the proportion
#https://stats.stackexchange.com/questions/207807/95-confidence-interval-for-proportions-in-r
#confidence interval for a proportion is given by:
#p_hat +/- z * sqrt(p_hat * (1-p_hat)/n)
# Set CI alpha level (1-alpha/2)*100%
alpha = 0.05
# Calculate the critical z-score
z = qnorm(1-alpha/2)
# Compute the CI
#p_hat + c(-1,1)*z*sqrt(p_hat*(1-p_hat)/n)
pbrm_graph <- pbrm_pcts2%>%
mutate(LCI = PBRM1mutant_Pct -1*z*sqrt(PBRM1mutant_Pct*(100-PBRM1mutant_Pct)/N_in_group))%>%
mutate(UCI = PBRM1mutant_Pct + 1*z*sqrt(PBRM1mutant_Pct*(100-PBRM1mutant_Pct)/N_in_group))
#Confidence interval cannot be <0
pbrm_graph$LCI[pbrm_graph$LCI <0] <-0
pbrm_by_ccrcc <- ggplot(pbrm_graph, aes(x = ccrccCluster, y = PBRM1mutant_Pct, fill = ccrccCluster)) +
geom_bar(stat = "identity") +
geom_errorbar( aes(x= ccrccCluster, ymin=LCI, ymax=UCI), width=0.05, colour="black", size=1)+
scale_fill_manual(values = ccrcc_colors) +
labs(title = "CM9: PBRM1 status in ccrccCluster",
subtitle = "Baseline, N=33",
x = "Groups from ccrccCluster",
y = "PBRM1 mutant, %",
color = "ORR") +
theme(legend.position = "bottom")+
geom_text(data = pbrm_graph,
aes(x = ccrccCluster, y = -10,
label = paste("N=",N_in_group)),
inherit.aes = FALSE, hjust = 0.5, vjust = 0,
size = 4) +
theme_dj(12)
pbrm_by_ccrcc
```
## Odds Ratio for PBRM1
I will compare Odds ratio for OR in the PBRM1 mutants versus WT patients.
Analysis requires a binary response metric
+ Response20pct=="Not20pct" <- 0
+ Response20pct=="20pctDec" <- 1
glm(OR_num ~ PBRM1_status, data=clinicalData_pbrm1 ,family="binomial")
```{r odds_PBRM1_status}
clinicalData_pbrm1$OR_num <- NA
clinicalData_pbrm1$OR_num[which(clinicalData_pbrm1$Response20pct=="Not20pct")] <- 0
clinicalData_pbrm1$OR_num[which(clinicalData_pbrm1$Response20pct=="20pctDec")] <- 1
or <- glm(OR_num ~ PBRM1_status, data=clinicalData_pbrm1,family="binomial")
#show the output
broom::tidy(or, exponentiate = FALSE)
broom::tidy(or, exponentiate = TRUE)
#Collect terms from model
pbrm_OR <- exp(summary(or)$coefficients["PBRM1_statusMutant",1])
pbrm_logOR <- (summary(or)$coefficients["PBRM1_statusMutant",1])
pbrm_SE.logOR <- summary(or)$coefficients["PBRM1_statusMutant",2]
pbrm_lo.logOR<- (summary(or)$coefficients["PBRM1_statusMutant",1] + qnorm(0.025) * summary(or)$coefficients["PBRM1_statusMutant",2])
pbrm_up.logOR<- (summary(or)$coefficients["PBRM1_statusMutant",1] + qnorm(0.975) * summary(or)$coefficients["PBRM1_statusMutant",2])
pbrm_Pvalue <- summary(or)$coefficients["PBRM1_statusMutant",4]
```
## Odds Ratio for ccrcc4 Cluster
I will compare Odds ratio for OR in the ccrcc4 cluster members versus rest of patients.
glm(OR_num ~ ccrcc4_binary, data=sdrfScreen,family="binomial")
```{r odds_ccrcc4}
#compare ccrcc4 cluster members to rest
sdrfScreen$ccrcc4_binary <- NA
sdrfScreen$ccrcc4_binary <- "Notccrcc4"
sdrfScreen$ccrcc4_binary[sdrfScreen$ccrccCluster == "ccrcc4"] <- "ccrcc4"
sdrfScreen$ccrcc4_binary <- factor(sdrfScreen$ccrcc4_binary,
levels = c("Notccrcc4", "ccrcc4"))
or <- glm(OR_num ~ ccrcc4_binary, data=sdrfScreen,family="binomial")
#show the output
broom::tidy(or, exponentiate = FALSE)
broom::tidy(or, exponentiate = TRUE)
#Collect terms from model
ccrcc4_OR <- exp(summary(or)$coefficients["ccrcc4_binaryccrcc4",1])
ccrcc4_logOR <- (summary(or)$coefficients["ccrcc4_binaryccrcc4",1])
ccrcc4_SE.logOR <- summary(or)$coefficients["ccrcc4_binaryccrcc4",2]
ccrcc4_lo.logOR<- (summary(or)$coefficients["ccrcc4_binaryccrcc4",1] + qnorm(0.025) * summary(or)$coefficients["ccrcc4_binaryccrcc4",2])
ccrcc4_up.logOR<- (summary(or)$coefficients["ccrcc4_binaryccrcc4",1] + qnorm(0.975) * summary(or)$coefficients["ccrcc4_binaryccrcc4",2])
ccrcc4_Pvalue <- summary(or)$coefficients["ccrcc4_binaryccrcc4",4]
```
## Odds ratio for Signature scores
This calculates the Odds Ratio for each Signature score (for the 75th vs 25th Percentile from continuous Score) against Overall Response (as a binary metric).
glm(OR_num ~ score)
Delta Score = 75th-25th percentile of Score
And use the glm and the delta score in contrastTable:: function to calculate the Odds Ratio.
```{r contrasts_signatures}
#Uses function contrastTable
comp_sign <-c("Merck18.Score",
"CD3TCR.Score",
"IM150_Teff.Score",
"IM150_Angio.Score",
"Adenosine.Score",
"IM150_MyeloidInfl.Score",
"EMTstroma.Score",
"Javelin.Score")
df_forestPl <- NULL
for(i in comp_sign){
df <- sdrfScreen
df$score <- df[[i]]
or <- glm(OR_num ~ score, data=df,family="binomial")
quant <- quantile(df$score, c( .25, .75))
deltaSc <- ( quant[2] -quant[1])
L <- cbind( Intercept=0, score = deltaSc )
ctrtbl <- as.data.frame(contrastTable( or, L, level = 0.95 ))
ctrtbl$Signature <- i
df_forestPl <- rbind(df_forestPl, ctrtbl)
}
```
## Odds ratio Table
Add the PBRM1 and ccrcc results to the Signature score results.
```{r forest_add_ccrcc}
#Add pbrm1 annotation
df_forestPl[nrow(df_forestPl)+1,] <- c(pbrm_OR,
pbrm_logOR,
pbrm_SE.logOR,
pbrm_lo.logOR,
pbrm_up.logOR,
"0.95",
NA,
pbrm_Pvalue,
"PBRM1_status")
#Add ccrcc annotation
df_forestPl[nrow(df_forestPl)+1,] <- c(ccrcc4_OR,
ccrcc4_logOR,
ccrcc4_SE.logOR,
ccrcc4_lo.logOR,
ccrcc4_up.logOR,
"0.95",
NA,
ccrcc4_Pvalue,
"ccrcc4.cluster")
df_forestPl <- df_forestPl %>% mutate_at(1:8,as.numeric)
```
```{r forest_label}
df_forestPl$label <- paste0("OR: ", format(round(exp(df_forestPl$logOR), 2), nsmall = 2),
" [", format(round(exp(df_forestPl$lo.logOR), 2), nsmall = 2),
", ", format(round(exp(df_forestPl$up.logOR), 2), nsmall = 2), "]")
df_forestPl$label <- paste0(df_forestPl$Signature, "\n", df_forestPl$label)
```
## Forest Plot of all Odds Ratios
```{r forest_plot}
#Sort the X axis by P value using 'reorder'
forestplot <- ggplot(data=df_forestPl,aes(x=(reorder(label, -Pvalue)), y=logOR*log2(exp(1)),ymin=lo.logOR*log2(exp(1)), ymax=up.logOR*log2(exp(1))), legend=label) +
geom_pointrange(show.legend=T) +
geom_hline(yintercept=0, lty=2) + # add a dotted line at x=1 after flip
xlab(NULL) +
ylab("log2(Odds Ratio)") +
theme(text = element_text(size=10)) +
ggtitle("CM9: Odds Ratio for ccrcc4, and Signature Scores")+
geom_text(data = df_forestPl,
aes(x = label, y = -2.5,
label = paste("P=",round(Pvalue,3))),
inherit.aes = FALSE, hjust = 0, vjust = -0.5,
size = 4) +
coord_flip() + # flip coordinates (puts labels on y axis)
theme_dj(12)
print(forestplot)
```
## Results table: AUC and Odds ratios for signatures
```{r AUC_Odds_table}
#This drops the ccrcc because it does not have a result in ROC analyses
results <- left_join(df_data, df_forestPl,
by = c("Biomarker" = "Signature"))
results <- results %>%
rename(AUC = Stat) %>%
select(-label)
results$AUC <- gsub("N= 56, AUC: ", "", results$AUC)