-
Notifications
You must be signed in to change notification settings - Fork 2
/
passive_analysis.R
164 lines (153 loc) · 7.26 KB
/
passive_analysis.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
library(drake)
library(tidyverse)
library(toxEval)
library(ggpubr)
options(drake_make_menu = FALSE)
path_to_data <- Sys.getenv("PASSIVE_PATH")
# source(file = "passive_data_setup.R")
source(file = "R/report/stack_plots.R")
source(file = "R/report/combo_plot2.R")
source(file = "R/analyze/graph_chem_data_CAS.R")
source(file = "R/report/plot_tox_endpoints_manuscript.R")
data_analysis_plan <- drake_plan(
cas_final = readRDS(file_in(!!file.path(path_to_data, "data/data_for_git_repo/clean/cas_df.rds"))),
tox_list = create_toxEval(file_in(!!file.path(path_to_data, "data/data_for_git_repo/clean/passive.xlsx"))),
ACC = get_ACC(tox_list$chem_info$CAS) %>%
remove_flags(),
cleaned_ep = clean_endPoint_info(end_point_info),
filtered_ep = filter_groups(cleaned_ep,
groupCol = 'intended_target_family',
remove_groups = c('Background Measurement','Undefined','Cell Cycle','NA')),
chemicalSummary = get_chemical_summary(tox_list, ACC, filtered_ep),
chem_sum_save_sync = saveRDS(chemicalSummary,
file = file_out(!!file.path(path_to_data,"data/data_for_git_repo/clean/chemical_summary.rds"))),
benchmarks = tox_list$chem_data %>%
select(CAS) %>%
distinct() %>%
left_join(select(cas_final, CAS, Class, chnm), by="CAS") %>%
mutate(endPoint = "Concentration",
Value = 1,
groupCol = "Concentration") %>%
data.frame(),
tox_list_concentrations = as.toxEval(tox_list, benchmarks = benchmarks),
tox_list_concentrations_sync = saveRDS(tox_list_concentrations,
file = file_out(!!file.path(path_to_data,
"data/data_for_git_repo/clean/tox_list_concentrations.rds"))),
chemicalSummary_conc = get_chemical_summary(tox_list_concentrations) %>%
distinct() %>%
filter(!is.na(CAS)),
chemicalSummary_conc_save = saveRDS(chemicalSummary_conc,
file = file_out(!!file.path(path_to_data,"data/data_for_git_repo/clean/chemicalSummary_conc.rds"))),
graphData_tox = graph_chem_data_CAS(chemicalSummary) %>%
mutate(guide_side = "ToxCast [EAR]") %>%
left_join(select(cas_final, CAS, chnm), by="CAS"),
graphData_conc = graph_chem_data_CAS(chemicalSummary_conc) %>%
mutate(guide_side = "Concentration [\U003BCg/L]") %>%
left_join(select(cas_final, CAS, chnm), by="CAS"),
toxPlot_ear_conc = fancy_combo(graphData_tox,
graphData_conc,
tox_list),
chemicalSummary_conc_det = filter(chemicalSummary_conc, EAR > 0),
chemicalSummary_tox_det = filter(chemicalSummary, EAR > 0),
graphData_conc_det = graph_chem_data_CAS(chemicalSummary_conc_det) %>%
mutate(guide_side = "Concentration [\U003BCg/L]") %>%
left_join(select(cas_final, CAS, chnm), by="CAS"),
graphData_tox_det = graph_chem_data_CAS(chemicalSummary_tox_det) %>%
mutate(guide_side = "ToxCast [EAR]") %>%
left_join(select(cas_final, CAS, chnm), by="CAS"),
graphData_tox_det_out = saveRDS(graphData_tox_det,
file = file_out(!!file.path(path_to_data,
"data/data_for_git_repo/clean/graphData_tox_det.rds"))),
toxPlot_ear_conc_detects = fancy_combo(graphData_tox_det,
graphData_conc_det,
tox_list),
chemicalSummary_conc_det_match = filter(chemicalSummary_conc_det, CAS %in% unique(graphData_tox_det$CAS)),
graphData_conc_det_match = graph_chem_data_CAS(chemicalSummary_conc_det_match) %>%
mutate(guide_side = "Concentration [\U003BCg/L]") %>%
left_join(select(cas_final, CAS, chnm), by="CAS"),
graphData_conc_det_match_save = saveRDS(graphData_conc_det_match,
file = file_out(!!file.path(path_to_data,
"data/data_for_git_repo/clean/graphData_conc_det_match.rds"))),
toxPlot_ear_conc_matches = fancy_combo(graphData_tox_det,
graphData_conc_det_match,
tox_list),
graphData_conc_det_match_filter = graphData_conc_det_match,
graphData_tox_det_filter = graphData_tox_det,
toxPlot_ear_conc_matches_filter = fancy_combo(graphData_tox_det_filter,
graphData_conc_det_match_filter,
tox_list),
AOP = readr::read_csv(file_in(!!file.path(path_to_data,"data/data_for_git_repo/raw/AOP_crosswalk.csv"))) %>%
select(endPoint=`Component Endpoint Name`, ID=`AOP #`) %>%
distinct(),
aop_graph = plot_tox_endpoints_manuscript(chemicalSummary, AOP,
category = "Chemical",
font_size = 7,title = " ",
pallette = c("steelblue", "white")),
site_info = prep_site_list(tox_list$chem_site), #this makes the data frame factors with the right order
stack_plot = plot_tox_stacks_manuscript(chemicalSummary,
site_info,
font_size = 6,
category = "Chemical Class")
)
vis_drake_graph(data_analysis_plan, build_times = "none")
make(data_analysis_plan, trigger = trigger(condition=TRUE))
# drake_config(data_analysis_plan)
# In R console:
# r_make("passive_data_setup.R")
# loadd(aop_graph)
# pdf("plots/AOP_v3.pdf", width = 4.5, height = 4.5)
# ggarrange(
# aop_graph$count_plot, aop_graph$stackedPlot,
# aop_graph$chem_plot, aop_graph$aop_plot,nrow = 1,ncol = 4,
# widths = c(4/10,4/10,1/10,1/10)
# )
# dev.off()
#
# loadd(toxPlot_ear_conc)
# pdf("plots/EAR_Conc_all.pdf", width = 4.5, height = 22, onefile=FALSE)
# ggarrange(
# toxPlot_ear_conc$site_graph,
# toxPlot_ear_conc$no_axis,
# widths = c(3.25/9, 5.75/9),
# common.legend = TRUE, legend = "bottom"
# )
# dev.off()
#
# loadd(toxPlot_ear_conc_detects)
# pdf("plots/EAR_Conc_detects.pdf", width = 4.5, height = 11, onefile=FALSE)
# ggarrange(
# toxPlot_ear_conc_detects$site_graph,
# toxPlot_ear_conc_detects$no_axis,
# widths = c(3.25/9, 5.75/9),
# common.legend = TRUE, legend = "bottom"
# )
# dev.off()
#
# loadd(toxPlot_ear_conc_matches)
# pdf("plots/EAR_Conc_detects_match.pdf", width = 4.75, height = 9, onefile=FALSE)
# ggarrange(
# toxPlot_ear_conc_matches$site_graph,
# toxPlot_ear_conc_matches$no_axis,
# widths = c(3.25/9, 5.75/9),
# common.legend = TRUE, legend = "bottom"
# )
# dev.off()
#
#
# ###########################
# loadd(graphData_tox_det)
# loadd(graphData_conc_det_match)
# loadd(tox_list)
# source(file = "R/report/combo_plot2.R")
# toxPlot_ear_conc_matches = fancy_combo(graphData_tox_det,
# graphData_conc_det_match,
# tox_list)
#
# pdf("plots/EAR_Conc_detects_match.pdf", width = 4.5, height = 9, onefile=FALSE)
# ggarrange(
# toxPlot_ear_conc_matches$site_graph,
# toxPlot_ear_conc_matches$no_axis,
# widths = c(3.25/9, 5.75/9),
# common.legend = TRUE, legend = "bottom"
# )
# dev.off()