about summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-11-16 00:30:42 +0000
committerPjotr <wrk@bosa.lan>2026-11-16 00:30:42 +0000
commit1ae2f5d712e18c016fdb7bd04da99eab4da6915b (patch)
tree31bb20e52585506351d81198b65c13ec3a229af0 /bin
parent9c3cd6f2300bb290ddd05c5a46c5b813b22c0ce1 (diff)
downloadgenenetwork4-1ae2f5d712e18c016fdb7bd04da99eab4da6915b.tar.gz
qtl2: permutations for the LOD thresholds
POST /compute/qtl2 gains nperm, perm_seed and perm_strata, and the reply
gains meta.permutation {n, seed, significant, suggestive, values} -- the
genome-wide maximum of every permutation, so a histogram needs no second
call. `data` stays the positional rows array on purpose: /plot/rqtl posts
it straight back and the monitor counts its rows, so the null went beside
the rows rather than around them (a generic Envelope::with_meta/Meta::extra,
skip_serializing_if, so no other endpoint's response changes).

Thresholds come from R/qtl2's scan1perm over the same genotype
probabilities, kinship and covariates as the scan, with chr_lengths from
the map -- without those it derives chromosome lengths from marker
positions and the numbers stop being comparable with R/qtl's. The
permutation CSV is written in R/qtl's two-column shape so one parser and
one percentile routine serve both engines: PermutationResult::from_values
is now shared with /compute/rqtl instead of duplicated.

Semantics, each with the note that says it:

* scan1perm shuffles phenotypes across individuals -- right for an
  outbred cross, only approximate for a selfing RIL panel, where qtl2perm
  is the correct package (not installed here, and not packaged);
* perm_strata takes a case attribute name (sex, Epoch, ...) and permutes
  within it, because shuffling across sexes inflates the null;
* fewer than 100 permutations gets a note that the 0.05 quantile is a
  quantile of too few values; more than 10 000 is refused, since each
  permutation is a whole genome scan;
* a seed is reported always -- without one, two identical requests would
  give different thresholds.

Cost, measured on BXD trait 10001 (34 phenotyped, 20 chromosomes, LOCO
kinship, 4 cores): 20 permutations 0.6 s, 100 in 2.2 s, 500 in 14 s,
1000 in 24 s through the API; 0.022-0.03 s per permutation. Thresholds
converge as expected (0.05: 4.331 at 100 and 200 permutations, 4.374 at
1000 on the raw probe) and are reproducible: the same seed gives the same
numbers on 1 and 4 cores.

Four things that only surfaced by running it, all commented where they
bit: optparse keeps the dash (--perm-out is opt[["perm-out"]], so
opt$perm_out was always NULL and the file landed somewhere the caller did
not look); perm_strata must be a named character vector, not a factor;
the LOD in the CSV is the LAST numeric field (R/qtl's shape puts the
permutation index first, and a first-field parser reads that as the LOD);
and percentiles interpolate at (n-1)p/100, so 100 maxima give 0.6733, not
0.67.

bin/monitor-gn4 gains compute-qtl2-perm (nperm 10, judging
meta.permutation) so a deploy that loses the R path shows up as a red
check rather than a surprise.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/monitor-gn419
1 files changed, 19 insertions, 0 deletions
diff --git a/bin/monitor-gn4 b/bin/monitor-gn4
index e92c0b4..ff76bc3 100755
--- a/bin/monitor-gn4
+++ b/bin/monitor-gn4
@@ -295,6 +295,16 @@ def has_rows(reply):
     return FAIL, "answered, but no rows"
 
 
+def has_permutation(reply):
+    """A qtl2 reply carrying the permutation null: n, thresholds, and values."""
+    data = reply.json or {}
+    permutation = ((data.get("meta") or {}).get("permutation") or {})
+    if permutation.get("n") and permutation.get("significant") is not None:
+        return OK, "%d permutations, sig LOD %.2f" % (
+            permutation["n"], permutation["significant"])
+    return FAIL, "no meta.permutation in the reply"
+
+
 def collection_ok(reply):
     """An empty list is the right answer for a user with no baskets yet."""
     data = reply.json
@@ -658,6 +668,15 @@ def build_checks(found, tiers):
                       "R + r-qtl2 + QTL2_SCRIPT_PATH",
                       body={"group": g, "samples": samples}, judge=has_rows,
                       caches=True, hint="r-qtl2 and scripts/qtl2_scan.R"))
+            # Permutations are the one qtl2 option whose failure is not a
+            # missing binary but a broken R path, so they get their own check.
+            # Ten keeps it cheap; the reply must carry meta.permutation.
+            add(Check("compute-qtl2-perm", "compute", "POST", "/compute/qtl2",
+                      "R + qtl2 + scan1perm (meta.permutation)",
+                      body={"group": g, "trait_name": found.trait,
+                            "samples": samples, "nperm": 10, "perm_seed": 1},
+                      judge=has_permutation,
+                      hint="scan1perm threshold code, or --nperm support"))
             add(Check("compute-fitqtl", "compute", "POST", "/compute/fitqtl",
                       "R + r-qtl", body={"group": g, "method": "hk",
                                          "markers": [found.marker] if found.marker else [],