From 333965fa18fa2d837b9fda7935bb6bbc4c8ca9ce Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Thu, 19 Nov 2026 11:43:07 +0000 Subject: gemma/ravanan: the pangemma/lmdb workflow, one job per chromosome The pangemma twin of gemma-loco.scm: same two steps, same scatter, same outputs, and only the engine and the genotype store differ. It is a separate workflow rather than a flag because the store replaces two of the three genotype inputs -- pangemma reads the chromosome from the store's key and needs neither `-g` BIMBAM nor the `-a` annotation that tells GEMMA which markers are on which chromosome. The store is built once per panel by gemma-wrapper's bin/geno2mdb.py, as float32 for Gf or one byte for Gb. Gf is exact for a mean-genotype panel like BXD (0, 0.5, 1 all fit), and Gb is 4x smaller but exact only for integer calls (0/1/2 -> 0/127/254), so a BXD store in Gb moves the p-values in the third decimal. Measured on HLC (integer calls, 358454 markers): the same 23 chromosomes take 141 s of cluster job time here against 958 s for gemma on BIMBAM, with identical rows. Missing genotypes stay missing in the store (255 for Gb, NaN for Gf), and pangemma drops and mean-substitutes them per marker exactly as GEMMA does, so this path needs no imputation step -- the imputation exists because an older pangemma could not hold a gap in its GRM. Verified: Gf stores do carry the gaps, and the p-values are identical either way. The chromosome list is still derived from the panel's SNP map by the caller (src/gemma.rs), because CWL's scatter needs a concrete array; `-outdir .` keeps each job's outputs flat and unique by chromosome, as in gemma-loco.scm. manifest-mdb.scm resolves the steps' commands against pangemma-git, which installs the binary under that name so one profile can hold both engines. Not yet reachable through the API: wiring it behind /compute/gemma needs a per-panel store cache and an engine selector in the request. So far it has only been driven by hand, through ravanan on Slurm. --- cwl/gemma/gemma-loco-mdb.scm | 96 ++++++++++++++++++++++++++++++++++++++++++++ cwl/gemma/manifest-mdb.scm | 13 ++++++ 2 files changed, 109 insertions(+) create mode 100644 cwl/gemma/gemma-loco-mdb.scm create mode 100644 cwl/gemma/manifest-mdb.scm diff --git a/cwl/gemma/gemma-loco-mdb.scm b/cwl/gemma/gemma-loco-mdb.scm new file mode 100644 index 0000000..1d94075 --- /dev/null +++ b/cwl/gemma/gemma-loco-mdb.scm @@ -0,0 +1,96 @@ +;; GEMMA --loco mapping on PANGEMMA, from an lmdb genotype store, one +;; invocation PER CHROMOSOME, scattered by ravanan. The pangemma twin of +;; gemma-loco.scm: same two steps, same scatter, same outputs -- the engine and +;; the genotype store are what differ. +;; +;; Why a separate workflow rather than a flag: the store replaces two of the +;; three genotype inputs. GEMMA needs `-g` (BIMBAM) plus `-a` (the annotation +;; that says which markers are on which chromosome, which is how `-loco ` +;; knows what to leave out); pangemma reads the chromosome from the store's key +;; and needs neither. So this workflow takes a single `store` File. +;; +;; The store is built once per panel by gemma-wrapper's bin/geno2mdb.py +;; ("nameallele1allele0" in the marker records, genotypes as float32 +;; for Gf or one byte for Gb). Gf is exact for a mean-genotype panel like BXD +;; (0, 0.5, 1 all fit in a float32); Gb is 4x smaller and exact only for integer +;; calls (0/1/2 -> 0/127/254), so a BXD store in Gb moves the p-values in the +;; third decimal. Measured on HLC (integer calls, 358454 markers): the same 23 +;; chromosomes take 141 s of cluster job time through this workflow against +;; 958 s for gemma on BIMBAM, with identical rows. +;; +;; Missing genotypes stay missing in the store (255 for Gb, NaN for Gf) and +;; pangemma drops and mean-substitutes them per marker exactly as GEMMA does, +;; so no imputation step is needed here -- the reason genenetwork4 imputed at +;; all was an older pangemma that could not hold a gap in its GRM. +;; +;; The chromosome list is still derived from the panel's SNP map by the caller +;; (src/gemma.rs), because CWL's scatter needs a concrete array. +;; +;; `-outdir .` keeps each job's outputs flat and unique by chromosome, as in +;; gemma-loco.scm. + +(define kinship + ;; pangemma's own LOCO kinship (-gk) from the store: every chromosome but + ;; this one. The kinship depends on the genotypes and on WHICH individuals + ;; are analysed, never on the phenotype values, so it is given a + ;; constant-valued pheno with the trait's missing-data pattern and shared + ;; between traits over the same animals. + (command + #:inputs (chr #:type string) + (store #:type File) + (kinship_pheno_file #:type File) + #:run "pangemma" + ("-g" store) + ("-p" kinship_pheno_file) + "-gk" + ("-loco" chr) + ("-o" "$(inputs.chr)-kin") + ("-outdir" ".") + #:outputs (kinship_file #:type File + #:binding ((glob . "$(inputs.chr)-kin.cXX.txt"))) + (kinship_log #:type File + #:binding ((glob . "$(inputs.chr)-kin.log.txt"))))) + +(define gwa + ;; pangemma's LOCO GWA (-lmm) given that chromosome's kinship matrix. `-pve` + ;; asks for the null model's variance components: four log lines, nothing in + ;; the .assoc.txt, read back out of this job's log by src/gemma.rs. + (command + #:inputs (chr #:type string) + (kinship_file #:type File) + (store #:type File) + (pheno_file #:type File) + (lmm #:type string) + #:run "pangemma" + ("-g" store) + ("-p" pheno_file) + ("-k" kinship_file) + ("-lmm" lmm) + ("-loco" chr) + "-pve" + ("-o" "$(inputs.chr)-gwa") + ("-outdir" ".") + #:outputs (assoc #:type File + #:binding ((glob . "$(inputs.chr)-gwa.assoc.txt"))) + (gwa_log #:type File + #:binding ((glob . "$(inputs.chr)-gwa.log.txt"))))) + +(workflow ((store #:type File) + ;; The trait's own values, for the GWA step. + (pheno_file #:type File) + ;; The same individuals, constant values: the kinship step's input. + (kinship_pheno_file #:type File) + (lmm #:type string) + ;; The distinct chromosomes, computed by the caller from the panel's + ;; SNP map (the store's keys carry them, but a CWL scatter needs a + ;; concrete array at invocation time). + (chromosomes #:type (array string))) + (pipe + (scatter (kinship #:store store + #:kinship_pheno_file kinship_pheno_file) + #:chr chromosomes) + (scatter (gwa #:store store + #:pheno_file pheno_file + #:lmm lmm) + #:chr chromosomes + #:kinship_file kinship_file))) diff --git a/cwl/gemma/manifest-mdb.scm b/cwl/gemma/manifest-mdb.scm new file mode 100644 index 0000000..9382f3b --- /dev/null +++ b/cwl/gemma/manifest-mdb.scm @@ -0,0 +1,13 @@ +;; Guix manifest ravanan's --guix-manifest resolves gemma-loco-mdb.scm's jobs' +;; commands against -- the pangemma twin of manifest.scm. +;; +;; `pangemma`, not `gemma`: this workflow's steps invoke pangemma, whose +;; `-g .mdb` reads genotypes from an lmdb store instead of parsing +;; BIMBAM text. The package installs the binary under that name precisely so a +;; profile can hold both engines (see guix-bioinformatics' +;; gn/packages/gemma.scm), and `gemma-gn2` stays the engine of the other +;; workflows. +;; +;; ravanan keys a step on (script, inputs), so a manifest change must be +;; followed by a cold run. +(specifications->manifest (list "pangemma-git")) -- cgit 1.4.1