-
Notifications
You must be signed in to change notification settings - Fork 0
/
Acute_NFA_manuscript_submit_Jan2024.Rmd
2150 lines (1792 loc) · 83.8 KB
/
Acute_NFA_manuscript_submit_Jan2024.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: "Manuscipt: Chemical effects on neural network activity: comparison of acute versus network formation exposure in microelectrode array assays"
author: "KEC"
date: "January 02, 2023"
output:
html_document:
toc: true
toc_depth: 3
toc_float: true
code_folding: hide
number_sections: true
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE, warning=FALSE}
library(tcpl)
library(data.table)
library(VennDiagram)
library(ggplot2)
library(dplyr)
library(openxlsx)
library(gplots)
library(viridis)
library(pheatmap)
library(corrplot)
library(ggrepel)
library(ggpp)
library(ggpmisc)
library(usedist)
library(factoextra)
knitr::opts_chunk$set(echo = TRUE)
sessionInfo()
```
# 1. Load data
Load ToxCast multi-concentration (mc) and single-concentration (sc) screening data from ToxCast invitrodb v3.5, levels mc5, mc6, sc2 for the MEA_acute and MEA_dev endpoints.
More information on tcpl data processing and retrieval: https://cran.r-project.org/web/packages/tcpl/vignettes/
## multi-conc
```{r warning=FALSE, message=FALSE}
tcplConf(user='_dataminer', pass='pass', #insert user and pass
db='prod_internal_invitrodb_v3_5', drvr='MySQL',
host='ccte-mysql-res.epa.gov') #insert host
# # Load mc data
# neuro.asids <- c(20)
# neuro.assays <- tcplLoadAeid(val=neuro.asids, fld='asid',add.fld='acid')
# all.assays <- tcplLoadAeid(add.fld='asid')
#
# mc5.neuro <- tcplPrepOtpt(tcplLoadData(lvl=5,type='mc', fld='aeid',val=neuro.assays$aeid))
# mc6 <- tcplPrepOtpt(tcplLoadData(lvl=6, fld='m4id', val=mc5.neuro$m4id, type='mc'))
# setDT(mc6)
# mc6_mthds <- mc6[ , .( mc6_mthd_id = paste(mc6_mthd_id, collapse=",")), by = m4id]
# mc6_flags <- mc6[ , .( flag = paste(flag, collapse=";")), by = m4id]
# mc5.neuro$mc6_flags <- mc6_mthds$mc6_mthd_id[match(mc5.neuro$m4id, mc6_mthds$m4id)]
# mc5.neuro[, flag.length := ifelse(!is.na(mc6_flags), count.fields(textConnection(mc6_flags), sep =','), NA)]
# mc5.neuro[hitc==1,ac50_uM := ifelse(!is.na(modl_ga), 10^modl_ga, NA)]
# mc5.neuro[hitc==1,acc_uM := ifelse(!is.na(modl_acc), 10^modl_ga, NA)]
#
# mc5.neuro <- tcplSubsetChid(mc5.neuro)
# # # Load sc data
# # # the necessary sc endpoints for this analysis are not in invitrodb v3.5
# # # sc2.neuro <- tcplPrepOtpt(tcplLoadData(lvl=2, type='sc',fld='aeid',val=neuro.assays$aeid))
# #
# save(mc5.neuro,
# mc6,
# neuro.assays,
# file="./source/mc_tcpl_MEA_invitrodb_v3_5_07June23.RData")
load(file="./source/mc_tcpl_MEA_invitrodb_v3_5_07June23.RData")
```
## single-conc
This sc MEA data was not released in invitrodb v3.5 but can be accessed in the source files of this manuscript.
```{r warning=FALSE, message=FALSE}
load("source/mea_acute_and_dev_sc2_tcplSubsetChid_2022-02-10.RData")
load("source/ccte_mfr_sc_data_20Sept2022.RData")
```
## Apply ToxCast flag filters
Exclude endpoints with 3 or more flags
```{r warning=FALSE, message=FALSE}
# filter the dataset, with coarse filters, adds a column called use.me
mc5_filter <- function(df) {
df[, use.me := 0]
df[hitc==1 & flag.length < 3, use.me := 1]
df[hitc==1 & is.na(flag.length), use.me := 1]
df[hitc==1 & flag.length >= 3, use.me := 0]
df[fitc %in% c(36,45), use.me := 0]
df[hitc==-1, use.me := 0] # make hitc interpretable as a positive sum
df[use.me==0, modl_ga := as.numeric(NA)]
df[use.me==0, hitc := 0]
df[hitc==0, modl_ga := as.numeric(NA)]
}
mc5.neuro <- mc5_filter(mc5.neuro)
mc5.neuro <- mc5.neuro[!is.na(casn),] # Remove control rows, e.g. DMSO/ water
```
## Update acute LDH SC cutoff to 10pc
```{r warning=FALSE, message=FALSE}
ldh <- sc2.chid[aenm %in% 'CCTE_Shafer_MEA_LDH',]
unique(ldh[, c('bmad','coff','hitc')])
ggplot(data=ldh, aes(x=max_med))+
geom_histogram()+
geom_vline(aes(xintercept = coff))
sc2.chid[aenm %in% 'CCTE_Shafer_MEA_LDH', coff := 10]
sc2.chid[aenm %in% 'CCTE_Shafer_MEA_LDH', hitc := ifelse(max_med>10,1,0)]
```
# 2. Wrangle data tables
## Filter endpoints
Only evaluate the sc cyto endpoints (AB + LDH) and the MFR endpoint.
```{r warning=FALSE, message=FALSE}
# mc
mc5.neuro[grep("_dev",aenm), assay_type := "dev"]
mc5.neuro[grep("_acute",aenm), assay_type := "acute"]
# sc
unique(sc2.chid$aenm) #26 endpoints
length(unique(sc2.chid$chnm)) #1172 chemicals
unique(sc2.mfr$aenm) # add data for pfas chemicals in mfr endpoint
length(unique(sc2.mfr$chnm)) # 133 chemicals
setdiff(colnames(sc2.chid), colnames(sc2.mfr))
sc2.neuro <- rbind(sc2.chid, sc2.mfr, fill=T)
sc2.neuro <- sc2.neuro[!grep("DIV12",aenm),]
sc2.neuro[, assay_type := "acute"]
sc2.neuro[grep("dev_",aenm), assay_type := "dev"]
sc2.neuro <- sc2.neuro[!is.na(casn),]
exclude.sc <- c(2500,2501,2512,2513,2518,2519,2526,2527) # only evaluate MFR + cyto
sc2.neuro <- sc2.neuro[!aeid %in% exclude.sc,]
unique(sc2.neuro[, c('aenm','aeid','assay_type')])
# aenm aeid assay_type
# 1: CCTE_Shafer_MEA_dev_LDH_dn 2529 dev
# 2: CCTE_Shafer_MEA_dev_AB_dn 2530 dev
# 3: CCTE_Shafer_MEA_MFR_up 2033 acute
# 4: CCTE_Shafer_MEA_MFR_dn 2034 acute
# 5: CCTE_Shafer_MEA_LDH 2035 acute
# 6: CCTE_Shafer_MEA_AB 2036 acute
# 7: CCTE_Shafer_MEA_dev_firing_rate_mean_dn 2494 dev
# 8: CCTE_Shafer_MEA_dev_firing_rate_mean_up 2495 dev
```
## Map sc + mc endpoint names
```{r warning=FALSE, message=FALSE}
# create table of mc and sc endpoints by aeid and find which ones don't match
aenm.tbl <- unique(mc5.neuro[,c('aeid','aenm')])
aenm.tbl$aenm.sc <- sc2.neuro$aenm[match(aenm.tbl$aeid, sc2.neuro$aeid)]
#check if any sc endpoint are missing
setdiff(sc2.neuro$aenm, aenm.tbl$aenm.sc)
# [1] "CCTE_Shafer_MEA_MFR_up" "CCTE_Shafer_MEA_MFR_dn" "CCTE_Shafer_MEA_LDH"
# [4] "CCTE_Shafer_MEA_AB"
# update aeid to match mc5 aeid
diff.aenm <- setdiff(sc2.neuro$aenm, aenm.tbl$aenm.sc)
unique(sc2.neuro[aenm %in% diff.aenm,c('aenm','aeid')])
# update sc data with the aeids that are used in mc
sc2.neuro[aenm %in% "CCTE_Shafer_MEA_MFR_up", aeid := 2457]
sc2.neuro[aenm %in% "CCTE_Shafer_MEA_MFR_up", aenm := "CCTE_Shafer_MEA_acute_firing_rate_mean_up"]
sc2.neuro[aenm %in% "CCTE_Shafer_MEA_MFR_dn", aeid := 2456]
sc2.neuro[aenm %in% "CCTE_Shafer_MEA_MFR_dn", aenm := "CCTE_Shafer_MEA_acute_firing_rate_mean_dn"]
sc2.neuro[aenm %in% "CCTE_Shafer_MEA_LDH", aeid := 2540]
sc2.neuro[aenm %in% "CCTE_Shafer_MEA_LDH", aenm := "CCTE_Shafer_MEA_acute_LDH_up"]
sc2.neuro[aenm %in% "CCTE_Shafer_MEA_AB", aeid := 2541]
sc2.neuro[aenm %in% "CCTE_Shafer_MEA_AB", aenm := "CCTE_Shafer_MEA_acute_AB_dn"]
# remapping the endpoints
aenm.tbl$aenm.sc <- sc2.neuro$aenm[match(aenm.tbl$aeid, sc2.neuro$aeid)]
setdiff(sc2.neuro$aenm, aenm.tbl$aenm.sc) # all were mapped successfully by aeid
```
## Extract tcpl methods
### mc
```{r warning=FALSE, message=FALSE}
methods.mc <- function(aeids, type.in) {
#acid
mc2_mthds <- tcplMthdLoad(2,aeids$acid, type.in)
mc2_mthds_agg <- aggregate(mthd_id ~ acid, mc2_mthds, toString)
mc2_list <- tcplMthdList(lvl=2, type=type.in)
mc2_mthds$mc2_desc <- mc2_list$mc2_mthd[match(mc2_mthds$mthd_id, mc2_list$mc2_mthd_id)]
mc2_mthds_agg2 <- aggregate(mc2_desc ~ acid, mc2_mthds, toString)
mc2_mthds_agg$mc2_desc <- mc2_mthds_agg2$mc2_desc[match(mc2_mthds_agg$acid, mc2_mthds_agg2$acid)]
setnames(mc2_mthds_agg, "mthd_id", "mc2_mthd_id")
#aeid
mc3_mthds <- tcplMthdLoad(3,aeids$aeid, type.in)
mc3_mthds_agg <- aggregate(mthd_id ~ aeid, mc3_mthds, toString)
mc3_list <- tcplMthdList(lvl=3, type=type.in)
mc3_mthds$mc3_desc <- mc3_list$mc3_mthd[match(mc3_mthds$mthd_id, mc3_list$mc3_mthd_id)]
mc3_mthds_agg2 <- aggregate(mc3_desc ~ aeid, mc3_mthds, toString)
mc3_mthds_agg$mc3_desc <- mc3_mthds_agg2$mc3_desc[match(mc3_mthds_agg$aeid, mc3_mthds_agg2$aeid)]
setnames(mc3_mthds_agg, "mthd_id", "mc3_mthd_id")
mc4_mthds <- tcplMthdLoad(4,aeids$aeid, type.in)
mc4_mthds_agg <- aggregate(mthd_id ~ aeid, mc4_mthds, toString)
mc4_list <- tcplMthdList(lvl=4, type=type.in)
mc4_mthds$mc4_desc <- mc4_list$mc4_mthd[match(mc4_mthds$mthd_id, mc4_list$mc4_mthd_id)]
mc4_mthds_agg2 <- aggregate(mc4_desc ~ aeid, mc4_mthds, toString)
mc4_mthds_agg$mc4_desc <- mc4_mthds_agg2$mc4_desc[match(mc4_mthds_agg$aeid, mc4_mthds_agg2$aeid)]
setnames(mc4_mthds_agg, "mthd_id", "mc4_mthd_id")
mc5_mthds <- tcplMthdLoad(5,aeids$aeid, type.in)
mc5_mthds_agg <- aggregate(mthd_id ~ aeid, mc5_mthds, toString)
mc5_list <- tcplMthdList(lvl=5, type=type.in)
mc5_mthds$mc5_desc <- mc5_list$mc5_mthd[match(mc5_mthds$mthd_id, mc5_list$mc5_mthd_id)]
mc5_mthds_agg2 <- aggregate(mc5_desc ~ aeid, mc5_mthds, toString)
mc5_mthds_agg$mc5_desc <- mc5_mthds_agg2$mc5_desc[match(mc5_mthds_agg$aeid, mc5_mthds_agg2$aeid)]
setnames(mc5_mthds_agg, "mthd_id", "mc5_mthd_id")
mc6_mthds <- tcplMthdLoad(6,aeids$aeid, type.in)
mc6_mthds_agg <- aggregate(mthd_id ~ aeid, mc6_mthds, toString)
mc6_list <- tcplMthdList(lvl=6, type=type.in)
mc6_mthds$mc6_desc <- mc6_list$mc6_mthd[match(mc6_mthds$mthd_id, mc6_list$mc6_mthd_id)]
mc6_mthds_agg2 <- aggregate(mc6_desc ~ aeid, mc6_mthds, toString)
mc6_mthds_agg$mc6_desc <- mc6_mthds_agg2$mc6_desc[match(mc6_mthds_agg$aeid, mc6_mthds_agg2$aeid)]
setnames(mc6_mthds_agg, "mthd_id", "mc6_mthd_id")
acid.methods <- merge(aeids, mc2_mthds_agg,by.x = "acid", by.y = "acid")
mthd36 <- merge (merge( merge(mc3_mthds_agg, mc4_mthds_agg, by = "aeid", all = TRUE ), mc5_mthds_agg, by = "aeid", all = TRUE ), mc6_mthds_agg, by = "aeid", all = TRUE )
methods <- merge(acid.methods[,c('aeid','acid','mc2_mthd_id','mc2_desc')], mthd36,by.x = "aeid", by.y = "aeid")
}
methods.tbl.mc <- methods.mc(aeids= neuro.assays, type.in="mc")
methods.tbl.mc$aenm <- neuro.assays$aenm[match(methods.tbl.mc$aeid, neuro.assays$aeid)]
# add bmad and coff
mc.bmad <- unique(mc5.neuro[, c('aenm','bmad','coff')])
setnames(mc.bmad, "bmad","bmad.mc")
setnames(mc.bmad, "coff","coff.mc")
methods.tbl.mc <- merge(methods.tbl.mc, mc.bmad, by='aenm')
```
### sc
```{r warning=FALSE, message=FALSE}
methods.sc <- function(aeids, type.in) {
sc2_mthds <- tcplMthdLoad(2,aeids$aeid, type.in)
sc2_mthds_agg <- aggregate(mthd_id ~ aeid, sc2_mthds, toString)
sc2_list <- tcplMthdList(lvl=2, type=type.in)
sc2_mthds$sc2_desc <- sc2_list$sc2_mthd[match(sc2_mthds$mthd_id, sc2_list$sc2_mthd_id)]
sc2_mthds_agg2 <- aggregate(sc2_desc ~ aeid, sc2_mthds, toString)
sc2_mthds_agg$sc2_desc <- sc2_mthds_agg2$sc2_desc[match(sc2_mthds_agg$aeid, sc2_mthds_agg2$aeid)]
setnames(sc2_mthds_agg, "mthd_id", "sc2_mthd_id")
}
methods.tbl.sc <- methods.sc(aeids= neuro.assays, type.in="sc")
# deduce bmad and coff from acute sc (not in invitrodb 3.5)
sc2.neuro[, n.chem := .N, by=aenm]
sc2.mthds <- unique(sc2.neuro[, c('aenm','aeid','bmad','coff','n.chem', 'assay_type')])
sc2.mthds[, coff.mthd := coff/bmad]
sc2.mthds[, coff.mthd2 := round(coff.mthd,1)]
sc2.mthds[coff==30, sc2_desc := paste0('ow_bmad_nwells, ','pc30')]
sc2.mthds[coff==23, sc2_desc := paste0('ow_bmad_nwells, ','pc25')]
sc2.mthds[is.na(sc2_desc), sc2_desc := paste0('ow_bmad_nwells, ','bmad',coff.mthd2)]
setnames(sc2.mthds, "bmad","bmad.sc")
setnames(sc2.mthds, "coff","coff.sc")
# bind new ids to desc
methods.tbl.mc.sc <- merge(methods.tbl.mc, sc2.mthds[, c('aeid','sc2_desc','bmad.sc','coff.sc')], by='aeid', all.x=T )
```
# 3. Chemical Overlap
```{r warning=FALSE, message=FALSE}
mc.acute <- unique(mc5.neuro[assay_type == "acute", dsstox_substance_id])
mc.dev <- unique(mc5.neuro[assay_type == "dev", dsstox_substance_id])
sc.acute <- unique(sc2.neuro[assay_type == "acute", dsstox_substance_id])
sc.dev <- unique(sc2.neuro[assay_type == "dev", dsstox_substance_id])
mc.sc.acute <- unique(c(mc.acute, sc.acute))
mc.sc.dev <- unique(c(mc.dev, sc.dev))
mc.acute.dev <- intersect(mc.acute, mc.dev) #154
chems.inter.acute.dev <- intersect(mc.sc.acute, mc.sc.dev) #243
```
Total number of chemicals tested in acute and dev mc screen: `r length(mc.acute.dev)`
Total number of chemicals tested in acute and dev (sc + mc screen): `r length(chems.inter.acute.dev)`
## Venn diagram
### Supp Figure 1: Venn: SC acute and dev overlap
```{r warning=FALSE, message=FALSE}
sc.acute.dev <- list("SC Acute" = sc.acute, "SC Dev" = sc.dev)
venn.diagram(sc.acute.dev, "figures/Supp_Fig1B_overlap_SC_acute_dev.png",
main = "Overlap of SC acute and dev chemicals",
main.pos = c(0.5, 0.80),
main.just = c(0.5, 1),
main.cex = 1.5,
fill=c("slateblue", "darkred"),
cat.cex = c(1.5),
main.fontface = "bold",
#cat.fontface = "bold",
alpha=c(0.5,0.5),
margin = 0.2,
cat.pos=c(315, 45),
cat.dist = c(0.03, 0.03),
output = TRUE,
height = 2500,
width = 2500,
scaled = TRUE,
lwd = 4)
```
### Supp Figure 1: Venn: MC acute and dev overlap
```{r warning=FALSE, message=FALSE}
mc.acute.dev.venn <- list("MC Acute" = mc.acute, "MC Dev" = mc.dev)
venn.diagram(mc.acute.dev.venn, "figures/Supp_Fig1B_overlap_MC_acute_dev.png",
main = "Overlap of MC acute and dev chemicals",
main.pos = c(0.5, 0.80),
main.just = c(0.5, 1),
main.cex = 1.5,
fill=c("slateblue", "darkred"),
cat.cex = c(1.5),
main.fontface = "bold",
#cat.fontface = "bold",
alpha=c(0.5,0.5),
margin = 0.2,
cat.pos=c(315, 45),
cat.dist = c(0.03, 0.03),
output = TRUE,
height = 2500,
width = 2500,
scaled = TRUE,
lwd = 4)
```
### Supp Figure 1: Venn: MC + SC acute and dev overlap
```{r warning=FALSE, message=FALSE}
mc.sc.acute.dev <- list("SC Acute" = mc.sc.acute, "SC Dev" = mc.sc.dev)
venn.diagram(mc.sc.acute.dev, "figures/Supp_Fig1B_overlap_MC_SC_acute_dev.png",
main = "Overlap of MC + SC acute and dev chemicals",
main.pos = c(0.5, 0.80),
main.just = c(0.5, 1),
main.cex = 1.5,
fill=c("slateblue", "darkred"),
cat.cex = c(1.5),
main.fontface = "bold",
#cat.fontface = "bold",
alpha=c(0.5,0.5),
margin = 0.2,
cat.pos=c(315, 45),
cat.dist = c(0.03, 0.03),
output = TRUE,
height = 2500,
width = 2500,
scaled = TRUE,
lwd = 4)
```
# 4. Hitcall Concordance
## Add selective activity filter
```{r warning=FALSE, message=FALSE}
# mc cyto data-------------------------------------------------------------
cyto.aeid<- c(2540,2541, 2529, 2530)
mc5.neuro[, is.cyto := 0]
mc5.neuro[aeid %in% cyto.aeid, is.cyto := 1]
# identify cyto coff by min cyto between LDH and AB for each assay type
cyto.hits <- mc5.neuro[is.cyto==1 & hitc==1,]
cyto.hits[, cyto.coff := min(modl_ga, na.rm=T), by=c('chnm','assay_type')]
cyto.hits.sum <- unique(cyto.hits[, c('chnm','assay_type','cyto.coff')])
mc5.neuro <- merge(mc5.neuro, cyto.hits.sum, by=c('chnm','assay_type'), all.x=T)
# add classification
mc5.neuro[, sel.score := cyto.coff-modl_ga]
mc5.neuro[, hitc.sel := ifelse(sel.score>0.3,1,0)]
mc5.neuro[hitc==1 & is.na(cyto.coff), hitc.sel := 1]
mc5.neuro[is.na(hitc.sel), hitc.sel := 0]
mc5.neuro[, hitc.non.sel := ifelse(hitc==1 & hitc.sel==0,1,0)]
# sc cyto data-------------------------------------------------------------
sc2.neuro[, is.cyto := 0]
sc2.neuro[aeid %in% cyto.aeid, is.cyto := 1]
# identify cyto coff by AB activity for each assay type (appears to be issues with LDH endpoint for sc so not going to use it as a benchmark)
cyto.hits <- sc2.neuro[is.cyto==1 & hitc==1,]
cyto.hits[, cyto.hit := 1]
cyto.hits[, cyto.sum := sum(cyto.hit), by=chnm]
cyto.hits[, cyto.coff := ifelse(cyto.sum>=1,1,0), by=chnm]
cyto.hits.sum <- unique(cyto.hits[, c('chnm','assay_type','cyto.coff')])
sc2.neuro <- merge(sc2.neuro, cyto.hits.sum, by=c('chnm','assay_type'), all.x=T)
# add classification
sc2.neuro[, hitc.sel := ifelse(hitc==1 & cyto.coff==0,1,0)]
sc2.neuro[hitc==1 & is.na(cyto.coff), hitc.sel := 1]
sc2.neuro[, hitc.non.sel := ifelse(hitc==1 & hitc.sel==0,1,0)]
```
## rbind MC + SC data
```{r warning=FALSE, message=FALSE}
# combine sc and mc tables
mc5.neuro$screen <- "mc"
sc2.neuro$screen <- "sc"
df <- rbind(mc5.neuro, sc2.neuro, fill=T)
# only overlapping chems
chems.inter.acute.dev <- intersect(mc.sc.acute, mc.sc.dev)
df <- df[dsstox_substance_id %in% chems.inter.acute.dev,]
df[, key := paste0(chnm,'_',assay_type,'_',aeid,'_',screen)]
# exclude sc chemicals that were screened in mc for each assay--------------------------------------------
# acute
sc.acute <- df[screen %in% "sc" & assay_type %in% "acute", dsstox_substance_id]
mc.acute <- df[screen %in% "mc" & assay_type %in% "acute", dsstox_substance_id]
inter.acute <- intersect(sc.acute, mc.acute)
exclude.acute <- df[dsstox_substance_id %in% inter.acute & assay_type %in% "acute" & screen %in% "sc",]
df <- df[!key %in% exclude.acute$key,]
# dev
sc.dev <- df[screen %in% "sc" & assay_type %in% "dev", dsstox_substance_id]
mc.dev<- df[screen %in% "mc" & assay_type %in% "dev", dsstox_substance_id]
inter.dev <- intersect(sc.dev, mc.dev)
exclude.dev <- df[dsstox_substance_id %in% inter.dev & assay_type %in% "dev" & screen %in% "sc",]
df <- df[!key %in% exclude.dev$key,]
# exposure chemical overlap for mc + sc + acute + dev
mc.sc.sum.chem <- unique(df[grep('firing_rate',aenm), c('chnm','dsstox_substance_id', 'assay_type','screen')])
#mc.sc.sum.chem$is.test <- 1
mc.sc.chem.wide <- as.data.table(dcast(mc.sc.sum.chem,
chnm + dsstox_substance_id ~ assay_type, value.var="screen"))
```
## Add activity type categories
```{r warning=FALSE, message=FALSE, error=TRUE}
# updated endpoint categories based on manual curation by KC on 07/05/2023
end.cat <- as.data.table(read.xlsx('input/Assay_endpoint_cat_desc_June2023.xlsx'))
end.cat$tcpl.fit.dir <- "down"
end.cat$tcpl.fit.dir <- end.cat[grep("_up",aenm), tcpl.fit.dir := "up" ]
end.cat[, use.me := ifelse(aenm %in% df$aenm,1,0)]
# table for supp
end.cat.tbl <- end.cat[order(use.me,aenm, decreasing=T)]
end.cat.tbl$assay_type <- "dev"
end.cat.tbl[grep("acute",aenm), assay_type := "acute"]
end.cat.tbl[, screen_sc := ifelse(aeid %in% sc2.neuro$aeid, 1,0)]
end.cat.tbl[, screen_mc := ifelse(aeid %in% mc5.neuro$aeid, 1,0)]
end.cat.tbl$Comments <- NULL
end.cat.tbl$Category2 <- NULL
df$category <- end.cat$Category[match(df$aeid, end.cat$aeid)]
df$dir <- end.cat$Activity.direction[match(df$aeid, end.cat$aeid)]
unique(df[, c('aenm','category')])
unique(df[, c('aenm','dir')])
df <- df[!(assay_type %in% "dev" & dir %in% "Increase"),]
dev.up.aeid <- c(2495,2497,2499,2501,2503,2505,2507,2509,2511,2513,2515,2517,2519,2521,2523,2525,2527) # exclude up endpoints in MEA NFA
df <- df[!aeid %in% dev.up.aeid,]
unique(df$aenm)
```
## MFR endpoint concordance (selective)
```{r warning=FALSE, message=FALSE}
mfr.aeid <- c(2456,2457,2494,2495)
df.mfr <- df[aeid %in% mfr.aeid,]
unique(df.mfr$aenm)
# add hitsum column by assay type (acute or dev)
df.mfr[, hitsum := sum(hitc.sel), by=c('dsstox_substance_id','assay_type')]
hitsum.tbl <- unique(df.mfr[dsstox_substance_id %in% chems.inter.acute.dev,
c('chnm','dsstox_substance_id','assay_type','hitsum')])
# output summary table of hitsum for overlapping chems
hitsum.tbl.wide <- as.data.table(dcast(hitsum.tbl,
chnm + dsstox_substance_id ~ assay_type, value.var="hitsum"))
hitsum.tbl.wide[, acute.active := ifelse(acute==0,0,1)]
hitsum.tbl.wide[, dev.active := ifelse(dev==0,0,1)]
hitsum.tbl.wide[, concor.overall := ifelse(acute.active==dev.active,1,0)]
hitsum.tbl.wide[, acute.inactive := ifelse(acute==0,1,0)]
hitsum.tbl.wide[, dev.inactive := ifelse(dev==0,1,0)]
hitsum.tbl.wide[, concor.active := ifelse(acute.active==1&dev.active==1,1,0)]
hitsum.tbl.wide[, concor.inactive := ifelse(acute.inactive==1&dev.inactive==1,1,0)]
# sum columns
mfr.sum <- hitsum.tbl.wide[, lapply(.SD, sum, na.rm=T), .SDcols=c('acute.active','dev.active','concor.active','acute.inactive','dev.inactive','concor.inactive','concor.overall')]
total.inter.chems <- length(chems.inter.acute.dev)
mfr.sum[, concor.perc := concor.overall/total.inter.chems*100]
mfr.sum
# Cohen's Kappa inter-rater reliability
# Contingency table
xtab <- table(hitsum.tbl.wide$acute.active, hitsum.tbl.wide$dev.active)
# Descriptive statistics
diagonal.counts <- diag(xtab)
N <- sum(xtab)
row.marginal.props <- rowSums(xtab)/N
col.marginal.props <- colSums(xtab)/N
# Compute kappa (k)
Po <- sum(diagonal.counts)/N
Pe <- sum(row.marginal.props*col.marginal.props)
k <- (Po - Pe)/(1 - Pe)
k
```
### Venn: MFR active overlap
```{r warning=FALSE, message=FALSE, error=TRUE}
mfr.active <- list("Acute Active" = hitsum.tbl.wide[acute.active==1,dsstox_substance_id], "Dev Active" = hitsum.tbl.wide[dev.active==1,dsstox_substance_id])
venn.diagram(mfr.active, "figures/Fig2B_Overlap_MFR_sel_active.png",
main = "Overlap of MFR active in acute and dev (MC + SC)",
main.pos = c(0.5, 0.80),
main.just = c(0.5, 1),
main.cex = 1.5,
fill=c("slateblue", "darkred"),
cat.cex = c(1.5),
main.fontface = "bold",
#cat.fontface = "bold",
alpha=c(0.5,0.5),
margin = 0.2,
cat.pos=c(315, 45),
cat.dist = c(0.03, 0.03),
output = TRUE,
height = 2500,
width = 2500,
scaled = TRUE,
lwd = 4)
# which were both
both.tbl <- hitsum.tbl.wide[ acute.active==1 & dev.active==1,]
# were any cyto
explore <- df[is.cyto==1 & chnm %in% both.tbl$chnm & hitc==1,]
unique(explore$chnm)
# explore activity of the 50 chemicals that were active in the nfa but not acute
acute.mfr <- hitsum.tbl.wide[dev.active==0 & acute.active==1,dsstox_substance_id]
explore <- df[dsstox_substance_id %in% acute.mfr & aeid %in% mfr.aeid & assay_type=="dev", c('chnm','aenm','hitc','hitc.sel') ]
explore[, hitsum := sum(hitc), by=chnm]
explore.sum <- unique(explore[, c('chnm','hitsum','hitc.sel')])
#table(explore.sum$hitsum)
# were any of the chemicals that were sel active in mfr acute, cytotoxic in acute?
explore <- df[dsstox_substance_id %in% acute.mfr & is.cyto==1 & assay_type=="acute", c('chnm','aenm','hitc') ]
explore[, hitsum := sum(hitc), by=chnm]
explore.sum <- unique(explore[, c('chnm','hitsum')])
#table(explore.sum$hitsum)
#write.csv(explore.sum, 'output/Chem_only_acute_w_cyto_dev_hits.csv')
# were any of the chemicals that were sel active in mfr acute, active in the NFA
explore <- df[dsstox_substance_id %in% acute.mfr & assay_type=="dev" & hitc==1, c('chnm','aenm','hitc','is.cyto') ]
unique(explore$chnm)
# how many were cyto
explore2 <- explore[is.cyto==1,]
unique(explore2$chnm)
# were any of the chemicals that were sel active in mfr acute, cytotoxic in nfa?
explore <- df[dsstox_substance_id %in% acute.mfr & is.cyto==1 & assay_type=="dev", c('chnm','aenm','hitc') ]
explore[, hitsum := sum(hitc), by=chnm]
explore.sum <- unique(explore[, c('chnm','hitsum')])
table(explore.sum$hitsum)
#write.csv(explore.sum, 'output/Chem_only_acute_w_cyto_dev_hits.csv')
# were any of these chemicals that were active in mfr acute, but did not demonstrate cyto in nfa, active in other nfa endpoints?
no.cyto <- unique(explore.sum[hitsum==0,chnm])
explore <- df[chnm %in% no.cyto & is.cyto==0 & assay_type=="dev", c('chnm','aenm','hitc','hitc.sel','screen') ]
explore[, hitsum := sum(hitc.sel), by=chnm]
explore.sum <- unique(explore[, c('chnm','hitsum')])
#table(explore.sum$hitsum)
# can we call 2 hits equivocal with 14 NFA endpoints? Look at plots
chem.explore <- c("Tris(1,3-dichloro-2-propyl) phosphate", "Fenamiphos")
graph <- df[hitc==1 & chnm %in% chem.explore & assay_type %in% "dev",]
#tcplPlotM4ID(graph$m4id, lvl=6)
# based on plots I think it makes sense to say only 1 hit is equivocal, although these cases were pretty borderline. It does look like something was going on at only the highest concentration.
# did any of the 18 chemicals that were active in mfr acute not active in nfa demonstrate increased mfr?
no.nfa.act <- explore.sum[hitsum<3,chnm]
explore <- df[chnm %in% no.nfa.act & aeid %in% mfr.aeid & assay_type=="acute", c('chnm','aenm','hitc','hitc.sel','screen','hitsum') ]
explore2 <- explore[hitc==1,]
table(explore2$aenm)
explore.sum <- unique(explore[, c('chnm','hitsum')])
#table(explore.sum$aenm)
# mean ac50 of the 11 chemicals that were active in only nfa
dev.mfr <- hitsum.tbl.wide[dev.active==1 & acute.active==0,dsstox_substance_id]
explore <- df[dsstox_substance_id %in% dev.mfr & is.cyto==0 & aenm %in% 'CCTE_Shafer_MEA_dev_firing_rate_mean_dn' & assay_type=="dev", c('chnm','aenm','hitc','hitc.sel','screen','modl_ga','sel.score') ]
mean(explore$modl_ga, na.rm=T)
sd(explore$modl_ga, na.rm=T)
mean(explore$sel.score, na.rm=T)
sd(explore$sel.score, na.rm=T)
# were the chemicals that were active in nfa mfr but not acute, also cytotoxic in nfa?
dev.mfr <- hitsum.tbl.wide[dev.active==1 & acute.active==0,dsstox_substance_id]
explore <- df[dsstox_substance_id %in% dev.mfr & is.cyto==1 & assay_type=="dev", c('chnm','aenm','hitc','screen','modl_ga') ]
explore[, hitsum := sum(hitc), by=chnm]
explore.sum <- unique(explore[, c('chnm','hitsum')])
# table(explore.sum$hitsum)
# write.csv(explore.sum, 'output/Chem_only_dev_w_cyto_dev_hits.csv')
# explore..
explore <- df[dsstox_substance_id %in% dev.mfr & is.cyto==1 & assay_type=="acute", c('chnm','aenm','hitc','assay_type','screen') ]
explore[, hitsum := sum(hitc), by=chnm]
explore.sum <- unique(explore[, c('chnm','hitsum')])
# table(explore.sum$hitsum)
# were the chemicals only active in the nfa mfr, active in other acute endpoints?
explore <- df[dsstox_substance_id %in% dev.mfr & assay_type=="acute" & hitc==1,]
# how many acute MFR were up versus down?
explore <- df[dsstox_substance_id %in% acute.mfr & hitc==1 & assay_type %in% "acute" & aeid %in% mfr.aeid, c('chnm','aenm','hitc','hitc.sel','assay_type','screen','dir')]
table(explore$aenm)
acute.up.only <- explore[dir %in% "Increase",chnm]
# were the chemicals that increased activity in the acute, cytotoxic in the NFA?
explore <- df[chnm %in% acute.up.only,]
explore <- df[chnm %in% acute.up.only & is.cyto==1 & assay_type=="dev", c('chnm','aenm','hitc','assay_type','screen') ]
explore[, hitsum := sum(hitc), by=chnm]
explore.sum <- unique(explore[, c('chnm','hitsum')])
table(explore.sum$hitsum)
# were there any other acute MFR up hits that were also active in NFA MFR?
explore <- df[hitc==1 & assay_type %in% "dev" & chnm %in% acute.up.only,]
explore <- df[hitc==1 & assay_type %in% "dev" & aeid %in% mfr.aeid & chnm %in% acute.up.only,]
explore <- df[hitc==1 & assay_type %in% "acute" & aeid %in% mfr.aeid & dir %in% "Increase",]
# test <- df[chnm %in% "Chlorpromazine hydrochloride", c('chnm','aenm','hitc','modl_ga')]
# test <- df[chnm %in% "Mancozeb", c('chnm','aenm','hitc','modl_ga','screen','assay_type')]
# test <- df[chnm %in% "Carbofuran", c('chnm','aenm','hitc','modl_ga','screen','assay_type')]
# compare the difference between mean cyto and mean MFR ac50's for the 9 chemicals that were selectively active in the MFR NFA
explore <- df[dsstox_substance_id %in% dev.mfr & is.cyto==1 & assay_type=="dev", c('chnm','aenm','hitc','screen') ]
nfa.mfr.cyto <- explore[hitc==1,]
nfa.mfr.cyto.df <- df[chnm %in% nfa.mfr.cyto$chnm & aeid %in% mfr.aeid & hitc==1 & assay_type=="dev", ]
mean(nfa.mfr.cyto.df$modl_ga)
sd(nfa.mfr.cyto.df$modl_ga)
# find cyto mean ac50 for these chems
nfa.mfr.cyto.df2 <- df[chnm %in% nfa.mfr.cyto$chnm & aeid %in% cyto.aeid & hitc==1 & assay_type=="dev", ]
mean(nfa.mfr.cyto.df2$modl_ga)
sd(nfa.mfr.cyto.df2$modl_ga)
# compare this to rest of chemicals active in NFA
explore <- df[aeid %in% mfr.aeid & assay_type=="dev" &
!chnm %in% nfa.mfr.cyto.df$chnm, c('chnm','aenm','hitc','screen') ]
nfa.mfr.other <- explore[hitc==1,]
nfa.mfr.other.df <- df[chnm %in% nfa.mfr.other$chnm & aeid %in% mfr.aeid & hitc==1 & assay_type=="dev", ]
mean(nfa.mfr.other.df$modl_ga)
sd(nfa.mfr.other.df$modl_ga)
# find cyto mean ac50 for these chems
nfa.mfr.other.df2 <- df[chnm %in% nfa.mfr.other.df$chnm & aeid %in% cyto.aeid & hitc==1 & assay_type=="dev", ]
mean(nfa.mfr.other.df2$modl_ga, na.rm=T)
sd(nfa.mfr.cyto.df2$modl_ga)
# print plots for 9 selectively active NFA MFR
graph <- nfa.mfr.cyto.df
# graphics.off()
# pdf(file=paste('figures/Tcpl_plots_NFA_MFR_9chem_hits',
# format(Sys.Date(),
# "%y%m%d.pdf"),
# sep="_"),
# height=6,
# width=10,
# pointsize=10)
# for (a in graph$m5id){
# tcplPlotM4ID(graph[m5id==a]$m4id, lvl=6)
# mtext(paste(unique(graph[m5id==a]$aenm)), outer=FALSE, cex=1, line=1.5, adj=0)
# }
# graphics.off()
```
## Chemical concordance (all MEA endpoints, mc + sc, including cyto)
```{r warning=FALSE, message=FALSE}
all.aenm <- df
# add hitsum column by screening type (mc or sc) and assay type (acute or dev)
all.aenm[, hitsum := sum(hitc), by=c('dsstox_substance_id','assay_type')]
hitsum.tbl <- unique(all.aenm[dsstox_substance_id %in% chems.inter.acute.dev,
c('chnm','dsstox_substance_id','assay_type','hitsum')])
hit2 <- all.aenm[hitsum==2 & hitc==1,c('chnm','aenm','hitc','modl_ga','assay_type','screen')]
hit1 <- all.aenm[hitsum==1 & hitc==1,c('chnm','aenm','hitc','modl_ga','assay_type','screen')]
# output summary table of hitsum for overlapping chems
hitsum.tbl.wide <- as.data.table(dcast(hitsum.tbl,
chnm + dsstox_substance_id ~ assay_type, value.var="hitsum"))
hitsum.tbl.wide[, acute.active := ifelse(acute==0,0,1)]
hitsum.tbl.wide[, dev.active := ifelse(dev==0,0,1)]
hitsum.tbl.wide[, concor.overall := ifelse(acute.active==dev.active,1,0)]
hitsum.tbl.wide[, acute.inactive := ifelse(acute==0,1,0)]
hitsum.tbl.wide[, dev.inactive := ifelse(dev==0,1,0)]
hitsum.tbl.wide[, concor.active := ifelse(acute.active==1&dev.active==1,1,0)]
hitsum.tbl.wide[, concor.inactive := ifelse(acute.inactive==1&dev.inactive==1,1,0)]
# sum columns
all.aenm.sum <- hitsum.tbl.wide[, lapply(.SD, sum, na.rm=T), .SDcols=c('acute.active','dev.active','concor.active','acute.inactive','dev.inactive','concor.inactive','concor.overall')]
total.inter.chems <- length(chems.inter.acute.dev)
all.aenm.sum[, concor.perc := concor.overall/total.inter.chems*100]
all.aenm.sum
```
### Venn: All endpoint active overlap
```{r warning=FALSE, message=FALSE, error=TRUE}
all.aenm.active <- list("Acute Active" = hitsum.tbl.wide[acute.active==1,dsstox_substance_id], "Dev Active" = hitsum.tbl.wide[dev.active==1,dsstox_substance_id])
venn.diagram(all.aenm.active, "figures/Fig2D_overlap_all_MEA_aenm_active.png",
main = "Overlap of MFR active in acute and dev (MC + SC)",
main.pos = c(0.5, 0.80),
main.just = c(0.5, 1),
main.cex = 1.5,
fill=c("slateblue", "darkred"),
cat.cex = c(1.5),
main.fontface = "bold",
#cat.fontface = "bold",
alpha=c(0.5,0.5),
margin = 0.2,
cat.pos=c(315, 45),
cat.dist = c(0.03, 0.03),
output = TRUE,
height = 2500,
width = 2500,
scaled = TRUE,
lwd = 4)
# Cohen's Kappa inter-rater reliability
# Contingency table
xtab <- table(hitsum.tbl.wide$acute.active, hitsum.tbl.wide$dev.active)
# Descriptive statistics
diagonal.counts <- diag(xtab)
N <- sum(xtab)
row.marginal.props <- rowSums(xtab)/N
col.marginal.props <- colSums(xtab)/N
# Compute kappa (k)
Po <- sum(diagonal.counts)/N
Pe <- sum(row.marginal.props*col.marginal.props)
k <- (Po - Pe)/(1 - Pe)
k
```
## Cyto endpoint concordance
```{r warning=FALSE, message=FALSE}
df.cyto <- df[aeid %in% cyto.aeid,]
unique(df.cyto$aenm)
# check the chemical overlap between acute and nfa in case missing cyto endpoints
df.cyto.acute <- unique(df.cyto[assay_type %in% "acute",dsstox_substance_id])
df.dev.acute <- unique(df.cyto[assay_type %in% "dev",dsstox_substance_id])
length(intersect(df.cyto.acute, df.dev.acute)) #243, all data available
# add hitsum column by screening type (mc or sc) and assay type (acute or dev)
df.cyto[, hitsum := sum(hitc), by=c('chnm','assay_type')]
df.cyto[, is.active := ifelse(hitsum==0,0,1)]
hitsum.tbl <- unique(df.cyto[dsstox_substance_id %in% chems.inter.acute.dev,
c('chnm','dsstox_substance_id','assay_type','is.active')])
# output summary table of hitsum for overlapping chems
hitsum.tbl.wide <- as.data.table(dcast(hitsum.tbl,
chnm + dsstox_substance_id ~ assay_type, value.var="is.active"))
hitsum.tbl.wide[, concor.overall := ifelse(acute==dev,1,0)]
hitsum.tbl.wide[, acute.inactive := ifelse(acute==0,1,0)]
hitsum.tbl.wide[, dev.inactive := ifelse(dev==0,1,0)]
hitsum.tbl.wide[, concor.active := ifelse(acute==1 & dev==1,1,0)]
hitsum.tbl.wide[, concor.inactive := ifelse(acute.inactive==1 & dev.inactive==1,1,0)]
# sum columns
cyto.sum <- hitsum.tbl.wide[, lapply(.SD, sum, na.rm=T), .SDcols=c('acute','dev','concor.active','acute.inactive','dev.inactive','concor.inactive','concor.overall')]
total.inter.chems <- length(chems.inter.acute.dev)
cyto.sum[, concor.perc := concor.overall/total.inter.chems*100]
cyto.sum$concor.perc
```
### Venn: Cyto active overlap
```{r warning=FALSE, message=FALSE, error=TRUE}
cyto.active <- list("Acute Active" = hitsum.tbl.wide[acute==1,dsstox_substance_id], "Dev Active" = hitsum.tbl.wide[dev==1,dsstox_substance_id])
venn.diagram(cyto.active, "figures/Fig2A_overlap_Cyto_active.png",
main = "Overlap of MFR active in acute and dev (MC + SC)",
main.pos = c(0.5, 0.80),
main.just = c(0.5, 1),
main.cex = 1.5,
fill=c("slateblue", "darkred"),
cat.cex = c(1.5),
main.fontface = "bold",
#cat.fontface = "bold",
alpha=c(0.5,0.5),
margin = 0.2,
cat.pos=c(315, 45),
cat.dist = c(0.03, 0.03),
output = TRUE,
height = 2500,
width = 2500,
scaled = TRUE,
lwd = 4)
# which chemicals were cyto in acute and not nfa
cyto.acute <- hitsum.tbl.wide[acute==1 & dev==0,]
# were most only screened in sc?
explore <- df.cyto[chnm %in% cyto.acute$chnm, c('chnm','aenm','screen','assay_type','hitc','hitsum','modl_ga','flag.length')]
# stats: what was the mean potency of chemicals that were cyto in both assays
cyto.both.chems <- hitsum.tbl.wide[concor.active==1,chnm]
cyto.both <- df.cyto[chnm %in% cyto.both.chems, ]
cyto.both[, all.mc := ifelse(any(screen %in% "sc"),0,1), by=chnm]
cyto.view <- cyto.both[, c('chnm','aenm','modl_ga','assay_type', 'screen','all.mc')]
cyto.both <- cyto.both[!all.mc==0,]
cyto.view <- cyto.view[!all.mc==0,]
length(unique(cyto.both$chnm))
# dev cyto mean for 12 chemicals that were cyto in both
median(cyto.both[assay_type %in% "dev", modl_ga], na.rm=T)
mean(cyto.both[assay_type %in% "dev", modl_ga], na.rm=T)
sd(cyto.both[assay_type %in% "dev", modl_ga], na.rm=T)
# acute cyto mean for 12 chemicals that were cyto in both
median(cyto.both[assay_type %in% "acute", modl_ga], na.rm=T)
mean(cyto.both[assay_type %in% "acute", modl_ga], na.rm=T)
sd(cyto.both[assay_type %in% "acute", modl_ga], na.rm=T)
cyto.both[hitc==1, c('chnm','aenm','modl_ga','assay_type')]
```
### Supp Figure 2: tcpl plots
```{r warning=FALSE, message=FALSE}
# print plots for Carbofuran and Mancozeb in NFA, which demonstrated selective activity in MFR and not cyto
chem.int <- c("Carbofuran","Mancozeb")
chem.int.hits <- df.mfr[chnm %in% chem.int & hitc.sel==1,]
# supplemental Figure 2
graph <- chem.int.hits
# tcplPlotM4ID(graph$m4id, lvl=6)
#
# graphics.off()
# pdf(file=paste('figures/Tcpl_plots_NFA_hit_MFR_manc_carb',
# format(Sys.Date(),
# "%y%m%d.pdf"),
# sep="_"),
# height=6,
# width=10,
# pointsize=10)
# for (a in graph$m5id){
# tcplPlotM4ID(graph[m5id==a]$m4id, lvl=6)
# mtext(paste(unique(graph[m5id==a]$aenm)), outer=FALSE, cex=1, line=1.5, adj=0)
# }
# graphics.off()
```
# 5. Correlation between endpoint categories
## Hitcall (mc only)
```{r warning=FALSE, message=FALSE}
# only mc data for chems tested in both
df.mc <- df[screen %in% "mc" & dsstox_substance_id %in% mc.acute.dev,] #only chemicals screened in mc in acute + nfa
#exclude cyto endpoints
df.stats <- df.mc[!aeid %in% cyto.aeid,]
df.stats[, sel.ac50 := modl_ga]
df.stats[hitc.sel==0, sel.ac50 := NA]
# create cats by screen
df.stats[, category2 := category]
df.stats[category %in% "Burst Structure", category2 := "Burst"]
df.stats[category %in% "Network Synchrony", category2 := "Network"]
unique(df.stats$category2)
df.stats[, cat_assay := paste0(category2,"_",assay_type)]
df.stats[ , cat.hitc.bin := ifelse(any(hitc.sel==1),1,0), by=c('chnm','cat_assay')]
df.stats[ , cat.ac50.min := quantile(sel.ac50, na.rm=T,0.05), by=c('chnm','cat_assay')]
df.stats2 <- unique(df.stats[, c('chnm','cat_assay','cat.hitc.bin','cat.ac50.min')])
mat.all <- dcast.data.table(df.stats2, chnm ~ cat_assay,
value.var = c('cat.hitc.bin'))
mat.all$chnm <- NULL
matrix <- as.matrix(mat.all)
#Correlogram
V <- cor(matrix)
#write.xlsx(cor_cov, "output/cor_cov_HCI_NFA_matrix.xlsx", rowNames=T)
#Corrplot
file.dir <- paste("./figures/", sep="")
file.name <- paste("/Fig2C_cat_corr_hitc_sel_mc_only", 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 =8, height = 8, unit='in',res = 600)
corrplot(corr = V, method = "color", tl.col = "black",
#tl.pos = "lt",
diag = F, type='lower', tl.pos='ld',
#tl.srt= 50,
cl.align.text = "l", cl.cex = 1.6, tl.cex = 1.6, number.cex = 1, addgrid.col = "grey", cl.pos = "b",
order = "hclust", addCoef.col = "black")
dev.off()
```
## Potency
```{r warning=FALSE, message=FALSE}
mat.all <- dcast.data.table(df.stats2, chnm ~ cat_assay,
value.var = c('cat.ac50.min'))
names(mat.all)
mat.all[is.na(mat.all),] <- 3
mat.all$chnm <- NULL
matrix <- as.matrix(mat.all)
#Correlogram
V <- cor(matrix)
#write.xlsx(cor_cov, "output/cor_cov_HCI_NFA_matrix.xlsx", rowNames=T)
#Corrplot
file.dir <- paste("./figures/", sep="")
file.name <- paste("/Supp_Fig3_cat_corr_pot", 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 =10, height = 10, unit='in',res = 600)
corrplot(corr = V, method = "color", tl.col = "black",
#tl.pos = "lt",
diag = TRUE, type='lower',
cl.align.text = "l", cl.cex = 1.6, tl.cex = 1.6, number.cex = 1, addgrid.col = "grey", cl.pos = "b",
order = "hclust", addCoef.col = "black")
dev.off()
```
# 6. Potency comparison
## Non-selective potency comparison
```{r warning=FALSE, message=FALSE}
# only mc data for chems tested in both
df.mc <- df[screen %in% "mc" & dsstox_substance_id %in% mc.acute.dev,] #only chemicals screened in mc in acute + nfa
plot <- ggplot(df.mc, aes(x=as.factor(assay_type), y= modl_ga))+
geom_boxplot()+
geom_jitter(width=0.2, alpha=0.3)+
theme_classic()+
xlab("")+
ylab("Potency (log10-AC50-uM)")+
scale_x_discrete(labels=c("Acute","NFA"))+
theme(text = element_text(size = 20))+
ggtitle("Non-selective Activity")+
theme(plot.title = element_text(hjust = 0.5))
plot
file.dir <- paste("./figures/", sep="")
file.name <- paste("/Fig3A_potency_binary_compare", 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 =5, height = 4.8, unit='in',res = 600)
plot
dev.off()
plot <- ggplot(df.mc, aes(x = modl_ga, fill=as.factor(assay_type)))+
geom_density(alpha=0.2)
plot
ks.test(df.mc[assay_type %in% "acute",modl_ga], "pnorm") # not normal
ks.test(df.mc[assay_type %in% "dev",modl_ga], "pnorm") # not normal
median(df.mc[assay_type %in% "acute",modl_ga], na.rm=T)
median(df.mc[assay_type %in% "dev",modl_ga], na.rm=T)