-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5-ber-flags.Rmd
1907 lines (1537 loc) · 80.5 KB
/
5-ber-flags.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: "5 Hazard Flags and BER"
author: "Katie Paul Friedman"
date: "`r Sys.Date()`"
output:
html_document:
code_folding: hide
collapsed: yes
df_print: paged
lightbox: no
number_sections: yes
self_contained: yes
thumbnails: no
toc: yes
toc_float: yes
pdf_document:
toc: yes
---
```{r setup, warning=FALSE, message=FALSE, echo=FALSE}
library(caret)
library(cowplot)
library(data.table)
library(DescTools)
library(dplyr)
library(DT)
library(ggplot2)
library(ggpmisc)
library(ggstance)
library(gplots)
library(grid)
library(gridExtra)
library(httk)
library(kableExtra)
library(jtools)
library(openxlsx)
library(parallel)
library(plotly)
library(randomForest)
library(RMySQL)
library(stringr)
library(tictoc)
library(tidyr)
library(tcpl)
library(viridis)
## this section for ComplexHeatmap ##
#if (!require("BiocManager", quietly = TRUE))
# install.packages("BiocManager")
#BiocManager::install("ComplexHeatmap")
library(circlize)
library(ComplexHeatmap)
```
# Load Data {.tabset .tabset-fade .tabset-pills}
```{r, warning=FALSE}
## these were the files originally loaded
#load(file='./source/in_vitro/tier1_NAMs_apcra_pro_02262024.RData')
#load(file='./source/chem/apcra_chem_ad.RData')
#asnm.tier1.all.invivo <- read.xlsx('./output/asnm_tier1_all_invivo.xlsx', colNames = TRUE, sheet=1) %>% as.data.table()
#seem3 <- fread('./source/exposure/SupTable-all.chem.preds-2018-11-28.txt')
## in subsequent revision, we load the RData to simplify
load('./output/APCRA_haz_flg_BER.RData')
# I tried using this RData from Git but it did not contain any of our DTXSIDs:
#load(file='./source/exposure/new.chem.preds-2019-12-13.RData')
#seem3 <- chem.preds
```
```{r, warning=FALSE}
colnames(mega.mc5) # this is going to have the hazard information we need
```
# Calculating BERs {.tabset .tabset-fade .tabset-pills}
## Examine and add SEEM3
* Here are the 8 APCRA substances for which there are no SEEM3 data reported.
* They appear generally to be salts, with a few that are not.
```{r, warning=FALSE, eval=FALSE}
seem.apcra <- seem3[dsstox_substance_id %in% apcra.list[,DTXSID]] # only 193...
apcra.list[!DTXSID %in% seem.apcra$dsstox_substance_id]
```
* Fifteen chemicals had missing SEEM3 U95 values.
```{r, warning=FALSE, eval=FALSE}
seem.apcra[is.na(seem3.u95) & !is.na(seem3)]
```
* For these, the median SEEM3 estimate was substituted.
* log10-SEEM3 values were also calculated for log10 BER computation.
```{r, warning=FALSE, eval=FALSE}
seem.apcra[is.na(seem3.u95)& !is.na(seem3), seem3.u95 := seem3]
seem.apcra[,seem3.log10 := log10(seem3)]
seem.apcra[,seem3.u95.log10 := log10(seem3.u95)]
```
* Adding in SEEM3 to the sheet and calculating BERs.
```{r calc-bers, warning=FALSE, eval=FALSE}
asnm.tier1.all.invivo$seem3.u95.log10 <- seem.apcra$seem3.u95.log10[match(asnm.tier1.all.invivo$dsstox_substance_id,
seem.apcra$dsstox_substance_id)]
asnm.tier1.all.invivo$seem3.log10 <- seem.apcra$seem3.log10[match(asnm.tier1.all.invivo$dsstox_substance_id,
seem.apcra$dsstox_substance_id)]
asnm.tier1.all.invivo[,ber.targeted := median(aed50.atg,
aed50.bsk,
aed50.ccte,
aed50.nvs, na.rm=TRUE) - seem3.u95.log10]
asnm.tier1.all.invivo[,ber.httr := median(aed50.httr.heparg,
aed50.httr.u2os,
aed50.httr.mcf7, na.rm=TRUE) - seem3.u95.log10]
asnm.tier1.all.invivo[,ber.htpp := ifelse(!is.na(aed50.htpp.u2os), aed50.htpp.u2os - seem3.u95.log10, NA)]
asnm.tier1.all.invivo[,ber.astar := median(aed50.astar.beas2b,
aed50.astar.hek293,
aed50.astar.hepg2,
na.rm=TRUE) - seem3.u95.log10]
asnm.tier1.all.invivo[,ber.med.aed50 := med.aed50 - seem3.u95.log10]
review <-
asnm.tier1.all.invivo[ber.med.aed50 < 4]
```
* In general, BER was NA when SEEM3 was missing, except for one silane with no median AED50.
```{r, warning=FALSE}
asnm.tier1.all.invivo[is.na(ber.med.aed50), c('chnm','med.aed50','seem3.u95.log10')] # these are missing exposure values and/or bioactivity values
```
* 56 APCRA pro only chemicals with BER <4
* 40 APCRA pro only chemicals with BER <3
```{r, warning=FALSE}
asnm.tier1.all.invivo <- asnm.tier1.all.invivo[order(-ber.med.aed50)]
asnm.tier1.all.invivo[ber.med.aed50 < 4 & apcra.pro.only==1,
c('chnm','apcra.pro.only','med.aed50','seem3.u95.log10','ber.med.aed50')] #56 rows
```
* As a group the silanes generally have caution on their AQC.
* Presence of silanes in the low BER group is therefore maybe associated with more uncertainty.
```{r,warning= FALSE}
asnm.tier1.all.invivo[grep('silane',chnm),c('chnm','dsstox_substance_id','T0','T4','Call','aqc_iv_pass','aqc_indicator')]
```
## Prepare BER plotting
```{r, warning=FALSE}
asnm.tier1.all.plot <- melt.data.table(asnm.tier1.all.invivo,
id.vars = c('dsstox_substance_id',
'chnm',
'CASRN',
'apcra.pro.only',
"ber.targeted",
"ber.httr",
"ber.htpp",
"ber.astar",
"ber.med.aed50",
"aqc_indicator"),
measure.vars = c("log.repdose.any.5th",
"aed50.atg",
"aed50.bsk",
"aed50.ccte",
"aed50.nvs",
"aed50.stm",
"aed50.httr.mcf7",
"aed50.httr.u2os",
"aed50.httr.heparg",
"aed50.htpp.u2os",
"aed50.astar.beas2b",
"aed50.astar.hepg2",
"aed50.astar.hek293",
"med.aed50",
"min.aed50",
"seem3.u95.log10",
"seem3.log10"),
variable.name = 'types',
value.name = 'values')
asnm.tier1.all.plot <- asnm.tier1.all.plot[order(-ber.med.aed50)]
```
```{r, warning=FALSE, fig.width=9, fig.height=21, dpi=450}
ber.all <- ggplot(data=asnm.tier1.all.plot[!is.na(ber.med.aed50)],
aes(x=reorder(factor(chnm),-ber.med.aed50),
y=values,
group = factor(types),
shape = factor(types),
color = factor(types)))+
geom_point(size=3)+
scale_colour_viridis(discrete=TRUE,
name = 'Values',
breaks=c("log.repdose.any.5th", "aed50.atg",
"aed50.bsk", "aed50.ccte", "aed50.nvs", "aed50.stm", "aed50.httr.mcf7",
"aed50.httr.u2os", "aed50.httr.heparg", "aed50.htpp.u2os", "aed50.astar.beas2b",
"aed50.astar.hepg2", "aed50.astar.hek293", "seem3.u95.log10", "seem3.log10"),
labels=c('5th%-ile POD All',
'ATG AED50',
'BSK AED50',
'MEA AED50',
'NVS AED50',
'STM AED50',
'HTTr MCF7 AED50',
'HTTr U2OS AED50',
'HTTr HepaRG AED50',
'HTPP U2OS AED50',
'ASTAR BEAS2B AED50',
'ASTAR HepG2 AED50',
'ASTAR HEK293 AED50',
'SEEM3 U95',
'SEEM MED'
)) +
scale_shape_manual(name = 'Values',
breaks=c("log.repdose.any.5th", "aed50.atg",
"aed50.bsk", "aed50.ccte", "aed50.nvs", "aed50.stm", "aed50.httr.mcf7",
"aed50.httr.u2os", "aed50.httr.heparg", "aed50.htpp.u2os", "aed50.astar.beas2b",
"aed50.astar.hepg2", "aed50.astar.hek293", "seem3.u95.log10", "seem3.log10"),
values=c(15,16,17,18,8,9,15,16,17,18,8,9,15,16,17,18,8,9),
labels=c('5th%-ile POD All',
'ATG AED50',
'BSK AED50',
'MEA AED50',
'NVS AED50',
'STM AED50',
'HTTr MCF7 AED50',
'HTTr U2OS AED50',
'HTTr HepaRG AED50',
'HTPP U2OS AED50',
'ASTAR BEAS2B AED50',
'ASTAR HepG2 AED50',
'ASTAR HEK293 AED50',
'SEEM3 U95',
'SEEM MED'))+
xlab('')+
#ylab('log10-mg/kg/day')+
theme_bw() +
theme(
#axis.text.x = element_text(angle=90, vjust=0.5),
axis.title.y = element_text(size=12, face='bold'),
axis.title.x = element_blank(),
axis.text.y = element_blank(),
legend.position = 'bottom')+
scale_y_continuous(breaks=seq(-13,5,2))+
guides(colour=guide_legend(nrow=5))+
annotate("rect",
ymin = -9,
ymax = 7,
xmin = 134,
xmax = 190,
fill = "red",
alpha = 0.1,
size = 1,
color = "red")+
annotate("text",
x = 188,
y=-11,
label="A",
size=10,
hjust=0,
vjust=1)+
coord_flip()
#+
# theme(axis.text.y = element_text(colour=retro))
ber.all
```
```{r, warning=FALSE, echo=FALSE, fig.width=9, fig.height=8, dpi=450}
asnm.tier1.a <- asnm.tier1.all.plot[ber.med.aed50 <4 & apcra.pro.only==1]
ber.complex <- ggplot(data=asnm.tier1.a[types %in% c("log.repdose.any.5th", "aed50.atg",
"aed50.bsk", "aed50.ccte", "aed50.nvs", "aed50.stm", "aed50.httr.mcf7",
"aed50.httr.u2os", "aed50.httr.heparg", "aed50.htpp.u2os", "aed50.astar.beas2b",
"aed50.astar.hepg2", "aed50.astar.hek293", "seem3.u95.log10")],
aes(x=reorder(factor(chnm),-ber.med.aed50),
y=values,
group = factor(types),
shape = factor(types),
color = factor(types)))+
geom_point(size=3)+
scale_colour_viridis(discrete=TRUE,
name = 'Values',
breaks=c("log.repdose.any.5th", "aed50.atg",
"aed50.bsk", "aed50.ccte", "aed50.nvs", "aed50.stm", "aed50.httr.mcf7",
"aed50.httr.u2os", "aed50.httr.heparg", "aed50.htpp.u2os", "aed50.astar.beas2b",
"aed50.astar.hepg2", "aed50.astar.hek293", "seem3.u95.log10"),
labels=c('5th%-ile POD All',
'ATG AED50',
'BSK AED50',
'MEA AED50',
'NVS AED50',
'STM AED50',
'HTTr MCF7 AED50',
'HTTr U2OS AED50',
'HTTr HepaRG AED50',
'HTPP U2OS AED50',
'ASTAR BEAS2B AED50',
'ASTAR HepG2 AED50',
'ASTAR HEK293 AED50',
'SEEM3 U95'
)) +
scale_shape_manual(name = 'Values',
breaks=c("log.repdose.any.5th", "aed50.atg",
"aed50.bsk", "aed50.ccte", "aed50.nvs", "aed50.stm", "aed50.httr.mcf7",
"aed50.httr.u2os", "aed50.httr.heparg", "aed50.htpp.u2os", "aed50.astar.beas2b",
"aed50.astar.hepg2", "aed50.astar.hek293", "seem3.u95.log10"),
values=c(15,16,17,18,8,9,15,16,17,18,8,9,15,16,17,18,8),
labels=c('5th%-ile POD All',
'ATG AED50',
'BSK AED50',
'MEA AED50',
'NVS AED50',
'STM AED50',
'HTTr MCF7 AED50',
'HTTr U2OS AED50',
'HTTr HepaRG AED50',
'HTPP U2OS AED50',
'ASTAR BEAS2B AED50',
'ASTAR HepG2 AED50',
'ASTAR HEK293 AED50',
'SEEM3 U95'
))+
xlab('')+
#ylab('log10-mg/kg/day')+
theme_bw() +
theme(
#axis.text.x = element_text(angle=90, vjust=0.5),
axis.title.y = element_text(size=12, face='bold'),
axis.text.y=element_text(size=10),
axis.title.x = element_blank(),
legend.position = 'bottom')+
scale_y_continuous(breaks=seq(-13,5,1))+
guides(colour=guide_legend(nrow=5))+
annotate("text",
x = 56,
y=-6,
label="B",
size=10,
hjust=0,
vjust=1)+
coord_flip()
ber.complex
```
* Reduce complexity
```{r, warning=FALSE, fig.width=8, fig.height=8, dpi=450}
asnm.tier1.b <- asnm.tier1.all.plot[ber.med.aed50 <4 & aqc_indicator==1 & apcra.pro.only==1]
#unique(asnm.tier1.b$dsstox_substance_id) #13 substances
#retro <- ifelse(asnm.tier1.a$apcra.ret==1, "red","black")
#retro.face <- ifelse(asnm.tier1.a$apcra.ret==1, "italic","plain")
ber.simple <- ggplot(data=asnm.tier1.b[ types %in% c("log.repdose.any.5th",
"med.aed50",
"seem3.log10",
"seem3.u95.log10")],
aes(x=reorder(factor(chnm),-ber.med.aed50),
y=values,
group = factor(types),
shape = factor(types),
color = factor(types)))+
geom_point(size=3)+
scale_colour_manual(values=c('#481567FF',
'#2D708EFF',
'#3CBB75FF',
'#95D840FF'),
name = 'Values',
breaks=c("log.repdose.any.5th",
"med.aed50",
"seem3.u95.log10",
"seem3.log10"),
labels=c('5th%-ile POD All',
"Med AED50",
"SEEM3 U95",
"SEEM3"
)) +
scale_shape_manual(name = 'Values',
breaks=c("log.repdose.any.pod",
"med.aed50",
"seem3.u95.log10",
"seem3.log10"),
labels=c('5th%-ile POD All',
"Med AED50",
"SEEM3 U95",
"SEEM3"),
values=c(15,16,17,18))+
xlab('')+
#ylab('log10-mg/kg/day')+
theme_bw() +
theme(
#axis.text.x = element_text(angle=90, vjust=0.5),
axis.text = element_text(size=10),
axis.title.y=element_text(size=14,face='bold'),
axis.title.x = element_blank(),
legend.position = 'bottom')+
scale_y_continuous(breaks=seq(-9,5,2))+
guides(colour=guide_legend(nrow=2))+
annotate("text",
x = 43,
y=-8,
label="C",
size=10,
hjust=0,
vjust=1)+
coord_flip()
#theme(axis.text.y = element_text(colour=retro, face=retro.face))
ber.simple
```
```{r, warning=FALSE, fig.height=9, fig.width=9}
bplusc <- plot_grid(ber.complex, ber.simple, rel_heights = c(1,1), rel_widths = c(1,1), nrow=2)
```
```{r, warning=FALSE, fig.width=18, fig.height=18}
plot_grid(ber.all, bplusc, rel_widths = c(1,1), rel_heights = c(1,1), ncol=2)
```
```{r, warning=FALSE}
layout <- matrix(c(1,1,2,2,2,
1,1,2,2,2,
1,1,3,3,3,
1,1,3,3,3), nrow=4, byrow=TRUE)
# multiplot was obtained from
# http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_%28ggplot2%29/
multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) {
require(grid)
# Make a list from the ... arguments and plotlist
plots <- c(list(...), plotlist)
numPlots = length(plots)
# If layout is NULL, then use 'cols' to determine layout
if (is.null(layout)) {
# Make the panel
# ncol: Number of columns of plots
# nrow: Number of rows needed, calculated from # of cols
layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),
ncol = cols, nrow = ceiling(numPlots/cols))
}
if (numPlots==1) {
print(plots[[1]])
} else {
# Set up the page
grid.newpage()
pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout))))
# Make each plot, in the correct location
for (i in 1:numPlots) {
# Get the i,j matrix positions of the regions that contain this subplot
matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))
print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,
layout.pos.col = matchidx$col))
}
}
}
file.dir <- paste("./output", sep="")
file.name <- paste("/Figure_BER_", Sys.Date(), ".png", sep="")
file.path <- paste(file.dir, file.name, sep="")
dir.create(path=file.dir, showWarnings = FALSE, recursive = TRUE)
png(file.path, width = 10000, height = 9000, res=600)
multiplot(ber.all, ber.complex, ber.simple, layout = layout)
dev.off()
```
```{r, warning=FALSE}
Table1redo <- asnm.tier1.all.invivo[ber.med.aed50< 4 & apcra.pro.only==1 & is.na(log.repdose.any.25th) & aqc_indicator==1, c('dsstox_substance_id','preferred_name','ber.med.aed50', 'log.repdose.any.25th','med.aed50', 'seem3.u95.log10', 'seem3.log10')]
Table1redo <- Table1redo %>% mutate_if(is.numeric, ~round(., 2))
Table1redo
```
```{r, warning=FALSE}
Table2redo <- asnm.tier1.all.invivo[ber.med.aed50 > 3 & med.aed50 > 2 & pod.ratio > -0.5 & aqc_indicator==1, c('dsstox_substance_id','preferred_name','log.repdose.any.5th', 'med.aed50', 'ber.med.aed50', 'pod.ratio', 'aqc_indicator')]
Table2redo <- Table2redo %>% mutate_if(is.numeric, ~round(., 2))
Table2redo
```
```{r, warning=FALSE, eval=FALSE}
redo_tables <- list('Table1_HighPriorityChems' = as.data.frame(Table1redo),
'Table2_LowPriorityChems' = as.data.frame(Table2redo))
#write.xlsx(redo_tables, './output/Draft_Table1_Table2_APCRA_Pro_27May2024.xlsx')
```
## Compare HepaRG POD to other POD
```{r, warning=FALSE}
heparg.comp <- asnm.tier1.all.invivo[,c('dsstox_substance_id',
'aed50.httr.heparg',
'aed50.httr.u2os',
'aed50.httr.mcf7',
'med.aed50',
'min.aed50',
'p5.toxval.numeric',
'p25.toxval.numeric'
)]
heparg.comp[, httr.min.aed50.nonheparg := min(aed50.httr.heparg,aed50.httr.mcf7, na.rm = TRUE), by=c('dsstox_substance_id')]
heparg.comp[, httr.heparg.diff := ifelse(!is.na(httr.min.aed50.nonheparg), httr.min.aed50.nonheparg - aed50.httr.heparg, NA), by=c('dsstox_substance_id')]
range(heparg.comp$httr.heparg.diff, na.rm=TRUE) #-3.2 to 0
hist(heparg.comp$httr.heparg.diff, na.rm=TRUE)
```
```{r, warning=FALSE}
heparg.comp.long <- melt.data.table(heparg.comp,
id.vars = c('dsstox_substance_id',
'aed50.httr.heparg'),
measure.vars = c('httr.min.aed50.nonheparg',
'med.aed50',
'p5.toxval.numeric',
'p25.toxval.numeric'),
variable.name = c('POD'),
value.name = c('value'))
```
```{r, warning=FALSE}
heparg.httr <- ggplot(data=heparg.comp.long,
aes(x=aed50.httr.heparg,
y=value))+
geom_point(aes(x=aed50.httr.heparg,
y=value), alpha=0.5, size=2)+
coord_cartesian(xlim=c(-4,6), ylim=c(-4,6))+
theme_bw()+
geom_abline(color='black')+
geom_abline(intercept = 0.5, slope = 1, color="dark gray",
linetype="dashed", size=0.75)+
geom_abline(intercept = -0.5, slope = 1, color="dark gray",
linetype="dashed", size=0.75)+
xlab('HepaRG HTTr AED50, log10-mg/kg/day')+
ylab('POD value, log10-mg/kg/day')+
theme(axis.text = element_text(size=12),
axis.title = element_text(size=14))+
facet_wrap(~POD, scales='fixed')+
theme(strip.background = element_rect(fill='white',size=1),
strip.text = element_text(size=10, color='black',face='bold'))
heparg.httr
```
```{r, warning=FALSE, eval=FALSE}
file.dir <- paste("./output", sep="")
file.name <- paste("/Figure_HepaRG_", Sys.Date(), ".png", sep="")
file.path <- paste(file.dir, file.name, sep="")
dir.create(path=file.dir, showWarnings = FALSE, recursive = TRUE)
png(file.path, width = 4000, height = 4000, res=600)
heparg.httr
dev.off()
```
## SEEM Credible Interval Size vs BER
```{r, warning=FALSE}
ber.v.seem <- asnm.tier1.all.invivo[,c('dsstox_substance_id','ber.med.aed50', 'seem3.u95.log10','seem3.log10', 'med.aed50')]
ber.v.seem[ ,cred.int.size := seem3.u95.log10 - seem3.log10]
ber_seem <- ggplot(data=ber.v.seem,
aes(x=cred.int.size,
y=ber.med.aed50))+
geom_point(aes(x=cred.int.size,
y=ber.med.aed50), alpha=0.5, size=2)+
#coord_cartesian(xlim=c(-4,6), ylim=c(-4,6))+
theme_bw()+
geom_smooth(method='lm',se=FALSE,color='blue',formula=y~x)+
stat_poly_eq(formula=y ~x,
eq.with.lhs = "y~`=`~",
aes(label=paste0("atop(", ..eq.label.., ",", ..rr.label.., ")")),
label.x.npc = 0.8,
label.y.npc = 0.8,
parse=TRUE)+
xlab('SEEM3 U95 - SEEM3 Median, log10-mg/kg/day')+
ylab('BER')+
theme(axis.text = element_text(size=12),
axis.title = element_text(size=14))
ber_seem
```
```{r, warning=FALSE}
file.dir <- paste("./output", sep="")
file.name <- paste("/Figure_BER_v_SEEMCredInt_", Sys.Date(), ".png", sep="")
file.path <- paste(file.dir, file.name, sep="")
dir.create(path=file.dir, showWarnings = FALSE, recursive = TRUE)
png(file.path, width = 4000, height = 4000, res=600)
ber_seem
dev.off()
```
# Developmental and reproductive toxicity (DART) {.tabset .tabset-fade .tabset-pills}
Dev tox flag will be added to the ER/AR flags as a set for DART prediction flag. The dev tox flag consists of Stemina devTox quick-Predict data and an in silico flag from TEST.
## Reference chemicals for developmental toxicity
Using Zurlinden et al 2019 for reference chemicals.
Can see that the devtox TEST prediction is not necessarily accurate.
```{r load-dev-refchem, warning=FALSE}
devref <- fread('./source/in_vitro/devtox_reference_zurlinden_2019.csv')
devref <- devref[-26,]
devref[1:17, ref:= 'TP']
devref[18:26, ref:= 'FN']
devref[27:42, ref:= 'TN']
devref[,c('DTXSID','PREFERRED_NAME','ref','DEVTOX_TEST_PRED')]
```
What is the overlap with APCRA 201 substances?
Seemingly only one true positive...and not one captured by Stemina (PTU).
```{r, warning=FALSE}
devref[DTXSID %in% apcra.list$DTXSID]
```
Load mc5 for some positive reference chemicals for DART overall (dev, ER, AR)
```{r, warning=FALSE}
dart.ref <- c(
'DTXSID5022308', #genistein
'DTXSID3020465', #diethylstilbestrol
'DTXSID7020182', #bisphenol a
'DTXSID7032004', #flutamide
'DTXSID4022361', #vinclozolin
'DTXSID7021239', #retinoic acid
'DTXSID9022524', #thalidomide
'DTXSID2020634', #5-fluorouracil
'DTXSID6025438', #hydroxyurea
'DTXSID1020194' #boric acid
)
```
Here we pull the DART reference chemical mc5 for Stemina from invitrodb v3.5.
```{r, eval=FALSE, echo=FALSE,warning=FALSE}
tcplConf(user='_dataminer', pass='pass', db='prod_internal_invitrodb_v3_5', drvr='MySQL', host='ccte-mysql-res.epa.gov')
```
```{r, warning=FALSE, eval=FALSE}
dart.mc5 <- tcplPrepOtpt(tcplLoadData(lvl=5, type='mc',fld='aeid', val=c(1691,1858)))
dart.mc5 <- dart.mc5[dsstox_substance_id %in% dart.ref]
```
## Add dev datasets
* 61 APCRA substances were screened in multi-conc in Stemina (STM).
* An additional 5 substances appeared positive in the single-conc screen but were not re-screened; as such a positive is inferred at the concentration screened in single conc (100 uM).
```{r, eval=FALSE, warning=FALSE}
stm <- mega.mc5[asnm=='STM']
#length(unique(stm$dsstox_substance_id)) #66
stm.mc.dtxsids <- unique(stm$dsstox_substance_id) # 6 of these were added as positives from sc that never advanced to mc (from previous processing)
#stm[hitc==1 & is.na(modl_tp)]
#added.dtxsid <- stm[is.na(modl_prob), dsstox_substance_id]
#stm[dsstox_substance_id %in% added.dtxsid, modl_acc := 2]
#stm[dsstox_substance_id %in% added.dtxsid, acc_uM := 100]
```
* Reshape the multi-conc data.
```{r, eval=FALSE, warning=FALSE}
# cast data to combine them.
mc5.stm.wide <- dcast.data.table(stm[aeid %in% c(1691,1858)], dsstox_substance_id + chnm ~ aenm,
value.var = 'modl_acc',
fun.aggregate= min)
mc5.dartref.wide <- dcast.data.table(dart.mc5[aeid %in% c(1691,1858)], dsstox_substance_id + chnm ~ aenm,
value.var = 'modl_acc',
fun.aggregate= min)
mc5.stm.wide <- rbind(mc5.stm.wide,
mc5.dartref.wide)
```
* Negatives need to be inferred for the single conc screened substances that were negative.
* 133 chemicals with single conc screening data from the APCRA list.
```{r, eval=FALSE, warning=FALSE}
add.wide <- dcast.data.table(sc2.stm[aeid==1691 & !dsstox_substance_id %in% stm.mc.dtxsids & hitc==0], dsstox_substance_id + chnm ~aenm,
value.var='hitc',
fun.aggregate=max)
add.wide[,STM_H9_Viability_norm := NA]
#length(unique(add.wide$dsstox_substance_id)) #133
```
## Calculate dev flag
* Calculate the DEV flag.
* Any hit in STM_H9_OrnCyssISnorm_ratio_dn considered relevant as a DEV flag.
* Hits where the distance from the parallel viability assay is more then 0.25 log are considered selective flags.
```{r, eval=FALSE, warning=FALSE}
dev.flag <- rbind(mc5.stm.wide,
add.wide, fill=TRUE)
dev.flag[,stm.cyto.dist := ifelse(!is.na(STM_H9_Viability_norm), STM_H9_Viability_norm - STM_H9_OrnCyssISnorm_ratio_dn, 3 - STM_H9_OrnCyssISnorm_ratio_dn)]
dev.flag[,dev.flag := 0]
dev.flag[!is.na(STM_H9_OrnCyssISnorm_ratio_dn), dev.flag := 1]
dev.flag[,dev.flag.specific := 0]
dev.flag[stm.cyto.dist >0.25, dev.flag.specific := 1]
```
Add TEST DEV TOX prediction and the applicability domain.
```{r, eval=FALSE, warning=FALSE}
load('./source/chem/apcra_chem_ad.RData')
setnames(test.opera.pred.total, c('DTXSID','PREFERRED_NAME'), c('dsstox_substance_id','chnm'), skip_absent = TRUE)
dev.flag$test.devtox.score <- test.opera.pred.total$DEVTOX_TEST_PRED[match(dev.flag$dsstox_substance_id,
test.opera.pred.total$dsstox_substance_id)]
# replace Inf with NA
for (j in 1:ncol(dev.flag)) set(dev.flag, which(is.infinite(dev.flag[[j]])), j, NA)
# replace - with NA
dev.flag[,c('test.devtox.score')] <- lapply(dev.flag[,c('test.devtox.score')], function(col) as.numeric(gsub("-$|\\,",NA, col)))
dev.flag$aqc_indicator <- ad.tbl$aqc_indicator[match(dev.flag$dsstox_substance_id, ad.tbl$DTXSID)]
dev.flag$apcra.pro.only <- ad.tbl$apcra.pro.only[match(dev.flag$dsstox_substance_id, ad.tbl$DTXSID)]
```
## Create Endocrine Hazard Flags
* Match the logic in the recent comments provided to the EPA program office partners on a prioritization and screening workflow using ER and AR models.
+ If ToxCast ER/AR pathway models available: these scores trump CERAPP and COMPARA.
+ ToxCast ER/AR pathway model positives: => 0.1
+ Grouped equivocals (0.001-0.1) with the negative to enable easier prioritization.
+ For ToxCast AR pathway model (older version to match what is in invitrodb version 3.3 and CompTox Chemicals Dashboard), require confidence flags to be > 2 for a positive.
+ Highlight substances with no data - could be a data gap?
```{r, eval=FALSE, warning=FALSE}
total.endo.dtxsid <- c(apcra.list$DTXSID, dart.ref)
## here we should really get the dtxsids for cerapp...
cerapp.compara <- merge.data.table(cerapp[,c('CASRN','CHEMICAL_NAME','input_SMILES','InChI_Key',
'Potency_class_2_binding', 'Potency_class_2_agonist', 'Potency_class_2_antagonist','consensus_2_binding', 'consensus_2_agonist','consensus_2_antagonist')],
by.x = 'CASRN',
all.x=TRUE,
compara[, c('dsstox_substance_id','casrn','consensus_binding', 'consensus_agonist','consensus_antagonist')],
by.y='casrn',
all.y=TRUE)
colnames(er) <- paste0('er_model_', colnames(er))
er.cerapp.compara <- merge.data.table(cerapp.compara,
er,
by.x='CASRN',
by.y='er_model_CASRN',
all.x=TRUE)
colnames(ar) <- paste0('ar_model_', colnames(ar))
er.ar.cerapp.compara <- merge.data.table(er.cerapp.compara,
ar,
by.x='CASRN',
by.y='ar_model_CASRN',
all.x=TRUE)
```
```{r erarflg-tbl, eval=FALSE, warning=FALSE}
er.ar.apcra <- er.ar.cerapp.compara[dsstox_substance_id %in% total.endo.dtxsid]
col.num <- c('consensus_2_binding', 'consensus_2_agonist', 'consensus_2_antagonist')
er.ar.apcra[, (col.num) := lapply (.SD, as.numeric), .SDcols = col.num ]
# indicate any active result from compara consensus qsar
er.ar.apcra[is.na(consensus_binding & consensus_agonist & consensus_antagonist),compara.flag := 2] # if data not available
er.ar.apcra[consensus_binding==0 & consensus_agonist==0 & consensus_antagonist==0, compara.flag := 0] # if data are all negative
er.ar.apcra[consensus_binding==1|consensus_agonist==1|consensus_antagonist==1, compara.flag := 1] # if any mode is positive
# indicate any active result from cerapp consensus qsar
er.ar.apcra[is.na(consensus_2_agonist & consensus_2_binding & consensus_2_antagonist),cerapp.flag := 2]
er.ar.apcra[consensus_2_agonist==0 & consensus_2_binding==0 & consensus_2_antagonist==0, cerapp.flag := 0]
er.ar.apcra[consensus_2_agonist==1|consensus_2_binding==1|consensus_2_antagonist==1, cerapp.flag := 1]
# create positive, equivocal, and negative code on ToxCast AR model
er.ar.apcra[is.na(ar_model_Agonist_AUC & ar_model_Antagonist_AUC), toxcast.ar.flag := 2] # data not available
er.ar.apcra[ar_model_Agonist_AUC < 0.1 & ar_model_Antagonist_AUC < 0.1|ar_model_Antagonist_AUC > 0.1 & ar_model_Antagonist_Confidence_Score <= 2, toxcast.ar.flag := 0] # grouped equivocals into the negative space
er.ar.apcra[ar_model_Agonist_AUC >= 0.1|ar_model_Antagonist_AUC >= 0.1 & ar_model_Antagonist_Confidence_Score >2,
toxcast.ar.flag := 1]
# create positive, equivocal, and negative code on ToxCast ER model
er.ar.apcra[is.na(er_model_Agonist_AUC & er_model_Antagonist_AUC), toxcast.er.flag := 2] # no data available
er.ar.apcra[er_model_Agonist_AUC< 0.1 & er_model_Antagonist_AUC < 0.1, toxcast.er.flag := 0] # grouped equivocals into the negative space
er.ar.apcra[er_model_Agonist_AUC >= 0.1|er_model_Antagonist_AUC >= 0.1, toxcast.er.flag := 1]
# require toxcast er model data to trump cerapp call
er.ar.apcra[toxcast.er.flag ==2 & cerapp.flag==2, final.er.flag :=0.1] # no data
er.ar.apcra[toxcast.er.flag ==2 & cerapp.flag==0, final.er.flag :=0] # only cerapp data and it's negative
er.ar.apcra[toxcast.er.flag ==2 & cerapp.flag==1, final.er.flag :=0.5] # only cerapp data and it's positive
er.ar.apcra[toxcast.er.flag ==0 & cerapp.flag %in% c(0,1,2), final.er.flag := 0] # er model available and negative
er.ar.apcra[toxcast.er.flag ==1 & cerapp.flag %in% c(0,1,2), final.er.flag := 1] # er model available and positive
# require toxcast ar model data to trump compara call
er.ar.apcra[toxcast.ar.flag ==2 & compara.flag==2, final.ar.flag :=0.1] # no data
er.ar.apcra[toxcast.ar.flag ==2 & compara.flag==0, final.ar.flag :=0] # only cerapp data and it's negative
er.ar.apcra[toxcast.ar.flag ==2 & compara.flag==1, final.ar.flag :=0.5] # only cerapp data and it's positive
er.ar.apcra[toxcast.ar.flag ==0 & compara.flag %in% c(0,1,2), final.ar.flag := 0] # er model available and negative
er.ar.apcra[toxcast.ar.flag ==1 & compara.flag %in% c(0,1,2), final.ar.flag := 1] # er model available and positive
er.ar.apcra[, ed.flag.sum := sum(final.er.flag, final.ar.flag), by=list(dsstox_substance_id)]
```
```{r deprecated-long-erartbl, eval=FALSE, echo=FALSE, warning=FALSE}
er.ar.apcra.long <- melt.data.table(er.ar.apcra,
id.vars = c('DTXSID', 'CASRN','preferred_name', 'ed.flag.sum',
'er_model_pseudo_AC50_median','er_model_pseudo_AC50_min','er_model_Agonist_AUC',
'er_model_Antagonist_AUC',
'ar_model_pseudo_AC50_median','ar_model_pseudo_AC50_min',
'ar_model_Agonist_AUC','ar_model_Antagonist_AUC'),
measure.vars = c('cerapp.flag',
'compara.flag',
'toxcast.er.flag',
'toxcast.ar.flag',
'final.ar.flag',
'final.er.flag'),
variable.name = 'flags',
value.name = 'flag.values')
#er.ar.apcra.long2 <- melt.data.table(er.ar.apcra.long,
# id.vars = c('DTXSID','CASRN','preferred_name','ed.flag.sum'),
# measure.vars = c('er_model_pseudo_AC50_median', 'er_model_pseudo_AC50_min',
# 'er_model_Agonist_AUC','er_model_Antagonist_AUC',
# 'ar_model_pseudo_AC50_median','ar_model_pseudo_AC50_min',
# 'ar_model_Agonist_AUC','ar_model_Antagonist_AUC'),
# variable.name = 'toxcast_models',
# value.name = 'toxcast_model_values')
er.ar.apcra.long <- er.ar.apcra.long[order(-ed.flag.sum)]
#er.ar.apcra.long2 <- unique(er.ar.apcra.long2) # this is for potency values. Maybe return to this later.
```
```{r, eval=FALSE, warning=FALSE}
er.ar.flag <- er.ar.apcra[,c("dsstox_substance_id","compara.flag","cerapp.flag","toxcast.ar.flag","toxcast.er.flag","final.er.flag", "final.ar.flag","ed.flag.sum")]
```
## DART flag
```{r, warning=FALSE}
load('./output/APCRA_haz_flg_BER.RData')
```
```{r dart-flag-prep-fig, warning=FALSE, eval=FALSE}
# add minimum NAM column for comparison
dev.flag$min_nam <- asnm.tier1$col_min[match(dev.flag$dsstox_substance_id,
asnm.tier1$dsstox_substance_id)]
dev.flag[min_nam=='CCTE', min_nam := 'MEA'] # the CCTE vendor is for the acute MEA data from Shafer lab
# define the binary flag for the TEST dev model
dev.flag[test.devtox.score > 0.7, dev.test := 0.5]
dev.flag[test.devtox.score < 0.7, dev.test := 0]
# merge dev and ER/AR flag
dart.flag <- merge.data.table(dev.flag,
er.ar.flag,
by=c('dsstox_substance_id'),
all.x=TRUE,
all.y=TRUE)
# make sure chnm is not missing
setnames(apcra.total, 'DTXSID', 'dsstox_substance_id')
setnames(apcra.total, 'preferred_name', 'chnm')
dart.flag.na <- dart.flag[is.na(chnm)]
dart.flag$chnm <- apcra.total$chnm[match(dart.flag$dsstox_substance_id,
apcra.total$dsstox_substance_id)]
dart.flag$chnm_dev <- dev.flag$chnm[match(dart.flag$dsstox_substance_id,
dev.flag$dsstox_substance_id)]
dart.flag[is.na(chnm), chnm := chnm_dev]
dart.flag[,c('chnm_dev') := NULL]
# add BER
dart.flag$ber.med.aed50 <- asnm.tier1.all.invivo$ber.med.aed50[match(dart.flag$dsstox_substance_id,
asnm.tier1.all.invivo$dsstox_substance_id)]
dart.flag <- dart.flag[order(ber.med.aed50)]
# TEST in CCD was missing values
dart.flag[dsstox_substance_id=='DTXSID2020634',test.devtox.score := 0.713]
dart.flag[dsstox_substance_id=='DTXSID6025438', test.devtox.score := 0.571]
dart.flag[dsstox_substance_id=='DTXSID7021239', test.devtox.score := 0.983]
dart.flag[dsstox_substance_id=='DTXSID9022524', test.devtox.score := 0.981]
dart.flag[dsstox_substance_id %in% c('DTXSID2020634',
'DTXSID6025438',
'DTXSID7021239',
'DTXSID9022524'), dev.test := 0.5]
```
```{r, warning=FALSE}
# further refine columns of data available
dart_mat <- dart.flag[apcra.pro.only==1]
dart_mat <- dart_mat[aqc_indicator==1]
dart_mat <- dart_mat[ber.med.aed50 < 4 ]
dart_ref_mat <- unique(dart.flag[dsstox_substance_id %in% dart.ref])
dart_ref_mat$chnm <- dev.flag$chnm[match(dart_ref_mat$dsstox_substance_id,
dev.flag$dsstox_substance_id)]
setnames(dart_mat, c('dev.test',
'dev.flag',
'dev.flag.specific',
'final.er.flag',
'final.ar.flag'),
c('DEV-TEST','DEV','DEV-S','ER','AR'))
setnames(dart_ref_mat, c('dev.test',
'dev.flag',
'dev.flag.specific',
'final.er.flag',
'final.ar.flag'),
c('DEV-TEST','DEV','DEV-S','ER','AR'))
# comprise the main matrices
dart_mat2 <- as.matrix(dart_mat[,c('DEV-TEST','DEV','DEV-S','ER','AR')])
rownames(dart_mat2) <- dart_mat[, chnm] # define rownames as chemical name
dart_ref2 <- as.matrix(dart_ref_mat[,c('DEV-TEST','DEV','DEV-S','ER','AR')])
rownames(dart_ref2) <- dart_ref_mat[, chnm] # define rownames as chemical name
head(dart_ref2)
```
```{r dart-ha, warning=FALSE}
# annotations for main hm