1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
;; GEMMA --loco mapping (kinship, then GWA) with GEMMA ITSELF, one
;; invocation PER CHROMOSOME, scattered by ravanan
;; (https://github.com/vepiteski/ravanan). Backs POST
;; /compute/gemma/ravanan -- an alternative runner for the same
;; computation /compute/gemma's direct subprocess calls do, so the two
;; can be compared (correctness, timing).
;;
;; No gemma-wrapper. GEMMA 0.98.6 has `-loco [chr]` natively for both
;; -gk and -lmm (it requires -a, the BIMBAM annotation file, which every
;; genotype shape here can supply), so gemma-wrapper's LOCO
;; orchestration duplicates what the tool already does -- and its
;; parallel fan-out was never used here anyway: ravanan's CWL scatter
;; replaces it, one job per chromosome. What the wrapper did add was a
;; content-hash cache of K matrices (whose key does not vary with
;; --chromosomes, so it needs care to share) and a --json output
;; record with the results packed into .tar.xz archives. Neither is
;; load-bearing: the K file now flows from the kinship step to the GWA
;; step as a CWL File output, and `-o` names each artifact
;; deterministically instead of hashing it.
;;
;; The gemma binary comes from the manifest, so a manifest change must be
;; followed by a cold run: ravanan keys a step on (script, inputs) and will
;; happily reuse a script built when the manifest named something else.
;;
;; CACHING here is ravanan's own store (`--store`), which keys a step on
;; (script, inputs): a repeat request is answered from the store -- 9.4 s
;; cold against ~4 s warm on the BXD fixture. There is no gemma-wrapper
;; cache in this path at all, so a job script under /gnu/store that
;; mentions `gemma-wrapper` or `--cache-dir /tmp/gn4-gemma-ravanan` is a
;; leftover from the pre-0.98.6 era, not something to debug. (Identify a
;; script through ravanan's store or the job itself: /gnu/store entries
;; carry epoch mtimes, so `ls -t` there says nothing about age.)
;;
;; Written in ccwl (https://ccwl.systemreboot.net/), per Arun's
;; request, not raw CWL. ravanan itself only runs compiled CWL, so
;; src/gemma.rs's compute_ravanan compiles this file fresh on every
;; call (`ccwl compile --output=<generated path> gemma-loco.scm`,
;; cheap: pure macro expansion, no Guix build involved) into a
;; throwaway file under its cache dir -- the compiled .cwl is never
;; checked into the repo. To compile it by hand for inspection:
;; ccwl compile --output=gemma-loco.cwl gemma-loco.scm
;;
;; `-outdir .` puts the outputs beside the job's other files instead of
;; in GEMMA's default output/ subdirectory, so the globs below are
;; flat and each job's file names are unique by chromosome.
(define kinship
;; GEMMA's own LOCO kinship (-gk) step: the relatedness matrix for
;; this chromosome computed from every OTHER chromosome, which is
;; what `-loco <chr>` means (the "-a" annotation file is what tells
;; GEMMA which markers belong to which chromosome). Mirrors
;; kinship step of the direct /compute/gemma path.
(command
#:inputs (chr #:type string)
(genotype_file #:type File)
;; The kinship matrix depends on the genotypes and on WHICH individuals
;; are analysed, never on the phenotype values: GEMMA reads `-p' only to
;; know who has a value. So this step gets a constant-valued pheno file
;; with the same missing-data pattern as the trait, and two traits over
;; the same set of animals then share all twenty K matrices instead of
;; storing a fresh scatter each (which was 11 MB per trait).
(kinship_pheno_file #:type File)
(snps_file #:type File)
#:run "gemma"
("-g" genotype_file)
("-p" kinship_pheno_file)
("-a" snps_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
;; GEMMA's own LOCO GWA (-lmm) step, given the kinship step's matrix
;; for the same chromosome and restricted to that chromosome's
;; markers. `-pve` asks for the variance components in the null
;; model: four log lines, nothing in the .assoc.txt, and
;; compute_ravanan reads them back out of this job's own log.
(command
#:inputs (chr #:type string)
(kinship_file #:type File)
(genotype_file #:type File)
(pheno_file #:type File)
(snps_file #:type File)
(lmm #:type string)
#:run "gemma"
("-g" genotype_file)
("-p" pheno_file)
("-a" snps_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 ((genotype_file #: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,
;; so that K is keyed by the animal set and not by the trait.
(kinship_pheno_file #:type File)
(snps_file #:type File)
(lmm #:type string)
;; The distinct chromosomes in snps_file, computed by
;; src/gemma.rs's compute_ravanan (GEMMA's annotation file is
;; the source of truth for which markers are on which
;; chromosome) -- CWL's scatter needs a concrete array at
;; invocation time, so this can't be discovered by a step
;; inside the workflow itself without another round of
;; plumbing.
(chromosomes #:type (array string)))
;; Scatter kinship over chromosomes; each job's kinship_file output is
;; itself a per-chromosome array, so it scatters into the gwa step
;; alongside chr rather than being passed as a whole array. The
;; workflow's outputs are gwa's: assoc (one per chromosome) and
;; gwa_log (where -pve's variance components are), plus each
;; chromosome's kinship log for the record.
(pipe
(scatter (kinship #:genotype_file genotype_file
#:kinship_pheno_file kinship_pheno_file
#:snps_file snps_file)
#:chr chromosomes)
(scatter (gwa #:genotype_file genotype_file
#:pheno_file pheno_file
#:snps_file snps_file
#:lmm lmm)
#:chr chromosomes
#:kinship_file kinship_file)))
|