-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
357 lines (315 loc) · 14.5 KB
/
app.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
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
library(shiny)
library(tidyverse)
library(ggpubr)
library(patchwork)
library(data.table)
library(DT)
library(htmltools)
# LOAD DATA
#https://www.illumina.com/systems/sequencing-platforms.html
sequencers <- read.csv("data/sequencers.csv") %>% mutate(read_length = as.factor(read_length))
sequencers2 <- sequencers %>% gather("min_max","output_Gbp",c("min_output_Gbp","max_output_Gbp")) %>%
mutate(min_max = gsub("_output_Gbp", "", min_max)) %>%
mutate(output_bp=output_Gbp*(10^9)) %>%
mutate(output_reads=ifelse(paired==1,
((output_bp/length/2)*(10^-6)),
((output_bp/length)*(10^-6)))) %>%
mutate(cost_per_lane=cost/num_lanes) %>%
mutate(output_Gbp_per_lane=output_Gbp/num_lanes) %>%
mutate(output_bp_per_lane=output_bp/num_lanes) %>%
mutate(output_reads_per_lane=output_reads/num_lanes)
{sketch <- withTags(
table(
class = "display",
thead(
tr(
th(colspan = 1, "Sequencer", style = "border-right: solid 2px;"),
th(colspan = 1, "No. Lanes", style = "border-right: solid 2px;"),
th(colspan = 2, "Flow Cell Gbp", style = "border-right: solid 2px;"),
th(colspan = 2, "Lane Gbp", style = "border-right: solid 2px;"),
th(colspan = 1, "Flow Cell Cost", style = "border-right: solid 2px;"),
th(colspan = 1, "Lane Cost", style = "border-right: solid 2px;"),
th(colspan = 2, "% Flow Cell", style = "border-right: solid 2px;"),
th(colspan = 2, "% Lane", style = "border-right: solid 2px;"),
th(colspan = 2, "% Cost", style = "border-right: solid 2px;"),
th(colspan = 1, "Overfilled?", style = "border-right: solid 2px;"),
),
tr(
th(colspan = 1, "", style = "border-right: solid 2px;"),
th(colspan = 1, "", style = "border-right: solid 2px;"),
th(colspan = 1, "min"),
th(colspan = 1, "max", style = "border-right: solid 2px;"),
th(colspan = 1, "min"),
th(colspan = 1, "max", style = "border-right: solid 2px;"),
th(colspan = 1, "", style = "border-right: solid 2px;"),
th(colspan = 1, "", style = "border-right: solid 2px;"),
th(colspan = 1, "min"),
th(colspan = 1, "max", style = "border-right: solid 2px;"),
th(colspan = 1, "min"),
th(colspan = 1, "max", style = "border-right: solid 2px;"),
th(colspan = 1, "min"),
th(colspan = 1, "max", style = "border-right: solid 2px;"),
th(colspan = 1, "", style = "border-right: solid 2px;"),
)
)
)
)
}
# Define UI for dataset viewer app ----
ui <- fluidPage(
fluidRow(
column(4,
img(src = "SequencingEstimator.png", height = 250, width = 240, style="float:right"),
titlePanel("Sequencing Estimator"),
h4("Rhett M. Rautsaw"),
h5(a(href="https://github.com/RhettRautsaw/SequencingEstimator","github.com/RhettRautsaw/SequencingEstimator")),
helpText("This application is designed to help you choose the right sequencing platform and estimate costs."),
helpText("The app currently provides space for Whole-Genome Sequencing (WGS), RNA-seq, Whole-Genome Bisulfite Sequencing (WGBS), ATAC-Seq, and ddRAD-Seq. However, given desired coverage or number of reads (in million), the fields could be used any type of sequencing."),
helpText("Most information was obtained from:",tags$a(href="https://www.illumina.com/systems/sequencing-platforms.html", "Illumina")),
helpText("The recommended number of reads and coverage are default input for all options")
),
column(2,
# Input: Genome Size
numericInput(inputId = "genome_size",
label = "Genome Size (Gb):",
value = 3.0),
helpText("Not required for RNA-Seq, ATAC-Seq, ddRAD-Seq, or any sequencing type based on
sequencing a specific number or reads rather than coverage."),
hr(),
# Input: Read Length
selectInput(inputId = "read_length_choice", label = "Read Length:",
choices = levels(sequencers$read_length), selected="2 x 150"),
helpText("Read length is not applicable for PacBio sequencing and will be included regardless."),
helpText("Illumina sequencers will be filtered by which are applicable with the chosen read length.")),
column(2,
# Input: Whole Genome Sequencing (WGS)
numericInput(inputId = "wgs_quantity",
label = "WGS Samples:",
value = 0),
numericInput(inputId = "wgs_coverage",
label = "WGS Coverage:",
value = 30),
hr(),
# Input: Transcriptome Sequencing (RNA-Seq)
numericInput(inputId = "rna_quantity",
label = "RNA-Seq Samples:",
value = 0),
numericInput(inputId = "rna_reads",
label = "RNA-Seq reads per sample (in millions):",
value = 20)),
column(2,
# Input: Whole Genome Bisulfite Sequencing (WGBS)
numericInput(inputId = "wgbs_quantity",
label = "WGBS Samples:",
value = 0),
numericInput(inputId = "wgbs_coverage",
label = "WGBS Coverage:",
value = 20),
hr(),
# Input: ATAC-Seq
numericInput(inputId = "atac_quantity",
label = "ATAC-Seq Samples:",
value = 0),
numericInput(inputId = "atac_reads",
label = "ATAC-Seq reads per sample (in millions):",
value = 60)),
column(2,
# Input: ddRAD-Seq
numericInput(inputId = "ddrad_quantity",
label = "ddRAD-Seq Samples:",
value = 0),
numericInput(inputId = "ddrad_reads",
label = "ddRAD-Seq reads per sample (in millions):",
value = 5),
hr(),
helpText("If you have updated information on sequencing platforms or costs, \
you can download an example of the necessary data, update it, and re-upload it here for your needs."),
downloadButton("downloadData", "Download"),
helpText(""),
fileInput("file1", "Choose CSV File",
multiple = TRUE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv"))
)
),
hr(),
fluidRow(
column(2,
h2("Total:"),
h4(textOutput("txtOutput1")),
h4(textOutput("txtOutput2")),
h4(textOutput("txtOutput3"))
),
column(10,
dataTableOutput("dataTableOutput1"))
),
fluidRow(
column(6,plotOutput("pltOutput1")),
column(6,plotOutput("pltOutput2"))
),
fluidRow(
column(12,plotOutput("pltOutput3"))
)
)
# Define server logic to summarize and view selected dataset ----
server <- function(input, output) {
data<-reactive({
if(is.null(input$file1)){
data<-sequencers2 %>% filter(is.na(read_length) | read_length==input$read_length_choice)
data
}else{
req(input$file1)
sequencers <- read.csv(input$file1$datapath)
sequencers2 <- sequencers %>% gather("min_max","output_Gbp",c("min_output_Gbp","max_output_Gbp")) %>%
mutate(min_max = gsub("_output_Gbp", "", min_max)) %>%
mutate(output_bp=output_Gbp*(10^9)) %>%
mutate(output_reads=ifelse(paired==1,
((output_bp/length/2)*(10^-6)),
((output_bp/length)*(10^-6)))) %>%
mutate(cost_per_lane=cost/num_lanes) %>%
mutate(output_Gbp_per_lane=output_Gbp/num_lanes) %>%
mutate(output_bp_per_lane=output_bp/num_lanes) %>%
mutate(output_reads_per_lane=output_reads/num_lanes)
data<-sequencers2 %>% filter(is.na(read_length) | read_length==input$read_length_choice)
data
}
})
read_var<-reactive({
read_var<-as.numeric(data() %>% select(length) %>% filter(!is.na(length)) %>% distinct())
read_var
})
total_bp<-reactive({
wgs_total_bp<-input$wgs_quantity*(input$genome_size*(10^9)*input$wgs_coverage)
rna_total_bp<-input$rna_quantity*(input$rna_reads*(10^6)*read_var())
wgbs_total_bp<-input$wgbs_quantity*(input$genome_size*(10^9)*input$wgbs_coverage)
atac_total_bp<-input$atac_quantity*(input$atac_reads*(10^6)*read_var())
ddrad_total_bp<-input$ddrad_quantity*(input$ddrad_reads*(10^6)*read_var())
total_bp<-sum(wgs_total_bp,
rna_total_bp,
wgbs_total_bp,
atac_total_bp,
ddrad_total_bp)
total_bp
})
total_Gbp<-reactive({
total_Gbp<-total_bp()*(10^-9)
total_Gbp
})
total_reads<-reactive({
total_reads<-(total_bp()/read_var())*(10^-6)
total_reads
})
data2<-reactive({
data2<-data() %>%
mutate(Percent_filled = (total_Gbp()/output_Gbp)*100) %>%
mutate(Percent_filled_lane = (total_Gbp()/output_Gbp_per_lane)*100) %>%
mutate(Percent_filled_cost = (cost*(Percent_filled/100)))
data2
})
output$txtOutput1 = renderText({
paste0(format(round(total_Gbp(),2),scientific = F, big.mark=","), " Gbp")
})
output$txtOutput2 = renderText({
paste0(format(round(total_bp(),2),scientific = F, big.mark=","), " bp")
})
output$txtOutput3 = renderText({
paste0(format(round(total_reads(),2),scientific = F, big.mark=","), " M reads")
})
output$dataTableOutput1 = DT::renderDataTable({
data3<-dcast(setDT(data2()), sequencer~min_max, value.var = c(names(data2()))) %>%
select(sequencer, num_lanes_min, output_Gbp_min, output_Gbp_max,
output_Gbp_per_lane_min, output_Gbp_per_lane_max,
cost_min, cost_per_lane_min,
Percent_filled_max,Percent_filled_min, Percent_filled_lane_max,Percent_filled_lane_min,
Percent_filled_cost_max,Percent_filled_cost_min) %>%
mutate(overfilled=ifelse(Percent_filled_min>100, "yes","no")) %>%
arrange(output_Gbp_max)
datatable(data3, rownames = FALSE, container = sketch,
options = list(
columnDefs = list(
list(targets = "_all", className = "dt-center")
),
pageLength = 20
)) %>%
formatStyle(c(1,2,4,6,7,8,10,12,14,15), `border-right` = "solid 2px") %>%
formatRound(c(9:14), digits=0) %>%
formatCurrency(c(7,8,13,14), digits=0) %>%
formatStyle(
'overfilled',
target = 'row',
backgroundColor = styleEqual(c("yes"), c("gray"))
)
})
output$pltOutput1 = renderPlot({
total_Gbp<-round(total_Gbp(),2)
total_reads<-round(total_reads(),2)
A<-ggbarplot(data2(),"sequencer","output_Gbp",add="mean_range",fill="sequencer",
xlab="",ylab="Gbp",title="Flow Cell Output (Gbp)",subtitle="log10 scale",
sort.val="desc",sort.by.groups = FALSE,
label=T,lab.hjust = 1.5, lab.vjust = 0.5,lab.nb.digits=1)+
yscale("log10")+coord_flip()+
geom_hline(yintercept=total_Gbp, size=2)+
geom_text(aes(10,total_Gbp,label = total_Gbp, hjust = 1.5))+
theme_pubclean()+rremove("legend")
C<-ggbarplot(data2(),"sequencer","output_reads",add="mean_range",fill="sequencer",
xlab="",ylab="Reads (millions)",title="Flow Cell Output (M reads)",subtitle="log10 scale",
sort.val="desc",sort.by.groups = FALSE,
label=T,lab.hjust = 1.5, lab.vjust = 0.5,lab.nb.digits=2)+
yscale("log10")+coord_flip()+
geom_hline(yintercept=total_reads, size=2)+
geom_text(aes(10,total_reads,label = total_reads, hjust = 1.5))+
theme_pubclean()+rremove("legend")
A+C
})
output$pltOutput2 = renderPlot({
total_Gbp<-round(total_Gbp(),2)
total_reads<-round(total_reads(),2)
B<-ggbarplot(data2(),"sequencer","output_Gbp_per_lane",add="mean_range",fill="sequencer",
xlab="",ylab="Gbp",title = "Lane Output (Gbp)",subtitle="log10 scale",
sort.val="desc",sort.by.groups = FALSE,
label=T,lab.hjust = 1.5, lab.vjust = 0.5,lab.nb.digits=1)+
yscale("log10")+coord_flip()+
geom_hline(yintercept=total_Gbp, size=2)+
geom_text(aes(10,total_Gbp,label = total_Gbp, hjust = 1.5))+
theme_pubclean()+rremove("legend")
D<-ggbarplot(data2(),"sequencer","output_reads_per_lane",add="mean_range",fill="sequencer",
xlab="",ylab="Reads (millions)",title = "Lane Output (M reads)", subtitle="log10 scale",
sort.val="desc",sort.by.groups = FALSE,
label=T,lab.hjust = 1.5, lab.vjust = 0.5,lab.nb.digits=2)+
yscale("log10")+coord_flip()+
geom_hline(yintercept=total_reads, size=2)+
geom_text(aes(10,total_reads,label = total_reads, hjust = 1.5))+
theme_pubclean()+rremove("legend")
B+D
})
output$pltOutput3 = renderPlot({
E<-ggbarplot(data2(),"sequencer","Percent_filled",add="mean_range",fill="sequencer",
xlab="",ylab="Percent Filled",title = "Flow Cell Filled",subtitle=">100% is overfilled",
sort.val="desc",sort.by.groups = FALSE,
label=T,lab.hjust = -0.5,lab.nb.digits=2)+
coord_flip(ylim=c(0,100))+theme_pubclean()+rremove("legend")
F<-ggbarplot(data2(),"sequencer","Percent_filled_lane",add="mean_range",fill="sequencer",
xlab="",ylab="Percent Filled",title = "Lane Filled",subtitle=">100% is overfilled",
sort.val="desc",sort.by.groups = FALSE,
label=T,lab.hjust = -0.5, lab.nb.digits=2)+
coord_flip(ylim=c(0,100))+theme_pubclean()+rremove("legend")
G<-ggbarplot(data2(),"sequencer","Percent_filled_cost",add="mean_range",fill="sequencer",
xlab="",ylab="Cost (USD)",title = "Cost", subtitle="",
sort.val="desc",sort.by.groups = FALSE,
label=T,lab.hjust = 1.5, lab.vjust = 0.5,lab.nb.digits=2)+
yscale("log10")+coord_flip()+
theme_pubclean()+rremove("legend")
E+F+G
})
output$downloadData <- downloadHandler(
filename = function() {
paste("sequencers.csv", sep = "")
},
content = function(file) {
write.csv(sequencers, file, row.names = FALSE)
}
)
}
# Create Shiny app ----
shinyApp(ui, server)