-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
228 lines (208 loc) · 6.69 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
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyWidgets)
library(DT)
library(ggplot2)
library(xgboost)
library(Biostrings)
library(GenomicRanges)
library(pROC)
library(plotly)
# sourcing the scripts
source("src/data_preprocessing.R")
source("src/feature_engineering.R")
source("src/model_training.R")
source("src/model_evaluation.R")
source("src/sql_processing.R")
# custom css for the app
custom_css <- "
.content-wrapper, .right-side {
background-color: #f4f6f9;
}
.box {
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
}
.box:hover {
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
}
.custom-file-input::-webkit-file-upload-button {
visibility: hidden;
}
.custom-file-input::before {
content: 'Select FASTQ file';
display: inline-block;
background: linear-gradient(top, #f9f9f9, #e3e3e3);
border: 1px solid #999;
border-radius: 3px;
padding: 5px 8px;
outline: none;
white-space: nowrap;
-webkit-user-select: none;
cursor: pointer;
text-shadow: 1px 1px #fff;
font-weight: 700;
font-size: 10pt;
}
.custom-file-input:hover::before {
border-color: black;
}
.custom-file-input:active::before {
background: -webkit-linear-gradient(top, #e3e3e3, #f9f9f9);
}
"
ui <- dashboardPagePlus(
header = dashboardHeaderPlus(
title = "NGS Data Analysis"
),
sidebar = dashboardSidebar(
sidebarMenu(
menuItem("Data Upload", tabName = "upload", icon = icon("upload")),
menuItem("Preprocessing", tabName = "preprocess", icon = icon("cogs")),
menuItem("Feature Engineering", tabName = "features", icon = icon("chart-bar")),
menuItem("Model Training", tabName = "train", icon = icon("robot")),
menuItem("Model Evaluation", tabName = "evaluate", icon = icon("chart-line"))
)
),
body = dashboardBody(
tags$head(tags$style(HTML(custom_css))),
tabItems(
# Data Upload tab
tabItem(tabName = "upload",
fluidRow(
box(
title = "Upload FASTQ File", status = "primary", solidHeader = TRUE,
fileInput("file", "Choose FASTQ File", accept = c(".fastq", ".fq"),
class = "custom-file-input"),
actionBttn("upload_btn", "Upload and Process",
style = "gradient", color = "primary")
)
)
),
# Preprocessing tab
tabItem(tabName = "preprocess",
fluidRow(
box(
title = "Data Preprocessing Summary", status = "info", solidHeader = TRUE,
verbatimTextOutput("preprocess_summary")
),
box(
title = "Quality Plot", status = "info", solidHeader = TRUE,
plotlyOutput("quality_plot")
)
)
),
# Feature Engineering tab
tabItem(tabName = "features",
fluidRow(
box(
title = "Featured Data", status = "success", solidHeader = TRUE, width = 12,
DTOutput("feature_table")
)
),
fluidRow(
box(
downloadBttn("download_features", "Download Featured Data",
style = "gradient", color = "success")
)
)
),
# Model Training tab
tabItem(tabName = "train",
fluidRow(
box(
title = "Model Training", status = "warning", solidHeader = TRUE,
sliderInput("train_ratio", "Training Data Ratio:",
min = 0.5, max = 0.9, value = 0.8, step = 0.1),
actionBttn("train_btn", "Train Model",
style = "gradient", color = "warning")
),
box(
title = "Training Summary", status = "warning", solidHeader = TRUE,
verbatimTextOutput("train_summary")
)
)
),
# Model Evaluation tab
tabItem(tabName = "evaluate",
fluidRow(
box(
title = "Evaluation Metrics", status = "danger", solidHeader = TRUE,
verbatimTextOutput("eval_summary")
),
box(
title = "ROC Curve", status = "danger", solidHeader = TRUE,
plotlyOutput("roc_plot")
)
),
fluidRow(
box(
title = "Feature Importance", status = "danger", solidHeader = TRUE, width = 12,
plotlyOutput("feature_importance_plot")
)
)
)
)
)
)
server <- function(input, output, session) {
values <- reactiveValues(
raw_data = NULL,
preprocessed_data = NULL,
featured_data = NULL,
model = NULL,
evaluation = NULL,
db_connection = NULL
)
source("data_handlers.R")
source("model_handlers.R")
source("ui_handlers.R")
observeEvent(input$upload_btn, {
values$raw_data <- load_and_preprocess_data(input$file$datapath)
})
observe({
req(values$preprocessed_data)
values$featured_data <- engineer_features(values$preprocessed_data)
})
observeEvent(input$train_btn, {
req(values$featured_data)
values$model <- train_model(values$featured_data, input$train_ratio)
})
observe({
req(values$model, values$featured_data)
values$evaluation <- evaluate_model(values$model, values$featured_data, input$train_ratio)
})
observe({
update_preprocessing_ui(input, output, values)
update_feature_engineering_ui(input, output, values)
update_model_training_ui(input, output, values)
update_model_evaluation_ui(input, output, values)
})
# Initialize database connection
observe({
values$db_connection <- create_db_connection("ngs_data.sqlite")
create_tables(values$db_connection)
})
# Insert raw data into database
observe({
req(values$raw_data)
insert_raw_data(values$db_connection, values$raw_data)
})
# Insert processed data into database
observe({
req(values$preprocessed_data)
insert_processed_data(values$db_connection, values$preprocessed_data)
})
# Insert featured data into database
observe({
req(values$featured_data)
insert_featured_data(values$db_connection, values$featured_data)
})
# Close database connection when the session ends
session$onSessionEnded(function() {
if (!is.null(values$db_connection)) {
close_db_connection(values$db_connection)
}
})
}