about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-11-12 16:37:01 +0000
committerPjotr <wrk@bosa.lan>2026-11-12 16:37:01 +0000
commit84ad4d1e3f96ad45fdf3d72abfbcf516802e4532 (patch)
treefc922095aee5c443ecfa5510848334350fc9c7fa
parent7daeb84295f076fb38dcc80d226e85471719a873 (diff)
downloadgn-bnw-84ad4d1e3f96ad45fdf3d72abfbcf516802e4532.tar.gz
Plan: a headless driver here, a call-out in GN4, and the parameters measured
Two corrections from the owner, both structural, so the plan is rewritten
around them rather than patched.

The split: BNW's knowledge stays in this repository. Phase 1 becomes a headless
driver with a contract GN4 can code against -- `bnw learn --input matrix.tsv
--maxparents 4 --k 1 --tiers 3 --threshold 0.5 [--ban] [--white] [--format
json|tsv] [--svg] [--workdir] [--keep]`, stdout as one edge per line plus a
header naming the parameters and version, exit 2 for bad input and 3 for a
failed computation -- with a private work directory per invocation instead of
/var/lib/genenet/bnw, the parameters as arguments instead of <key>*.txt files,
and no PHP, web server or /var/www. Acceptance is unchanged: byte-identical
structure_input.txt and postProbEachEdge.txt against the web app's own answer.

GN4's side is then a call-out and nothing more: BNW_CMD in config, a matrix in
a temp file, one subprocess, edges parsed out. No knowledge of run.sh, of the C
programs or of the <key> layout enters GN4, so they can change without a GN4
release. The guix.scm dependency lands last, once the driver works --
gn-bioinformatics/gn/packages/bnw.scm already pins this repository.

The parameters are now measured rather than guessed. GN2 sends none:
send_to_bnw.py builds only the payload (traits' shared samples, comma-joined
rows, semicolon-terminated, My_Genenet) and the user picks parameters in BNW's
own settings page afterwards. BNW's defaults are in
sourcecodes/create_tiers_gom_part1.php, which writes parent.txt, k.txt and
thr.txt from a | -joined form value: maxparents 4 (with an "All" option capped
at variables-1), k 1 (no model averaging), tiers 3, edge-posterior threshold
0.5. A single-call endpoint has to expose all four, because the UI step that
would set them is gone.

Licence question settled by the owner: we own the code, so shipping the
binaries in GN4's profile needs no third-party permission. The repository still
has no LICENSE/COPYING and the C sources carry no header -- worth adding before
GN4 distributes it.
-rw-r--r--info_files/gn4-integration-plan.md109
1 files changed, 95 insertions, 14 deletions
diff --git a/info_files/gn4-integration-plan.md b/info_files/gn4-integration-plan.md
index b1feaa6f..b0276eb0 100644
--- a/info_files/gn4-integration-plan.md
+++ b/info_files/gn4-integration-plan.md
@@ -45,6 +45,26 @@ Verified in the code, worth stating because it shapes the embedding:
   compare files byte for byte. **Confirm before promising determinism** — if
   there is sampling, the test needs a seed or a tolerance.
 
+## Where the work goes: a headless CLI here, a call-out in GN4
+
+The split is deliberate, and it is the same one GN4 uses for every other
+engine it embeds (`gemma-wrapper`, the Julia BulkLMM driver, the R/qtl2 scan):
+
+* **this repository gains a headless driver** — one program that takes a matrix
+  and parameters, runs the three C programs in a private directory, and writes
+  machine-readable results. That is where BNW's knowledge stays: the file
+  layout, the flags, the three-stage pipeline, the C binaries.
+* **GN4 only calls out.** Its endpoint resolves inputs from the database or a
+  basket, writes them out, runs `$BNW_CMD`, parses what comes back, and reports
+  it. GN4 must not learn the internals of `run.sh`, and it must not gain a
+  second copy of the parameter semantics.
+* **the dependency lands in `guix.scm` last**, once the driver works and is
+  tested — `guix-bioinformatics/gn/packages/bnw.scm` already pins this
+  repository for the container tests, so the packaging path exists.
+
+The contract between the two is therefore the first thing to write down, and
+the rest of this plan is about making it true.
+
 ## What GN4 already has to build on
 
 The shape is the same three-step shape as the engines already embedded:
@@ -61,6 +81,32 @@ The shape is the same three-step shape as the engines already embedded:
 So the work is not a new architecture; it is one script, one module, one gate,
 one route, one plotter — each of which has a worked example in the tree.
 
+## Parameters: what BNW and GN2 actually use
+
+Measured, because "look at genenetwork2" turned out to answer only half of it.
+
+**GN2 sends no parameters at all.** `gn2/wqflask/external_tools/send_to_bnw.py`
+builds the payload only: the selected traits' shared samples, comma-joined
+rows, `;`-terminated — `My_Genenet` posted by `templates/bnw_page.html` to
+`https://bnw.genenetwork.org/sourcecodes/bn_genenet.php`. The parameters are
+chosen *after* that, by the user, in BNW's own settings page.
+
+**BNW's defaults are in `sourcecodes/create_tiers_gom_part1.php`**, which writes
+`<key>parent.txt`, `<key>k.txt` and `<key>thr.txt` from a `|`-joined form value
+(`parent|k|tiers|threshold|key`):
+
+| parameter | file | default | note |
+|---|---|---|---|
+| maxparents | `<key>parent.txt` | **4** | the form also offers `All`, capped at *variables − 1* |
+| k (k-best models averaged) | `<key>k.txt` | **1** | 1 means no model averaging |
+| tiers | `<key>` … `tier_number` | **3** | variable ordering tiers |
+| edge-posterior threshold | `<key>thr.txt` | **0.5** | passed to `structure` |
+
+So an endpoint that is a single call has to expose these four, because the UI
+step that would otherwise set them is gone. Defaults should be BNW's own, and
+the reply's `notes` should name the values used — a network learned at
+threshold 0.5 and one at 0.9 are different answers to the same question.
+
 ## The plan
 
 ### Phase 0 — a golden reference (half a day)
@@ -79,20 +125,46 @@ is the case the endpoint exists for.
 Decide here: **deterministic or not** (see the RNG note above), and the
 tolerance if not.
 
-### Phase 1 — a driver that does not need PHP (1–2 days)
+### Phase 1 — the driver this repository owns (2–3 days)
 
-`scripts/bnw_scan.sh` (or a small C/Rust driver) that takes:
+A headless program in **this** repository — `bin/bnw` (a shell wrapper around
+the existing binaries is enough for the first version) — with a contract GN4
+can code against without knowing anything else:
 
 ```
---input  matrix.tsv          variables × samples, header row, GN's own probe ids as names
---ban / --white              optional constraints
---maxparents N --k N --threshold X
---out DIR                    where structure_input.txt + postProbEachEdge.txt land
+bnw learn --input matrix.tsv \
+          --maxparents 4 --k 1 --tiers 3 --threshold 0.5 \
+          [--ban edges.tsv] [--white edges.tsv] \
+          [--format json|tsv] [--svg out.svg] \
+          [--workdir DIR] [--keep]
+
+  matrix.tsv   variables × samples: one header line, one row per sample;
+               column names are the variable names GN4 hands over
+  stdout       the result: one edge per line, {from, to, posterior},
+               plus a header object naming the parameters and the version
+  exit codes   0 ok · 2 bad input (the message names the problem)
+               3 computation failed (the message is the C program's own)
 ```
 
-and runs the three C programs in a private directory, then writes a single TSV
-or JSON: one row per edge, `from, to, posterior`, plus a header of what was run.
-No `/var/lib/genenet/bnw`, no temporary directory leaking, no PHP.
+Design points that matter more than the flags:
+
+* **a private work directory per invocation** (`--workdir`, default
+  `mktemp -d`), never `/var/lib/genenet/bnw`. Two concurrent networks must not
+  collide, and `--keep` exists so a failed run can be inspected.
+* **the parameters are arguments, not files**: `<key>parent.txt` and friends
+  were a consequence of the web app's session keys, not of the computation.
+* **machine-readable by default**; the SVG is a convenience (`--svg`) and GN4's
+  plot endpoint can equally render from the edges.
+* **`--version` and the parameters echoed in the header**, so a saved result
+  can be reproduced later.
+* the driver must also work from the container and from a checkout
+  (`var_lib_genenet_bnw/build.sh` builds `network_score` and `structure`; the
+  k-best binaries build with `k-best/src/buildk_poster.sh`), and it must not
+  need PHP, a web server or `/var/www`.
+
+Acceptance: byte-identical `structure_input.txt` and `postProbEachEdge.txt` to
+Phase 0's golden files, and one documented invocation that reproduces the web
+app's answer.
 
 Acceptance: byte-identical `structure_input.txt` and `postProbEachEdge.txt` to
 Phase 0's golden files.
@@ -113,10 +185,16 @@ cost grows with the number of nodes, not with the number of individuals.
 Cache by digest of (matrix, parameters) in `BNW_CACHE_DIR`, so the same
 network is not learned twice.
 
+GN4's side is a call-out and nothing more: `BNW_CMD` in config (default
+`bnw`), the matrix written to a temp file, one subprocess, parse the edges. No
+knowledge of `run.sh`, of the C programs, or of the `<key>` file layout enters
+GN4 — that all stays in this repository, where it can change without a GN4
+release.
+
 Return: the edge rows (`from, to, posterior`, sorted by posterior), the
-structure in a compact form, and notes stating the method's limits — an edge
-posterior is not a p-value, a high-posterior edge is not a QTL, and the network
-is a summary of the *sample's* correlation structure.
+structure in a compact form, the parameter values used, and notes stating the
+method's limits — an edge posterior is not a p-value, a high-posterior edge is
+not a QTL, and the network is a summary of the *sample's* correlation structure.
 
 `next` links: `/plot/bnw` with the posted rows, and `/compute/bnw/features`.
 
@@ -191,5 +269,8 @@ user can cite it.
 4. Where may the learned networks be cached — per user (a basket-style SQLite
    file) or shared by content digest? A network is derived state, so a content
    cache is defensible, but a user may consider their matrix private.
-5. Who owns the C binaries' licensing for redistribution inside GN4's profile?
-   They ship in this repository, but the endpoint makes GN4 a distributor.
+5. ~~Who owns the C binaries' licensing?~~ **Settled: we do.** The C sources
+   and the driver are ours, so shipping them in GN4's profile needs no
+   third-party permission. The repository still has no `LICENSE`/`COPYING`
+   file and the C sources carry no header — worth adding one before GN4
+   distributes them, so a downstream packager has something to point at.