Spaces:
Sleeping
Sleeping
International Rice Research Institute commited on
Update app.R
Browse files
app.R
CHANGED
|
@@ -1,23 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
# QTL-Mapper v3 — Composite Interval Mapping (CIM) + Fixed Flanking
|
| 3 |
-
#
|
| 4 |
-
# KEY FIXES:
|
| 5 |
-
# 1. REPLACED Random Forest QTL mapping with Composite Interval Mapping (CIM)
|
| 6 |
-
# - CIM fits lm(pheno ~ marker + cofactors) at each marker position
|
| 7 |
-
# - Cofactors = top markers from initial RF screen (controls background)
|
| 8 |
-
# - LOD = -log10(p-value of marker term)
|
| 9 |
-
# - PVE computed from FULL model including cofactors → MUCH higher PVE
|
| 10 |
-
#
|
| 11 |
-
# 2. FIXED flanking markers
|
| 12 |
-
# - Flanking search now uses the FULL marker list (not post-NZV subset)
|
| 13 |
-
# - Correctly finds adjacent markers on same chromosome by sorted position
|
| 14 |
-
#
|
| 15 |
-
# 3. PVE FORMULA (unchanged, still correct):
|
| 16 |
-
# Full model: lm(phenotype ~ a + d) [additive + dominance]
|
| 17 |
-
# PVE (%) = R²_full × 100
|
| 18 |
-
# Additive_Effect = beta_a, Dominance_Effect = beta_d
|
| 19 |
-
# Reference: Falconer & Mackay (1996); Lynch & Walsh (1998)
|
| 20 |
-
# ============================================================
|
| 21 |
|
| 22 |
options(repos = c(CRAN = "https://cloud.r-project.org"))
|
| 23 |
|
|
@@ -63,22 +44,7 @@ model_choices <- setNames(
|
|
| 63 |
sapply(available_models, function(m) paste0(m$label, " [", m$tier, "]"))
|
| 64 |
)
|
| 65 |
|
| 66 |
-
|
| 67 |
-
# CIM CORE FUNCTION
|
| 68 |
-
# ============================================================
|
| 69 |
-
#
|
| 70 |
-
# Composite Interval Mapping (Zeng 1993, 1994):
|
| 71 |
-
# For each marker m:
|
| 72 |
-
# 1. Select cofactors = top K markers from RF (excluding nearby markers on same chr)
|
| 73 |
-
# 2. Fit: Y ~ marker_m + cofactors (additive model)
|
| 74 |
-
# 3. LOD = -log10( p-value of marker_m term )
|
| 75 |
-
# 4. PVE = R²_full × 100 (full model including cofactors)
|
| 76 |
-
#
|
| 77 |
-
# This gives HIGHER PVE because:
|
| 78 |
-
# - Cofactors absorb background genetic variance
|
| 79 |
-
# - Each marker's contribution is estimated after controlling for rest
|
| 80 |
-
# - Much more powerful than single-marker regression
|
| 81 |
-
# ============================================================
|
| 82 |
|
| 83 |
run_cim <- function(genotype_matrix, phenotype_vector, marker_info,
|
| 84 |
n_cofactors = 10, window_size = 10,
|
|
@@ -441,7 +407,7 @@ enhanced_rule_response <- function(user_message, rv) {
|
|
| 441 |
return(out)
|
| 442 |
}
|
| 443 |
|
| 444 |
-
paste0("👋
|
| 445 |
"Ask me about:\n• **PVE / CIM** — how variance is explained\n",
|
| 446 |
"• **Top QTLs** — flanking markers included\n• **Model performance**\n",
|
| 447 |
"• **What is CIM?** — Composite Interval Mapping explained\n\n",
|
|
|
|
| 1 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
options(repos = c(CRAN = "https://cloud.r-project.org"))
|
| 4 |
|
|
|
|
| 44 |
sapply(available_models, function(m) paste0(m$label, " [", m$tier, "]"))
|
| 45 |
)
|
| 46 |
|
| 47 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
run_cim <- function(genotype_matrix, phenotype_vector, marker_info,
|
| 50 |
n_cofactors = 10, window_size = 10,
|
|
|
|
| 407 |
return(out)
|
| 408 |
}
|
| 409 |
|
| 410 |
+
paste0("👋 Hello! TerraByte-AI here (CIM mode).\n\n",
|
| 411 |
"Ask me about:\n• **PVE / CIM** — how variance is explained\n",
|
| 412 |
"• **Top QTLs** — flanking markers included\n• **Model performance**\n",
|
| 413 |
"• **What is CIM?** — Composite Interval Mapping explained\n\n",
|