softwareDevelopment commited on
Commit
c43e3f2
·
verified ·
1 Parent(s): e0172b7

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +42 -8
app.R CHANGED
@@ -1567,18 +1567,52 @@ server <- function(input, output, session) {
1567
  observeEvent(input$predict_test_phenotype, {
1568
  req(values$model_fit, values$test_genotype_data)
1569
  tryCatch({
1570
- common_m <- intersect(colnames(values$test_genotype_data), colnames(values$genotype_data))
1571
- if (length(common_m) == 0) { showNotification("No common markers", type = "error"); return() }
1572
- X_test <- values$test_genotype_data[, common_m, drop = FALSE]
1573
- preds <- predict(values$model_fit, newdata = X_test)
1574
- values$predicted_test_phenotype_data <- data.frame(
1575
- id = rownames(X_test), Predicted_Phenotype = as.numeric(preds), stringsAsFactors = FALSE)
1576
- showNotification("Predictions done! Use the Download button below to save.", type = "message")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1577
  add_message("assistant", paste0(
1578
  "✅ **Test phenotypes predicted!**\n\n",
1579
  "• ", nrow(values$predicted_test_phenotype_data), " samples predicted\n",
 
1580
  "• Preview in Data Upload → 'Predicted Test Phenotype' tab\n",
1581
- "• Click **Download Predicted Phenotypes (.xlsx)** to save"))
 
1582
  }, error = function(e) showNotification(paste("Predict error:", e$message), type = "error"))
1583
  })
1584
 
 
1567
  observeEvent(input$predict_test_phenotype, {
1568
  req(values$model_fit, values$test_genotype_data)
1569
  tryCatch({
1570
+ withProgress(message = "Predicting test phenotypes...", value = 0, {
1571
+
1572
+ incProgress(0.15, detail = "Checking test genotype data...")
1573
+ Sys.sleep(0.1)
1574
+
1575
+ common_m <- intersect(colnames(values$test_genotype_data), colnames(values$genotype_data))
1576
+ if (length(common_m) == 0) {
1577
+ showNotification("No common markers between test and training genotype.", type = "error")
1578
+ return()
1579
+ }
1580
+
1581
+ incProgress(0.20, detail = paste0("Matched ", length(common_m), " markers to training set..."))
1582
+ Sys.sleep(0.1)
1583
+
1584
+ X_test <- values$test_genotype_data[, common_m, drop = FALSE]
1585
+ n_test <- nrow(X_test)
1586
+
1587
+ incProgress(0.25, detail = paste0("Prepared ", n_test, " test samples..."))
1588
+ Sys.sleep(0.1)
1589
+
1590
+ incProgress(0.25, detail = paste0("Running RF model on ", n_test, " samples..."))
1591
+ preds <- predict(values$model_fit, newdata = X_test)
1592
+
1593
+ incProgress(0.10, detail = "Assembling predictions table...")
1594
+ values$predicted_test_phenotype_data <- data.frame(
1595
+ id = rownames(X_test),
1596
+ Predicted_Phenotype = as.numeric(preds),
1597
+ stringsAsFactors = FALSE
1598
+ )
1599
+
1600
+ incProgress(0.05, detail = "Done!")
1601
+ Sys.sleep(0.15)
1602
+ })
1603
+
1604
+ showNotification(
1605
+ paste0("✅ Predicted ", nrow(values$predicted_test_phenotype_data),
1606
+ " samples. Use Download button to save."),
1607
+ type = "message", duration = 5
1608
+ )
1609
  add_message("assistant", paste0(
1610
  "✅ **Test phenotypes predicted!**\n\n",
1611
  "• ", nrow(values$predicted_test_phenotype_data), " samples predicted\n",
1612
+ "• Markers used: ", length(intersect(colnames(values$test_genotype_data), colnames(values$genotype_data))), "\n",
1613
  "• Preview in Data Upload → 'Predicted Test Phenotype' tab\n",
1614
+ "• Click **Download Predicted Phenotypes (.xlsx)** to save"
1615
+ ))
1616
  }, error = function(e) showNotification(paste("Predict error:", e$message), type = "error"))
1617
  })
1618