Spaces:
Sleeping
Sleeping
Update app.R
Browse files
app.R
CHANGED
|
@@ -17,22 +17,27 @@ ui <- fluidPage(
|
|
| 17 |
useShinyjs(),
|
| 18 |
tags$head(
|
| 19 |
tags$link(
|
| 20 |
-
href = "https://fonts.googleapis.com/css2?family=
|
| 21 |
rel = "stylesheet"
|
| 22 |
),
|
| 23 |
tags$style(HTML("
|
| 24 |
:root {
|
| 25 |
-
--bg: #
|
| 26 |
-
--panel: #
|
| 27 |
-
--
|
| 28 |
-
--
|
| 29 |
-
--
|
| 30 |
-
--
|
| 31 |
-
--
|
| 32 |
-
--
|
| 33 |
-
--
|
| 34 |
-
--
|
| 35 |
-
--
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
}
|
| 37 |
|
| 38 |
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
@@ -42,74 +47,78 @@ ui <- fluidPage(
|
|
| 42 |
color: var(--text);
|
| 43 |
font-family: var(--font-body);
|
| 44 |
min-height: 100vh;
|
|
|
|
| 45 |
}
|
| 46 |
|
| 47 |
/* ββ Header ββ */
|
| 48 |
.qtl-header {
|
| 49 |
-
background:
|
| 50 |
-
border-bottom:
|
| 51 |
-
padding:
|
|
|
|
| 52 |
display: flex;
|
| 53 |
align-items: center;
|
| 54 |
gap: 16px;
|
| 55 |
position: sticky;
|
| 56 |
top: 0;
|
| 57 |
z-index: 100;
|
|
|
|
| 58 |
}
|
| 59 |
.qtl-header .logo-mark {
|
| 60 |
-
width:
|
| 61 |
background: var(--accent1);
|
| 62 |
border-radius: 8px;
|
| 63 |
display: flex; align-items: center; justify-content: center;
|
| 64 |
font-family: var(--font-mono);
|
| 65 |
-
font-weight:
|
| 66 |
-
font-size:
|
| 67 |
-
color:
|
| 68 |
-
letter-spacing: -1px;
|
| 69 |
flex-shrink: 0;
|
|
|
|
| 70 |
}
|
| 71 |
.qtl-header h1 {
|
| 72 |
font-family: var(--font-mono);
|
| 73 |
-
font-size:
|
| 74 |
-
color: var(--
|
| 75 |
-
letter-spacing:
|
| 76 |
-
|
| 77 |
}
|
| 78 |
.qtl-header .subtitle {
|
| 79 |
-
font-size:
|
| 80 |
color: var(--muted);
|
| 81 |
-
letter-spacing:
|
| 82 |
-
margin-top:
|
| 83 |
}
|
| 84 |
.header-badges {
|
| 85 |
margin-left: auto;
|
| 86 |
-
display: flex; gap:
|
| 87 |
}
|
| 88 |
.badge-pill {
|
| 89 |
-
padding:
|
| 90 |
border-radius: 100px;
|
| 91 |
font-size: 10px;
|
| 92 |
font-family: var(--font-mono);
|
| 93 |
-
letter-spacing:
|
| 94 |
border: 1px solid;
|
|
|
|
| 95 |
}
|
| 96 |
-
.badge-pill.
|
| 97 |
-
.badge-pill.
|
| 98 |
-
.badge-pill.orange { color: var(--accent2); border-color:
|
| 99 |
|
| 100 |
/* ββ Layout ββ */
|
| 101 |
.qtl-layout {
|
| 102 |
display: grid;
|
| 103 |
-
grid-template-columns:
|
| 104 |
-
height: calc(100vh -
|
| 105 |
}
|
| 106 |
|
| 107 |
/* ββ Sidebar ββ */
|
| 108 |
.qtl-sidebar {
|
| 109 |
background: var(--panel);
|
| 110 |
-
border-right:
|
| 111 |
overflow-y: auto;
|
| 112 |
-
padding: 20px 16px;
|
| 113 |
}
|
| 114 |
.qtl-sidebar::-webkit-scrollbar { width: 4px; }
|
| 115 |
.qtl-sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
|
|
@@ -117,12 +126,12 @@ ui <- fluidPage(
|
|
| 117 |
.section-label {
|
| 118 |
font-family: var(--font-mono);
|
| 119 |
font-size: 9px;
|
| 120 |
-
letter-spacing:
|
| 121 |
color: var(--muted);
|
| 122 |
text-transform: uppercase;
|
| 123 |
margin-bottom: 10px;
|
| 124 |
-
margin-top:
|
| 125 |
-
padding-left:
|
| 126 |
display: flex;
|
| 127 |
align-items: center;
|
| 128 |
gap: 8px;
|
|
@@ -138,39 +147,53 @@ ui <- fluidPage(
|
|
| 138 |
/* file upload */
|
| 139 |
.qtl-upload {
|
| 140 |
border: 1.5px dashed var(--border);
|
| 141 |
-
border-radius:
|
| 142 |
-
padding:
|
| 143 |
-
transition: border-color .2s;
|
| 144 |
-
background:
|
| 145 |
margin-bottom: 8px;
|
| 146 |
}
|
| 147 |
-
.qtl-upload:hover { border-color: var(--accent1); }
|
| 148 |
.qtl-upload label {
|
| 149 |
-
font-size:
|
| 150 |
color: var(--accent1);
|
| 151 |
font-family: var(--font-mono);
|
| 152 |
letter-spacing: 1px;
|
| 153 |
-
margin-bottom:
|
| 154 |
display: block;
|
|
|
|
| 155 |
}
|
| 156 |
.qtl-upload .shiny-input-container { margin: 0 !important; }
|
| 157 |
-
.shiny-input-container { color: var(--text) !important; }
|
| 158 |
|
| 159 |
-
/*
|
| 160 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
.control-block label {
|
| 162 |
font-size: 10px;
|
| 163 |
-
color: var(--
|
| 164 |
-
letter-spacing:
|
| 165 |
font-family: var(--font-mono);
|
| 166 |
text-transform: uppercase;
|
| 167 |
display: block;
|
| 168 |
margin-bottom: 4px;
|
|
|
|
| 169 |
}
|
| 170 |
select, input[type='number'], input[type='text'] {
|
| 171 |
width: 100%;
|
| 172 |
-
background: #
|
| 173 |
-
border:
|
| 174 |
border-radius: 6px;
|
| 175 |
color: var(--text);
|
| 176 |
padding: 7px 10px;
|
|
@@ -180,60 +203,62 @@ ui <- fluidPage(
|
|
| 180 |
transition: border-color .2s;
|
| 181 |
appearance: none;
|
| 182 |
}
|
| 183 |
-
select:focus, input:focus { border-color: var(--accent1); }
|
| 184 |
|
| 185 |
-
/* checkbox group */
|
| 186 |
.shiny-input-checkboxgroup .checkbox label {
|
| 187 |
font-size: 11px;
|
| 188 |
-
color: var(--
|
| 189 |
display: flex;
|
| 190 |
align-items: center;
|
| 191 |
gap: 6px;
|
| 192 |
}
|
| 193 |
|
| 194 |
-
/*
|
| 195 |
.btn-run {
|
| 196 |
width: 100%;
|
| 197 |
-
padding:
|
| 198 |
-
background:
|
| 199 |
border: none;
|
| 200 |
border-radius: 8px;
|
| 201 |
-
color:
|
| 202 |
font-family: var(--font-mono);
|
| 203 |
font-size: 12px;
|
| 204 |
-
font-weight:
|
| 205 |
-
letter-spacing:
|
| 206 |
cursor: pointer;
|
| 207 |
-
transition:
|
| 208 |
margin-top: 16px;
|
|
|
|
| 209 |
}
|
| 210 |
-
.btn-run:hover {
|
| 211 |
.btn-run:active { transform: translateY(0); }
|
|
|
|
| 212 |
|
| 213 |
.btn-export {
|
| 214 |
width: 100%;
|
| 215 |
-
padding:
|
| 216 |
-
background:
|
| 217 |
-
border:
|
| 218 |
border-radius: 8px;
|
| 219 |
color: var(--accent3);
|
| 220 |
font-family: var(--font-mono);
|
| 221 |
font-size: 11px;
|
|
|
|
| 222 |
letter-spacing: 1px;
|
| 223 |
cursor: pointer;
|
| 224 |
margin-top: 8px;
|
| 225 |
transition: background .2s;
|
| 226 |
}
|
| 227 |
-
.btn-export:hover { background:
|
| 228 |
|
| 229 |
-
/* status
|
| 230 |
.status-row {
|
| 231 |
display: flex;
|
| 232 |
align-items: center;
|
| 233 |
gap: 8px;
|
| 234 |
padding: 8px 10px;
|
| 235 |
-
background:
|
| 236 |
-
border:
|
| 237 |
border-radius: 6px;
|
| 238 |
margin-top: 12px;
|
| 239 |
font-size: 11px;
|
|
@@ -246,7 +271,8 @@ ui <- fluidPage(
|
|
| 246 |
background: var(--muted);
|
| 247 |
flex-shrink: 0;
|
| 248 |
}
|
| 249 |
-
.status-dot.active { background: var(--accent3); box-shadow: 0 0
|
|
|
|
| 250 |
|
| 251 |
/* ββ Main content ββ */
|
| 252 |
.qtl-main {
|
|
@@ -256,21 +282,22 @@ ui <- fluidPage(
|
|
| 256 |
.qtl-main::-webkit-scrollbar { width: 6px; }
|
| 257 |
.qtl-main::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
|
| 258 |
|
| 259 |
-
/*
|
| 260 |
.qtl-tabs {
|
| 261 |
display: flex;
|
| 262 |
-
gap:
|
| 263 |
-
padding:
|
| 264 |
-
border-bottom:
|
| 265 |
-
background:
|
| 266 |
position: sticky;
|
| 267 |
top: 0;
|
| 268 |
z-index: 50;
|
| 269 |
overflow-x: auto;
|
|
|
|
| 270 |
}
|
| 271 |
.qtl-tabs::-webkit-scrollbar { display: none; }
|
| 272 |
.qtl-tab-btn {
|
| 273 |
-
padding:
|
| 274 |
border: none;
|
| 275 |
background: transparent;
|
| 276 |
color: var(--muted);
|
|
@@ -279,10 +306,11 @@ ui <- fluidPage(
|
|
| 279 |
letter-spacing: 1px;
|
| 280 |
text-transform: uppercase;
|
| 281 |
cursor: pointer;
|
| 282 |
-
border-bottom:
|
| 283 |
transition: color .2s, border-color .2s;
|
| 284 |
white-space: nowrap;
|
| 285 |
-
|
|
|
|
| 286 |
}
|
| 287 |
.qtl-tab-btn:hover { color: var(--text); }
|
| 288 |
.qtl-tab-btn.active { color: var(--accent1); border-bottom-color: var(--accent1); }
|
|
@@ -291,20 +319,21 @@ ui <- fluidPage(
|
|
| 291 |
.tab-content { display: none; padding: 24px; }
|
| 292 |
.tab-content.active { display: block; }
|
| 293 |
|
| 294 |
-
/*
|
| 295 |
.plot-card {
|
| 296 |
-
background:
|
| 297 |
-
border:
|
| 298 |
border-radius: 12px;
|
| 299 |
overflow: hidden;
|
| 300 |
margin-bottom: 20px;
|
|
|
|
| 301 |
}
|
| 302 |
.plot-card-header {
|
| 303 |
display: flex;
|
| 304 |
align-items: center;
|
| 305 |
-
padding:
|
| 306 |
border-bottom: 1px solid var(--border);
|
| 307 |
-
background:
|
| 308 |
gap: 10px;
|
| 309 |
}
|
| 310 |
.plot-card-icon {
|
|
@@ -314,15 +343,17 @@ ui <- fluidPage(
|
|
| 314 |
font-size: 13px;
|
| 315 |
flex-shrink: 0;
|
| 316 |
}
|
| 317 |
-
.plot-card-icon.
|
| 318 |
-
.plot-card-icon.orange { background:
|
| 319 |
-
.plot-card-icon.green { background:
|
| 320 |
-
.plot-card-icon.pink { background:
|
|
|
|
| 321 |
.plot-card-title {
|
| 322 |
font-family: var(--font-mono);
|
| 323 |
font-size: 12px;
|
| 324 |
color: var(--text);
|
| 325 |
-
letter-spacing:
|
|
|
|
| 326 |
}
|
| 327 |
.plot-card-subtitle { font-size: 10px; color: var(--muted); margin-top: 1px; }
|
| 328 |
.plot-card-body { padding: 16px; }
|
|
@@ -332,99 +363,89 @@ ui <- fluidPage(
|
|
| 332 |
display: flex;
|
| 333 |
gap: 10px;
|
| 334 |
flex-wrap: wrap;
|
| 335 |
-
margin-bottom:
|
| 336 |
}
|
| 337 |
.stat-chip {
|
| 338 |
-
padding:
|
| 339 |
-
border-radius:
|
| 340 |
font-family: var(--font-mono);
|
| 341 |
-
font-size:
|
|
|
|
|
|
|
|
|
|
| 342 |
}
|
| 343 |
-
.stat-chip.blue { background:
|
| 344 |
-
.stat-chip.orange { background:
|
| 345 |
-
.stat-chip.green { background:
|
| 346 |
-
.stat-chip.pink { background:
|
| 347 |
|
| 348 |
-
/*
|
| 349 |
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
|
| 350 |
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
|
| 351 |
@media (max-width: 1100px) { .grid-3 { grid-template-columns: 1fr 1fr; } }
|
| 352 |
@media (max-width: 800px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
|
| 353 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
/* DataTable */
|
| 355 |
.dataTables_wrapper { color: var(--text) !important; font-size: 12px; }
|
| 356 |
table.dataTable { background: transparent !important; color: var(--text) !important; border-collapse: collapse !important; }
|
| 357 |
table.dataTable thead th {
|
| 358 |
-
background:
|
| 359 |
color: var(--accent1) !important;
|
| 360 |
font-family: var(--font-mono) !important;
|
| 361 |
font-size: 10px !important;
|
| 362 |
letter-spacing: 1px !important;
|
| 363 |
-
border-bottom:
|
| 364 |
padding: 10px 12px !important;
|
|
|
|
| 365 |
}
|
| 366 |
table.dataTable tbody tr { background: transparent !important; }
|
| 367 |
-
table.dataTable tbody tr:hover td { background:
|
| 368 |
-
table.dataTable tbody td { border-bottom: 1px solid var(--border) !important; padding: 8px 12px !important; }
|
| 369 |
.dataTables_info, .dataTables_paginate { color: var(--muted) !important; font-size: 11px !important; }
|
| 370 |
-
.paginate_button { color: var(--
|
| 371 |
-
.paginate_button.current { background: var(--accent1) !important; color:
|
| 372 |
.dataTables_filter input, .dataTables_length select {
|
| 373 |
-
background: #
|
| 374 |
-
border:
|
| 375 |
color: var(--text) !important;
|
| 376 |
border-radius: 4px !important;
|
| 377 |
padding: 4px 8px !important;
|
| 378 |
}
|
| 379 |
|
| 380 |
-
/* ggplot backgrounds */
|
| 381 |
-
.shiny-plot-output { background: transparent !important; }
|
| 382 |
-
|
| 383 |
-
/* loading overlay */
|
| 384 |
-
.loading-overlay {
|
| 385 |
-
position: fixed;
|
| 386 |
-
inset: 0;
|
| 387 |
-
background: rgba(10,14,26,.85);
|
| 388 |
-
z-index: 9999;
|
| 389 |
-
display: flex;
|
| 390 |
-
flex-direction: column;
|
| 391 |
-
align-items: center;
|
| 392 |
-
justify-content: center;
|
| 393 |
-
gap: 16px;
|
| 394 |
-
}
|
| 395 |
-
.spinner {
|
| 396 |
-
width: 48px; height: 48px;
|
| 397 |
-
border: 3px solid var(--border);
|
| 398 |
-
border-top-color: var(--accent1);
|
| 399 |
-
border-radius: 50%;
|
| 400 |
-
animation: spin .8s linear infinite;
|
| 401 |
-
}
|
| 402 |
-
@keyframes spin { to { transform: rotate(360deg); } }
|
| 403 |
-
.loading-text { font-family: var(--font-mono); font-size: 12px; color: var(--accent1); letter-spacing: 2px; }
|
| 404 |
-
|
| 405 |
-
/* misc */
|
| 406 |
.info-box {
|
| 407 |
-
background:
|
| 408 |
-
border: 1px solid
|
| 409 |
border-radius: 8px;
|
| 410 |
padding: 12px 16px;
|
| 411 |
font-size: 12px;
|
| 412 |
-
color: var(--
|
| 413 |
line-height: 1.6;
|
| 414 |
margin-bottom: 16px;
|
| 415 |
}
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
|
|
|
| 420 |
font-size: 10px;
|
| 421 |
-
font-family: var(--font-mono);
|
| 422 |
-
margin: 2px;
|
| 423 |
-
background: rgba(255,255,255,.05);
|
| 424 |
-
border: 1px solid var(--border);
|
| 425 |
color: var(--muted);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 426 |
}
|
| 427 |
-
hr.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
|
| 428 |
"))
|
| 429 |
),
|
| 430 |
|
|
@@ -450,19 +471,33 @@ ui <- fluidPage(
|
|
| 450 |
|
| 451 |
div(class = "section-label", "Data Input"),
|
| 452 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 453 |
div(class = "qtl-upload",
|
| 454 |
tags$label("Genotype CSV"),
|
| 455 |
fileInput("geno_file", NULL, accept = ".csv",
|
| 456 |
-
buttonLabel = "Browse", placeholder = "genotypes.csv")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
),
|
|
|
|
| 458 |
div(class = "qtl-upload",
|
| 459 |
tags$label("Phenotype CSV"),
|
| 460 |
fileInput("pheno_file", NULL, accept = ".csv",
|
| 461 |
-
buttonLabel = "Browse", placeholder = "phenotypes.csv")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
),
|
| 463 |
|
| 464 |
-
checkboxInput("use_example", "Use built-in example data", value = TRUE),
|
| 465 |
-
|
| 466 |
div(class = "section-label", "Cross Type"),
|
| 467 |
div(class = "control-block",
|
| 468 |
selectInput("cross_type", NULL,
|
|
@@ -471,7 +506,7 @@ ui <- fluidPage(
|
|
| 471 |
"RIL (selfing)" = "riself",
|
| 472 |
"RIL (sib-mating)" = "risib",
|
| 473 |
"4-way cross" = "4way"),
|
| 474 |
-
selected = "
|
| 475 |
),
|
| 476 |
|
| 477 |
div(class = "section-label", "Phenotype"),
|
|
@@ -548,222 +583,52 @@ ui <- fluidPage(
|
|
| 548 |
|
| 549 |
# ββ OVERVIEW ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 550 |
div(id = "tab_overview", class = "tab-content active",
|
| 551 |
-
|
| 552 |
-
uiOutput("stat_markers"),
|
| 553 |
-
uiOutput("stat_inds"),
|
| 554 |
-
uiOutput("stat_chrs"),
|
| 555 |
-
uiOutput("stat_qtls")
|
| 556 |
-
),
|
| 557 |
-
div(class = "grid-2",
|
| 558 |
-
div(class = "plot-card",
|
| 559 |
-
div(class = "plot-card-header",
|
| 560 |
-
div(class = "plot-card-icon cyan", "π"),
|
| 561 |
-
div(div(class = "plot-card-title", "GENOME MAP"), div(class = "plot-card-subtitle", "Marker distribution"))
|
| 562 |
-
),
|
| 563 |
-
div(class = "plot-card-body", plotOutput("plot_genome_map", height = "320px") %>% withSpinner(color = "#00d4ff", type = 4))
|
| 564 |
-
),
|
| 565 |
-
div(class = "plot-card",
|
| 566 |
-
div(class = "plot-card-header",
|
| 567 |
-
div(class = "plot-card-icon orange", "π"),
|
| 568 |
-
div(div(class = "plot-card-title", "PHENOTYPE DIST"), div(class = "plot-card-subtitle", "Distribution & QQ"))
|
| 569 |
-
),
|
| 570 |
-
div(class = "plot-card-body", plotOutput("plot_pheno_dist", height = "320px") %>% withSpinner(color = "#ff6b35", type = 4))
|
| 571 |
-
)
|
| 572 |
-
),
|
| 573 |
-
div(class = "plot-card",
|
| 574 |
-
div(class = "plot-card-header",
|
| 575 |
-
div(class = "plot-card-icon green", "πΊ"),
|
| 576 |
-
div(div(class = "plot-card-title", "PHYSICAL MAP"), div(class = "plot-card-subtitle", "All chromosomes β marker positions"))
|
| 577 |
-
),
|
| 578 |
-
div(class = "plot-card-body", plotOutput("plot_physical_map", height = "260px") %>% withSpinner(color = "#7cfc00", type = 4))
|
| 579 |
-
)
|
| 580 |
),
|
| 581 |
|
| 582 |
# ββ MANHATTAN βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 583 |
div(id = "tab_manhattan", class = "tab-content",
|
| 584 |
-
|
| 585 |
-
"Manhattan plot shows βlog10(p-value) or LOD score across all chromosomes. Peaks above the threshold line are candidate QTL regions."
|
| 586 |
-
),
|
| 587 |
-
div(class = "plot-card",
|
| 588 |
-
div(class = "plot-card-header",
|
| 589 |
-
div(class = "plot-card-icon cyan", "π"),
|
| 590 |
-
div(div(class = "plot-card-title", "MANHATTAN PLOT"), div(class = "plot-card-subtitle", "LOD scores genome-wide"))
|
| 591 |
-
),
|
| 592 |
-
div(class = "plot-card-body",
|
| 593 |
-
div(class = "control-block", style = "max-width:200px; margin-bottom:12px;",
|
| 594 |
-
selectInput("manhattan_model", "Model:", choices = NULL)
|
| 595 |
-
),
|
| 596 |
-
plotOutput("plot_manhattan", height = "420px") %>% withSpinner(color = "#00d4ff", type = 4)
|
| 597 |
-
)
|
| 598 |
-
),
|
| 599 |
-
div(class = "plot-card",
|
| 600 |
-
div(class = "plot-card-header",
|
| 601 |
-
div(class = "plot-card-icon pink", "π―"),
|
| 602 |
-
div(div(class = "plot-card-title", "INTERACTIVE MANHATTAN"), div(class = "plot-card-subtitle", "Hover for marker details"))
|
| 603 |
-
),
|
| 604 |
-
div(class = "plot-card-body",
|
| 605 |
-
plotlyOutput("plot_manhattan_interactive", height = "380px") %>% withSpinner(color = "#ff3e8a", type = 4)
|
| 606 |
-
)
|
| 607 |
-
)
|
| 608 |
),
|
| 609 |
|
| 610 |
# ββ GENOME SCAN βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 611 |
div(id = "tab_genome", class = "tab-content",
|
| 612 |
-
|
| 613 |
-
div(class = "plot-card-header",
|
| 614 |
-
div(class = "plot-card-icon cyan", "π¬"),
|
| 615 |
-
div(div(class = "plot-card-title", "GENOME SCAN β ALL MODELS"), div(class = "plot-card-subtitle", "LOD profiles overlaid"))
|
| 616 |
-
),
|
| 617 |
-
div(class = "plot-card-body",
|
| 618 |
-
plotOutput("plot_scan_all_models", height = "480px") %>% withSpinner(color = "#00d4ff", type = 4)
|
| 619 |
-
)
|
| 620 |
-
)
|
| 621 |
),
|
| 622 |
|
| 623 |
# ββ CHROMOSOME PLOTS ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 624 |
div(id = "tab_chromosome", class = "tab-content",
|
| 625 |
-
|
| 626 |
-
"Per-chromosome LOD profiles styled like R/qtl's plotQTL. Significant peaks are labelled with QTL names."
|
| 627 |
-
),
|
| 628 |
-
div(class = "control-block", style = "max-width:200px; margin-bottom:16px;",
|
| 629 |
-
selectInput("chr_plot_model", "Model:", choices = NULL)
|
| 630 |
-
),
|
| 631 |
-
plotOutput("plot_chr_grid", height = "900px") %>% withSpinner(color = "#7cfc00", type = 4)
|
| 632 |
),
|
| 633 |
|
| 634 |
# ββ MODEL COMPARISON ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 635 |
div(id = "tab_model_comp", class = "tab-content",
|
| 636 |
-
|
| 637 |
-
div(class = "plot-card",
|
| 638 |
-
div(class = "plot-card-header",
|
| 639 |
-
div(class = "plot-card-icon orange", "βοΈ"),
|
| 640 |
-
div(div(class = "plot-card-title", "PEAK LOD COMPARISON"), div(class = "plot-card-subtitle", "Max LOD per model"))
|
| 641 |
-
),
|
| 642 |
-
div(class = "plot-card-body", plotOutput("plot_model_bar", height = "340px") %>% withSpinner(color="#ff6b35",type=4))
|
| 643 |
-
),
|
| 644 |
-
div(class = "plot-card",
|
| 645 |
-
div(class = "plot-card-header",
|
| 646 |
-
div(class = "plot-card-icon pink", "π·"),
|
| 647 |
-
div(div(class = "plot-card-title", "LOD HEATMAP"), div(class = "plot-card-subtitle", "Marker Γ Model"))
|
| 648 |
-
),
|
| 649 |
-
div(class = "plot-card-body", plotOutput("plot_lod_heatmap", height = "340px") %>% withSpinner(color="#ff3e8a",type=4))
|
| 650 |
-
)
|
| 651 |
-
),
|
| 652 |
-
div(class = "plot-card",
|
| 653 |
-
div(class = "plot-card-header",
|
| 654 |
-
div(class = "plot-card-icon cyan", "π"),
|
| 655 |
-
div(div(class = "plot-card-title", "MODEL CORRELATION"), div(class = "plot-card-subtitle", "LOD score agreement across models"))
|
| 656 |
-
),
|
| 657 |
-
div(class = "plot-card-body", plotOutput("plot_model_corr", height = "340px") %>% withSpinner(color="#00d4ff",type=4))
|
| 658 |
-
)
|
| 659 |
),
|
| 660 |
|
| 661 |
# ββ QTL EFFECTS βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 662 |
div(id = "tab_effects", class = "tab-content",
|
| 663 |
-
|
| 664 |
-
div(class = "plot-card",
|
| 665 |
-
div(class = "plot-card-header",
|
| 666 |
-
div(class = "plot-card-icon green", "π»"),
|
| 667 |
-
div(div(class = "plot-card-title", "EFFECT PLOT"), div(class = "plot-card-subtitle", "Genotype effect at peak markers"))
|
| 668 |
-
),
|
| 669 |
-
div(class = "plot-card-body",
|
| 670 |
-
div(class = "control-block", style = "margin-bottom:10px;",
|
| 671 |
-
selectInput("effect_qtl", "Select QTL:", choices = NULL)
|
| 672 |
-
),
|
| 673 |
-
plotOutput("plot_effects", height = "320px") %>% withSpinner(color="#7cfc00",type=4)
|
| 674 |
-
)
|
| 675 |
-
),
|
| 676 |
-
div(class = "plot-card",
|
| 677 |
-
div(class = "plot-card-header",
|
| 678 |
-
div(class = "plot-card-icon orange", "π¦"),
|
| 679 |
-
div(div(class = "plot-card-title", "PHENOTYPE Γ GENOTYPE"), div(class = "plot-card-subtitle", "Boxplot at peak marker"))
|
| 680 |
-
),
|
| 681 |
-
div(class = "plot-card-body",
|
| 682 |
-
plotOutput("plot_pheno_geno", height = "320px") %>% withSpinner(color="#ff6b35",type=4)
|
| 683 |
-
)
|
| 684 |
-
)
|
| 685 |
-
),
|
| 686 |
-
div(class = "plot-card",
|
| 687 |
-
div(class = "plot-card-header",
|
| 688 |
-
div(class = "plot-card-icon pink", "π‘"),
|
| 689 |
-
div(div(class = "plot-card-title", "PVE PROFILE"), div(class = "plot-card-subtitle", "Proportion of variance explained per position"))
|
| 690 |
-
),
|
| 691 |
-
div(class = "plot-card-body", plotOutput("plot_pve", height = "280px") %>% withSpinner(color="#ff3e8a",type=4))
|
| 692 |
-
)
|
| 693 |
),
|
| 694 |
|
| 695 |
# ββ 2D SCAN ββββββββββββββββββββββββββββββββββββββββββοΏ½οΏ½οΏ½ββββββββββββββββββ
|
| 696 |
div(id = "tab_pairwise", class = "tab-content",
|
| 697 |
-
|
| 698 |
-
div(class = "plot-card-header",
|
| 699 |
-
div(class = "plot-card-icon cyan", "π²"),
|
| 700 |
-
div(div(class = "plot-card-title", "2D GENOME SCAN"), div(class = "plot-card-subtitle", "Pairwise LOD / epistasis"))
|
| 701 |
-
),
|
| 702 |
-
div(class = "plot-card-body", plotOutput("plot_2d_scan", height = "560px") %>% withSpinner(color="#00d4ff",type=4))
|
| 703 |
-
)
|
| 704 |
),
|
| 705 |
|
| 706 |
# ββ DIAGNOSTICS βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 707 |
div(id = "tab_diagnostics", class = "tab-content",
|
| 708 |
-
|
| 709 |
-
div(class = "plot-card",
|
| 710 |
-
div(class = "plot-card-header",
|
| 711 |
-
div(class = "plot-card-icon orange", "π"),
|
| 712 |
-
div(div(class = "plot-card-title", "MISSING DATA"), div(class = "plot-card-subtitle", "Genotype completeness"))
|
| 713 |
-
),
|
| 714 |
-
div(class = "plot-card-body", plotOutput("plot_missing", height = "300px") %>% withSpinner(color="#ff6b35",type=4))
|
| 715 |
-
),
|
| 716 |
-
div(class = "plot-card",
|
| 717 |
-
div(class = "plot-card-header",
|
| 718 |
-
div(class = "plot-card-icon green", "π"),
|
| 719 |
-
div(div(class = "plot-card-title", "GENOTYPE FREQ"), div(class = "plot-card-subtitle", "Allele frequency per marker"))
|
| 720 |
-
),
|
| 721 |
-
div(class = "plot-card-body", plotOutput("plot_geno_freq", height = "300px") %>% withSpinner(color="#7cfc00",type=4))
|
| 722 |
-
)
|
| 723 |
-
),
|
| 724 |
-
div(class = "plot-card",
|
| 725 |
-
div(class = "plot-card-header",
|
| 726 |
-
div(class = "plot-card-icon pink", "π"),
|
| 727 |
-
div(div(class = "plot-card-title", "MARKER DISTANCE"), div(class = "plot-card-subtitle", "Inter-marker spacing"))
|
| 728 |
-
),
|
| 729 |
-
div(class = "plot-card-body", plotOutput("plot_marker_dist", height = "260px") %>% withSpinner(color="#ff3e8a",type=4))
|
| 730 |
-
)
|
| 731 |
),
|
| 732 |
|
| 733 |
# ββ RESULTS TABLE βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 734 |
div(id = "tab_results", class = "tab-content",
|
| 735 |
-
|
| 736 |
-
div(class = "plot-card-header",
|
| 737 |
-
div(class = "plot-card-icon cyan", "π"),
|
| 738 |
-
div(div(class = "plot-card-title", "QTL RESULTS TABLE"),
|
| 739 |
-
div(class = "plot-card-subtitle", "Peak marker, flanking markers, LOD, PVE, effects, CI"))
|
| 740 |
-
),
|
| 741 |
-
div(class = "plot-card-body",
|
| 742 |
-
DTOutput("table_qtl_results")
|
| 743 |
-
)
|
| 744 |
-
)
|
| 745 |
),
|
| 746 |
|
| 747 |
# ββ SUMMARY βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 748 |
div(id = "tab_summary", class = "tab-content",
|
| 749 |
-
|
| 750 |
-
div(class = "plot-card-header",
|
| 751 |
-
div(class = "plot-card-icon green", "π"),
|
| 752 |
-
div(div(class = "plot-card-title", "ANALYSIS SUMMARY"), div(class = "plot-card-subtitle", "All models"))
|
| 753 |
-
),
|
| 754 |
-
div(class = "plot-card-body",
|
| 755 |
-
DTOutput("table_model_summary")
|
| 756 |
-
)
|
| 757 |
-
),
|
| 758 |
-
div(class = "plot-card", style = "margin-top:20px;",
|
| 759 |
-
div(class = "plot-card-header",
|
| 760 |
-
div(class = "plot-card-icon orange", "π"),
|
| 761 |
-
div(div(class = "plot-card-title", "PERMUTATION THRESHOLDS"), div(class = "plot-card-subtitle", "Significance levels per model"))
|
| 762 |
-
),
|
| 763 |
-
div(class = "plot-card-body",
|
| 764 |
-
DTOutput("table_perm_thresholds")
|
| 765 |
-
)
|
| 766 |
-
)
|
| 767 |
)
|
| 768 |
)
|
| 769 |
),
|
|
@@ -784,93 +649,113 @@ ui <- fluidPage(
|
|
| 784 |
# βββ SERVER βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 785 |
server <- function(input, output, session) {
|
| 786 |
|
| 787 |
-
#
|
| 788 |
theme_qtl <- function(base_size = 11) {
|
| 789 |
theme_minimal(base_size = base_size) +
|
| 790 |
theme(
|
| 791 |
-
plot.background = element_rect(fill = "#
|
| 792 |
-
panel.background = element_rect(fill = "#
|
| 793 |
-
panel.grid.major = element_line(color = "#
|
| 794 |
-
panel.grid.minor = element_line(color = "#
|
| 795 |
-
panel.border = element_rect(color = "#
|
| 796 |
-
axis.text = element_text(color = "#
|
| 797 |
-
axis.title = element_text(color = "#
|
| 798 |
-
plot.title = element_text(color = "#
|
| 799 |
-
plot.subtitle = element_text(color = "#
|
| 800 |
-
legend.background = element_rect(fill = "#
|
| 801 |
-
legend.text = element_text(color = "#
|
| 802 |
-
legend.title = element_text(color = "#
|
| 803 |
-
strip.background = element_rect(fill = "#
|
| 804 |
-
strip.text = element_text(color = "#
|
| 805 |
plot.margin = margin(12, 16, 12, 16)
|
| 806 |
)
|
| 807 |
}
|
| 808 |
|
| 809 |
model_colors <- c(
|
| 810 |
-
em
|
| 811 |
-
hk
|
| 812 |
-
ehk
|
| 813 |
-
imp
|
| 814 |
-
cim
|
| 815 |
-
`2part`
|
| 816 |
-
np
|
| 817 |
-
mr
|
| 818 |
-
`mr-imp`
|
| 819 |
-
`mr-argmax` = "#
|
| 820 |
)
|
| 821 |
|
| 822 |
-
# ββ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 823 |
cross_data <- reactive({
|
| 824 |
-
if (input$use_example || (is.null(input$geno_file) && is.null(input$pheno_file))) {
|
| 825 |
-
data(hyper, package = "qtl")
|
| 826 |
-
return(hyper)
|
| 827 |
-
}
|
| 828 |
req(input$geno_file, input$pheno_file)
|
| 829 |
tryCatch({
|
| 830 |
-
read.cross(
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
|
|
|
|
|
|
|
|
|
| 834 |
}, error = function(e) {
|
| 835 |
-
showNotification(paste("Error loading data:", e$message), type = "error")
|
| 836 |
NULL
|
| 837 |
})
|
| 838 |
})
|
| 839 |
|
| 840 |
-
#
|
| 841 |
observe({
|
| 842 |
cross <- cross_data()
|
| 843 |
req(cross)
|
| 844 |
pheno_names <- names(cross$pheno)
|
| 845 |
updateSelectInput(session, "pheno_col", choices = pheno_names, selected = pheno_names[1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 846 |
})
|
| 847 |
|
| 848 |
-
# ββ analysis results
|
| 849 |
analysis_results <- reactiveVal(NULL)
|
| 850 |
|
| 851 |
observeEvent(input$run_analysis, {
|
| 852 |
cross <- cross_data()
|
| 853 |
-
|
|
|
|
|
|
|
|
|
|
| 854 |
|
| 855 |
-
runjs("document.getElementById('status_dot').classList.
|
| 856 |
output$status_text <- renderText("Running analysis...")
|
| 857 |
|
| 858 |
withProgress(message = "QTL Mapping in progress...", value = 0, {
|
| 859 |
|
| 860 |
cross <- calc.genoprob(cross,
|
| 861 |
-
|
| 862 |
-
|
| 863 |
incProgress(0.1, detail = "Genoprobs calculated")
|
| 864 |
|
| 865 |
-
cross <- sim.geno(cross, n.draws = 64,
|
|
|
|
|
|
|
| 866 |
incProgress(0.1, detail = "Simulated genotypes done")
|
| 867 |
|
| 868 |
pheno_idx <- which(names(cross$pheno) == input$pheno_col)
|
| 869 |
|
| 870 |
scan_results <- list()
|
|
|
|
| 871 |
models_to_run <- input$models
|
| 872 |
n_models <- length(models_to_run)
|
| 873 |
-
perm_results <- list()
|
| 874 |
|
| 875 |
for (i in seq_along(models_to_run)) {
|
| 876 |
mdl <- models_to_run[i]
|
|
@@ -894,15 +779,15 @@ server <- function(input, output, session) {
|
|
| 894 |
}
|
| 895 |
incProgress(0.1, detail = "Summarising QTLs")
|
| 896 |
|
| 897 |
-
# Threshold
|
| 898 |
lod_thr <- input$lod_thresh
|
| 899 |
if (length(perm_results) > 0) {
|
| 900 |
first_perm <- perm_results[[1]]
|
| 901 |
-
if (!is.null(first_perm))
|
| 902 |
-
|
|
|
|
|
|
|
| 903 |
}
|
| 904 |
|
| 905 |
-
# Build results table
|
| 906 |
qtl_table <- build_qtl_table(cross, scan_results, lod_thr, pheno_idx)
|
| 907 |
|
| 908 |
analysis_results(list(
|
|
@@ -917,7 +802,6 @@ server <- function(input, output, session) {
|
|
| 917 |
incProgress(0.1, detail = "Done")
|
| 918 |
})
|
| 919 |
|
| 920 |
-
# update dropdowns that depend on results
|
| 921 |
res <- analysis_results()
|
| 922 |
model_choices <- names(res$scan_results)
|
| 923 |
updateSelectInput(session, "manhattan_model", choices = model_choices, selected = model_choices[1])
|
|
@@ -928,10 +812,13 @@ server <- function(input, output, session) {
|
|
| 928 |
updateSelectInput(session, "effect_qtl", choices = qtl_choices)
|
| 929 |
|
| 930 |
runjs("document.getElementById('status_dot').classList.add('active')")
|
| 931 |
-
output$status_text <- renderText(
|
|
|
|
|
|
|
|
|
|
| 932 |
})
|
| 933 |
|
| 934 |
-
# ββ Helper: build QTL
|
| 935 |
build_qtl_table <- function(cross, scan_results, lod_thr, pheno_idx) {
|
| 936 |
rows <- list()
|
| 937 |
for (mdl in names(scan_results)) {
|
|
@@ -939,31 +826,26 @@ server <- function(input, output, session) {
|
|
| 939 |
sig <- sc[sc$lod >= lod_thr, , drop = FALSE]
|
| 940 |
if (nrow(sig) == 0) next
|
| 941 |
|
| 942 |
-
# find peaks per chromosome
|
| 943 |
for (ch in unique(sig$chr)) {
|
| 944 |
-
chr_sc
|
| 945 |
-
peak_row
|
| 946 |
-
peak_pos
|
| 947 |
-
peak_lod
|
| 948 |
peak_marker <- rownames(peak_row)
|
| 949 |
|
| 950 |
-
# CI via drop-1.5 LOD
|
| 951 |
ci <- tryCatch(lodint(sc, chr = ch, drop = 1.5), error = function(e) NULL)
|
| 952 |
-
left_marker <- if (!is.null(ci)) rownames(ci)[1]
|
| 953 |
right_marker <- if (!is.null(ci)) rownames(ci)[nrow(ci)] else NA_character_
|
| 954 |
-
left_pos <- if (!is.null(ci)) ci$pos[1]
|
| 955 |
-
right_pos <- if (!is.null(ci)) ci$pos[nrow(ci)]
|
| 956 |
|
| 957 |
-
# additive/dom effects (try)
|
| 958 |
eff <- tryCatch({
|
| 959 |
m <- find.marker(cross, chr = ch, pos = peak_pos)
|
| 960 |
effectplot(cross, mname1 = m, pheno.col = pheno_idx, draw = FALSE)
|
| 961 |
}, error = function(e) NULL)
|
| 962 |
|
| 963 |
add_eff <- if (!is.null(eff)) round(diff(range(eff$Means)), 4) else NA
|
| 964 |
-
dom_eff <- NA
|
| 965 |
|
| 966 |
-
# PVE approx: r2 from lod
|
| 967 |
n <- nind(cross)
|
| 968 |
pve <- round((1 - 10^(-2 * peak_lod / n)) * 100, 2)
|
| 969 |
|
|
@@ -975,7 +857,7 @@ server <- function(input, output, session) {
|
|
| 975 |
LOD = round(peak_lod, 3),
|
| 976 |
PVE_pct = pve,
|
| 977 |
Additive_Eff = add_eff,
|
| 978 |
-
Dom_Eff =
|
| 979 |
Left_Marker = left_marker,
|
| 980 |
Left_pos_cM = round(left_pos, 2),
|
| 981 |
Right_Marker = right_marker,
|
|
@@ -989,28 +871,301 @@ server <- function(input, output, session) {
|
|
| 989 |
dplyr::bind_rows(rows) %>% dplyr::arrange(Chr, Peak_pos_cM)
|
| 990 |
}
|
| 991 |
|
| 992 |
-
# ββ
|
| 993 |
-
output$
|
| 994 |
-
|
| 995 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 996 |
})
|
| 997 |
-
|
| 998 |
-
|
| 999 |
-
|
|
|
|
|
|
|
| 1000 |
})
|
| 1001 |
-
|
| 1002 |
-
|
| 1003 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1004 |
})
|
| 1005 |
-
|
|
|
|
|
|
|
| 1006 |
res <- analysis_results()
|
| 1007 |
-
|
| 1008 |
-
div(class = "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1009 |
})
|
| 1010 |
|
| 1011 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1012 |
|
| 1013 |
-
# ββ PLOT: genome map βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1014 |
output$plot_genome_map <- renderPlot({
|
| 1015 |
cross <- cross_data(); req(cross)
|
| 1016 |
map <- pull.map(cross)
|
|
@@ -1020,36 +1175,33 @@ server <- function(input, output, session) {
|
|
| 1020 |
df$chr <- factor(df$chr, levels = names(map))
|
| 1021 |
|
| 1022 |
ggplot(df, aes(x = chr, y = pos)) +
|
| 1023 |
-
geom_segment(aes(xend = chr, yend = pos), color = "#
|
| 1024 |
-
geom_point(color = "#
|
| 1025 |
scale_y_reverse() +
|
| 1026 |
labs(title = "Genetic Map", x = "Chromosome", y = "Position (cM)") +
|
| 1027 |
theme_qtl()
|
| 1028 |
-
}, bg = "
|
| 1029 |
|
| 1030 |
-
# ββ PLOT: phenotype distribution βββββββββββββββββββββββββββββββββββββββββββββ
|
| 1031 |
output$plot_pheno_dist <- renderPlot({
|
| 1032 |
-
cross <- cross_data(); req(cross)
|
| 1033 |
-
req(input$pheno_col)
|
| 1034 |
ph <- cross$pheno[[input$pheno_col]]
|
| 1035 |
df <- data.frame(value = ph[!is.na(ph)])
|
| 1036 |
|
| 1037 |
p1 <- ggplot(df, aes(value)) +
|
| 1038 |
-
geom_histogram(fill = "#
|
| 1039 |
-
geom_density(aes(y = after_stat(count)), color = "#
|
| 1040 |
labs(title = input$pheno_col, x = "Value", y = "Count") +
|
| 1041 |
theme_qtl()
|
| 1042 |
|
| 1043 |
p2 <- ggplot(df, aes(sample = value)) +
|
| 1044 |
-
stat_qq(color = "#
|
| 1045 |
-
stat_qq_line(color = "#
|
| 1046 |
labs(title = "Q-Q Plot", x = "Theoretical", y = "Sample") +
|
| 1047 |
theme_qtl()
|
| 1048 |
|
| 1049 |
gridExtra::grid.arrange(p1, p2, ncol = 2)
|
| 1050 |
-
}, bg = "
|
| 1051 |
|
| 1052 |
-
# ββ PLOT: physical map strip βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1053 |
output$plot_physical_map <- renderPlot({
|
| 1054 |
cross <- cross_data(); req(cross)
|
| 1055 |
map <- pull.map(cross)
|
|
@@ -1063,52 +1215,46 @@ server <- function(input, output, session) {
|
|
| 1063 |
geom_rect(data = chr_len,
|
| 1064 |
aes(xmin = as.numeric(chr) - .35, xmax = as.numeric(chr) + .35,
|
| 1065 |
ymin = 0, ymax = len),
|
| 1066 |
-
fill = "#
|
| 1067 |
geom_point(data = df %>% mutate(chr = factor(chr, levels = names(map))),
|
| 1068 |
aes(x = as.numeric(chr), y = pos),
|
| 1069 |
-
color = "#
|
| 1070 |
scale_x_continuous(breaks = seq_along(names(map)), labels = names(map)) +
|
| 1071 |
scale_y_reverse() +
|
| 1072 |
labs(title = "Physical Map Overview", x = "Chromosome", y = "cM") +
|
| 1073 |
theme_qtl()
|
| 1074 |
-
}, bg = "
|
| 1075 |
|
| 1076 |
-
# ββ PLOT: Manhattan ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1077 |
output$plot_manhattan <- renderPlot({
|
| 1078 |
res <- analysis_results(); req(res)
|
| 1079 |
mdl <- input$manhattan_model; req(mdl)
|
| 1080 |
sc <- res$scan_results[[mdl]]; req(sc)
|
| 1081 |
|
| 1082 |
chrs <- unique(sc$chr)
|
| 1083 |
-
chr_offsets <- setNames(cumsum(c(0, sapply(chrs[-length(chrs)], function(ch)
|
| 1084 |
-
max(sc[sc$chr == ch, "pos"])
|
| 1085 |
-
}))), chrs)
|
| 1086 |
-
|
| 1087 |
sc$global_pos <- sc$pos + chr_offsets[as.character(sc$chr)]
|
| 1088 |
sc$chr_num <- as.integer(factor(sc$chr, levels = chrs))
|
| 1089 |
-
sc$color <- ifelse(sc$chr_num %% 2 == 0, "#
|
| 1090 |
sig <- sc[sc$lod >= res$lod_thr, ]
|
| 1091 |
-
|
| 1092 |
chr_mid <- tapply(sc$global_pos, sc$chr, mean)
|
| 1093 |
|
| 1094 |
ggplot(sc, aes(x = global_pos, y = lod)) +
|
| 1095 |
geom_point(aes(color = color), size = 1.2, alpha = .75) +
|
| 1096 |
scale_color_identity() +
|
| 1097 |
geom_point(data = sig, aes(x = global_pos, y = lod),
|
| 1098 |
-
color = "#
|
| 1099 |
-
geom_hline(yintercept = res$lod_thr, color = "#
|
| 1100 |
linetype = "dashed", linewidth = .8) +
|
| 1101 |
annotate("text", x = max(sc$global_pos) * .98, y = res$lod_thr + .15,
|
| 1102 |
label = paste0("LOD = ", round(res$lod_thr, 2)),
|
| 1103 |
-
color = "#
|
| 1104 |
scale_x_continuous(breaks = chr_mid, labels = names(chr_mid)) +
|
| 1105 |
labs(title = paste("Manhattan Plot β", toupper(mdl)),
|
| 1106 |
x = "Chromosome", y = "LOD Score") +
|
| 1107 |
-
theme_qtl() +
|
| 1108 |
-
|
| 1109 |
-
}, bg = "transparent")
|
| 1110 |
|
| 1111 |
-
# ββ PLOT: Interactive Manhattan ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1112 |
output$plot_manhattan_interactive <- renderPlotly({
|
| 1113 |
res <- analysis_results(); req(res)
|
| 1114 |
mdl <- input$manhattan_model; req(mdl)
|
|
@@ -1119,29 +1265,28 @@ server <- function(input, output, session) {
|
|
| 1119 |
max(sc[sc$chr == ch, "pos"])))), chrs)
|
| 1120 |
sc$global_pos <- sc$pos + chr_offsets[as.character(sc$chr)]
|
| 1121 |
sc$sig <- sc$lod >= res$lod_thr
|
| 1122 |
-
sc$label <- paste0(rownames(sc), "<br>Chr:", sc$chr,
|
| 1123 |
-
|
| 1124 |
-
|
| 1125 |
-
|
| 1126 |
-
|
| 1127 |
-
|
| 1128 |
-
|
|
|
|
| 1129 |
add_lines(y = res$lod_thr,
|
| 1130 |
-
line = list(color = "#
|
| 1131 |
showlegend = FALSE, name = "Threshold") %>%
|
| 1132 |
layout(
|
| 1133 |
-
paper_bgcolor = "#
|
| 1134 |
-
plot_bgcolor = "#
|
| 1135 |
-
font = list(color = "#
|
| 1136 |
-
xaxis = list(title = "Position", gridcolor = "#
|
| 1137 |
-
yaxis = list(title = "LOD Score", gridcolor = "#
|
| 1138 |
-
legend = list(font = list(color = "#
|
| 1139 |
margin = list(t = 10, b = 40, l = 50, r = 20)
|
| 1140 |
)
|
| 1141 |
-
p
|
| 1142 |
})
|
| 1143 |
|
| 1144 |
-
# ββ PLOT: All models genome scan βββββββββββββββββββββββββββββββββββββββββββββ
|
| 1145 |
output$plot_scan_all_models <- renderPlot({
|
| 1146 |
res <- analysis_results(); req(res)
|
| 1147 |
req(length(res$scan_results) > 0)
|
|
@@ -1157,25 +1302,23 @@ server <- function(input, output, session) {
|
|
| 1157 |
df_all <- dplyr::bind_rows(dfs)
|
| 1158 |
df_all$model <- factor(df_all$model)
|
| 1159 |
|
| 1160 |
-
sc_ref
|
| 1161 |
-
chrs
|
| 1162 |
offsets <- setNames(cumsum(c(0, sapply(chrs[-length(chrs)], function(ch)
|
| 1163 |
max(sc_ref[sc_ref$chr==ch,"pos"])))), chrs)
|
| 1164 |
-
vlines
|
| 1165 |
|
| 1166 |
ggplot(df_all, aes(x = global_pos, y = lod, color = model)) +
|
| 1167 |
-
geom_vline(data = vlines, aes(xintercept = x), color = "#
|
| 1168 |
geom_line(linewidth = .6, alpha = .85) +
|
| 1169 |
-
geom_hline(yintercept = res$lod_thr, color = "#
|
| 1170 |
linetype = "dashed", linewidth = .7) +
|
| 1171 |
scale_color_manual(values = model_colors) +
|
| 1172 |
labs(title = "Genome Scan β All Models",
|
| 1173 |
x = "Genome Position (cM)", y = "LOD Score", color = "Model") +
|
| 1174 |
-
theme_qtl() +
|
| 1175 |
-
|
| 1176 |
-
}, bg = "transparent")
|
| 1177 |
|
| 1178 |
-
# ββ PLOT: Chromosome grid ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1179 |
output$plot_chr_grid <- renderPlot({
|
| 1180 |
res <- analysis_results(); req(res)
|
| 1181 |
mdl <- input$chr_plot_model; req(mdl)
|
|
@@ -1190,68 +1333,61 @@ server <- function(input, output, session) {
|
|
| 1190 |
plots <- lapply(chrs, function(ch) {
|
| 1191 |
chr_sc <- sc[sc$chr == ch, ]
|
| 1192 |
p <- ggplot(chr_sc, aes(x = pos, y = lod)) +
|
| 1193 |
-
geom_line(color = "#
|
| 1194 |
-
geom_hline(yintercept = res$lod_thr, color = "#
|
| 1195 |
linetype = "dashed", linewidth = .6) +
|
| 1196 |
scale_x_continuous(expand = c(.02,.02)) +
|
| 1197 |
scale_y_continuous(limits = c(0, max(sc$lod) * 1.1)) +
|
| 1198 |
labs(title = paste0("Chr ", ch), x = NULL, y = "LOD") +
|
| 1199 |
theme_qtl(base_size = 9) +
|
| 1200 |
-
theme(plot.title = element_text(size = 9, color = "#
|
| 1201 |
axis.title.y = element_text(size = 7),
|
| 1202 |
plot.margin = margin(6, 8, 6, 8))
|
| 1203 |
|
| 1204 |
-
# label significant QTLs
|
| 1205 |
if (!is.null(qt) && nrow(qt) > 0) {
|
| 1206 |
qt_chr <- qt[qt$Chr == ch & qt$Model == mdl, ]
|
| 1207 |
if (nrow(qt_chr) > 0) {
|
| 1208 |
p <- p +
|
| 1209 |
-
geom_point(data = qt_chr,
|
| 1210 |
-
|
| 1211 |
-
color = "#ff3e8a", size = 3, shape = 23, fill = "#ff3e8a") +
|
| 1212 |
ggrepel::geom_label_repel(
|
| 1213 |
data = qt_chr,
|
| 1214 |
aes(x = Peak_pos_cM, y = LOD,
|
| 1215 |
label = paste0("q", toupper(substr(mdl,1,1)), "R", ch)),
|
| 1216 |
-
fill = "#
|
| 1217 |
-
|
| 1218 |
-
min.segment.length = 0
|
| 1219 |
)
|
| 1220 |
}
|
| 1221 |
}
|
| 1222 |
p
|
| 1223 |
})
|
| 1224 |
|
| 1225 |
-
do.call(gridExtra::grid.arrange,
|
| 1226 |
-
|
| 1227 |
-
}, bg = "transparent")
|
| 1228 |
|
| 1229 |
-
# ββ PLOT: Model bar comparison βββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1230 |
output$plot_model_bar <- renderPlot({
|
| 1231 |
res <- analysis_results(); req(res)
|
| 1232 |
df <- data.frame(
|
| 1233 |
-
model
|
| 1234 |
max_lod = sapply(res$scan_results, function(sc) max(sc$lod, na.rm = TRUE))
|
| 1235 |
)
|
| 1236 |
df$model <- factor(df$model, levels = df$model[order(df$max_lod)])
|
| 1237 |
|
| 1238 |
ggplot(df, aes(x = model, y = max_lod, fill = model)) +
|
| 1239 |
geom_col(width = .6, alpha = .85) +
|
| 1240 |
-
geom_hline(yintercept = res$lod_thr, color = "#
|
| 1241 |
linetype = "dashed", linewidth = .8) +
|
| 1242 |
geom_text(aes(label = round(max_lod, 2)), hjust = -0.2,
|
| 1243 |
-
color = "#
|
| 1244 |
scale_fill_manual(values = model_colors) +
|
| 1245 |
coord_flip(ylim = c(0, max(df$max_lod) * 1.15)) +
|
| 1246 |
labs(title = "Peak LOD by Model", x = NULL, y = "Max LOD") +
|
| 1247 |
theme_qtl() + theme(legend.position = "none")
|
| 1248 |
-
}, bg = "
|
| 1249 |
|
| 1250 |
-
# ββ PLOT: LOD heatmap ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1251 |
output$plot_lod_heatmap <- renderPlot({
|
| 1252 |
res <- analysis_results(); req(res)
|
| 1253 |
|
| 1254 |
-
# thin to top 50 markers by max LOD across models
|
| 1255 |
all_sc <- dplyr::bind_rows(lapply(names(res$scan_results), function(m) {
|
| 1256 |
sc <- res$scan_results[[m]]
|
| 1257 |
sc$model <- m; sc$marker <- rownames(sc); sc
|
|
@@ -1263,28 +1399,24 @@ server <- function(input, output, session) {
|
|
| 1263 |
slice_head(n = 40) %>%
|
| 1264 |
pull(marker)
|
| 1265 |
|
| 1266 |
-
hm <- all_sc %>%
|
| 1267 |
-
filter(marker %in% top_markers) %>%
|
| 1268 |
-
select(model, marker, lod)
|
| 1269 |
|
| 1270 |
ggplot(hm, aes(x = model, y = marker, fill = lod)) +
|
| 1271 |
-
geom_tile(color = "#
|
| 1272 |
scale_fill_gradientn(
|
| 1273 |
-
colors = c("#
|
| 1274 |
name = "LOD"
|
| 1275 |
) +
|
| 1276 |
labs(title = "LOD Heatmap", x = "Model", y = "Marker") +
|
| 1277 |
theme_qtl() +
|
| 1278 |
theme(axis.text.x = element_text(angle = 30, hjust = 1),
|
| 1279 |
axis.text.y = element_text(size = 6))
|
| 1280 |
-
}, bg = "
|
| 1281 |
|
| 1282 |
-
# ββ PLOT: Model correlation ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1283 |
output$plot_model_corr <- renderPlot({
|
| 1284 |
res <- analysis_results(); req(res)
|
| 1285 |
req(length(res$scan_results) >= 2)
|
| 1286 |
|
| 1287 |
-
# build wide LOD matrix
|
| 1288 |
sc_list <- lapply(names(res$scan_results), function(m) {
|
| 1289 |
sc <- res$scan_results[[m]]
|
| 1290 |
data.frame(marker = rownames(sc), lod = sc$lod, stringsAsFactors = FALSE)
|
|
@@ -1292,96 +1424,85 @@ server <- function(input, output, session) {
|
|
| 1292 |
names(sc_list) <- names(res$scan_results)
|
| 1293 |
|
| 1294 |
common_markers <- Reduce(intersect, lapply(sc_list, `[[`, "marker"))
|
| 1295 |
-
mat
|
| 1296 |
corr_mat <- cor(mat, use = "complete.obs")
|
| 1297 |
-
|
| 1298 |
-
corr_df <- as.data.frame(as.table(corr_mat))
|
| 1299 |
names(corr_df) <- c("m1","m2","corr")
|
| 1300 |
|
| 1301 |
ggplot(corr_df, aes(x = m1, y = m2, fill = corr)) +
|
| 1302 |
-
geom_tile(color = "#
|
| 1303 |
-
geom_text(aes(label = round(corr, 2)), size = 3, color = "#
|
| 1304 |
-
scale_fill_gradient2(low = "#
|
| 1305 |
midpoint = 0, limits = c(-1,1), name = "r") +
|
| 1306 |
labs(title = "Model LOD Correlation", x = NULL, y = NULL) +
|
| 1307 |
-
theme_qtl() +
|
| 1308 |
-
|
| 1309 |
-
}, bg = "transparent")
|
| 1310 |
|
| 1311 |
-
# ββ PLOT: Effects ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1312 |
output$plot_effects <- renderPlot({
|
| 1313 |
res <- analysis_results(); req(res)
|
| 1314 |
-
qtl_sel <- input$effect_qtl; req(qtl_sel)
|
| 1315 |
-
req(qtl_sel != "none")
|
| 1316 |
|
| 1317 |
-
parts
|
| 1318 |
-
ch
|
| 1319 |
|
| 1320 |
tryCatch({
|
| 1321 |
-
eff <- effectplot(res$cross, mname1 = mk,
|
| 1322 |
-
pheno.col = res$pheno_idx, draw = FALSE)
|
| 1323 |
df <- data.frame(geno = names(eff$Means), mean = eff$Means, se = eff$SEs)
|
| 1324 |
ggplot(df, aes(x = geno, y = mean, fill = geno)) +
|
| 1325 |
-
geom_col(width = .5, alpha = .
|
| 1326 |
geom_errorbar(aes(ymin = mean - se, ymax = mean + se),
|
| 1327 |
-
width = .15, color = "#
|
| 1328 |
-
scale_fill_manual(values = c("#
|
| 1329 |
-
labs(title = paste("Effect Plot β", mk),
|
| 1330 |
-
x = "Genotype", y = "Mean Phenotype") +
|
| 1331 |
theme_qtl() + theme(legend.position = "none")
|
| 1332 |
}, error = function(e) {
|
| 1333 |
-
ggplot() + annotate("text", x=.5, y=.5, label="Effect not available",
|
| 1334 |
-
color="#64748b") + theme_qtl()
|
| 1335 |
})
|
| 1336 |
-
}, bg = "
|
| 1337 |
|
| 1338 |
-
# ββ PLOT: Phenotype Γ genotype boxplot βββββββββββββββββββββββββββββββββββββββ
|
| 1339 |
output$plot_pheno_geno <- renderPlot({
|
| 1340 |
res <- analysis_results(); req(res)
|
| 1341 |
qtl_sel <- input$effect_qtl; req(qtl_sel != "none")
|
| 1342 |
|
| 1343 |
parts <- strsplit(qtl_sel, "@")[[1]]; mk <- parts[2]
|
| 1344 |
tryCatch({
|
| 1345 |
-
geno_idx
|
| 1346 |
-
geno_vec
|
| 1347 |
pheno_vec <- res$cross$pheno[[res$pheno_idx]]
|
| 1348 |
-
df <- data.frame(geno = as.character(geno_vec), pheno = pheno_vec) %>%
|
|
|
|
| 1349 |
geno_labs <- c("1" = "AA", "2" = "AB", "3" = "BB")
|
| 1350 |
df$geno <- dplyr::recode(df$geno, !!!geno_labs)
|
| 1351 |
|
| 1352 |
ggplot(df, aes(x = geno, y = pheno, fill = geno)) +
|
| 1353 |
geom_violin(alpha = .4, trim = FALSE) +
|
| 1354 |
-
geom_boxplot(width = .15, outlier.color = "#
|
| 1355 |
-
scale_fill_manual(values = c("#
|
| 1356 |
labs(title = paste("Phenotype by Genotype β", mk),
|
| 1357 |
x = "Genotype", y = input$pheno_col) +
|
| 1358 |
theme_qtl() + theme(legend.position = "none")
|
| 1359 |
}, error = function(e) {
|
| 1360 |
-
ggplot() + annotate("text", x=.5, y=.5, label
|
| 1361 |
})
|
| 1362 |
-
}, bg = "
|
| 1363 |
|
| 1364 |
-
# ββ PLOT: PVE ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1365 |
output$plot_pve <- renderPlot({
|
| 1366 |
res <- analysis_results(); req(res)
|
| 1367 |
qt <- res$qtl_table; req(!is.null(qt) && nrow(qt) > 0)
|
| 1368 |
|
| 1369 |
qt_avg <- qt %>%
|
| 1370 |
group_by(Chr, Peak_pos_cM) %>%
|
| 1371 |
-
summarise(PVE = mean(PVE_pct, na.rm = TRUE),
|
| 1372 |
-
LOD = mean(LOD, na.rm=TRUE), .groups = "drop")
|
| 1373 |
|
| 1374 |
ggplot(qt_avg, aes(x = interaction(Chr, round(Peak_pos_cM)), y = PVE, fill = PVE)) +
|
| 1375 |
geom_col(width = .7) +
|
| 1376 |
-
scale_fill_gradientn(colors = c("#
|
| 1377 |
geom_text(aes(label = paste0(round(PVE,1),"%")), vjust = -0.4, size = 3,
|
| 1378 |
-
color = "#
|
| 1379 |
labs(title = "PVE per QTL", x = "Chr @ Position", y = "PVE (%)") +
|
| 1380 |
-
theme_qtl() +
|
| 1381 |
-
|
| 1382 |
-
}, bg = "transparent")
|
| 1383 |
|
| 1384 |
-
# ββ PLOT: 2D scan ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1385 |
output$plot_2d_scan <- renderPlot({
|
| 1386 |
res <- analysis_results(); req(res)
|
| 1387 |
|
|
@@ -1390,10 +1511,10 @@ server <- function(input, output, session) {
|
|
| 1390 |
error = function(e) NULL
|
| 1391 |
)
|
| 1392 |
if (is.null(sc2)) {
|
| 1393 |
-
ggplot() + annotate("text", x=.5, y=.5,
|
| 1394 |
-
|
|
|
|
| 1395 |
} else {
|
| 1396 |
-
# Extract the full 2D LOD matrix
|
| 1397 |
lod_mat <- sc2$lod
|
| 1398 |
n <- nrow(lod_mat)
|
| 1399 |
df2d <- expand.grid(x = 1:n, y = 1:n)
|
|
@@ -1402,137 +1523,116 @@ server <- function(input, output, session) {
|
|
| 1402 |
ggplot(df2d, aes(x=x, y=y, fill=lod)) +
|
| 1403 |
geom_tile() +
|
| 1404 |
scale_fill_gradientn(
|
| 1405 |
-
colors = c("#
|
| 1406 |
-
name = "LOD", na.value = "#
|
| 1407 |
) +
|
| 1408 |
labs(title = "2D Genome Scan (Pairwise)", x = "Position 1", y = "Position 2") +
|
| 1409 |
theme_qtl() + coord_equal()
|
| 1410 |
}
|
| 1411 |
-
}, bg = "
|
| 1412 |
|
| 1413 |
-
# ββ PLOT: missing data βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1414 |
output$plot_missing <- renderPlot({
|
| 1415 |
cross <- cross_data(); req(cross)
|
| 1416 |
-
miss
|
| 1417 |
-
df
|
| 1418 |
|
| 1419 |
ggplot(df, aes(x = reorder(marker, missing), y = missing, fill = missing)) +
|
| 1420 |
geom_col() +
|
| 1421 |
-
scale_fill_gradientn(colors = c("#
|
| 1422 |
labs(title = "Missing Genotype Data", x = "Marker", y = "# Missing") +
|
| 1423 |
theme_qtl() +
|
| 1424 |
theme(axis.text.x = element_blank(), axis.ticks.x = element_blank())
|
| 1425 |
-
}, bg = "
|
| 1426 |
|
| 1427 |
-
# ββ PLOT: genotype frequency βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1428 |
output$plot_geno_freq <- renderPlot({
|
| 1429 |
cross <- cross_data(); req(cross)
|
| 1430 |
-
gt
|
| 1431 |
freq_A <- colMeans(gt == 1, na.rm = TRUE)
|
| 1432 |
freq_B <- colMeans(gt == 2, na.rm = TRUE)
|
| 1433 |
-
df <- data.frame(
|
| 1434 |
-
|
| 1435 |
-
A = freq_A, B = freq_B
|
| 1436 |
-
) %>% tidyr::pivot_longer(cols = c(A, B), names_to = "allele", values_to = "freq")
|
| 1437 |
|
| 1438 |
ggplot(df, aes(x = marker, y = freq, fill = allele)) +
|
| 1439 |
geom_col(position = "stack", width = 1) +
|
| 1440 |
-
scale_fill_manual(values = c(A = "#
|
| 1441 |
labs(title = "Allele Frequency per Marker", x = "Marker", y = "Frequency") +
|
| 1442 |
theme_qtl() +
|
| 1443 |
theme(axis.text.x = element_blank(), axis.ticks.x = element_blank())
|
| 1444 |
-
}, bg = "
|
| 1445 |
|
| 1446 |
-
# ββ PLOT: marker distance ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1447 |
output$plot_marker_dist <- renderPlot({
|
| 1448 |
cross <- cross_data(); req(cross)
|
| 1449 |
-
map
|
| 1450 |
-
diffs <- unlist(lapply(map, function(m)
|
| 1451 |
-
|
| 1452 |
-
}))
|
| 1453 |
-
df <- data.frame(dist = diffs)
|
| 1454 |
|
| 1455 |
ggplot(df, aes(x = dist)) +
|
| 1456 |
-
geom_histogram(fill = "#
|
| 1457 |
-
geom_vline(xintercept = median(diffs), color = "#
|
| 1458 |
linetype = "dashed", linewidth = .8) +
|
| 1459 |
labs(title = "Inter-Marker Distance",
|
| 1460 |
subtitle = paste0("Median: ", round(median(diffs),1), " cM"),
|
| 1461 |
x = "Distance (cM)", y = "Count") +
|
| 1462 |
theme_qtl()
|
| 1463 |
-
}, bg = "
|
|
|
|
|
|
|
| 1464 |
|
| 1465 |
-
# ββ TABLE: QTL results βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1466 |
output$table_qtl_results <- renderDT({
|
| 1467 |
res <- analysis_results(); req(res)
|
| 1468 |
-
qt <- res$qtl_table
|
| 1469 |
-
|
| 1470 |
-
|
| 1471 |
-
|
| 1472 |
-
|
| 1473 |
-
|
| 1474 |
-
pageLength = 20,
|
| 1475 |
-
scrollX = TRUE,
|
| 1476 |
-
dom = "Blfrtip",
|
| 1477 |
-
columnDefs = list(list(className = "dt-center", targets = "_all"))
|
| 1478 |
-
),
|
| 1479 |
-
class = "display nowrap"
|
| 1480 |
-
) %>%
|
| 1481 |
formatStyle("LOD",
|
| 1482 |
-
|
| 1483 |
-
|
| 1484 |
-
|
| 1485 |
formatStyle("PVE_pct",
|
| 1486 |
-
|
| 1487 |
-
|
| 1488 |
-
|
| 1489 |
-
formatStyle(0, color = "#e2e8f0") %>%
|
| 1490 |
formatRound(c("Peak_pos_cM","LOD","PVE_pct","Left_pos_cM","Right_pos_cM","CI_width_cM"), 3)
|
| 1491 |
})
|
| 1492 |
|
| 1493 |
-
# ββ TABLE: Model summary βββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1494 |
output$table_model_summary <- renderDT({
|
| 1495 |
res <- analysis_results(); req(res)
|
| 1496 |
df <- data.frame(
|
| 1497 |
-
Model
|
| 1498 |
-
Max_LOD
|
| 1499 |
-
Mean_LOD
|
| 1500 |
-
QTLs_Found
|
| 1501 |
if (!is.null(res$qtl_table) && nrow(res$qtl_table) > 0)
|
| 1502 |
sum(res$qtl_table$Model == m) else 0
|
| 1503 |
}),
|
| 1504 |
-
Threshold
|
| 1505 |
)
|
| 1506 |
datatable(df, rownames = FALSE,
|
| 1507 |
options = list(dom = "t", pageLength = 15),
|
| 1508 |
class = "display") %>%
|
| 1509 |
-
formatStyle(
|
| 1510 |
-
formatStyle("
|
| 1511 |
-
formatStyle("QTLs_Found", color = "#ff3e8a")
|
| 1512 |
})
|
| 1513 |
|
| 1514 |
-
# ββ TABLE: Permutation thresholds βββββββββββββββββββββββββββββββββββββββββββ
|
| 1515 |
output$table_perm_thresholds <- renderDT({
|
| 1516 |
res <- analysis_results(); req(res)
|
| 1517 |
req(length(res$perm_results) > 0)
|
| 1518 |
|
| 1519 |
rows <- lapply(names(res$perm_results), function(m) {
|
| 1520 |
-
p
|
| 1521 |
-
if (is.null(p)) return(NULL)
|
| 1522 |
sm <- tryCatch(summary(p, alpha = c(0.05, 0.1, 0.2)), error = function(e) NULL)
|
| 1523 |
if (is.null(sm)) return(NULL)
|
| 1524 |
-
data.frame(Model = m,
|
| 1525 |
-
alpha_0.
|
| 1526 |
-
alpha_0.10 = round(sm[2], 3),
|
| 1527 |
-
alpha_0.20 = round(sm[3], 3))
|
| 1528 |
})
|
| 1529 |
df <- dplyr::bind_rows(Filter(Negate(is.null), rows))
|
| 1530 |
req(nrow(df) > 0)
|
| 1531 |
-
datatable(df, rownames = FALSE, options = list(dom = "t"), class = "display")
|
| 1532 |
-
formatStyle(0, color = "#e2e8f0")
|
| 1533 |
})
|
| 1534 |
|
| 1535 |
-
# ββ Download
|
| 1536 |
output$download_results <- downloadHandler(
|
| 1537 |
filename = function() paste0("qtl_results_", Sys.Date(), ".csv"),
|
| 1538 |
content = function(file) {
|
|
|
|
| 17 |
useShinyjs(),
|
| 18 |
tags$head(
|
| 19 |
tags$link(
|
| 20 |
+
href = "https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600&family=IBM+Plex+Sans:wght@300;400;500;600&display=swap",
|
| 21 |
rel = "stylesheet"
|
| 22 |
),
|
| 23 |
tags$style(HTML("
|
| 24 |
:root {
|
| 25 |
+
--bg: #ffffff;
|
| 26 |
+
--panel: #f8f9fb;
|
| 27 |
+
--panel2: #f1f4f8;
|
| 28 |
+
--border: #dde2ea;
|
| 29 |
+
--accent1: #1a6cf5;
|
| 30 |
+
--accent2: #e8500a;
|
| 31 |
+
--accent3: #18a058;
|
| 32 |
+
--accent4: #c2185b;
|
| 33 |
+
--accent5: #7c3aed;
|
| 34 |
+
--text: #1a202c;
|
| 35 |
+
--text2: #4a5568;
|
| 36 |
+
--muted: #8a95a3;
|
| 37 |
+
--font-mono: 'IBM Plex Mono', monospace;
|
| 38 |
+
--font-body: 'IBM Plex Sans', sans-serif;
|
| 39 |
+
--shadow: 0 1px 4px rgba(0,0,0,0.07), 0 4px 16px rgba(0,0,0,0.05);
|
| 40 |
+
--shadow-lg: 0 2px 8px rgba(0,0,0,0.08), 0 8px 32px rgba(0,0,0,0.07);
|
| 41 |
}
|
| 42 |
|
| 43 |
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
|
|
| 47 |
color: var(--text);
|
| 48 |
font-family: var(--font-body);
|
| 49 |
min-height: 100vh;
|
| 50 |
+
font-size: 14px;
|
| 51 |
}
|
| 52 |
|
| 53 |
/* ββ Header ββ */
|
| 54 |
.qtl-header {
|
| 55 |
+
background: #ffffff;
|
| 56 |
+
border-bottom: 1.5px solid var(--border);
|
| 57 |
+
padding: 0 32px;
|
| 58 |
+
height: 60px;
|
| 59 |
display: flex;
|
| 60 |
align-items: center;
|
| 61 |
gap: 16px;
|
| 62 |
position: sticky;
|
| 63 |
top: 0;
|
| 64 |
z-index: 100;
|
| 65 |
+
box-shadow: 0 1px 6px rgba(0,0,0,0.06);
|
| 66 |
}
|
| 67 |
.qtl-header .logo-mark {
|
| 68 |
+
width: 36px; height: 36px;
|
| 69 |
background: var(--accent1);
|
| 70 |
border-radius: 8px;
|
| 71 |
display: flex; align-items: center; justify-content: center;
|
| 72 |
font-family: var(--font-mono);
|
| 73 |
+
font-weight: 600;
|
| 74 |
+
font-size: 13px;
|
| 75 |
+
color: #ffffff;
|
|
|
|
| 76 |
flex-shrink: 0;
|
| 77 |
+
letter-spacing: -0.5px;
|
| 78 |
}
|
| 79 |
.qtl-header h1 {
|
| 80 |
font-family: var(--font-mono);
|
| 81 |
+
font-size: 15px;
|
| 82 |
+
color: var(--text);
|
| 83 |
+
letter-spacing: 1px;
|
| 84 |
+
font-weight: 600;
|
| 85 |
}
|
| 86 |
.qtl-header .subtitle {
|
| 87 |
+
font-size: 11px;
|
| 88 |
color: var(--muted);
|
| 89 |
+
letter-spacing: 0.3px;
|
| 90 |
+
margin-top: 1px;
|
| 91 |
}
|
| 92 |
.header-badges {
|
| 93 |
margin-left: auto;
|
| 94 |
+
display: flex; gap: 6px;
|
| 95 |
}
|
| 96 |
.badge-pill {
|
| 97 |
+
padding: 3px 10px;
|
| 98 |
border-radius: 100px;
|
| 99 |
font-size: 10px;
|
| 100 |
font-family: var(--font-mono);
|
| 101 |
+
letter-spacing: 0.5px;
|
| 102 |
border: 1px solid;
|
| 103 |
+
font-weight: 600;
|
| 104 |
}
|
| 105 |
+
.badge-pill.blue { color: var(--accent1); border-color: #bcd0fc; background: #eef3fe; }
|
| 106 |
+
.badge-pill.green { color: var(--accent3); border-color: #b3dfc7; background: #edf7f2; }
|
| 107 |
+
.badge-pill.orange { color: var(--accent2); border-color: #f8c4a8; background: #fef4ee; }
|
| 108 |
|
| 109 |
/* ββ Layout ββ */
|
| 110 |
.qtl-layout {
|
| 111 |
display: grid;
|
| 112 |
+
grid-template-columns: 272px 1fr;
|
| 113 |
+
height: calc(100vh - 60px);
|
| 114 |
}
|
| 115 |
|
| 116 |
/* ββ Sidebar ββ */
|
| 117 |
.qtl-sidebar {
|
| 118 |
background: var(--panel);
|
| 119 |
+
border-right: 1.5px solid var(--border);
|
| 120 |
overflow-y: auto;
|
| 121 |
+
padding: 20px 16px 32px;
|
| 122 |
}
|
| 123 |
.qtl-sidebar::-webkit-scrollbar { width: 4px; }
|
| 124 |
.qtl-sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
|
|
|
|
| 126 |
.section-label {
|
| 127 |
font-family: var(--font-mono);
|
| 128 |
font-size: 9px;
|
| 129 |
+
letter-spacing: 2.5px;
|
| 130 |
color: var(--muted);
|
| 131 |
text-transform: uppercase;
|
| 132 |
margin-bottom: 10px;
|
| 133 |
+
margin-top: 22px;
|
| 134 |
+
padding-left: 2px;
|
| 135 |
display: flex;
|
| 136 |
align-items: center;
|
| 137 |
gap: 8px;
|
|
|
|
| 147 |
/* file upload */
|
| 148 |
.qtl-upload {
|
| 149 |
border: 1.5px dashed var(--border);
|
| 150 |
+
border-radius: 8px;
|
| 151 |
+
padding: 12px;
|
| 152 |
+
transition: border-color .2s, background .2s;
|
| 153 |
+
background: #ffffff;
|
| 154 |
margin-bottom: 8px;
|
| 155 |
}
|
| 156 |
+
.qtl-upload:hover { border-color: var(--accent1); background: #f5f8ff; }
|
| 157 |
.qtl-upload label {
|
| 158 |
+
font-size: 10px;
|
| 159 |
color: var(--accent1);
|
| 160 |
font-family: var(--font-mono);
|
| 161 |
letter-spacing: 1px;
|
| 162 |
+
margin-bottom: 5px;
|
| 163 |
display: block;
|
| 164 |
+
font-weight: 600;
|
| 165 |
}
|
| 166 |
.qtl-upload .shiny-input-container { margin: 0 !important; }
|
|
|
|
| 167 |
|
| 168 |
+
/* ββ Required file notice ββ */
|
| 169 |
+
.required-notice {
|
| 170 |
+
background: #fff8e1;
|
| 171 |
+
border: 1px solid #f5c842;
|
| 172 |
+
border-radius: 6px;
|
| 173 |
+
padding: 8px 11px;
|
| 174 |
+
font-size: 11px;
|
| 175 |
+
color: #7a5800;
|
| 176 |
+
font-family: var(--font-mono);
|
| 177 |
+
line-height: 1.5;
|
| 178 |
+
margin-bottom: 10px;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
/* controls */
|
| 182 |
+
.control-block { margin-bottom: 11px; }
|
| 183 |
.control-block label {
|
| 184 |
font-size: 10px;
|
| 185 |
+
color: var(--text2);
|
| 186 |
+
letter-spacing: 0.8px;
|
| 187 |
font-family: var(--font-mono);
|
| 188 |
text-transform: uppercase;
|
| 189 |
display: block;
|
| 190 |
margin-bottom: 4px;
|
| 191 |
+
font-weight: 600;
|
| 192 |
}
|
| 193 |
select, input[type='number'], input[type='text'] {
|
| 194 |
width: 100%;
|
| 195 |
+
background: #ffffff;
|
| 196 |
+
border: 1.5px solid var(--border);
|
| 197 |
border-radius: 6px;
|
| 198 |
color: var(--text);
|
| 199 |
padding: 7px 10px;
|
|
|
|
| 203 |
transition: border-color .2s;
|
| 204 |
appearance: none;
|
| 205 |
}
|
| 206 |
+
select:focus, input:focus { border-color: var(--accent1); box-shadow: 0 0 0 3px rgba(26,108,245,0.1); }
|
| 207 |
|
|
|
|
| 208 |
.shiny-input-checkboxgroup .checkbox label {
|
| 209 |
font-size: 11px;
|
| 210 |
+
color: var(--text2);
|
| 211 |
display: flex;
|
| 212 |
align-items: center;
|
| 213 |
gap: 6px;
|
| 214 |
}
|
| 215 |
|
| 216 |
+
/* buttons */
|
| 217 |
.btn-run {
|
| 218 |
width: 100%;
|
| 219 |
+
padding: 11px;
|
| 220 |
+
background: var(--accent1);
|
| 221 |
border: none;
|
| 222 |
border-radius: 8px;
|
| 223 |
+
color: #ffffff;
|
| 224 |
font-family: var(--font-mono);
|
| 225 |
font-size: 12px;
|
| 226 |
+
font-weight: 600;
|
| 227 |
+
letter-spacing: 1.5px;
|
| 228 |
cursor: pointer;
|
| 229 |
+
transition: background .2s, transform .1s, box-shadow .2s;
|
| 230 |
margin-top: 16px;
|
| 231 |
+
box-shadow: 0 2px 8px rgba(26,108,245,0.25);
|
| 232 |
}
|
| 233 |
+
.btn-run:hover { background: #1558d4; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(26,108,245,0.3); }
|
| 234 |
.btn-run:active { transform: translateY(0); }
|
| 235 |
+
.btn-run:disabled { background: var(--muted); cursor: not-allowed; box-shadow: none; }
|
| 236 |
|
| 237 |
.btn-export {
|
| 238 |
width: 100%;
|
| 239 |
+
padding: 9px;
|
| 240 |
+
background: #ffffff;
|
| 241 |
+
border: 1.5px solid var(--accent3);
|
| 242 |
border-radius: 8px;
|
| 243 |
color: var(--accent3);
|
| 244 |
font-family: var(--font-mono);
|
| 245 |
font-size: 11px;
|
| 246 |
+
font-weight: 600;
|
| 247 |
letter-spacing: 1px;
|
| 248 |
cursor: pointer;
|
| 249 |
margin-top: 8px;
|
| 250 |
transition: background .2s;
|
| 251 |
}
|
| 252 |
+
.btn-export:hover { background: #edf7f2; }
|
| 253 |
|
| 254 |
+
/* status */
|
| 255 |
.status-row {
|
| 256 |
display: flex;
|
| 257 |
align-items: center;
|
| 258 |
gap: 8px;
|
| 259 |
padding: 8px 10px;
|
| 260 |
+
background: #ffffff;
|
| 261 |
+
border: 1.5px solid var(--border);
|
| 262 |
border-radius: 6px;
|
| 263 |
margin-top: 12px;
|
| 264 |
font-size: 11px;
|
|
|
|
| 271 |
background: var(--muted);
|
| 272 |
flex-shrink: 0;
|
| 273 |
}
|
| 274 |
+
.status-dot.active { background: var(--accent3); box-shadow: 0 0 5px rgba(24,160,88,0.5); }
|
| 275 |
+
.status-dot.error { background: var(--accent2); box-shadow: 0 0 5px rgba(232,80,10,0.5); }
|
| 276 |
|
| 277 |
/* ββ Main content ββ */
|
| 278 |
.qtl-main {
|
|
|
|
| 282 |
.qtl-main::-webkit-scrollbar { width: 6px; }
|
| 283 |
.qtl-main::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
|
| 284 |
|
| 285 |
+
/* tabs */
|
| 286 |
.qtl-tabs {
|
| 287 |
display: flex;
|
| 288 |
+
gap: 0;
|
| 289 |
+
padding: 0 24px;
|
| 290 |
+
border-bottom: 1.5px solid var(--border);
|
| 291 |
+
background: #ffffff;
|
| 292 |
position: sticky;
|
| 293 |
top: 0;
|
| 294 |
z-index: 50;
|
| 295 |
overflow-x: auto;
|
| 296 |
+
box-shadow: 0 1px 4px rgba(0,0,0,0.04);
|
| 297 |
}
|
| 298 |
.qtl-tabs::-webkit-scrollbar { display: none; }
|
| 299 |
.qtl-tab-btn {
|
| 300 |
+
padding: 14px 16px;
|
| 301 |
border: none;
|
| 302 |
background: transparent;
|
| 303 |
color: var(--muted);
|
|
|
|
| 306 |
letter-spacing: 1px;
|
| 307 |
text-transform: uppercase;
|
| 308 |
cursor: pointer;
|
| 309 |
+
border-bottom: 2.5px solid transparent;
|
| 310 |
transition: color .2s, border-color .2s;
|
| 311 |
white-space: nowrap;
|
| 312 |
+
font-weight: 600;
|
| 313 |
+
margin-bottom: -1.5px;
|
| 314 |
}
|
| 315 |
.qtl-tab-btn:hover { color: var(--text); }
|
| 316 |
.qtl-tab-btn.active { color: var(--accent1); border-bottom-color: var(--accent1); }
|
|
|
|
| 319 |
.tab-content { display: none; padding: 24px; }
|
| 320 |
.tab-content.active { display: block; }
|
| 321 |
|
| 322 |
+
/* cards */
|
| 323 |
.plot-card {
|
| 324 |
+
background: #ffffff;
|
| 325 |
+
border: 1.5px solid var(--border);
|
| 326 |
border-radius: 12px;
|
| 327 |
overflow: hidden;
|
| 328 |
margin-bottom: 20px;
|
| 329 |
+
box-shadow: var(--shadow);
|
| 330 |
}
|
| 331 |
.plot-card-header {
|
| 332 |
display: flex;
|
| 333 |
align-items: center;
|
| 334 |
+
padding: 13px 18px;
|
| 335 |
border-bottom: 1px solid var(--border);
|
| 336 |
+
background: var(--panel);
|
| 337 |
gap: 10px;
|
| 338 |
}
|
| 339 |
.plot-card-icon {
|
|
|
|
| 343 |
font-size: 13px;
|
| 344 |
flex-shrink: 0;
|
| 345 |
}
|
| 346 |
+
.plot-card-icon.blue { background: #eef3fe; }
|
| 347 |
+
.plot-card-icon.orange { background: #fef4ee; }
|
| 348 |
+
.plot-card-icon.green { background: #edf7f2; }
|
| 349 |
+
.plot-card-icon.pink { background: #fce8f1; }
|
| 350 |
+
.plot-card-icon.purple { background: #f3effe; }
|
| 351 |
.plot-card-title {
|
| 352 |
font-family: var(--font-mono);
|
| 353 |
font-size: 12px;
|
| 354 |
color: var(--text);
|
| 355 |
+
letter-spacing: 0.8px;
|
| 356 |
+
font-weight: 600;
|
| 357 |
}
|
| 358 |
.plot-card-subtitle { font-size: 10px; color: var(--muted); margin-top: 1px; }
|
| 359 |
.plot-card-body { padding: 16px; }
|
|
|
|
| 363 |
display: flex;
|
| 364 |
gap: 10px;
|
| 365 |
flex-wrap: wrap;
|
| 366 |
+
margin-bottom: 20px;
|
| 367 |
}
|
| 368 |
.stat-chip {
|
| 369 |
+
padding: 10px 18px;
|
| 370 |
+
border-radius: 10px;
|
| 371 |
font-family: var(--font-mono);
|
| 372 |
+
font-size: 12px;
|
| 373 |
+
border: 1.5px solid;
|
| 374 |
+
font-weight: 600;
|
| 375 |
+
box-shadow: var(--shadow);
|
| 376 |
}
|
| 377 |
+
.stat-chip.blue { background: #eef3fe; color: var(--accent1); border-color: #bcd0fc; }
|
| 378 |
+
.stat-chip.orange { background: #fef4ee; color: var(--accent2); border-color: #f8c4a8; }
|
| 379 |
+
.stat-chip.green { background: #edf7f2; color: var(--accent3); border-color: #b3dfc7; }
|
| 380 |
+
.stat-chip.pink { background: #fce8f1; color: var(--accent4); border-color: #f0a8c8; }
|
| 381 |
|
| 382 |
+
/* grids */
|
| 383 |
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
|
| 384 |
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
|
| 385 |
@media (max-width: 1100px) { .grid-3 { grid-template-columns: 1fr 1fr; } }
|
| 386 |
@media (max-width: 800px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
|
| 387 |
|
| 388 |
+
/* empty state */
|
| 389 |
+
.empty-state {
|
| 390 |
+
text-align: center;
|
| 391 |
+
padding: 60px 24px;
|
| 392 |
+
color: var(--muted);
|
| 393 |
+
}
|
| 394 |
+
.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; }
|
| 395 |
+
.empty-state h3 { font-size: 16px; color: var(--text2); margin-bottom: 8px; font-family: var(--font-mono); }
|
| 396 |
+
.empty-state p { font-size: 13px; line-height: 1.6; max-width: 400px; margin: 0 auto; }
|
| 397 |
+
|
| 398 |
/* DataTable */
|
| 399 |
.dataTables_wrapper { color: var(--text) !important; font-size: 12px; }
|
| 400 |
table.dataTable { background: transparent !important; color: var(--text) !important; border-collapse: collapse !important; }
|
| 401 |
table.dataTable thead th {
|
| 402 |
+
background: var(--panel) !important;
|
| 403 |
color: var(--accent1) !important;
|
| 404 |
font-family: var(--font-mono) !important;
|
| 405 |
font-size: 10px !important;
|
| 406 |
letter-spacing: 1px !important;
|
| 407 |
+
border-bottom: 1.5px solid var(--border) !important;
|
| 408 |
padding: 10px 12px !important;
|
| 409 |
+
font-weight: 600 !important;
|
| 410 |
}
|
| 411 |
table.dataTable tbody tr { background: transparent !important; }
|
| 412 |
+
table.dataTable tbody tr:hover td { background: #f5f8ff !important; }
|
| 413 |
+
table.dataTable tbody td { border-bottom: 1px solid var(--border) !important; padding: 8px 12px !important; color: var(--text) !important; }
|
| 414 |
.dataTables_info, .dataTables_paginate { color: var(--muted) !important; font-size: 11px !important; }
|
| 415 |
+
.paginate_button { color: var(--text2) !important; }
|
| 416 |
+
.paginate_button.current { background: var(--accent1) !important; color: #ffffff !important; border-radius: 4px !important; }
|
| 417 |
.dataTables_filter input, .dataTables_length select {
|
| 418 |
+
background: #ffffff !important;
|
| 419 |
+
border: 1.5px solid var(--border) !important;
|
| 420 |
color: var(--text) !important;
|
| 421 |
border-radius: 4px !important;
|
| 422 |
padding: 4px 8px !important;
|
| 423 |
}
|
| 424 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
.info-box {
|
| 426 |
+
background: #f0f5ff;
|
| 427 |
+
border: 1px solid #bcd0fc;
|
| 428 |
border-radius: 8px;
|
| 429 |
padding: 12px 16px;
|
| 430 |
font-size: 12px;
|
| 431 |
+
color: var(--text2);
|
| 432 |
line-height: 1.6;
|
| 433 |
margin-bottom: 16px;
|
| 434 |
}
|
| 435 |
+
|
| 436 |
+
hr.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
|
| 437 |
+
|
| 438 |
+
/* file format help */
|
| 439 |
+
.format-help {
|
| 440 |
font-size: 10px;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 441 |
color: var(--muted);
|
| 442 |
+
font-family: var(--font-mono);
|
| 443 |
+
line-height: 1.6;
|
| 444 |
+
margin-top: 4px;
|
| 445 |
+
padding: 6px 8px;
|
| 446 |
+
background: var(--panel2);
|
| 447 |
+
border-radius: 4px;
|
| 448 |
}
|
|
|
|
| 449 |
"))
|
| 450 |
),
|
| 451 |
|
|
|
|
| 471 |
|
| 472 |
div(class = "section-label", "Data Input"),
|
| 473 |
|
| 474 |
+
div(class = "required-notice",
|
| 475 |
+
"β Both CSV files are required.", tags$br(),
|
| 476 |
+
"No example/simulated data is used."
|
| 477 |
+
),
|
| 478 |
+
|
| 479 |
div(class = "qtl-upload",
|
| 480 |
tags$label("Genotype CSV"),
|
| 481 |
fileInput("geno_file", NULL, accept = ".csv",
|
| 482 |
+
buttonLabel = "Browse", placeholder = "genotypes.csv"),
|
| 483 |
+
div(class = "format-help",
|
| 484 |
+
"Row 1: marker IDs", tags$br(),
|
| 485 |
+
"Row 2: chromosome", tags$br(),
|
| 486 |
+
"Row 3: position (cM)", tags$br(),
|
| 487 |
+
"Rows 4+: individual genotypes"
|
| 488 |
+
)
|
| 489 |
),
|
| 490 |
+
|
| 491 |
div(class = "qtl-upload",
|
| 492 |
tags$label("Phenotype CSV"),
|
| 493 |
fileInput("pheno_file", NULL, accept = ".csv",
|
| 494 |
+
buttonLabel = "Browse", placeholder = "phenotypes.csv"),
|
| 495 |
+
div(class = "format-help",
|
| 496 |
+
"Col 1: individual IDs", tags$br(),
|
| 497 |
+
"Col 2+: phenotype values"
|
| 498 |
+
)
|
| 499 |
),
|
| 500 |
|
|
|
|
|
|
|
| 501 |
div(class = "section-label", "Cross Type"),
|
| 502 |
div(class = "control-block",
|
| 503 |
selectInput("cross_type", NULL,
|
|
|
|
| 506 |
"RIL (selfing)" = "riself",
|
| 507 |
"RIL (sib-mating)" = "risib",
|
| 508 |
"4-way cross" = "4way"),
|
| 509 |
+
selected = "f2")
|
| 510 |
),
|
| 511 |
|
| 512 |
div(class = "section-label", "Phenotype"),
|
|
|
|
| 583 |
|
| 584 |
# ββ OVERVIEW ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 585 |
div(id = "tab_overview", class = "tab-content active",
|
| 586 |
+
uiOutput("overview_content")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 587 |
),
|
| 588 |
|
| 589 |
# ββ MANHATTAN βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 590 |
div(id = "tab_manhattan", class = "tab-content",
|
| 591 |
+
uiOutput("manhattan_content")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 592 |
),
|
| 593 |
|
| 594 |
# ββ GENOME SCAN βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 595 |
div(id = "tab_genome", class = "tab-content",
|
| 596 |
+
uiOutput("genome_content")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 597 |
),
|
| 598 |
|
| 599 |
# ββ CHROMOSOME PLOTS ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 600 |
div(id = "tab_chromosome", class = "tab-content",
|
| 601 |
+
uiOutput("chromosome_content")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 602 |
),
|
| 603 |
|
| 604 |
# ββ MODEL COMPARISON ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 605 |
div(id = "tab_model_comp", class = "tab-content",
|
| 606 |
+
uiOutput("model_comp_content")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 607 |
),
|
| 608 |
|
| 609 |
# ββ QTL EFFECTS βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 610 |
div(id = "tab_effects", class = "tab-content",
|
| 611 |
+
uiOutput("effects_content")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 612 |
),
|
| 613 |
|
| 614 |
# ββ 2D SCAN ββββββββββββββββββββββββββββββββββββββββββοΏ½οΏ½οΏ½ββββββββββββββββββ
|
| 615 |
div(id = "tab_pairwise", class = "tab-content",
|
| 616 |
+
uiOutput("pairwise_content")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 617 |
),
|
| 618 |
|
| 619 |
# ββ DIAGNOSTICS βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 620 |
div(id = "tab_diagnostics", class = "tab-content",
|
| 621 |
+
uiOutput("diagnostics_content")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 622 |
),
|
| 623 |
|
| 624 |
# ββ RESULTS TABLE βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 625 |
div(id = "tab_results", class = "tab-content",
|
| 626 |
+
uiOutput("results_content")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 627 |
),
|
| 628 |
|
| 629 |
# ββ SUMMARY βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 630 |
div(id = "tab_summary", class = "tab-content",
|
| 631 |
+
uiOutput("summary_content")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 632 |
)
|
| 633 |
)
|
| 634 |
),
|
|
|
|
| 649 |
# βββ SERVER βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 650 |
server <- function(input, output, session) {
|
| 651 |
|
| 652 |
+
# ββ Light ggplot theme βββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 653 |
theme_qtl <- function(base_size = 11) {
|
| 654 |
theme_minimal(base_size = base_size) +
|
| 655 |
theme(
|
| 656 |
+
plot.background = element_rect(fill = "#ffffff", color = NA),
|
| 657 |
+
panel.background = element_rect(fill = "#f8f9fb", color = NA),
|
| 658 |
+
panel.grid.major = element_line(color = "#e8ecf2", linewidth = .45),
|
| 659 |
+
panel.grid.minor = element_line(color = "#f1f4f8", linewidth = .25),
|
| 660 |
+
panel.border = element_rect(color = "#dde2ea", fill = NA, linewidth = .8),
|
| 661 |
+
axis.text = element_text(color = "#8a95a3", size = 9, family = "mono"),
|
| 662 |
+
axis.title = element_text(color = "#4a5568", size = 10),
|
| 663 |
+
plot.title = element_text(color = "#1a202c", size = 12, face = "bold", family = "mono"),
|
| 664 |
+
plot.subtitle = element_text(color = "#8a95a3", size = 9),
|
| 665 |
+
legend.background = element_rect(fill = "#ffffff", color = "#dde2ea", linewidth = .5),
|
| 666 |
+
legend.text = element_text(color = "#4a5568", size = 9),
|
| 667 |
+
legend.title = element_text(color = "#8a95a3", size = 9),
|
| 668 |
+
strip.background = element_rect(fill = "#f1f4f8", color = "#dde2ea"),
|
| 669 |
+
strip.text = element_text(color = "#1a6cf5", size = 9, family = "mono", face = "bold"),
|
| 670 |
plot.margin = margin(12, 16, 12, 16)
|
| 671 |
)
|
| 672 |
}
|
| 673 |
|
| 674 |
model_colors <- c(
|
| 675 |
+
em = "#1a6cf5",
|
| 676 |
+
hk = "#e8500a",
|
| 677 |
+
ehk = "#18a058",
|
| 678 |
+
imp = "#c2185b",
|
| 679 |
+
cim = "#7c3aed",
|
| 680 |
+
`2part` = "#d97706",
|
| 681 |
+
np = "#0891b2",
|
| 682 |
+
mr = "#dc2626",
|
| 683 |
+
`mr-imp` = "#2563eb",
|
| 684 |
+
`mr-argmax` = "#ea580c"
|
| 685 |
)
|
| 686 |
|
| 687 |
+
# ββ Helper: empty state UI βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 688 |
+
empty_state_ui <- function(icon = "π", title = "No Data Loaded",
|
| 689 |
+
msg = "Upload your genotype and phenotype CSV files, then click RUN ANALYSIS.") {
|
| 690 |
+
div(class = "empty-state",
|
| 691 |
+
div(class = "empty-icon", icon),
|
| 692 |
+
tags$h3(title),
|
| 693 |
+
tags$p(msg)
|
| 694 |
+
)
|
| 695 |
+
}
|
| 696 |
+
|
| 697 |
+
# ββ reactive: cross object from CSV only ββββββββββββββββββββββββββββββββββ
|
| 698 |
cross_data <- reactive({
|
|
|
|
|
|
|
|
|
|
|
|
|
| 699 |
req(input$geno_file, input$pheno_file)
|
| 700 |
tryCatch({
|
| 701 |
+
cross <- read.cross(
|
| 702 |
+
format = "csv",
|
| 703 |
+
genfile = input$geno_file$datapath,
|
| 704 |
+
phefile = input$pheno_file$datapath,
|
| 705 |
+
crosstype = input$cross_type
|
| 706 |
+
)
|
| 707 |
+
cross
|
| 708 |
}, error = function(e) {
|
| 709 |
+
showNotification(paste("Error loading data:", e$message), type = "error", duration = 8)
|
| 710 |
NULL
|
| 711 |
})
|
| 712 |
})
|
| 713 |
|
| 714 |
+
# ββ Update phenotype dropdown when cross loads βββββββββββββββββββββββββββββ
|
| 715 |
observe({
|
| 716 |
cross <- cross_data()
|
| 717 |
req(cross)
|
| 718 |
pheno_names <- names(cross$pheno)
|
| 719 |
updateSelectInput(session, "pheno_col", choices = pheno_names, selected = pheno_names[1])
|
| 720 |
+
runjs("document.getElementById('status_dot').classList.add('active')")
|
| 721 |
+
output$status_text <- renderText(paste0(
|
| 722 |
+
totmar(cross), " markers Β· ",
|
| 723 |
+
nind(cross), " inds Β· ",
|
| 724 |
+
nchr(cross), " chrs β Ready"
|
| 725 |
+
))
|
| 726 |
})
|
| 727 |
|
| 728 |
+
# ββ analysis results βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 729 |
analysis_results <- reactiveVal(NULL)
|
| 730 |
|
| 731 |
observeEvent(input$run_analysis, {
|
| 732 |
cross <- cross_data()
|
| 733 |
+
if (is.null(cross)) {
|
| 734 |
+
showNotification("Please upload both CSV files first.", type = "warning")
|
| 735 |
+
return()
|
| 736 |
+
}
|
| 737 |
|
| 738 |
+
runjs("document.getElementById('status_dot').classList.remove('active')")
|
| 739 |
output$status_text <- renderText("Running analysis...")
|
| 740 |
|
| 741 |
withProgress(message = "QTL Mapping in progress...", value = 0, {
|
| 742 |
|
| 743 |
cross <- calc.genoprob(cross,
|
| 744 |
+
step = input$step_size,
|
| 745 |
+
error.prob = input$error_prob)
|
| 746 |
incProgress(0.1, detail = "Genoprobs calculated")
|
| 747 |
|
| 748 |
+
cross <- sim.geno(cross, n.draws = 64,
|
| 749 |
+
step = input$step_size,
|
| 750 |
+
error.prob = input$error_prob)
|
| 751 |
incProgress(0.1, detail = "Simulated genotypes done")
|
| 752 |
|
| 753 |
pheno_idx <- which(names(cross$pheno) == input$pheno_col)
|
| 754 |
|
| 755 |
scan_results <- list()
|
| 756 |
+
perm_results <- list()
|
| 757 |
models_to_run <- input$models
|
| 758 |
n_models <- length(models_to_run)
|
|
|
|
| 759 |
|
| 760 |
for (i in seq_along(models_to_run)) {
|
| 761 |
mdl <- models_to_run[i]
|
|
|
|
| 779 |
}
|
| 780 |
incProgress(0.1, detail = "Summarising QTLs")
|
| 781 |
|
|
|
|
| 782 |
lod_thr <- input$lod_thresh
|
| 783 |
if (length(perm_results) > 0) {
|
| 784 |
first_perm <- perm_results[[1]]
|
| 785 |
+
if (!is.null(first_perm)) {
|
| 786 |
+
thr_try <- tryCatch(summary(first_perm, alpha = input$alpha_thresh)[1], error = function(e) NULL)
|
| 787 |
+
if (!is.null(thr_try)) lod_thr <- thr_try
|
| 788 |
+
}
|
| 789 |
}
|
| 790 |
|
|
|
|
| 791 |
qtl_table <- build_qtl_table(cross, scan_results, lod_thr, pheno_idx)
|
| 792 |
|
| 793 |
analysis_results(list(
|
|
|
|
| 802 |
incProgress(0.1, detail = "Done")
|
| 803 |
})
|
| 804 |
|
|
|
|
| 805 |
res <- analysis_results()
|
| 806 |
model_choices <- names(res$scan_results)
|
| 807 |
updateSelectInput(session, "manhattan_model", choices = model_choices, selected = model_choices[1])
|
|
|
|
| 812 |
updateSelectInput(session, "effect_qtl", choices = qtl_choices)
|
| 813 |
|
| 814 |
runjs("document.getElementById('status_dot').classList.add('active')")
|
| 815 |
+
output$status_text <- renderText(paste0(
|
| 816 |
+
"Done β ", length(model_choices), " models Β· ",
|
| 817 |
+
if (!is.null(res$qtl_table)) nrow(res$qtl_table) else 0, " QTLs"
|
| 818 |
+
))
|
| 819 |
})
|
| 820 |
|
| 821 |
+
# ββ Helper: build QTL table ββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 822 |
build_qtl_table <- function(cross, scan_results, lod_thr, pheno_idx) {
|
| 823 |
rows <- list()
|
| 824 |
for (mdl in names(scan_results)) {
|
|
|
|
| 826 |
sig <- sc[sc$lod >= lod_thr, , drop = FALSE]
|
| 827 |
if (nrow(sig) == 0) next
|
| 828 |
|
|
|
|
| 829 |
for (ch in unique(sig$chr)) {
|
| 830 |
+
chr_sc <- sc[sc$chr == ch, ]
|
| 831 |
+
peak_row <- chr_sc[which.max(chr_sc$lod), ]
|
| 832 |
+
peak_pos <- peak_row$pos
|
| 833 |
+
peak_lod <- peak_row$lod
|
| 834 |
peak_marker <- rownames(peak_row)
|
| 835 |
|
|
|
|
| 836 |
ci <- tryCatch(lodint(sc, chr = ch, drop = 1.5), error = function(e) NULL)
|
| 837 |
+
left_marker <- if (!is.null(ci)) rownames(ci)[1] else NA_character_
|
| 838 |
right_marker <- if (!is.null(ci)) rownames(ci)[nrow(ci)] else NA_character_
|
| 839 |
+
left_pos <- if (!is.null(ci)) ci$pos[1] else NA_real_
|
| 840 |
+
right_pos <- if (!is.null(ci)) ci$pos[nrow(ci)] else NA_real_
|
| 841 |
|
|
|
|
| 842 |
eff <- tryCatch({
|
| 843 |
m <- find.marker(cross, chr = ch, pos = peak_pos)
|
| 844 |
effectplot(cross, mname1 = m, pheno.col = pheno_idx, draw = FALSE)
|
| 845 |
}, error = function(e) NULL)
|
| 846 |
|
| 847 |
add_eff <- if (!is.null(eff)) round(diff(range(eff$Means)), 4) else NA
|
|
|
|
| 848 |
|
|
|
|
| 849 |
n <- nind(cross)
|
| 850 |
pve <- round((1 - 10^(-2 * peak_lod / n)) * 100, 2)
|
| 851 |
|
|
|
|
| 857 |
LOD = round(peak_lod, 3),
|
| 858 |
PVE_pct = pve,
|
| 859 |
Additive_Eff = add_eff,
|
| 860 |
+
Dom_Eff = NA,
|
| 861 |
Left_Marker = left_marker,
|
| 862 |
Left_pos_cM = round(left_pos, 2),
|
| 863 |
Right_Marker = right_marker,
|
|
|
|
| 871 |
dplyr::bind_rows(rows) %>% dplyr::arrange(Chr, Peak_pos_cM)
|
| 872 |
}
|
| 873 |
|
| 874 |
+
# ββ Status text default ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 875 |
+
output$status_text <- renderText("Upload CSV files to begin")
|
| 876 |
+
|
| 877 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 878 |
+
# TAB CONTENT RENDERERS (show empty state until data loaded)
|
| 879 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 880 |
+
|
| 881 |
+
# ββ OVERVIEW ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 882 |
+
output$overview_content <- renderUI({
|
| 883 |
+
cross <- cross_data()
|
| 884 |
+
if (is.null(cross)) return(empty_state_ui())
|
| 885 |
+
|
| 886 |
+
tagList(
|
| 887 |
+
div(class = "stat-row",
|
| 888 |
+
div(class = "stat-chip blue", paste0(totmar(cross), " MARKERS")),
|
| 889 |
+
div(class = "stat-chip orange", paste0(nind(cross), " INDIVIDUALS")),
|
| 890 |
+
div(class = "stat-chip green", paste0(nchr(cross), " CHROMOSOMES")),
|
| 891 |
+
div(class = "stat-chip pink", uiOutput("stat_qtls_inline"))
|
| 892 |
+
),
|
| 893 |
+
div(class = "grid-2",
|
| 894 |
+
div(class = "plot-card",
|
| 895 |
+
div(class = "plot-card-header",
|
| 896 |
+
div(class = "plot-card-icon blue", "π"),
|
| 897 |
+
div(div(class = "plot-card-title", "GENOME MAP"),
|
| 898 |
+
div(class = "plot-card-subtitle", "Marker distribution"))
|
| 899 |
+
),
|
| 900 |
+
div(class = "plot-card-body",
|
| 901 |
+
plotOutput("plot_genome_map", height = "320px") %>% withSpinner(color = "#1a6cf5", type = 4))
|
| 902 |
+
),
|
| 903 |
+
div(class = "plot-card",
|
| 904 |
+
div(class = "plot-card-header",
|
| 905 |
+
div(class = "plot-card-icon orange", "π"),
|
| 906 |
+
div(div(class = "plot-card-title", "PHENOTYPE DIST"),
|
| 907 |
+
div(class = "plot-card-subtitle", "Distribution & QQ"))
|
| 908 |
+
),
|
| 909 |
+
div(class = "plot-card-body",
|
| 910 |
+
plotOutput("plot_pheno_dist", height = "320px") %>% withSpinner(color = "#e8500a", type = 4))
|
| 911 |
+
)
|
| 912 |
+
),
|
| 913 |
+
div(class = "plot-card",
|
| 914 |
+
div(class = "plot-card-header",
|
| 915 |
+
div(class = "plot-card-icon green", "πΊ"),
|
| 916 |
+
div(div(class = "plot-card-title", "PHYSICAL MAP"),
|
| 917 |
+
div(class = "plot-card-subtitle", "All chromosomes β marker positions"))
|
| 918 |
+
),
|
| 919 |
+
div(class = "plot-card-body",
|
| 920 |
+
plotOutput("plot_physical_map", height = "260px") %>% withSpinner(color = "#18a058", type = 4))
|
| 921 |
+
)
|
| 922 |
+
)
|
| 923 |
})
|
| 924 |
+
|
| 925 |
+
output$stat_qtls_inline <- renderUI({
|
| 926 |
+
res <- analysis_results()
|
| 927 |
+
n <- if (!is.null(res) && !is.null(res$qtl_table)) nrow(res$qtl_table) else 0
|
| 928 |
+
paste0(n, " QTLs FOUND")
|
| 929 |
})
|
| 930 |
+
|
| 931 |
+
# ββ MANHATTAN βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 932 |
+
output$manhattan_content <- renderUI({
|
| 933 |
+
res <- analysis_results()
|
| 934 |
+
if (is.null(res)) return(empty_state_ui("π", "Run Analysis First",
|
| 935 |
+
"Upload your CSV files and click RUN ANALYSIS to generate the Manhattan plot."))
|
| 936 |
+
tagList(
|
| 937 |
+
div(class = "info-box",
|
| 938 |
+
"Manhattan plot shows LOD score across all chromosomes. Peaks above the threshold line are candidate QTL regions."
|
| 939 |
+
),
|
| 940 |
+
div(class = "plot-card",
|
| 941 |
+
div(class = "plot-card-header",
|
| 942 |
+
div(class = "plot-card-icon blue", "π"),
|
| 943 |
+
div(div(class = "plot-card-title", "MANHATTAN PLOT"),
|
| 944 |
+
div(class = "plot-card-subtitle", "LOD scores genome-wide"))
|
| 945 |
+
),
|
| 946 |
+
div(class = "plot-card-body",
|
| 947 |
+
div(class = "control-block", style = "max-width:200px; margin-bottom:12px;",
|
| 948 |
+
selectInput("manhattan_model", "Model:", choices = names(res$scan_results))
|
| 949 |
+
),
|
| 950 |
+
plotOutput("plot_manhattan", height = "420px") %>% withSpinner(color = "#1a6cf5", type = 4)
|
| 951 |
+
)
|
| 952 |
+
),
|
| 953 |
+
div(class = "plot-card",
|
| 954 |
+
div(class = "plot-card-header",
|
| 955 |
+
div(class = "plot-card-icon pink", "π―"),
|
| 956 |
+
div(div(class = "plot-card-title", "INTERACTIVE MANHATTAN"),
|
| 957 |
+
div(class = "plot-card-subtitle", "Hover for marker details"))
|
| 958 |
+
),
|
| 959 |
+
div(class = "plot-card-body",
|
| 960 |
+
plotlyOutput("plot_manhattan_interactive", height = "380px") %>% withSpinner(color = "#c2185b", type = 4)
|
| 961 |
+
)
|
| 962 |
+
)
|
| 963 |
+
)
|
| 964 |
})
|
| 965 |
+
|
| 966 |
+
# ββ GENOME SCAN βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 967 |
+
output$genome_content <- renderUI({
|
| 968 |
res <- analysis_results()
|
| 969 |
+
if (is.null(res)) return(empty_state_ui("π¬", "Run Analysis First"))
|
| 970 |
+
div(class = "plot-card",
|
| 971 |
+
div(class = "plot-card-header",
|
| 972 |
+
div(class = "plot-card-icon blue", "π¬"),
|
| 973 |
+
div(div(class = "plot-card-title", "GENOME SCAN β ALL MODELS"),
|
| 974 |
+
div(class = "plot-card-subtitle", "LOD profiles overlaid"))
|
| 975 |
+
),
|
| 976 |
+
div(class = "plot-card-body",
|
| 977 |
+
plotOutput("plot_scan_all_models", height = "480px") %>% withSpinner(color = "#1a6cf5", type = 4)
|
| 978 |
+
)
|
| 979 |
+
)
|
| 980 |
+
})
|
| 981 |
+
|
| 982 |
+
# ββ CHROMOSOME PLOTS ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 983 |
+
output$chromosome_content <- renderUI({
|
| 984 |
+
res <- analysis_results()
|
| 985 |
+
if (is.null(res)) return(empty_state_ui("π", "Run Analysis First"))
|
| 986 |
+
tagList(
|
| 987 |
+
div(class = "info-box", "Per-chromosome LOD profiles. Significant peaks are labelled with QTL names."),
|
| 988 |
+
div(class = "control-block", style = "max-width:200px; margin-bottom:16px;",
|
| 989 |
+
selectInput("chr_plot_model", "Model:", choices = names(res$scan_results))
|
| 990 |
+
),
|
| 991 |
+
plotOutput("plot_chr_grid", height = "900px") %>% withSpinner(color = "#18a058", type = 4)
|
| 992 |
+
)
|
| 993 |
+
})
|
| 994 |
+
|
| 995 |
+
# ββ MODEL COMPARISON ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 996 |
+
output$model_comp_content <- renderUI({
|
| 997 |
+
res <- analysis_results()
|
| 998 |
+
if (is.null(res)) return(empty_state_ui("βοΈ", "Run Analysis First"))
|
| 999 |
+
tagList(
|
| 1000 |
+
div(class = "grid-2",
|
| 1001 |
+
div(class = "plot-card",
|
| 1002 |
+
div(class = "plot-card-header",
|
| 1003 |
+
div(class = "plot-card-icon orange", "βοΈ"),
|
| 1004 |
+
div(div(class = "plot-card-title", "PEAK LOD COMPARISON"),
|
| 1005 |
+
div(class = "plot-card-subtitle", "Max LOD per model"))
|
| 1006 |
+
),
|
| 1007 |
+
div(class = "plot-card-body",
|
| 1008 |
+
plotOutput("plot_model_bar", height = "340px") %>% withSpinner(color = "#e8500a", type = 4))
|
| 1009 |
+
),
|
| 1010 |
+
div(class = "plot-card",
|
| 1011 |
+
div(class = "plot-card-header",
|
| 1012 |
+
div(class = "plot-card-icon pink", "π·"),
|
| 1013 |
+
div(div(class = "plot-card-title", "LOD HEATMAP"),
|
| 1014 |
+
div(class = "plot-card-subtitle", "Marker Γ Model"))
|
| 1015 |
+
),
|
| 1016 |
+
div(class = "plot-card-body",
|
| 1017 |
+
plotOutput("plot_lod_heatmap", height = "340px") %>% withSpinner(color = "#c2185b", type = 4))
|
| 1018 |
+
)
|
| 1019 |
+
),
|
| 1020 |
+
div(class = "plot-card",
|
| 1021 |
+
div(class = "plot-card-header",
|
| 1022 |
+
div(class = "plot-card-icon blue", "π"),
|
| 1023 |
+
div(div(class = "plot-card-title", "MODEL CORRELATION"),
|
| 1024 |
+
div(class = "plot-card-subtitle", "LOD score agreement across models"))
|
| 1025 |
+
),
|
| 1026 |
+
div(class = "plot-card-body",
|
| 1027 |
+
plotOutput("plot_model_corr", height = "340px") %>% withSpinner(color = "#1a6cf5", type = 4))
|
| 1028 |
+
)
|
| 1029 |
+
)
|
| 1030 |
+
})
|
| 1031 |
+
|
| 1032 |
+
# ββ QTL EFFECTS βββββββββββββββββββββββββββββββββββββββββββββββββββοΏ½οΏ½οΏ½βββββββ
|
| 1033 |
+
output$effects_content <- renderUI({
|
| 1034 |
+
res <- analysis_results()
|
| 1035 |
+
if (is.null(res)) return(empty_state_ui("π»", "Run Analysis First"))
|
| 1036 |
+
qtl_choices <- if (!is.null(res$qtl_table) && nrow(res$qtl_table) > 0)
|
| 1037 |
+
paste0(res$qtl_table$Chr, "@", res$qtl_table$Peak_Marker) else "none"
|
| 1038 |
+
tagList(
|
| 1039 |
+
div(class = "grid-2",
|
| 1040 |
+
div(class = "plot-card",
|
| 1041 |
+
div(class = "plot-card-header",
|
| 1042 |
+
div(class = "plot-card-icon green", "π»"),
|
| 1043 |
+
div(div(class = "plot-card-title", "EFFECT PLOT"),
|
| 1044 |
+
div(class = "plot-card-subtitle", "Genotype effect at peak markers"))
|
| 1045 |
+
),
|
| 1046 |
+
div(class = "plot-card-body",
|
| 1047 |
+
div(class = "control-block", style = "margin-bottom:10px;",
|
| 1048 |
+
selectInput("effect_qtl", "Select QTL:", choices = qtl_choices)
|
| 1049 |
+
),
|
| 1050 |
+
plotOutput("plot_effects", height = "320px") %>% withSpinner(color = "#18a058", type = 4)
|
| 1051 |
+
)
|
| 1052 |
+
),
|
| 1053 |
+
div(class = "plot-card",
|
| 1054 |
+
div(class = "plot-card-header",
|
| 1055 |
+
div(class = "plot-card-icon orange", "π¦"),
|
| 1056 |
+
div(div(class = "plot-card-title", "PHENOTYPE Γ GENOTYPE"),
|
| 1057 |
+
div(class = "plot-card-subtitle", "Boxplot at peak marker"))
|
| 1058 |
+
),
|
| 1059 |
+
div(class = "plot-card-body",
|
| 1060 |
+
plotOutput("plot_pheno_geno", height = "320px") %>% withSpinner(color = "#e8500a", type = 4))
|
| 1061 |
+
)
|
| 1062 |
+
),
|
| 1063 |
+
div(class = "plot-card",
|
| 1064 |
+
div(class = "plot-card-header",
|
| 1065 |
+
div(class = "plot-card-icon pink", "π‘"),
|
| 1066 |
+
div(div(class = "plot-card-title", "PVE PROFILE"),
|
| 1067 |
+
div(class = "plot-card-subtitle", "Proportion of variance explained per position"))
|
| 1068 |
+
),
|
| 1069 |
+
div(class = "plot-card-body",
|
| 1070 |
+
plotOutput("plot_pve", height = "280px") %>% withSpinner(color = "#c2185b", type = 4))
|
| 1071 |
+
)
|
| 1072 |
+
)
|
| 1073 |
+
})
|
| 1074 |
+
|
| 1075 |
+
# ββ 2D SCAN βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1076 |
+
output$pairwise_content <- renderUI({
|
| 1077 |
+
res <- analysis_results()
|
| 1078 |
+
if (is.null(res)) return(empty_state_ui("π²", "Run Analysis First"))
|
| 1079 |
+
div(class = "plot-card",
|
| 1080 |
+
div(class = "plot-card-header",
|
| 1081 |
+
div(class = "plot-card-icon blue", "π²"),
|
| 1082 |
+
div(div(class = "plot-card-title", "2D GENOME SCAN"),
|
| 1083 |
+
div(class = "plot-card-subtitle", "Pairwise LOD / epistasis"))
|
| 1084 |
+
),
|
| 1085 |
+
div(class = "plot-card-body",
|
| 1086 |
+
plotOutput("plot_2d_scan", height = "560px") %>% withSpinner(color = "#1a6cf5", type = 4))
|
| 1087 |
+
)
|
| 1088 |
+
})
|
| 1089 |
+
|
| 1090 |
+
# ββ DIAGNOSTICS βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1091 |
+
output$diagnostics_content <- renderUI({
|
| 1092 |
+
cross <- cross_data()
|
| 1093 |
+
if (is.null(cross)) return(empty_state_ui("π", "No Data Loaded", "Upload CSV files to view diagnostics."))
|
| 1094 |
+
tagList(
|
| 1095 |
+
div(class = "grid-2",
|
| 1096 |
+
div(class = "plot-card",
|
| 1097 |
+
div(class = "plot-card-header",
|
| 1098 |
+
div(class = "plot-card-icon orange", "π"),
|
| 1099 |
+
div(div(class = "plot-card-title", "MISSING DATA"),
|
| 1100 |
+
div(class = "plot-card-subtitle", "Genotype completeness"))
|
| 1101 |
+
),
|
| 1102 |
+
div(class = "plot-card-body",
|
| 1103 |
+
plotOutput("plot_missing", height = "300px") %>% withSpinner(color = "#e8500a", type = 4))
|
| 1104 |
+
),
|
| 1105 |
+
div(class = "plot-card",
|
| 1106 |
+
div(class = "plot-card-header",
|
| 1107 |
+
div(class = "plot-card-icon green", "π"),
|
| 1108 |
+
div(div(class = "plot-card-title", "GENOTYPE FREQ"),
|
| 1109 |
+
div(class = "plot-card-subtitle", "Allele frequency per marker"))
|
| 1110 |
+
),
|
| 1111 |
+
div(class = "plot-card-body",
|
| 1112 |
+
plotOutput("plot_geno_freq", height = "300px") %>% withSpinner(color = "#18a058", type = 4))
|
| 1113 |
+
)
|
| 1114 |
+
),
|
| 1115 |
+
div(class = "plot-card",
|
| 1116 |
+
div(class = "plot-card-header",
|
| 1117 |
+
div(class = "plot-card-icon pink", "π"),
|
| 1118 |
+
div(div(class = "plot-card-title", "MARKER DISTANCE"),
|
| 1119 |
+
div(class = "plot-card-subtitle", "Inter-marker spacing"))
|
| 1120 |
+
),
|
| 1121 |
+
div(class = "plot-card-body",
|
| 1122 |
+
plotOutput("plot_marker_dist", height = "260px") %>% withSpinner(color = "#c2185b", type = 4))
|
| 1123 |
+
)
|
| 1124 |
+
)
|
| 1125 |
})
|
| 1126 |
|
| 1127 |
+
# ββ RESULTS TABLE βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1128 |
+
output$results_content <- renderUI({
|
| 1129 |
+
res <- analysis_results()
|
| 1130 |
+
if (is.null(res)) return(empty_state_ui("π", "Run Analysis First"))
|
| 1131 |
+
div(class = "plot-card",
|
| 1132 |
+
div(class = "plot-card-header",
|
| 1133 |
+
div(class = "plot-card-icon blue", "π"),
|
| 1134 |
+
div(div(class = "plot-card-title", "QTL RESULTS TABLE"),
|
| 1135 |
+
div(class = "plot-card-subtitle", "Peak marker, flanking markers, LOD, PVE, effects, CI"))
|
| 1136 |
+
),
|
| 1137 |
+
div(class = "plot-card-body", DTOutput("table_qtl_results"))
|
| 1138 |
+
)
|
| 1139 |
+
})
|
| 1140 |
+
|
| 1141 |
+
# ββ SUMMARY βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1142 |
+
output$summary_content <- renderUI({
|
| 1143 |
+
res <- analysis_results()
|
| 1144 |
+
if (is.null(res)) return(empty_state_ui("π", "Run Analysis First"))
|
| 1145 |
+
tagList(
|
| 1146 |
+
div(class = "plot-card",
|
| 1147 |
+
div(class = "plot-card-header",
|
| 1148 |
+
div(class = "plot-card-icon green", "π"),
|
| 1149 |
+
div(div(class = "plot-card-title", "ANALYSIS SUMMARY"),
|
| 1150 |
+
div(class = "plot-card-subtitle", "All models"))
|
| 1151 |
+
),
|
| 1152 |
+
div(class = "plot-card-body", DTOutput("table_model_summary"))
|
| 1153 |
+
),
|
| 1154 |
+
div(class = "plot-card", style = "margin-top:20px;",
|
| 1155 |
+
div(class = "plot-card-header",
|
| 1156 |
+
div(class = "plot-card-icon orange", "π"),
|
| 1157 |
+
div(div(class = "plot-card-title", "PERMUTATION THRESHOLDS"),
|
| 1158 |
+
div(class = "plot-card-subtitle", "Significance levels per model"))
|
| 1159 |
+
),
|
| 1160 |
+
div(class = "plot-card-body", DTOutput("table_perm_thresholds"))
|
| 1161 |
+
)
|
| 1162 |
+
)
|
| 1163 |
+
})
|
| 1164 |
+
|
| 1165 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1166 |
+
# PLOTS
|
| 1167 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1168 |
|
|
|
|
| 1169 |
output$plot_genome_map <- renderPlot({
|
| 1170 |
cross <- cross_data(); req(cross)
|
| 1171 |
map <- pull.map(cross)
|
|
|
|
| 1175 |
df$chr <- factor(df$chr, levels = names(map))
|
| 1176 |
|
| 1177 |
ggplot(df, aes(x = chr, y = pos)) +
|
| 1178 |
+
geom_segment(aes(xend = chr, yend = pos), color = "#dde2ea", linewidth = 8) +
|
| 1179 |
+
geom_point(color = "#1a6cf5", size = 1.5, alpha = .8) +
|
| 1180 |
scale_y_reverse() +
|
| 1181 |
labs(title = "Genetic Map", x = "Chromosome", y = "Position (cM)") +
|
| 1182 |
theme_qtl()
|
| 1183 |
+
}, bg = "white")
|
| 1184 |
|
|
|
|
| 1185 |
output$plot_pheno_dist <- renderPlot({
|
| 1186 |
+
cross <- cross_data(); req(cross); req(input$pheno_col)
|
|
|
|
| 1187 |
ph <- cross$pheno[[input$pheno_col]]
|
| 1188 |
df <- data.frame(value = ph[!is.na(ph)])
|
| 1189 |
|
| 1190 |
p1 <- ggplot(df, aes(value)) +
|
| 1191 |
+
geom_histogram(fill = "#1a6cf5", color = "#ffffff", bins = 30, alpha = .8) +
|
| 1192 |
+
geom_density(aes(y = after_stat(count)), color = "#e8500a", linewidth = 1) +
|
| 1193 |
labs(title = input$pheno_col, x = "Value", y = "Count") +
|
| 1194 |
theme_qtl()
|
| 1195 |
|
| 1196 |
p2 <- ggplot(df, aes(sample = value)) +
|
| 1197 |
+
stat_qq(color = "#18a058", size = 1.5, alpha = .8) +
|
| 1198 |
+
stat_qq_line(color = "#c2185b", linewidth = .8) +
|
| 1199 |
labs(title = "Q-Q Plot", x = "Theoretical", y = "Sample") +
|
| 1200 |
theme_qtl()
|
| 1201 |
|
| 1202 |
gridExtra::grid.arrange(p1, p2, ncol = 2)
|
| 1203 |
+
}, bg = "white")
|
| 1204 |
|
|
|
|
| 1205 |
output$plot_physical_map <- renderPlot({
|
| 1206 |
cross <- cross_data(); req(cross)
|
| 1207 |
map <- pull.map(cross)
|
|
|
|
| 1215 |
geom_rect(data = chr_len,
|
| 1216 |
aes(xmin = as.numeric(chr) - .35, xmax = as.numeric(chr) + .35,
|
| 1217 |
ymin = 0, ymax = len),
|
| 1218 |
+
fill = "#e8ecf2", color = "#c8d0dc", linewidth = .7) +
|
| 1219 |
geom_point(data = df %>% mutate(chr = factor(chr, levels = names(map))),
|
| 1220 |
aes(x = as.numeric(chr), y = pos),
|
| 1221 |
+
color = "#1a6cf5", size = 1, alpha = .7) +
|
| 1222 |
scale_x_continuous(breaks = seq_along(names(map)), labels = names(map)) +
|
| 1223 |
scale_y_reverse() +
|
| 1224 |
labs(title = "Physical Map Overview", x = "Chromosome", y = "cM") +
|
| 1225 |
theme_qtl()
|
| 1226 |
+
}, bg = "white")
|
| 1227 |
|
|
|
|
| 1228 |
output$plot_manhattan <- renderPlot({
|
| 1229 |
res <- analysis_results(); req(res)
|
| 1230 |
mdl <- input$manhattan_model; req(mdl)
|
| 1231 |
sc <- res$scan_results[[mdl]]; req(sc)
|
| 1232 |
|
| 1233 |
chrs <- unique(sc$chr)
|
| 1234 |
+
chr_offsets <- setNames(cumsum(c(0, sapply(chrs[-length(chrs)], function(ch)
|
| 1235 |
+
max(sc[sc$chr == ch, "pos"])))), chrs)
|
|
|
|
|
|
|
| 1236 |
sc$global_pos <- sc$pos + chr_offsets[as.character(sc$chr)]
|
| 1237 |
sc$chr_num <- as.integer(factor(sc$chr, levels = chrs))
|
| 1238 |
+
sc$color <- ifelse(sc$chr_num %% 2 == 0, "#1a6cf5", "#5b9cf5")
|
| 1239 |
sig <- sc[sc$lod >= res$lod_thr, ]
|
|
|
|
| 1240 |
chr_mid <- tapply(sc$global_pos, sc$chr, mean)
|
| 1241 |
|
| 1242 |
ggplot(sc, aes(x = global_pos, y = lod)) +
|
| 1243 |
geom_point(aes(color = color), size = 1.2, alpha = .75) +
|
| 1244 |
scale_color_identity() +
|
| 1245 |
geom_point(data = sig, aes(x = global_pos, y = lod),
|
| 1246 |
+
color = "#c2185b", size = 2.5, shape = 18) +
|
| 1247 |
+
geom_hline(yintercept = res$lod_thr, color = "#e8500a",
|
| 1248 |
linetype = "dashed", linewidth = .8) +
|
| 1249 |
annotate("text", x = max(sc$global_pos) * .98, y = res$lod_thr + .15,
|
| 1250 |
label = paste0("LOD = ", round(res$lod_thr, 2)),
|
| 1251 |
+
color = "#e8500a", size = 3, hjust = 1, family = "mono") +
|
| 1252 |
scale_x_continuous(breaks = chr_mid, labels = names(chr_mid)) +
|
| 1253 |
labs(title = paste("Manhattan Plot β", toupper(mdl)),
|
| 1254 |
x = "Chromosome", y = "LOD Score") +
|
| 1255 |
+
theme_qtl() + theme(panel.grid.major.x = element_blank())
|
| 1256 |
+
}, bg = "white")
|
|
|
|
| 1257 |
|
|
|
|
| 1258 |
output$plot_manhattan_interactive <- renderPlotly({
|
| 1259 |
res <- analysis_results(); req(res)
|
| 1260 |
mdl <- input$manhattan_model; req(mdl)
|
|
|
|
| 1265 |
max(sc[sc$chr == ch, "pos"])))), chrs)
|
| 1266 |
sc$global_pos <- sc$pos + chr_offsets[as.character(sc$chr)]
|
| 1267 |
sc$sig <- sc$lod >= res$lod_thr
|
| 1268 |
+
sc$label <- paste0(rownames(sc), "<br>Chr:", sc$chr,
|
| 1269 |
+
" Pos:", round(sc$pos,1), " LOD:", round(sc$lod,2))
|
| 1270 |
+
|
| 1271 |
+
plot_ly(sc, x = ~global_pos, y = ~lod,
|
| 1272 |
+
color = ~sig, colors = c("#1a6cf5","#c2185b"),
|
| 1273 |
+
text = ~label, hovertemplate = "%{text}<extra></extra>",
|
| 1274 |
+
type = "scatter", mode = "markers",
|
| 1275 |
+
marker = list(size = 4, opacity = .8)) %>%
|
| 1276 |
add_lines(y = res$lod_thr,
|
| 1277 |
+
line = list(color = "#e8500a", dash = "dash", width = 1.5),
|
| 1278 |
showlegend = FALSE, name = "Threshold") %>%
|
| 1279 |
layout(
|
| 1280 |
+
paper_bgcolor = "#ffffff",
|
| 1281 |
+
plot_bgcolor = "#f8f9fb",
|
| 1282 |
+
font = list(color = "#4a5568", family = "monospace"),
|
| 1283 |
+
xaxis = list(title = "Position", gridcolor = "#e8ecf2", color = "#8a95a3"),
|
| 1284 |
+
yaxis = list(title = "LOD Score", gridcolor = "#e8ecf2", color = "#8a95a3"),
|
| 1285 |
+
legend = list(font = list(color = "#4a5568")),
|
| 1286 |
margin = list(t = 10, b = 40, l = 50, r = 20)
|
| 1287 |
)
|
|
|
|
| 1288 |
})
|
| 1289 |
|
|
|
|
| 1290 |
output$plot_scan_all_models <- renderPlot({
|
| 1291 |
res <- analysis_results(); req(res)
|
| 1292 |
req(length(res$scan_results) > 0)
|
|
|
|
| 1302 |
df_all <- dplyr::bind_rows(dfs)
|
| 1303 |
df_all$model <- factor(df_all$model)
|
| 1304 |
|
| 1305 |
+
sc_ref <- res$scan_results[[1]]
|
| 1306 |
+
chrs <- unique(sc_ref$chr)
|
| 1307 |
offsets <- setNames(cumsum(c(0, sapply(chrs[-length(chrs)], function(ch)
|
| 1308 |
max(sc_ref[sc_ref$chr==ch,"pos"])))), chrs)
|
| 1309 |
+
vlines <- data.frame(x = offsets[-1])
|
| 1310 |
|
| 1311 |
ggplot(df_all, aes(x = global_pos, y = lod, color = model)) +
|
| 1312 |
+
geom_vline(data = vlines, aes(xintercept = x), color = "#e8ecf2", linewidth = .5) +
|
| 1313 |
geom_line(linewidth = .6, alpha = .85) +
|
| 1314 |
+
geom_hline(yintercept = res$lod_thr, color = "#e8500a",
|
| 1315 |
linetype = "dashed", linewidth = .7) +
|
| 1316 |
scale_color_manual(values = model_colors) +
|
| 1317 |
labs(title = "Genome Scan β All Models",
|
| 1318 |
x = "Genome Position (cM)", y = "LOD Score", color = "Model") +
|
| 1319 |
+
theme_qtl() + theme(legend.position = "right")
|
| 1320 |
+
}, bg = "white")
|
|
|
|
| 1321 |
|
|
|
|
| 1322 |
output$plot_chr_grid <- renderPlot({
|
| 1323 |
res <- analysis_results(); req(res)
|
| 1324 |
mdl <- input$chr_plot_model; req(mdl)
|
|
|
|
| 1333 |
plots <- lapply(chrs, function(ch) {
|
| 1334 |
chr_sc <- sc[sc$chr == ch, ]
|
| 1335 |
p <- ggplot(chr_sc, aes(x = pos, y = lod)) +
|
| 1336 |
+
geom_line(color = "#1a6cf5", linewidth = .9) +
|
| 1337 |
+
geom_hline(yintercept = res$lod_thr, color = "#e8500a",
|
| 1338 |
linetype = "dashed", linewidth = .6) +
|
| 1339 |
scale_x_continuous(expand = c(.02,.02)) +
|
| 1340 |
scale_y_continuous(limits = c(0, max(sc$lod) * 1.1)) +
|
| 1341 |
labs(title = paste0("Chr ", ch), x = NULL, y = "LOD") +
|
| 1342 |
theme_qtl(base_size = 9) +
|
| 1343 |
+
theme(plot.title = element_text(size = 9, color = "#1a6cf5"),
|
| 1344 |
axis.title.y = element_text(size = 7),
|
| 1345 |
plot.margin = margin(6, 8, 6, 8))
|
| 1346 |
|
|
|
|
| 1347 |
if (!is.null(qt) && nrow(qt) > 0) {
|
| 1348 |
qt_chr <- qt[qt$Chr == ch & qt$Model == mdl, ]
|
| 1349 |
if (nrow(qt_chr) > 0) {
|
| 1350 |
p <- p +
|
| 1351 |
+
geom_point(data = qt_chr, aes(x = Peak_pos_cM, y = LOD),
|
| 1352 |
+
color = "#c2185b", size = 3, shape = 23, fill = "#c2185b") +
|
|
|
|
| 1353 |
ggrepel::geom_label_repel(
|
| 1354 |
data = qt_chr,
|
| 1355 |
aes(x = Peak_pos_cM, y = LOD,
|
| 1356 |
label = paste0("q", toupper(substr(mdl,1,1)), "R", ch)),
|
| 1357 |
+
fill = "#ffffff", color = "#18a058", size = 2.5,
|
| 1358 |
+
label.padding = unit(.15,"lines"), min.segment.length = 0
|
|
|
|
| 1359 |
)
|
| 1360 |
}
|
| 1361 |
}
|
| 1362 |
p
|
| 1363 |
})
|
| 1364 |
|
| 1365 |
+
do.call(gridExtra::grid.arrange, c(plots, list(ncol = n_cols, nrow = n_rows)))
|
| 1366 |
+
}, bg = "white")
|
|
|
|
| 1367 |
|
|
|
|
| 1368 |
output$plot_model_bar <- renderPlot({
|
| 1369 |
res <- analysis_results(); req(res)
|
| 1370 |
df <- data.frame(
|
| 1371 |
+
model = names(res$scan_results),
|
| 1372 |
max_lod = sapply(res$scan_results, function(sc) max(sc$lod, na.rm = TRUE))
|
| 1373 |
)
|
| 1374 |
df$model <- factor(df$model, levels = df$model[order(df$max_lod)])
|
| 1375 |
|
| 1376 |
ggplot(df, aes(x = model, y = max_lod, fill = model)) +
|
| 1377 |
geom_col(width = .6, alpha = .85) +
|
| 1378 |
+
geom_hline(yintercept = res$lod_thr, color = "#e8500a",
|
| 1379 |
linetype = "dashed", linewidth = .8) +
|
| 1380 |
geom_text(aes(label = round(max_lod, 2)), hjust = -0.2,
|
| 1381 |
+
color = "#1a202c", size = 3, family = "mono") +
|
| 1382 |
scale_fill_manual(values = model_colors) +
|
| 1383 |
coord_flip(ylim = c(0, max(df$max_lod) * 1.15)) +
|
| 1384 |
labs(title = "Peak LOD by Model", x = NULL, y = "Max LOD") +
|
| 1385 |
theme_qtl() + theme(legend.position = "none")
|
| 1386 |
+
}, bg = "white")
|
| 1387 |
|
|
|
|
| 1388 |
output$plot_lod_heatmap <- renderPlot({
|
| 1389 |
res <- analysis_results(); req(res)
|
| 1390 |
|
|
|
|
| 1391 |
all_sc <- dplyr::bind_rows(lapply(names(res$scan_results), function(m) {
|
| 1392 |
sc <- res$scan_results[[m]]
|
| 1393 |
sc$model <- m; sc$marker <- rownames(sc); sc
|
|
|
|
| 1399 |
slice_head(n = 40) %>%
|
| 1400 |
pull(marker)
|
| 1401 |
|
| 1402 |
+
hm <- all_sc %>% filter(marker %in% top_markers) %>% select(model, marker, lod)
|
|
|
|
|
|
|
| 1403 |
|
| 1404 |
ggplot(hm, aes(x = model, y = marker, fill = lod)) +
|
| 1405 |
+
geom_tile(color = "#f8f9fb", linewidth = .3) +
|
| 1406 |
scale_fill_gradientn(
|
| 1407 |
+
colors = c("#f8f9fb","#bcd0fc","#1a6cf5","#18a058","#c2185b"),
|
| 1408 |
name = "LOD"
|
| 1409 |
) +
|
| 1410 |
labs(title = "LOD Heatmap", x = "Model", y = "Marker") +
|
| 1411 |
theme_qtl() +
|
| 1412 |
theme(axis.text.x = element_text(angle = 30, hjust = 1),
|
| 1413 |
axis.text.y = element_text(size = 6))
|
| 1414 |
+
}, bg = "white")
|
| 1415 |
|
|
|
|
| 1416 |
output$plot_model_corr <- renderPlot({
|
| 1417 |
res <- analysis_results(); req(res)
|
| 1418 |
req(length(res$scan_results) >= 2)
|
| 1419 |
|
|
|
|
| 1420 |
sc_list <- lapply(names(res$scan_results), function(m) {
|
| 1421 |
sc <- res$scan_results[[m]]
|
| 1422 |
data.frame(marker = rownames(sc), lod = sc$lod, stringsAsFactors = FALSE)
|
|
|
|
| 1424 |
names(sc_list) <- names(res$scan_results)
|
| 1425 |
|
| 1426 |
common_markers <- Reduce(intersect, lapply(sc_list, `[[`, "marker"))
|
| 1427 |
+
mat <- sapply(sc_list, function(sc) sc$lod[match(common_markers, sc$marker)])
|
| 1428 |
corr_mat <- cor(mat, use = "complete.obs")
|
| 1429 |
+
corr_df <- as.data.frame(as.table(corr_mat))
|
|
|
|
| 1430 |
names(corr_df) <- c("m1","m2","corr")
|
| 1431 |
|
| 1432 |
ggplot(corr_df, aes(x = m1, y = m2, fill = corr)) +
|
| 1433 |
+
geom_tile(color = "#ffffff", linewidth = .5) +
|
| 1434 |
+
geom_text(aes(label = round(corr, 2)), size = 3, color = "#1a202c", family = "mono") +
|
| 1435 |
+
scale_fill_gradient2(low = "#c2185b", mid = "#f1f4f8", high = "#1a6cf5",
|
| 1436 |
midpoint = 0, limits = c(-1,1), name = "r") +
|
| 1437 |
labs(title = "Model LOD Correlation", x = NULL, y = NULL) +
|
| 1438 |
+
theme_qtl() + theme(axis.text.x = element_text(angle = 30, hjust = 1))
|
| 1439 |
+
}, bg = "white")
|
|
|
|
| 1440 |
|
|
|
|
| 1441 |
output$plot_effects <- renderPlot({
|
| 1442 |
res <- analysis_results(); req(res)
|
| 1443 |
+
qtl_sel <- input$effect_qtl; req(qtl_sel); req(qtl_sel != "none")
|
|
|
|
| 1444 |
|
| 1445 |
+
parts <- strsplit(qtl_sel, "@")[[1]]
|
| 1446 |
+
ch <- parts[1]; mk <- parts[2]
|
| 1447 |
|
| 1448 |
tryCatch({
|
| 1449 |
+
eff <- effectplot(res$cross, mname1 = mk, pheno.col = res$pheno_idx, draw = FALSE)
|
|
|
|
| 1450 |
df <- data.frame(geno = names(eff$Means), mean = eff$Means, se = eff$SEs)
|
| 1451 |
ggplot(df, aes(x = geno, y = mean, fill = geno)) +
|
| 1452 |
+
geom_col(width = .5, alpha = .85) +
|
| 1453 |
geom_errorbar(aes(ymin = mean - se, ymax = mean + se),
|
| 1454 |
+
width = .15, color = "#4a5568", linewidth = .8) +
|
| 1455 |
+
scale_fill_manual(values = c("#1a6cf5","#c2185b","#18a058")) +
|
| 1456 |
+
labs(title = paste("Effect Plot β", mk), x = "Genotype", y = "Mean Phenotype") +
|
|
|
|
| 1457 |
theme_qtl() + theme(legend.position = "none")
|
| 1458 |
}, error = function(e) {
|
| 1459 |
+
ggplot() + annotate("text", x=.5, y=.5, label="Effect not available", color="#8a95a3", size=5) + theme_qtl()
|
|
|
|
| 1460 |
})
|
| 1461 |
+
}, bg = "white")
|
| 1462 |
|
|
|
|
| 1463 |
output$plot_pheno_geno <- renderPlot({
|
| 1464 |
res <- analysis_results(); req(res)
|
| 1465 |
qtl_sel <- input$effect_qtl; req(qtl_sel != "none")
|
| 1466 |
|
| 1467 |
parts <- strsplit(qtl_sel, "@")[[1]]; mk <- parts[2]
|
| 1468 |
tryCatch({
|
| 1469 |
+
geno_idx <- find.markerindex(res$cross, mk)
|
| 1470 |
+
geno_vec <- pull.geno(res$cross)[, geno_idx]
|
| 1471 |
pheno_vec <- res$cross$pheno[[res$pheno_idx]]
|
| 1472 |
+
df <- data.frame(geno = as.character(geno_vec), pheno = pheno_vec) %>%
|
| 1473 |
+
filter(!is.na(geno), !is.na(pheno))
|
| 1474 |
geno_labs <- c("1" = "AA", "2" = "AB", "3" = "BB")
|
| 1475 |
df$geno <- dplyr::recode(df$geno, !!!geno_labs)
|
| 1476 |
|
| 1477 |
ggplot(df, aes(x = geno, y = pheno, fill = geno)) +
|
| 1478 |
geom_violin(alpha = .4, trim = FALSE) +
|
| 1479 |
+
geom_boxplot(width = .15, outlier.color = "#c2185b", alpha = .7) +
|
| 1480 |
+
scale_fill_manual(values = c("#1a6cf5","#e8500a","#18a058")) +
|
| 1481 |
labs(title = paste("Phenotype by Genotype β", mk),
|
| 1482 |
x = "Genotype", y = input$pheno_col) +
|
| 1483 |
theme_qtl() + theme(legend.position = "none")
|
| 1484 |
}, error = function(e) {
|
| 1485 |
+
ggplot() + annotate("text", x=.5, y=.5, label="Unavailable", color="#8a95a3", size=5) + theme_qtl()
|
| 1486 |
})
|
| 1487 |
+
}, bg = "white")
|
| 1488 |
|
|
|
|
| 1489 |
output$plot_pve <- renderPlot({
|
| 1490 |
res <- analysis_results(); req(res)
|
| 1491 |
qt <- res$qtl_table; req(!is.null(qt) && nrow(qt) > 0)
|
| 1492 |
|
| 1493 |
qt_avg <- qt %>%
|
| 1494 |
group_by(Chr, Peak_pos_cM) %>%
|
| 1495 |
+
summarise(PVE = mean(PVE_pct, na.rm = TRUE), .groups = "drop")
|
|
|
|
| 1496 |
|
| 1497 |
ggplot(qt_avg, aes(x = interaction(Chr, round(Peak_pos_cM)), y = PVE, fill = PVE)) +
|
| 1498 |
geom_col(width = .7) +
|
| 1499 |
+
scale_fill_gradientn(colors = c("#bcd0fc","#1a6cf5","#18a058","#c2185b"), name = "PVE%") +
|
| 1500 |
geom_text(aes(label = paste0(round(PVE,1),"%")), vjust = -0.4, size = 3,
|
| 1501 |
+
color = "#1a202c", family = "mono") +
|
| 1502 |
labs(title = "PVE per QTL", x = "Chr @ Position", y = "PVE (%)") +
|
| 1503 |
+
theme_qtl() + theme(axis.text.x = element_text(angle = 40, hjust = 1))
|
| 1504 |
+
}, bg = "white")
|
|
|
|
| 1505 |
|
|
|
|
| 1506 |
output$plot_2d_scan <- renderPlot({
|
| 1507 |
res <- analysis_results(); req(res)
|
| 1508 |
|
|
|
|
| 1511 |
error = function(e) NULL
|
| 1512 |
)
|
| 1513 |
if (is.null(sc2)) {
|
| 1514 |
+
ggplot() + annotate("text", x=.5, y=.5,
|
| 1515 |
+
label = "2D scan failed or insufficient data",
|
| 1516 |
+
color = "#8a95a3", size=5) + theme_qtl()
|
| 1517 |
} else {
|
|
|
|
| 1518 |
lod_mat <- sc2$lod
|
| 1519 |
n <- nrow(lod_mat)
|
| 1520 |
df2d <- expand.grid(x = 1:n, y = 1:n)
|
|
|
|
| 1523 |
ggplot(df2d, aes(x=x, y=y, fill=lod)) +
|
| 1524 |
geom_tile() +
|
| 1525 |
scale_fill_gradientn(
|
| 1526 |
+
colors = c("#f8f9fb","#bcd0fc","#1a6cf5","#18a058","#c2185b"),
|
| 1527 |
+
name = "LOD", na.value = "#f8f9fb"
|
| 1528 |
) +
|
| 1529 |
labs(title = "2D Genome Scan (Pairwise)", x = "Position 1", y = "Position 2") +
|
| 1530 |
theme_qtl() + coord_equal()
|
| 1531 |
}
|
| 1532 |
+
}, bg = "white")
|
| 1533 |
|
|
|
|
| 1534 |
output$plot_missing <- renderPlot({
|
| 1535 |
cross <- cross_data(); req(cross)
|
| 1536 |
+
miss <- nmissing(cross, what = "mar")
|
| 1537 |
+
df <- data.frame(marker = names(miss), missing = miss)
|
| 1538 |
|
| 1539 |
ggplot(df, aes(x = reorder(marker, missing), y = missing, fill = missing)) +
|
| 1540 |
geom_col() +
|
| 1541 |
+
scale_fill_gradientn(colors = c("#bcd0fc","#1a6cf5","#c2185b"), guide = "none") +
|
| 1542 |
labs(title = "Missing Genotype Data", x = "Marker", y = "# Missing") +
|
| 1543 |
theme_qtl() +
|
| 1544 |
theme(axis.text.x = element_blank(), axis.ticks.x = element_blank())
|
| 1545 |
+
}, bg = "white")
|
| 1546 |
|
|
|
|
| 1547 |
output$plot_geno_freq <- renderPlot({
|
| 1548 |
cross <- cross_data(); req(cross)
|
| 1549 |
+
gt <- pull.geno(cross)
|
| 1550 |
freq_A <- colMeans(gt == 1, na.rm = TRUE)
|
| 1551 |
freq_B <- colMeans(gt == 2, na.rm = TRUE)
|
| 1552 |
+
df <- data.frame(marker = names(freq_A), A = freq_A, B = freq_B) %>%
|
| 1553 |
+
tidyr::pivot_longer(cols = c(A, B), names_to = "allele", values_to = "freq")
|
|
|
|
|
|
|
| 1554 |
|
| 1555 |
ggplot(df, aes(x = marker, y = freq, fill = allele)) +
|
| 1556 |
geom_col(position = "stack", width = 1) +
|
| 1557 |
+
scale_fill_manual(values = c(A = "#1a6cf5", B = "#e8500a")) +
|
| 1558 |
labs(title = "Allele Frequency per Marker", x = "Marker", y = "Frequency") +
|
| 1559 |
theme_qtl() +
|
| 1560 |
theme(axis.text.x = element_blank(), axis.ticks.x = element_blank())
|
| 1561 |
+
}, bg = "white")
|
| 1562 |
|
|
|
|
| 1563 |
output$plot_marker_dist <- renderPlot({
|
| 1564 |
cross <- cross_data(); req(cross)
|
| 1565 |
+
map <- pull.map(cross)
|
| 1566 |
+
diffs <- unlist(lapply(map, function(m) if (length(m) > 1) diff(m) else numeric(0)))
|
| 1567 |
+
df <- data.frame(dist = diffs)
|
|
|
|
|
|
|
| 1568 |
|
| 1569 |
ggplot(df, aes(x = dist)) +
|
| 1570 |
+
geom_histogram(fill = "#1a6cf5", color = "#ffffff", bins = 40, alpha = .8) +
|
| 1571 |
+
geom_vline(xintercept = median(diffs), color = "#c2185b",
|
| 1572 |
linetype = "dashed", linewidth = .8) +
|
| 1573 |
labs(title = "Inter-Marker Distance",
|
| 1574 |
subtitle = paste0("Median: ", round(median(diffs),1), " cM"),
|
| 1575 |
x = "Distance (cM)", y = "Count") +
|
| 1576 |
theme_qtl()
|
| 1577 |
+
}, bg = "white")
|
| 1578 |
+
|
| 1579 |
+
# ββ TABLES ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1580 |
|
|
|
|
| 1581 |
output$table_qtl_results <- renderDT({
|
| 1582 |
res <- analysis_results(); req(res)
|
| 1583 |
+
qt <- res$qtl_table; req(!is.null(qt) && nrow(qt) > 0)
|
| 1584 |
+
|
| 1585 |
+
datatable(qt, rownames = FALSE,
|
| 1586 |
+
options = list(pageLength = 20, scrollX = TRUE, dom = "Blfrtip",
|
| 1587 |
+
columnDefs = list(list(className = "dt-center", targets = "_all"))),
|
| 1588 |
+
class = "display nowrap") %>%
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1589 |
formatStyle("LOD",
|
| 1590 |
+
background = styleColorBar(range(qt$LOD), "#bcd0fc"),
|
| 1591 |
+
backgroundSize = "100% 80%", backgroundRepeat = "no-repeat",
|
| 1592 |
+
backgroundPosition = "center") %>%
|
| 1593 |
formatStyle("PVE_pct",
|
| 1594 |
+
background = styleColorBar(c(0,100), "#b3dfc7"),
|
| 1595 |
+
backgroundSize = "100% 80%", backgroundRepeat = "no-repeat",
|
| 1596 |
+
backgroundPosition = "center") %>%
|
|
|
|
| 1597 |
formatRound(c("Peak_pos_cM","LOD","PVE_pct","Left_pos_cM","Right_pos_cM","CI_width_cM"), 3)
|
| 1598 |
})
|
| 1599 |
|
|
|
|
| 1600 |
output$table_model_summary <- renderDT({
|
| 1601 |
res <- analysis_results(); req(res)
|
| 1602 |
df <- data.frame(
|
| 1603 |
+
Model = names(res$scan_results),
|
| 1604 |
+
Max_LOD = round(sapply(res$scan_results, function(sc) max(sc$lod, na.rm=TRUE)), 3),
|
| 1605 |
+
Mean_LOD = round(sapply(res$scan_results, function(sc) mean(sc$lod, na.rm=TRUE)), 3),
|
| 1606 |
+
QTLs_Found = sapply(names(res$scan_results), function(m) {
|
| 1607 |
if (!is.null(res$qtl_table) && nrow(res$qtl_table) > 0)
|
| 1608 |
sum(res$qtl_table$Model == m) else 0
|
| 1609 |
}),
|
| 1610 |
+
Threshold = round(res$lod_thr, 3)
|
| 1611 |
)
|
| 1612 |
datatable(df, rownames = FALSE,
|
| 1613 |
options = list(dom = "t", pageLength = 15),
|
| 1614 |
class = "display") %>%
|
| 1615 |
+
formatStyle("Max_LOD", color = "#1a6cf5", fontWeight = "bold") %>%
|
| 1616 |
+
formatStyle("QTLs_Found", color = "#c2185b", fontWeight = "bold")
|
|
|
|
| 1617 |
})
|
| 1618 |
|
|
|
|
| 1619 |
output$table_perm_thresholds <- renderDT({
|
| 1620 |
res <- analysis_results(); req(res)
|
| 1621 |
req(length(res$perm_results) > 0)
|
| 1622 |
|
| 1623 |
rows <- lapply(names(res$perm_results), function(m) {
|
| 1624 |
+
p <- res$perm_results[[m]]; if (is.null(p)) return(NULL)
|
|
|
|
| 1625 |
sm <- tryCatch(summary(p, alpha = c(0.05, 0.1, 0.2)), error = function(e) NULL)
|
| 1626 |
if (is.null(sm)) return(NULL)
|
| 1627 |
+
data.frame(Model = m, alpha_0.05 = round(sm[1],3),
|
| 1628 |
+
alpha_0.10 = round(sm[2],3), alpha_0.20 = round(sm[3],3))
|
|
|
|
|
|
|
| 1629 |
})
|
| 1630 |
df <- dplyr::bind_rows(Filter(Negate(is.null), rows))
|
| 1631 |
req(nrow(df) > 0)
|
| 1632 |
+
datatable(df, rownames = FALSE, options = list(dom = "t"), class = "display")
|
|
|
|
| 1633 |
})
|
| 1634 |
|
| 1635 |
+
# ββ Download ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1636 |
output$download_results <- downloadHandler(
|
| 1637 |
filename = function() paste0("qtl_results_", Sys.Date(), ".csv"),
|
| 1638 |
content = function(file) {
|