about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-11-17 12:21:18 +0000
committerPjotr <wrk@bosa.lan>2026-11-17 12:21:18 +0000
commit9be4832dd827a3486848bd45960e51111e2e589d (patch)
tree2197ecd2fe1533203f85db5ad6b6112ca056a62f /src
parent5419674c1f6635f31095b95ff4c1d5ca0e4fbcdc (diff)
downloadgenenetwork4-9be4832dd827a3486848bd45960e51111e2e589d.tar.gz
qtl2: number the surviving alleles 1..n, because the HMM cannot use 3
A riself cross is converted with its heterozygous calls dropped, so the
CSV carries two genotypes -- but the control file still numbered them
A=1, H=2, B=3.  Allele code 3 does not exist in a two-state HMM: qtl2
read the second allele as unusable, P(BB) never rose above 0.5 at a
marker where 125 of 235 individuals are BB, every individual was called
AA, and the scan was left with nothing of the signal (2.0e-01 where the
same marker is 5.9e-07 from the BIMBAM, /compute/qtl2's own top hit
3.685 LOD elsewhere).

Numbering the genotypes the file actually carries, 1 and 2, gives
agreement with the calls 209 of 209.

The codes now follow the crosstype and the heterozygous policy, and
CONVERSION_VERSION is v5 so no cached cross is reused.  This is a
holding fix: the conversion belongs in an R script, where qtl2's
write_control_file owns this metadata.
Diffstat (limited to 'src')
-rw-r--r--src/qtl2.rs25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/qtl2.rs b/src/qtl2.rs
index 2bb11f7..44011de 100644
--- a/src/qtl2.rs
+++ b/src/qtl2.rs
@@ -214,7 +214,15 @@ pub fn prepare_cross(
     // reuse the previous cross's probabilities and kinship.
     // v3 keyed the heterozygous policy in as well: a cross converted with the
     // calls kept is a different cross from one with them dropped.
-    const CONVERSION_VERSION: &str = "v3";
+    // v4: the allele *codes*.  With H=2, B=3 in a cross where the
+    // heterozygous class is dropped, the surviving pair is 1/3 -- and qtl2's
+    // two-state riself HMM cannot use an allele code outside 1..2.  It treats
+    // that allele as unusable: measured, P(BB) never rose above 0.5, every
+    // individual was called AA at a marker where 125 of 235 are BB, and a scan
+    // built on those calls had nothing left of the signal (p 2.0e-01 where the
+    // same marker is 5.9e-07 from the BIMBAM).  Recoding to 1/2 fixed it
+    // completely: agreement with the calls 209 of 209.
+    const CONVERSION_VERSION: &str = "v5";
     let directory = cache_dir.join("crosses").join(format!(
         "{CONVERSION_VERSION}-{}-{}-{stamp}",
         het.as_str(),
@@ -363,7 +371,20 @@ pub fn prepare_cross(
             "pheno": "pheno.csv",
             "sep": ",",
             "na.strings": [""],
-            "genotypes": {"A": 1, "H": 2, "B": 3},
+                    // The codes must be 1..n over the genotypes the CSV actually
+            // carries.  A riself cross with the heterozygous class dropped
+            // (the default) carries only A and B, so they are 1 and 2: leaving
+            // B as 3 hands qtl2 an allele code outside 1..2, which its
+            // two-state HMM cannot use -- it then reads that allele as
+            // unusable, P(BB) never rises above 0.5, every individual is
+            // called AA, and a scan built on those calls loses the signal
+            // (measured: 2.0e-01 where the same marker is 5.9e-07 from the
+            // BIMBAM; recoded, agreement with the calls is 209 of 209).
+            "genotypes": if crosstype != "riself" || het == Het::Keep {
+                serde_json::json!({"A": 1, "H": 2, "B": 3})
+            } else {
+                serde_json::json!({"A": 1, "B": 2})
+            },
             // Our own CSVs are markers-in-rows, individuals-in-columns.
             "geno_transposed": true,
         });