-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pooling visualization 3.Rmd
196 lines (159 loc) · 6.66 KB
/
Pooling visualization 3.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
---
title: 'Pooling: Visualization 3'
author: "Xianbin Cheng"
date: "February 16, 2019"
output: html_document
---
# Objective
Visualize the metrics for 48- and 96-well plate scenarios under the assumptions that healthy kernels follow modified PERT(0, 0.7, 19.99, 80) and contaminated kernels follow Gamma(2, mode = 40000).
# Method
1. Load all the necessary packages and source codes.
```{r, message=FALSE, warning = FALSE}
library(tidyverse)
library(Hmisc)
source("1D_pooling_simulation.R")
source("2D_pooling_simulation.R")
source("STD_simulation.R")
```
2. Read rds files and necessary parameters.
* These files contain simulation results of STD(48; 7; 2) pooling, STD(96; 5; 3), one-dimensional and two-dimensional poolings. The iteration time is 1000. The seed is set at 123.
```{r, eval = FALSE}
# 48-well
STD_48 = readRDS(file = "STD_48_7_2_10000.rds")
pool_row_48 = readRDS("1D_row_48_10000.rds")
pool_col_48 = readRDS("1D_col_48_10000.rds")
pool_2d_48 = readRDS("2D_48_10000.rds")
STD_scheme_48 = read.csv("STD_48_7_2_1pos.csv", header = TRUE, row.names = 1)
# 96-well
STD_96 = readRDS(file = "STD_96_5_3_10000.rds")
pool_row_96 = readRDS("1D_row_96_10000.rds")
pool_col_96 = readRDS("1D_col_96_10000.rds")
pool_2d_96 = readRDS("2D_96_10000.rds")
STD_scheme_96 = read.csv("STD_96_5_3_1pos.csv", header = TRUE, row.names = 1)
```
3. Clean them up for visualization.
```{r, eval= FALSE}
### STD
# 48-well
metrics_STD_48 = do.call(what = rbind.data.frame, args = STD_48) %>%
gather(data = ., key = "Type", value = "Value", - n_pos)
cost_STD_48 = calc_STD_cost(data = STD_48, n = 48, scheme = STD_scheme_48)
# 96-well
metrics_STD_96 = do.call(what = rbind.data.frame, args = STD_96) %>%
gather(data = ., key = "Type", value = "Value", - n_pos)
cost_STD_96 = calc_STD_cost(data = STD_96, n = 96, scheme = STD_scheme_96)
```
```{r, eval= FALSE}
### 48-well
# Pool by rows
metrics_row_48 = do.call(what = rbind.data.frame, args = pool_row_48) %>%
gather(data = ., key = "Type", value = "Value", - n_pos)
cost_row_48 = calc_1d_cost(data = pool_row_48, n = 48, by = "row")
# Pool by columns
metrics_col_48 = do.call(what = rbind.data.frame, args = pool_col_48) %>%
gather(data = ., key = "Type", value = "Value", - n_pos)
cost_col_48 = calc_1d_cost(data = pool_col_48, n = 48, by = "column")
### 96-well
# Pool by rows
metrics_row_96 = do.call(what = rbind.data.frame, args = pool_row_96) %>%
gather(data = ., key = "Type", value = "Value", - n_pos)
cost_row_96 = calc_1d_cost(data = pool_row_96, n = 96, by = "row")
# Pool by columns
metrics_col_96 = do.call(what = rbind.data.frame, args = pool_col_96) %>%
gather(data = ., key = "Type", value = "Value", - n_pos)
cost_col_96 = calc_1d_cost(data = pool_col_96, n = 96, by = "column")
```
```{r, eval = FALSE}
## 2D Pool
# 48-well
metrics_2d_48 = do.call(what = rbind.data.frame, args = pool_2d_48) %>%
gather(data = ., key = "Type", value = "Value", - n_pos)
cost_2d_48 = calc_2d_cost(data = pool_2d_48, n = 48)
# 96-well
metrics_2d_96 = do.call(what = rbind.data.frame, args = pool_2d_96) %>%
gather(data = ., key = "Type", value = "Value", - n_pos)
cost_2d_96 = calc_2d_cost(data = pool_2d_96, n = 96)
```
```{r, eval= FALSE}
#### 48-well
### All metrics
metrics_all_48 = bind_rows(metrics_STD_48, metrics_row_48, metrics_col_48, metrics_2d_48) %>%
mutate(Pooling = c(rep("STD", times = nrow(metrics_STD_48)),
rep("Row", times = nrow(metrics_row_48)),
rep("Column", times = nrow(metrics_col_48)),
rep("2D", times = nrow(metrics_2d_48))))
### All cost
cost_all_48 = bind_rows(cost_STD_48, cost_row_48, cost_col_48, cost_2d_48) %>%
mutate(Pooling = c(rep("STD", times = nrow(cost_STD_48)),
rep("Row", times = nrow(cost_row_48)),
rep("Column", times = nrow(cost_col_48)),
rep("2D", times = nrow(cost_2d_48))))
### 96-well
### All metrics
metrics_all_96 = bind_rows(metrics_STD_96, metrics_row_96, metrics_col_96, metrics_2d_96) %>%
mutate(Pooling = c(rep("STD", times = nrow(metrics_STD_96)),
rep("Row", times = nrow(metrics_row_96)),
rep("Column", times = nrow(metrics_col_96)),
rep("2D", times = nrow(metrics_2d_96))))
### All cost
cost_all_96 = bind_rows(cost_STD_96, cost_row_96, cost_col_96, cost_2d_96) %>%
mutate(Pooling = c(rep("STD", times = nrow(cost_STD_96)),
rep("Row", times = nrow(cost_row_96)),
rep("Column", times = nrow(cost_col_96)),
rep("2D", times = nrow(cost_2d_96))))
```
```{r, eval= FALSE}
write.csv(x = metrics_all_48, file = "Metrics_all_48_02_16_19.csv")
write.csv(x = metrics_all_96, file = "Metrics_all_96_02_16_19.csv")
write.csv(x = cost_all_48, file = "Cost_all_48_02_16_19.csv")
write.csv(x = cost_all_96, file = "Cost_all_96_02_16_19.csv")
```
```{r, echo= FALSE}
fix_levels = function(data){
data$Pooling = factor(x = data$Pooling, levels = c("Column", "Row", "2D","STD"))
levels(data$Pooling) = c("1D: Column", "1D: Row", "2D", "STD")
return(data)
}
metrics_all_48 = read.csv(file = "Metrics_all_48_02_10_19.csv", row.names = 1) %>% fix_levels(.)
metrics_all_96 = read.csv(file = "Metrics_all_96_02_10_19.csv", row.names = 1) %>% fix_levels(.)
cost_all_48 = read.csv(file = "Cost_all_48_02_10_19.csv", row.names = 1) %>% fix_levels(.)
cost_all_96 = read.csv(file = "Cost_all_96_02_10_19.csv", row.names = 1) %>% fix_levels(.)
```
# Result
1. Visualization of metrics
```{r, fig.show = "hold", out.width = "50%"}
# 48-well
p1 = draw_metrics_all(df = metrics_all_48, n = 48, ylab = "Metric values (48-well plate)")
p1
# 96-well
p2 = draw_metrics_all(df = metrics_all_96, n = 96, ylab = "Metric values (96-well plate)")
p2
```
2. Visualization of reagent cost.
```{r, fig.show = "hold", out.width = "50%"}
# 48-well
p3 = draw_cost_all(df = cost_all_48, n = 48, var = n_test_total, ylab = "Total number of assays (48-well plate)")
p3
# 96-well
p4 = draw_cost_all(df = cost_all_96, n = 96, var = n_test_total, ylab = "Total number of assays (96-well plate)")
p4
```
3. Visualization of labor cost
```{r, fig.show = "hold", out.width = "50%"}
# 48-well
p5 = draw_cost_all(df = cost_all_48, n = 48, var = n_pipette, ylab = "Total number of pipetting (48-well plate)")
p5
# 96-well
p6 = draw_cost_all(df = cost_all_96, n = 96, var = n_pipette, ylab = "Total number of pipetting (96-well plate)")
p6
```
```{r, eval = FALSE, echo= FALSE}
pdf(file = "Pooling Visualization 5.pdf")
p1
p2
p3
p4
p5
p6
dev.off()
```