about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--cwl/gemma/gemma-loco-mdb.scm96
-rw-r--r--cwl/gemma/manifest-mdb.scm13
2 files changed, 109 insertions, 0 deletions
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 <chr>`
+;; 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
+;; ("name<TAB>allele1<TAB>allele0" 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 <store>.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"))