about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPjotr Prins <pjotr.public01@thebird.nl>2026-11-24 10:47:37 +0000
committerPjotr Prins <pjotr.public01@thebird.nl>2026-11-24 10:47:37 +0000
commit00202ef14e34ee97190516a010fd9633c4c7eb75 (patch)
tree3ebf1997d18d7636b8594fdbf1780bec59c8fd81 /src
parentf139fb3f1d1b9738aea403520e64fd121cd8ee62 (diff)
downloadgenenetwork4-00202ef14e34ee97190516a010fd9633c4c7eb75.tar.gz
gemma: named values on a file request align through the sibling .geno
`genotype_file` + `samples` (or a basket) against a **BIMBAM** file could not
work: a BIMBAM has no individual names, so `align_to_file` read it as if it were
a `.geno`, found no header, and dropped every value -- the request then failed
with "ravanan needs a genotype file and a SNP map ... and at least one trait
value", which named nothing that was actually wrong (measured on At-Serin:
R/qtl accepted the basket, GEMMA refused it).

The deployment keeps the two files under one stem
(`genotype/<stem>.geno`, `genotype/bimbam/<stem>_geno.txt`) and the BIMBAM is
generated from the `.geno`, so the sibling is the name source: a named request
for a bimabm file now aligns onto the `.geno` beside it and places the values in
the BIMBAM's column order.  The reply's note says which happened, so a caller
can tell an alignment from positional values.
Diffstat (limited to 'src')
-rw-r--r--src/routes/gemma.rs24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/routes/gemma.rs b/src/routes/gemma.rs
index 232e965..38f33a4 100644
--- a/src/routes/gemma.rs
+++ b/src/routes/gemma.rs
@@ -837,6 +837,9 @@ pub(crate) async fn resolve_inputs(
         })
         .unwrap_or_default();
     let supplied_values = request.trait_values.clone();
+    // Whether the caller named its values: `named` moves into the alignment
+    // closure below, and the note after it still has to say which it was.
+    let had_named_values = !named.is_empty();
 
     match (request.genotype_file.clone(), request.snps_file.clone(), group) {
         (Some(genotype_file), Some(snps_file), None) => {
@@ -856,7 +859,15 @@ pub(crate) async fn resolve_inputs(
             } else {
                 let path = std::path::PathBuf::from(&genotype_file);
                 let aligned = tokio::task::spawn_blocking(move || {
-                    genotypes::align_to_file(&path, &named)
+                    // A `.geno` names its individuals in the header; a BIMBAM
+                    // does not, so its names come from the `.geno` beside it
+                    // (see `names_for_bimbam`).  Without that, named values on
+                    // a file request aligned against nothing and every value
+                    // was dropped.
+                    match genotypes::names_for_bimbam(&path) {
+                        Some(names_source) => genotypes::align_to_columns_of(&names_source, &named),
+                        None => genotypes::align_to_file(&path, &named),
+                    }
                 })
                 .await
                 .map_err(|error| {
@@ -873,8 +884,15 @@ pub(crate) async fn resolve_inputs(
                 aligned
             };
             notes.push(format!(
-                "Genotype: given file and SNP map; {} values used.",
-                trait_values.iter().filter(|value| value.is_some()).count()
+                // Name the order the values ended up in, so a caller can check
+                // it without knowing the file by heart.
+                "Genotype: given file and SNP map; {} values used{}.",
+                trait_values.iter().filter(|value| value.is_some()).count(),
+                if had_named_values {
+                    ", aligned by name onto the genotype file's individuals"
+                } else {
+                    ""
+                }
             ));
             Ok(ResolvedInputs {
                 individuals: trait_values.len(),