about summary refs log tree commit diff
path: root/src/fitqtl.rs
AgeCommit message (Collapse)Author
14 dayscompute: fit covariates in /compute/fitqtl tooPjotr
`fitqtl` takes a `covar` argument, so the effect it reports can be the one *after* conditioning -- which is usually the number worth quoting for a peak that overlaps a known confounder. `covariates` now works on /compute/fitqtl exactly as on /compute/rqtl: the same `covariates::resolve` (case attribute by name, inline values, explicit map, same coding and same note), so the two endpoints report a covariate identically. The R side does what R/qtl needs: the phenotype file carries one column per covariate after the trait, `--covarstruct` says which are categorical, and the script dummy-expands those (k-1 against the first sorted level, missing values left missing). Two things it has to get right: * `model.matrix()` drops rows with a missing value, which silently misaligns the covariate frame against the cross -- so the dummies are built directly (`ifelse(is.na(x), NA, x == level)`), not through `model.matrix`; * a covariate can be perfectly spread across the panel and **constant among the individuals a trait covers** -- BXD's `Status` is exactly that -- and R/qtl then stops with `Lapack routine dgesv: system is exactly singular`. Columns that do not vary among the phenotyped individuals are left out, and the reply names them, the same rule the GEMMA covariate file applies. Measured on BXD trait 10001 at its peak, `BXD.4`: no covariate LOD 2.9310 additive +2.394 32.8% var with Status LOD 3.3602 additive +2.463 36.6% var with an inline numeric covariate LOD 2.9373 additive +2.361 The LOD is no longer the scan's once a covariate is fitted -- it is a different model -- which the docs now say, next to the no-covariate parity check that still holds. * scripts/qtl_fitqtl.R: `--covarstruct`, dummy expansion, the degenerate column rule, and the dropped names in the summary line. * src/fitqtl.rs: writes the covariates into the phenotype file and the struct file, and passes both. * src/routes/fitqtl.rs: the `covariates` field, resolved after alignment so the coding and the complete-case count match /compute/rqtl. * tests/fitqtl.rs: a covariate run (the note, the fitted row, a changed LOD) and an unknown attribute refused with the list of valid ones. * README.md, docs/www/SKILL.md: covariates on this endpoint, and why its LOD stops matching the scan's. 306 tests pass; the same four as before do not.
2026-11-09compute: add /compute/fitqtl for effect sizes at named markersPjotr
`/compute/rqtl` answers "where" -- scanone gives a LOD per marker -- but not "how much": a scan statistic is not a fitted model. R/qtl's `fitqtl` fits one, and reports the QTL's effect, its standard error, the model LOD and the variance explained. That is what a table of effects needs, and it is a separate endpoint because it is a separate question, asked about a handful of markers (a scan's peaks) rather than a genome: `fitqtl` fits one model per marker, so a genome-wide version would be thousands of fits. Cap: 100 markers per request. Rows are positional: marker, chr, pos, lod, pct_var, additive, se, t, p `additive` is fitqtl's estimate for the QTL term -- R/qtl codes the QTL genotype +-1, so it is half the difference between the two homozygote classes, the same convention GeneNetwork's published `additive` uses. **Two independent checks that the numbers are right.** On BXD trait 10001 (`BXD.4`), at the scan's peak: * `lod` = 2.930985, and `/compute/rqtl`'s scanone gives 2.930985 at the same marker -- identical to every digit the CSV carries, because they are the same cross and the same phenotype. That parity is now an integration test; * `additive` = 2.394472, against the value genenetwork.org publishes for that trait (`/api/v_pre1/trait/BXD/10001` -> 2.394444), which is 28 ppm away -- and that published number came from qtlreaper, a different engine. * scripts/qtl_fitqtl.R (new): reads the same `.geno` and two-column phenotype file as `rqtl_wrapper.R` (which is a verbatim copy of GN3's script and so not extended), builds the cross the same way, fits `fitqtl` at each named marker with `get.ests=TRUE`, and writes one CSV row per marker -- plus a one-line summary naming the strongest fit. `calc.genoprob(step=0)`: marker-level probabilities are all a marker-level fit needs. * src/fitqtl.rs (new): runs it, parses the CSV into positional rows (`chr` stays text, it can be `X`), keeps the command line for `notes`. * src/routes/fitqtl.rs (new): the endpoint -- same alignment rules as `/compute/rqtl` (by name onto the panel, parents/F1s excluded unless asked), the same `normalize`/`winsor_*` pipeline (effects come out on that scale), and the same R/qtl gate, so a fitqtl request and a scan queue against one another rather than competing for cores. * src/config.rs: `FITQTL_SCRIPT_PATH` (default `scripts/qtl_fitqtl.R`). * tests/fitqtl.rs: the fixture (columns, sign of the effect, notes), the LOD parity against scanone, and the refusals (no markers, both genotype inputs). * README.md, docs/www/SKILL.md: the endpoint, what each column means, and when to reach for it instead of the scan. 305 tests pass; the same four as before do not.