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|
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
library(shiny)
|
| 2 |
+
library(QTLseqr)
|
| 3 |
+
library(data.table)
|
| 4 |
library(dplyr)
|
| 5 |
+
library(tidyr)
|
| 6 |
+
library(vcfR)
|
| 7 |
library(ggplot2)
|
| 8 |
|
| 9 |
+
# QTL-seq Analysis Function
|
| 10 |
+
qtlseq <- function(input_csv = NULL,
|
| 11 |
+
output_table = "output_file.table",
|
| 12 |
+
delta_snp_plot = NULL,
|
| 13 |
+
qtlseq_csv = NULL,
|
| 14 |
+
refAlleleFreq = 0.20,
|
| 15 |
+
minTotalDepth = 100,
|
| 16 |
+
maxTotalDepth = 400,
|
| 17 |
+
minSampleDepth = 40,
|
| 18 |
+
minGQ = 99,
|
| 19 |
+
windowSize = NULL,
|
| 20 |
+
popStruc = NULL,
|
| 21 |
+
bulkSize = NULL,
|
| 22 |
+
replications = 10000,
|
| 23 |
+
intervals = c(95, 99),
|
| 24 |
+
alpha = 0.01) {
|
| 25 |
+
|
| 26 |
+
data <- read.csv(input_csv)
|
| 27 |
+
write.table(data, file = output_table, sep = "\t", row.names = FALSE, quote = FALSE)
|
| 28 |
+
|
| 29 |
+
col_data <- colnames(data[5:ncol(data)])
|
| 30 |
+
unique_samples <- unique(sub("\\..*", "", col_data))
|
| 31 |
+
|
| 32 |
+
HighBulk <- unique_samples[1]
|
| 33 |
+
LowBulk <- unique_samples[2]
|
| 34 |
+
chroms <- as.vector(unique(data[1]))
|
| 35 |
+
df <- importFromGATK(file = output_table, highBulk = HighBulk, lowBulk = LowBulk)
|
| 36 |
+
|
| 37 |
+
df_filt <- filterSNPs(
|
| 38 |
+
SNPset = df,
|
| 39 |
+
refAlleleFreq = refAlleleFreq,
|
| 40 |
+
minTotalDepth = minTotalDepth,
|
| 41 |
+
maxTotalDepth = maxTotalDepth,
|
| 42 |
+
minSampleDepth = minSampleDepth,
|
| 43 |
+
minGQ = minGQ
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
df_filt <- runGprimeAnalysis(
|
| 47 |
+
SNPset = df_filt,
|
| 48 |
+
windowSize = windowSize,
|
| 49 |
+
outlierFilter = "deltaSNP"
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
df_filt1 <- runQTLseqAnalysis(
|
| 53 |
+
SNPset = df_filt,
|
| 54 |
+
windowSize = windowSize,
|
| 55 |
+
popStruc = popStruc,
|
| 56 |
+
bulkSize = bulkSize,
|
| 57 |
+
replications = replications,
|
| 58 |
+
intervals = intervals
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
p <- ggplot(df_filt1, aes(x = POS)) +
|
| 62 |
+
geom_point(aes(y = deltaSNP), color = "#3b82f6", size = 0.5) +
|
| 63 |
+
geom_line(aes(y = tricubeDeltaSNP), color = "#ef4444", size = 0.8) +
|
| 64 |
+
geom_line(aes(y = CI_95), color = "#f97316", linetype = "solid", size = 0.6) +
|
| 65 |
+
geom_line(aes(y = -CI_95), color = "#f97316", linetype = "solid", size = 0.6) +
|
| 66 |
+
geom_line(aes(y = CI_99), color = "#10b981", linetype = "solid", size = 0.6) +
|
| 67 |
+
geom_line(aes(y = -CI_99), color = "#10b981", linetype = "solid", size = 0.6) +
|
| 68 |
+
geom_hline(yintercept = c(-1, 0, 1), linetype = "dashed", color = "#0ea5e9") +
|
| 69 |
+
facet_wrap(~CHROM, ncol = 4, scales = "free_x") +
|
| 70 |
+
labs(x = "Position (Mb)", y = expression(Delta *"SNP-index")) +
|
| 71 |
+
theme_minimal(base_size = 12) +
|
| 72 |
+
theme(
|
| 73 |
+
strip.text = element_text(face = "bold"),
|
| 74 |
+
axis.title = element_text(face = "bold")
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
ggsave("deltaSNPIndex.png", plot = p, dpi = 600, width = 12, height = 10, units = "in")
|
| 78 |
+
|
| 79 |
+
getQTLTable(SNPset = df_filt1, alpha = alpha, export = TRUE, fileName = "BSA_QTLseq.csv")
|
| 80 |
+
|
| 81 |
+
return(list(QTLseqResults = df_filt1, GprimeResults = df_filt, plot = p))
|
| 82 |
+
}
|
| 83 |
|
| 84 |
+
# UI
|
| 85 |
+
ui <- fluidPage(
|
| 86 |
+
tags$head(
|
| 87 |
+
tags$style(HTML("
|
| 88 |
+
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&display=swap');
|
| 89 |
+
|
| 90 |
+
body {
|
| 91 |
+
font-family: 'Poppins', sans-serif;
|
| 92 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 93 |
+
min-height: 100vh;
|
| 94 |
+
padding: 20px;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
.main-container {
|
| 98 |
+
background: white;
|
| 99 |
+
border-radius: 20px;
|
| 100 |
+
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
| 101 |
+
padding: 0;
|
| 102 |
+
overflow: hidden;
|
| 103 |
+
max-width: 1400px;
|
| 104 |
+
margin: 0 auto;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
.header {
|
| 108 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 109 |
+
color: white;
|
| 110 |
+
padding: 30px 40px;
|
| 111 |
+
text-align: center;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
.header h1 {
|
| 115 |
+
margin: 0;
|
| 116 |
+
font-size: 2.5em;
|
| 117 |
+
font-weight: 700;
|
| 118 |
+
text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
.header p {
|
| 122 |
+
margin: 10px 0 0 0;
|
| 123 |
+
font-size: 1.1em;
|
| 124 |
+
opacity: 0.95;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
.content-wrapper {
|
| 128 |
+
padding: 40px;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
.section-title {
|
| 132 |
+
color: #667eea;
|
| 133 |
+
font-size: 1.5em;
|
| 134 |
+
font-weight: 600;
|
| 135 |
+
margin-bottom: 20px;
|
| 136 |
+
padding-bottom: 10px;
|
| 137 |
+
border-bottom: 3px solid #667eea;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.card {
|
| 141 |
+
background: #f8f9fa;
|
| 142 |
+
border-radius: 15px;
|
| 143 |
+
padding: 25px;
|
| 144 |
+
margin-bottom: 30px;
|
| 145 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
| 146 |
+
transition: transform 0.3s ease;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
.card:hover {
|
| 150 |
+
transform: translateY(-5px);
|
| 151 |
+
box-shadow: 0 8px 12px rgba(0,0,0,0.15);
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.upload-area {
|
| 155 |
+
border: 3px dashed #667eea;
|
| 156 |
+
border-radius: 15px;
|
| 157 |
+
padding: 30px;
|
| 158 |
+
text-align: center;
|
| 159 |
+
background: linear-gradient(135deg, #f0f4ff 0%, #e9d5ff 100%);
|
| 160 |
+
transition: all 0.3s ease;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
.upload-area:hover {
|
| 164 |
+
border-color: #764ba2;
|
| 165 |
+
background: linear-gradient(135deg, #e9d5ff 0%, #f0f4ff 100%);
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.btn-primary {
|
| 169 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 170 |
+
border: none;
|
| 171 |
+
color: white;
|
| 172 |
+
padding: 12px 30px;
|
| 173 |
+
font-size: 1.1em;
|
| 174 |
+
font-weight: 600;
|
| 175 |
+
border-radius: 25px;
|
| 176 |
+
cursor: pointer;
|
| 177 |
+
transition: all 0.3s ease;
|
| 178 |
+
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
.btn-primary:hover {
|
| 182 |
+
transform: translateY(-2px);
|
| 183 |
+
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
.shiny-input-container {
|
| 187 |
+
margin-bottom: 20px;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
.shiny-input-container label {
|
| 191 |
+
color: #4a5568;
|
| 192 |
+
font-weight: 600;
|
| 193 |
+
margin-bottom: 8px;
|
| 194 |
+
display: block;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
input[type='number'], input[type='text'], select {
|
| 198 |
+
width: 100%;
|
| 199 |
+
padding: 12px;
|
| 200 |
+
border: 2px solid #e2e8f0;
|
| 201 |
+
border-radius: 10px;
|
| 202 |
+
font-size: 1em;
|
| 203 |
+
transition: all 0.3s ease;
|
| 204 |
+
font-family: 'Poppins', sans-serif;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
input[type='number']:focus, input[type='text']:focus, select:focus {
|
| 208 |
+
outline: none;
|
| 209 |
+
border-color: #667eea;
|
| 210 |
+
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
.param-grid {
|
| 214 |
+
display: grid;
|
| 215 |
+
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
| 216 |
+
gap: 20px;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
.progress-section {
|
| 220 |
+
background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
|
| 221 |
+
border-radius: 15px;
|
| 222 |
+
padding: 20px;
|
| 223 |
+
margin: 20px 0;
|
| 224 |
+
text-align: center;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
.results-section {
|
| 228 |
+
background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
|
| 229 |
+
border-radius: 15px;
|
| 230 |
+
padding: 25px;
|
| 231 |
+
margin-top: 20px;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
.plot-container {
|
| 235 |
+
background: white;
|
| 236 |
+
border-radius: 10px;
|
| 237 |
+
padding: 20px;
|
| 238 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
| 239 |
+
margin-top: 20px;
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
.download-btn {
|
| 243 |
+
background: linear-gradient(135deg, #10b981 0%, #059669 100%);
|
| 244 |
+
border: none;
|
| 245 |
+
color: white;
|
| 246 |
+
padding: 10px 25px;
|
| 247 |
+
font-weight: 600;
|
| 248 |
+
border-radius: 20px;
|
| 249 |
+
cursor: pointer;
|
| 250 |
+
margin: 5px;
|
| 251 |
+
transition: all 0.3s ease;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
.download-btn:hover {
|
| 255 |
+
transform: translateY(-2px);
|
| 256 |
+
box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
.info-box {
|
| 260 |
+
background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
|
| 261 |
+
border-left: 4px solid #3b82f6;
|
| 262 |
+
padding: 15px;
|
| 263 |
+
border-radius: 10px;
|
| 264 |
+
margin: 15px 0;
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
.shiny-notification {
|
| 268 |
+
position: fixed;
|
| 269 |
+
top: 20px;
|
| 270 |
+
right: 20px;
|
| 271 |
+
border-radius: 10px;
|
| 272 |
+
font-family: 'Poppins', sans-serif;
|
| 273 |
+
}
|
| 274 |
+
"))
|
| 275 |
),
|
| 276 |
+
|
| 277 |
+
div(class = "main-container",
|
| 278 |
+
div(class = "header",
|
| 279 |
+
h1("𧬠QTL-seq Analysis Platform"),
|
| 280 |
+
p("Quantitative Trait Loci Sequencing Analysis Tool")
|
| 281 |
+
),
|
| 282 |
+
|
| 283 |
+
div(class = "content-wrapper",
|
| 284 |
+
# File Upload Section
|
| 285 |
+
div(class = "card",
|
| 286 |
+
h3(class = "section-title", "π Data Input"),
|
| 287 |
+
div(class = "upload-area",
|
| 288 |
+
fileInput("csvFile",
|
| 289 |
+
label = NULL,
|
| 290 |
+
accept = c(".csv"),
|
| 291 |
+
buttonLabel = "Browse...",
|
| 292 |
+
placeholder = "Select CSV file"),
|
| 293 |
+
p(style = "color: #667eea; font-weight: 600; margin-top: 10px;",
|
| 294 |
+
"Upload your QTL-seq data in CSV format")
|
| 295 |
+
)
|
| 296 |
+
),
|
| 297 |
+
|
| 298 |
+
# Parameters Section
|
| 299 |
+
div(class = "card",
|
| 300 |
+
h3(class = "section-title", "βοΈ Analysis Parameters"),
|
| 301 |
+
div(class = "info-box",
|
| 302 |
+
p(style = "margin: 0; color: #1e40af;",
|
| 303 |
+
"π Configure analysis parameters below. Default values are pre-filled.")
|
| 304 |
+
),
|
| 305 |
+
|
| 306 |
+
div(class = "param-grid",
|
| 307 |
+
numericInput("refAlleleFreq", "Reference Allele Frequency", 0.20, min = 0, max = 1, step = 0.01),
|
| 308 |
+
numericInput("minTotalDepth", "Min Total Depth", 100, min = 0),
|
| 309 |
+
numericInput("maxTotalDepth", "Max Total Depth", 400, min = 0),
|
| 310 |
+
numericInput("minSampleDepth", "Min Sample Depth", 40, min = 0),
|
| 311 |
+
numericInput("minGQ", "Min Genotype Quality", 99, min = 0, max = 100),
|
| 312 |
+
numericInput("windowSize", "Window Size", 500000, min = 0)
|
| 313 |
+
),
|
| 314 |
+
|
| 315 |
+
div(class = "param-grid", style = "margin-top: 20px;",
|
| 316 |
+
selectInput("popStruc", "Population Structure",
|
| 317 |
+
choices = c("F2" = "F2", "RIL" = "RIL", "BC" = "BC")),
|
| 318 |
+
textInput("bulkSize", "Bulk Sizes (comma-separated)", "20,20"),
|
| 319 |
+
numericInput("replications", "Replications", 10000, min = 1000),
|
| 320 |
+
numericInput("alpha", "Alpha Level", 0.01, min = 0, max = 1, step = 0.01)
|
| 321 |
+
)
|
| 322 |
+
),
|
| 323 |
+
|
| 324 |
+
# Run Analysis Button
|
| 325 |
+
div(style = "text-align: center; margin: 30px 0;",
|
| 326 |
+
actionButton("runAnalysis", "π Run QTL-seq Analysis",
|
| 327 |
+
class = "btn-primary",
|
| 328 |
+
style = "font-size: 1.2em; padding: 15px 40px;")
|
| 329 |
+
),
|
| 330 |
+
|
| 331 |
+
# Progress Section
|
| 332 |
+
conditionalPanel(
|
| 333 |
+
condition = "input.runAnalysis > 0",
|
| 334 |
+
div(class = "progress-section",
|
| 335 |
+
h4(style = "color: #92400e; margin-top: 0;", "β³ Analysis in Progress..."),
|
| 336 |
+
uiOutput("progressText")
|
| 337 |
+
)
|
| 338 |
+
),
|
| 339 |
+
|
| 340 |
+
# Results Section
|
| 341 |
+
conditionalPanel(
|
| 342 |
+
condition = "output.plotReady",
|
| 343 |
+
div(class = "results-section",
|
| 344 |
+
h3(class = "section-title", style = "color: #059669;", "β
Analysis Complete!"),
|
| 345 |
+
|
| 346 |
+
div(class = "plot-container",
|
| 347 |
+
h4(style = "color: #4a5568; margin-top: 0;", "Delta SNP-index Plot"),
|
| 348 |
+
plotOutput("deltaPlot", height = "800px")
|
| 349 |
+
),
|
| 350 |
+
|
| 351 |
+
div(style = "text-align: center; margin-top: 20px;",
|
| 352 |
+
downloadButton("downloadPlot", "π Download Plot", class = "download-btn"),
|
| 353 |
+
downloadButton("downloadQTL", "π Download QTL Table", class = "download-btn"),
|
| 354 |
+
downloadButton("downloadResults", "πΎ Download All Results", class = "download-btn")
|
| 355 |
+
),
|
| 356 |
+
|
| 357 |
+
div(style = "margin-top: 30px;",
|
| 358 |
+
h4(style = "color: #4a5568;", "π QTL Summary Statistics"),
|
| 359 |
+
tableOutput("qtlSummary")
|
| 360 |
+
)
|
| 361 |
+
)
|
| 362 |
+
)
|
| 363 |
+
)
|
| 364 |
+
)
|
| 365 |
)
|
| 366 |
|
| 367 |
+
# Server
|
| 368 |
server <- function(input, output, session) {
|
| 369 |
+
results <- reactiveValues(data = NULL, plot = NULL)
|
| 370 |
+
|
| 371 |
+
observeEvent(input$runAnalysis, {
|
| 372 |
+
req(input$csvFile)
|
| 373 |
+
|
| 374 |
+
withProgress(message = 'Running QTL-seq Analysis', value = 0, {
|
| 375 |
+
tryCatch({
|
| 376 |
+
incProgress(0.2, detail = "Loading data...")
|
| 377 |
+
|
| 378 |
+
bulkSizes <- as.numeric(strsplit(input$bulkSize, ",")[[1]])
|
| 379 |
+
|
| 380 |
+
incProgress(0.3, detail = "Filtering SNPs...")
|
| 381 |
+
|
| 382 |
+
result <- qtlseq(
|
| 383 |
+
input_csv = input$csvFile$datapath,
|
| 384 |
+
refAlleleFreq = input$refAlleleFreq,
|
| 385 |
+
minTotalDepth = input$minTotalDepth,
|
| 386 |
+
maxTotalDepth = input$maxTotalDepth,
|
| 387 |
+
minSampleDepth = input$minSampleDepth,
|
| 388 |
+
minGQ = input$minGQ,
|
| 389 |
+
windowSize = input$windowSize,
|
| 390 |
+
popStruc = input$popStruc,
|
| 391 |
+
bulkSize = bulkSizes,
|
| 392 |
+
replications = input$replications,
|
| 393 |
+
alpha = input$alpha
|
| 394 |
)
|
| 395 |
+
|
| 396 |
+
incProgress(0.8, detail = "Generating plots...")
|
| 397 |
+
|
| 398 |
+
results$data <- result
|
| 399 |
+
results$plot <- result$plot
|
| 400 |
+
|
| 401 |
+
incProgress(1, detail = "Complete!")
|
| 402 |
+
|
| 403 |
+
showNotification("Analysis completed successfully!", type = "message", duration = 5)
|
| 404 |
+
|
| 405 |
+
}, error = function(e) {
|
| 406 |
+
showNotification(paste("Error:", e$message), type = "error", duration = 10)
|
| 407 |
+
})
|
| 408 |
+
})
|
| 409 |
+
})
|
| 410 |
+
|
| 411 |
+
output$plotReady <- reactive({
|
| 412 |
+
return(!is.null(results$plot))
|
| 413 |
+
})
|
| 414 |
+
outputOptions(output, "plotReady", suspendWhenHidden = FALSE)
|
| 415 |
+
|
| 416 |
+
output$deltaPlot <- renderPlot({
|
| 417 |
+
req(results$plot)
|
| 418 |
+
results$plot
|
| 419 |
+
})
|
| 420 |
+
|
| 421 |
+
output$qtlSummary <- renderTable({
|
| 422 |
+
req(results$data)
|
| 423 |
+
qtl_table <- read.csv("BSA_QTLseq.csv")
|
| 424 |
+
head(qtl_table, 10)
|
| 425 |
+
})
|
| 426 |
+
|
| 427 |
+
output$progressText <- renderUI({
|
| 428 |
+
p(style = "color: #92400e; font-weight: 600;",
|
| 429 |
+
"Please wait while the analysis is running. This may take several minutes...")
|
| 430 |
+
})
|
| 431 |
+
|
| 432 |
+
output$downloadPlot <- downloadHandler(
|
| 433 |
+
filename = function() {
|
| 434 |
+
paste("deltaSNPIndex_", Sys.Date(), ".png", sep = "")
|
| 435 |
},
|
| 436 |
+
content = function(file) {
|
| 437 |
+
file.copy("deltaSNPIndex.png", file)
|
| 438 |
+
}
|
| 439 |
+
)
|
| 440 |
+
|
| 441 |
+
output$downloadQTL <- downloadHandler(
|
| 442 |
+
filename = function() {
|
| 443 |
+
paste("BSA_QTLseq_", Sys.Date(), ".csv", sep = "")
|
| 444 |
+
},
|
| 445 |
+
content = function(file) {
|
| 446 |
+
file.copy("BSA_QTLseq.csv", file)
|
| 447 |
+
}
|
| 448 |
+
)
|
| 449 |
+
|
| 450 |
+
output$downloadResults <- downloadHandler(
|
| 451 |
+
filename = function() {
|
| 452 |
+
paste("QTLseq_results_", Sys.Date(), ".zip", sep = "")
|
| 453 |
+
},
|
| 454 |
+
content = function(file) {
|
| 455 |
+
files <- c("deltaSNPIndex.png", "BSA_QTLseq.csv", "output_file.table")
|
| 456 |
+
zip(file, files[file.exists(files)])
|
| 457 |
+
}
|
| 458 |
)
|
| 459 |
}
|
| 460 |
|
| 461 |
+
# Run the application
|
| 462 |
+
shinyApp(ui = ui, server = server)
|
| 463 |
+
|
| 464 |
+
|