softwareDevelopment commited on
Commit
de8807b
·
verified ·
1 Parent(s): ad737ae

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +48 -74
app.R CHANGED
@@ -1,28 +1,17 @@
1
  library(shiny)
2
  library(htmltools)
3
- library(ggplot2)
4
- library(plotly)
5
 
6
  # ============================================================
7
  # HELPER: Parse uploaded genotype CSV (handles your format)
8
- # Expected format:
9
- # Row 1 (header): empty, marker1, marker2, ...
10
- # Each data row: sample_id, genotype_code, ...
11
- # Genotype codes: 1 = AA, 2 = BB, 0 = AB (het), -1 or NA = missing
12
  # ============================================================
13
  parse_geno_csv <- function(path) {
14
  df <- tryCatch({
15
  df_raw <- read.csv(path, stringsAsFactors = FALSE, check.names = FALSE, header = TRUE)
16
 
17
- # Handle case where first column has no header (empty or "id")
18
  if (ncol(df_raw) > 0) {
19
- # First column is sample IDs
20
  colnames(df_raw)[1] <- "id"
21
-
22
- # Remove any completely empty rows
23
  df_raw <- df_raw[!apply(df_raw[,1, drop=FALSE], 1, function(x) is.na(x) | x == ""), ]
24
 
25
- # Convert genotype columns to numeric
26
  for (i in 2:ncol(df_raw)) {
27
  df_raw[[i]] <- suppressWarnings(as.numeric(df_raw[[i]]))
28
  }
@@ -35,8 +24,6 @@ parse_geno_csv <- function(path) {
35
 
36
  if (is.null(df)) return(NULL)
37
  if (nrow(df) < 1) return(NULL)
38
-
39
- # Ensure at least one marker column exists
40
  if (ncol(df) < 2) return(NULL)
41
 
42
  df
@@ -44,18 +31,13 @@ parse_geno_csv <- function(path) {
44
 
45
  # ============================================================
46
  # HELPER: Parse uploaded phenotype CSV
47
- # Expected format:
48
- # Row 1 (header): id, trait1, trait2, ...
49
- # Each data row: sample_id, numeric_value, ...
50
  # ============================================================
51
  parse_pheno_csv <- function(path) {
52
  df <- tryCatch({
53
  df_raw <- read.csv(path, stringsAsFactors = FALSE, check.names = FALSE)
54
- # Ensure first column is id
55
  if (ncol(df_raw) > 0) {
56
  colnames(df_raw)[1] <- "id"
57
  }
58
- # Convert trait columns to numeric
59
  for (i in 2:ncol(df_raw)) {
60
  df_raw[[i]] <- suppressWarnings(as.numeric(df_raw[[i]]))
61
  }
@@ -69,18 +51,14 @@ parse_pheno_csv <- function(path) {
69
 
70
  # ============================================================
71
  # HELPER: Parse uploaded genetic map CSV
72
- # Expected format:
73
- # marker, chromosome, position_cM
74
  # ============================================================
75
  parse_map_csv <- function(path) {
76
  df <- tryCatch(read.csv(path, stringsAsFactors = FALSE, check.names = FALSE),
77
  error = function(e) NULL)
78
  if (is.null(df)) return(NULL)
79
 
80
- # Standardise column names
81
  names(df) <- tolower(trimws(names(df)))
82
 
83
- # Try to find marker, chr, pos columns
84
  mk_col <- names(df)[grepl("marker|name|snp|locus", names(df), ignore.case=TRUE)][1]
85
  chr_col <- names(df)[grepl("chr|chrom|scaffold|linkage", names(df), ignore.case=TRUE)][1]
86
  pos_col <- names(df)[grepl("pos|cM|cm|map|dist|bp|location", names(df), ignore.case=TRUE)][1]
@@ -102,7 +80,6 @@ parse_map_csv <- function(path) {
102
  # QTL ANALYSIS FUNCTIONS
103
  # ============================================================
104
  prepare_cross <- function(geno_df, pheno_df, trait) {
105
- # Merge by id
106
  merged <- merge(geno_df, pheno_df[, c("id", trait), drop=FALSE], by = "id", all=FALSE)
107
 
108
  if (nrow(merged) == 0) {
@@ -113,8 +90,6 @@ prepare_cross <- function(geno_df, pheno_df, trait) {
113
  marker_cols <- setdiff(names(merged), c("id", trait))
114
  X_raw <- as.matrix(merged[, marker_cols, drop = FALSE])
115
  mode(X_raw) <- "numeric"
116
-
117
- # Replace -1 with NA for missing
118
  X_raw[X_raw == -1] <- NA
119
 
120
  list(y = y, X = X_raw, markers = marker_cols, ids = merged$id)
@@ -139,7 +114,7 @@ encode_additive <- function(X) {
139
  mn <- min(u); mx <- max(u)
140
  X2[, j] <- (X[, j] - (mn + mx) / 2) / ((mx - mn) / 2)
141
  } else {
142
- X2[, j] <- X[, j] - 1.5 # Center around 0
143
  }
144
  }
145
  X2
@@ -155,7 +130,7 @@ run_smr <- function(y, X, mpos, mchr, progress=NULL) {
155
 
156
  for (j in seq_len(n_m)) {
157
  if (!is.null(progress)) {
158
- progress$inc(1/n_m, detail = paste("SMR: Processing marker", j, "of", n_m))
159
  }
160
 
161
  g <- X[, j]; valid <- !is.na(g)
@@ -185,7 +160,7 @@ run_smr <- function(y, X, mpos, mchr, progress=NULL) {
185
  results
186
  }
187
 
188
- # ---- 2. Interval Mapping (Haley-Knott) ----
189
  run_im <- function(y, X, mpos, mchr, progress=NULL) {
190
  Xa <- encode_additive(X)
191
  results <- data.frame(marker=colnames(X), position=mpos[seq_len(ncol(X))],
@@ -195,7 +170,7 @@ run_im <- function(y, X, mpos, mchr, progress=NULL) {
195
 
196
  for (j in seq_len(ncol(Xa))) {
197
  if (!is.null(progress)) {
198
- progress$inc(1/ncol(Xa), detail = paste("IM: Processing marker", j, "of", ncol(Xa)))
199
  }
200
 
201
  g <- Xa[, j]; valid <- !is.na(g)
@@ -229,7 +204,7 @@ run_cim <- function(y, X, mpos, mchr, progress=NULL) {
229
 
230
  for (j in seq_len(ncol(Xa))) {
231
  if (!is.null(progress)) {
232
- progress$inc(1/ncol(Xa), detail = paste("CIM: Processing marker", j, "of", ncol(Xa)))
233
  }
234
 
235
  cofactors <- setdiff(seq_len(ncol(Xa)), j)
@@ -303,7 +278,7 @@ run_lasso_qtl <- function(y, X, mpos, mchr, progress=NULL) {
303
 
304
  for (iter in 1:50) {
305
  if (!is.null(progress)) {
306
- progress$inc(1/50, detail = paste("LASSO: Iteration", iter, "of 50"))
307
  }
308
  for (j in 1:p) {
309
  r <- yv - Xv %*% beta + Xv[,j] * beta[j]
@@ -345,7 +320,7 @@ run_ridge_qtl <- function(y, X, mpos, mchr, progress=NULL) {
345
  }
346
 
347
  if (!is.null(progress)) {
348
- progress$inc(0.5, detail = "Ridge: Computing coefficients")
349
  }
350
 
351
  lambda <- 1.0
@@ -381,7 +356,7 @@ run_epistasis <- function(y, X, mpos, mchr, progress=NULL) {
381
 
382
  for (j in seq_len(n_m)) {
383
  if (!is.null(progress)) {
384
- progress$inc(1/n_m, detail = paste("Epistasis: Processing marker", j, "of", n_m))
385
  }
386
 
387
  partners <- setdiff(seq_len(n_m), j)
@@ -431,7 +406,7 @@ run_mlm <- function(y, X, mpos, mchr, progress=NULL) {
431
 
432
  for (j in seq_len(ncol(Xa))) {
433
  if (!is.null(progress)) {
434
- progress$inc(1/ncol(Xa), detail = paste("MLM: Processing marker", j, "of", ncol(Xa)))
435
  }
436
 
437
  g <- Xa[, j]
@@ -467,7 +442,7 @@ run_kruskal <- function(y, X, mpos, mchr, progress=NULL) {
467
 
468
  for (j in seq_len(ncol(X))) {
469
  if (!is.null(progress)) {
470
- progress$inc(1/ncol(X), detail = paste("KW: Processing marker", j, "of", ncol(X)))
471
  }
472
 
473
  g <- X[, j]
@@ -503,7 +478,6 @@ run_all_models <- function(geno_df, pheno_df, trait, map_df, progress_callback =
503
  X <- impute_markers(cross$X)
504
  mk_names <- colnames(X)
505
 
506
- # Get positions and chromosomes from map
507
  mpos <- sapply(mk_names, function(m) {
508
  idx <- which(map_df$marker == m)
509
  if (length(idx) > 0) map_df$position[idx[1]] else NA_real_
@@ -514,7 +488,6 @@ run_all_models <- function(geno_df, pheno_df, trait, map_df, progress_callback =
514
  if (length(idx) > 0) as.character(map_df$chromosome[idx[1]]) else "1"
515
  })
516
 
517
- # Fill NA positions with sequential fallback
518
  if (any(is.na(mpos))) {
519
  seq_pos <- seq(0, 100, length.out = length(mpos))
520
  mpos[is.na(mpos)] <- seq_pos[is.na(mpos)]
@@ -528,20 +501,20 @@ run_all_models <- function(geno_df, pheno_df, trait, map_df, progress_callback =
528
 
529
  for (i in 1:10) {
530
  if (!is.null(progress_callback)) {
531
- progress_callback(value = i/10, detail = paste("Running", model_names[i], "..."))
532
  }
533
 
534
  model <- switch(i,
535
- run_smr(y, X, mpos, mchr, progress_callback),
536
- run_im(y, X, mpos, mchr, progress_callback),
537
- run_cim(y, X, mpos, mchr, progress_callback),
538
- run_mqm(y, X, mpos, mchr, progress_callback),
539
- run_bim(y, X, mpos, mchr, progress_callback),
540
- run_lasso_qtl(y, X, mpos, mchr, progress_callback),
541
- run_ridge_qtl(y, X, mpos, mchr, progress_callback),
542
- run_epistasis(y, X, mpos, mchr, progress_callback),
543
- run_mlm(y, X, mpos, mchr, progress_callback),
544
- run_kruskal(y, X, mpos, mchr, progress_callback)
545
  )
546
  models[[i]] <- model
547
  }
@@ -617,7 +590,6 @@ ui <- fluidPage(
617
  --accent-green: #28a745;
618
  --accent-orange: #fd7e14;
619
  --accent-red: #dc3545;
620
- --accent-purple: #6f42c1;
621
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
622
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
623
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
@@ -638,7 +610,6 @@ ui <- fluidPage(
638
  display: flex;
639
  align-items: center;
640
  gap: 20px;
641
- position: relative;
642
  box-shadow: var(--shadow-md);
643
  }
644
 
@@ -656,7 +627,6 @@ ui <- fluidPage(
656
 
657
  .dna-icon {
658
  font-size: 2rem;
659
- filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
660
  }
661
 
662
  .main-layout {
@@ -706,7 +676,7 @@ ui <- fluidPage(
706
  margin-bottom: 6px;
707
  }
708
 
709
- select, input[type=range], .file-input {
710
  width: 100%;
711
  background: var(--bg-white);
712
  border: 1px solid var(--border-light);
@@ -875,12 +845,6 @@ ui <- fluidPage(
875
  border: 1px solid #f5c6cb;
876
  }
877
 
878
- .file-info {
879
- background: #d1ecf1;
880
- color: #0c5460;
881
- border: 1px solid #bee5eb;
882
- }
883
-
884
  .upload-sep {
885
  text-align: center;
886
  font-size: 0.7rem;
@@ -998,6 +962,7 @@ ui <- fluidPage(
998
  padding: 15px;
999
  box-shadow: var(--shadow-lg);
1000
  z-index: 1000;
 
1001
  }
1002
 
1003
  .progress-bar {
@@ -1021,6 +986,8 @@ ui <- fluidPage(
1021
  background: var(--bg-white);
1022
  border-radius: 8px;
1023
  padding: 20px;
 
 
1024
  }
1025
  "))
1026
  ),
@@ -1033,7 +1000,7 @@ ui <- fluidPage(
1033
  tags$div(class="header-sub","Quantitative Trait Loci Analysis Suite — Upload Your Data")
1034
  ),
1035
  tags$div(style="margin-left:auto;",
1036
- tags$div(class="badge", style="background:rgba(255,255,255,0.2);color:white;", "Multi-Model QTL Analysis")
1037
  )
1038
  ),
1039
 
@@ -1109,10 +1076,12 @@ ui <- fluidPage(
1109
 
1110
  tags$script(HTML("
1111
  function switchTab(name){
1112
- document.querySelectorAll('.tab-btn').forEach(b=>b.classList.remove('active'));
1113
- document.querySelectorAll('.tab-pane').forEach(p=>p.style.display='none');
 
 
1114
  document.getElementById('tab_'+name).classList.add('active');
1115
- document.getElementById('pane_'+name).style.display='block';
1116
  }
1117
  ")),
1118
 
@@ -1439,7 +1408,7 @@ server <- function(input, output, session) {
1439
 
1440
  if (!is.null(rv$results)) {
1441
  showNotification("✓ Analysis complete!", type="message", duration=3)
1442
- # Switch to LOD tab
1443
  runjs("switchTab('lod')")
1444
  }
1445
  })
@@ -1495,6 +1464,21 @@ server <- function(input, output, session) {
1495
  showNotification(paste("Permutation threshold (α=0.05): LOD =", rv$perm_thresh), type="message", duration=5)
1496
  })
1497
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1498
  # ---- Results download ----
1499
  output$dl_results <- downloadHandler(
1500
  filename=function() paste0("QTL_results_", Sys.Date(), ".csv"),
@@ -1527,7 +1511,7 @@ server <- function(input, output, session) {
1527
  # ---- Plot outputs (placeholder) ----
1528
  output$lodPlotUI <- renderUI({
1529
  req(rv$results)
1530
- tags$div(class="plot-container", "LOD Plot - Ready. Select a model to view.")
1531
  })
1532
 
1533
  output$multiModelPlotUI <- renderUI({
@@ -1639,16 +1623,6 @@ server <- function(input, output, session) {
1639
  )
1640
  )
1641
  })
1642
-
1643
- # Need to add runjs function
1644
- runjs <- function(code) {
1645
- session$sendCustomMessage(type='runjs', message=list(code=code))
1646
- }
1647
-
1648
- # Add JS handler
1649
- observe({
1650
- session$sendCustomMessage('runjs', list(code=''))
1651
- })
1652
  }
1653
 
1654
  # Run the app
 
1
  library(shiny)
2
  library(htmltools)
 
 
3
 
4
  # ============================================================
5
  # HELPER: Parse uploaded genotype CSV (handles your format)
 
 
 
 
6
  # ============================================================
7
  parse_geno_csv <- function(path) {
8
  df <- tryCatch({
9
  df_raw <- read.csv(path, stringsAsFactors = FALSE, check.names = FALSE, header = TRUE)
10
 
 
11
  if (ncol(df_raw) > 0) {
 
12
  colnames(df_raw)[1] <- "id"
 
 
13
  df_raw <- df_raw[!apply(df_raw[,1, drop=FALSE], 1, function(x) is.na(x) | x == ""), ]
14
 
 
15
  for (i in 2:ncol(df_raw)) {
16
  df_raw[[i]] <- suppressWarnings(as.numeric(df_raw[[i]]))
17
  }
 
24
 
25
  if (is.null(df)) return(NULL)
26
  if (nrow(df) < 1) return(NULL)
 
 
27
  if (ncol(df) < 2) return(NULL)
28
 
29
  df
 
31
 
32
  # ============================================================
33
  # HELPER: Parse uploaded phenotype CSV
 
 
 
34
  # ============================================================
35
  parse_pheno_csv <- function(path) {
36
  df <- tryCatch({
37
  df_raw <- read.csv(path, stringsAsFactors = FALSE, check.names = FALSE)
 
38
  if (ncol(df_raw) > 0) {
39
  colnames(df_raw)[1] <- "id"
40
  }
 
41
  for (i in 2:ncol(df_raw)) {
42
  df_raw[[i]] <- suppressWarnings(as.numeric(df_raw[[i]]))
43
  }
 
51
 
52
  # ============================================================
53
  # HELPER: Parse uploaded genetic map CSV
 
 
54
  # ============================================================
55
  parse_map_csv <- function(path) {
56
  df <- tryCatch(read.csv(path, stringsAsFactors = FALSE, check.names = FALSE),
57
  error = function(e) NULL)
58
  if (is.null(df)) return(NULL)
59
 
 
60
  names(df) <- tolower(trimws(names(df)))
61
 
 
62
  mk_col <- names(df)[grepl("marker|name|snp|locus", names(df), ignore.case=TRUE)][1]
63
  chr_col <- names(df)[grepl("chr|chrom|scaffold|linkage", names(df), ignore.case=TRUE)][1]
64
  pos_col <- names(df)[grepl("pos|cM|cm|map|dist|bp|location", names(df), ignore.case=TRUE)][1]
 
80
  # QTL ANALYSIS FUNCTIONS
81
  # ============================================================
82
  prepare_cross <- function(geno_df, pheno_df, trait) {
 
83
  merged <- merge(geno_df, pheno_df[, c("id", trait), drop=FALSE], by = "id", all=FALSE)
84
 
85
  if (nrow(merged) == 0) {
 
90
  marker_cols <- setdiff(names(merged), c("id", trait))
91
  X_raw <- as.matrix(merged[, marker_cols, drop = FALSE])
92
  mode(X_raw) <- "numeric"
 
 
93
  X_raw[X_raw == -1] <- NA
94
 
95
  list(y = y, X = X_raw, markers = marker_cols, ids = merged$id)
 
114
  mn <- min(u); mx <- max(u)
115
  X2[, j] <- (X[, j] - (mn + mx) / 2) / ((mx - mn) / 2)
116
  } else {
117
+ X2[, j] <- X[, j] - 1.5
118
  }
119
  }
120
  X2
 
130
 
131
  for (j in seq_len(n_m)) {
132
  if (!is.null(progress)) {
133
+ progress$inc(1/n_m, detail = paste("SMR:", j, "of", n_m))
134
  }
135
 
136
  g <- X[, j]; valid <- !is.na(g)
 
160
  results
161
  }
162
 
163
+ # ---- 2. Interval Mapping ----
164
  run_im <- function(y, X, mpos, mchr, progress=NULL) {
165
  Xa <- encode_additive(X)
166
  results <- data.frame(marker=colnames(X), position=mpos[seq_len(ncol(X))],
 
170
 
171
  for (j in seq_len(ncol(Xa))) {
172
  if (!is.null(progress)) {
173
+ progress$inc(1/ncol(Xa), detail = paste("IM:", j, "of", ncol(Xa)))
174
  }
175
 
176
  g <- Xa[, j]; valid <- !is.na(g)
 
204
 
205
  for (j in seq_len(ncol(Xa))) {
206
  if (!is.null(progress)) {
207
+ progress$inc(1/ncol(Xa), detail = paste("CIM:", j, "of", ncol(Xa)))
208
  }
209
 
210
  cofactors <- setdiff(seq_len(ncol(Xa)), j)
 
278
 
279
  for (iter in 1:50) {
280
  if (!is.null(progress)) {
281
+ progress$inc(1/50, detail = paste("LASSO: Iter", iter, "of 50"))
282
  }
283
  for (j in 1:p) {
284
  r <- yv - Xv %*% beta + Xv[,j] * beta[j]
 
320
  }
321
 
322
  if (!is.null(progress)) {
323
+ progress$inc(0.5, detail = "Ridge: Computing")
324
  }
325
 
326
  lambda <- 1.0
 
356
 
357
  for (j in seq_len(n_m)) {
358
  if (!is.null(progress)) {
359
+ progress$inc(1/n_m, detail = paste("Epi:", j, "of", n_m))
360
  }
361
 
362
  partners <- setdiff(seq_len(n_m), j)
 
406
 
407
  for (j in seq_len(ncol(Xa))) {
408
  if (!is.null(progress)) {
409
+ progress$inc(1/ncol(Xa), detail = paste("MLM:", j, "of", ncol(Xa)))
410
  }
411
 
412
  g <- Xa[, j]
 
442
 
443
  for (j in seq_len(ncol(X))) {
444
  if (!is.null(progress)) {
445
+ progress$inc(1/ncol(X), detail = paste("KW:", j, "of", ncol(X)))
446
  }
447
 
448
  g <- X[, j]
 
478
  X <- impute_markers(cross$X)
479
  mk_names <- colnames(X)
480
 
 
481
  mpos <- sapply(mk_names, function(m) {
482
  idx <- which(map_df$marker == m)
483
  if (length(idx) > 0) map_df$position[idx[1]] else NA_real_
 
488
  if (length(idx) > 0) as.character(map_df$chromosome[idx[1]]) else "1"
489
  })
490
 
 
491
  if (any(is.na(mpos))) {
492
  seq_pos <- seq(0, 100, length.out = length(mpos))
493
  mpos[is.na(mpos)] <- seq_pos[is.na(mpos)]
 
501
 
502
  for (i in 1:10) {
503
  if (!is.null(progress_callback)) {
504
+ progress_callback(value = i/10, detail = paste("Running:", model_names[i]))
505
  }
506
 
507
  model <- switch(i,
508
+ run_smr(y, X, mpos, mchr, NULL),
509
+ run_im(y, X, mpos, mchr, NULL),
510
+ run_cim(y, X, mpos, mchr, NULL),
511
+ run_mqm(y, X, mpos, mchr, NULL),
512
+ run_bim(y, X, mpos, mchr, NULL),
513
+ run_lasso_qtl(y, X, mpos, mchr, NULL),
514
+ run_ridge_qtl(y, X, mpos, mchr, NULL),
515
+ run_epistasis(y, X, mpos, mchr, NULL),
516
+ run_mlm(y, X, mpos, mchr, NULL),
517
+ run_kruskal(y, X, mpos, mchr, NULL)
518
  )
519
  models[[i]] <- model
520
  }
 
590
  --accent-green: #28a745;
591
  --accent-orange: #fd7e14;
592
  --accent-red: #dc3545;
 
593
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
594
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
595
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
 
610
  display: flex;
611
  align-items: center;
612
  gap: 20px;
 
613
  box-shadow: var(--shadow-md);
614
  }
615
 
 
627
 
628
  .dna-icon {
629
  font-size: 2rem;
 
630
  }
631
 
632
  .main-layout {
 
676
  margin-bottom: 6px;
677
  }
678
 
679
+ select, input[type=range] {
680
  width: 100%;
681
  background: var(--bg-white);
682
  border: 1px solid var(--border-light);
 
845
  border: 1px solid #f5c6cb;
846
  }
847
 
 
 
 
 
 
 
848
  .upload-sep {
849
  text-align: center;
850
  font-size: 0.7rem;
 
962
  padding: 15px;
963
  box-shadow: var(--shadow-lg);
964
  z-index: 1000;
965
+ border: 1px solid var(--border-light);
966
  }
967
 
968
  .progress-bar {
 
986
  background: var(--bg-white);
987
  border-radius: 8px;
988
  padding: 20px;
989
+ text-align: center;
990
+ color: var(--text-secondary);
991
  }
992
  "))
993
  ),
 
1000
  tags$div(class="header-sub","Quantitative Trait Loci Analysis Suite — Upload Your Data")
1001
  ),
1002
  tags$div(style="margin-left:auto;",
1003
+ tags$div(class="badge", style="background:rgba(255,255,255,0.2);color:white;", "10 Statistical Models")
1004
  )
1005
  ),
1006
 
 
1076
 
1077
  tags$script(HTML("
1078
  function switchTab(name){
1079
+ var tabs = document.querySelectorAll('.tab-btn');
1080
+ var panes = document.querySelectorAll('.tab-pane');
1081
+ for(var i=0; i<tabs.length; i++) tabs[i].classList.remove('active');
1082
+ for(var i=0; i<panes.length; i++) panes[i].style.display = 'none';
1083
  document.getElementById('tab_'+name).classList.add('active');
1084
+ document.getElementById('pane_'+name).style.display = 'block';
1085
  }
1086
  ")),
1087
 
 
1408
 
1409
  if (!is.null(rv$results)) {
1410
  showNotification("✓ Analysis complete!", type="message", duration=3)
1411
+ # Switch to LOD tab using JavaScript
1412
  runjs("switchTab('lod')")
1413
  }
1414
  })
 
1464
  showNotification(paste("Permutation threshold (α=0.05): LOD =", rv$perm_thresh), type="message", duration=5)
1465
  })
1466
 
1467
+ # Helper function to run JavaScript
1468
+ runjs <- function(code) {
1469
+ session$sendCustomMessage(type='jsCode', list(code=code))
1470
+ }
1471
+
1472
+ # Add JavaScript handler
1473
+ observe({
1474
+ session$sendCustomMessage('jsCode', list(code=''))
1475
+ })
1476
+
1477
+ # Register JavaScript handler
1478
+ session$onSessionEnded(function() {
1479
+ # Clean up
1480
+ })
1481
+
1482
  # ---- Results download ----
1483
  output$dl_results <- downloadHandler(
1484
  filename=function() paste0("QTL_results_", Sys.Date(), ".csv"),
 
1511
  # ---- Plot outputs (placeholder) ----
1512
  output$lodPlotUI <- renderUI({
1513
  req(rv$results)
1514
+ tags$div(class="plot-container", "LOD Plot - Ready. Analysis complete.")
1515
  })
1516
 
1517
  output$multiModelPlotUI <- renderUI({
 
1623
  )
1624
  )
1625
  })
 
 
 
 
 
 
 
 
 
 
1626
  }
1627
 
1628
  # Run the app