diff options
| author | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-11-20 17:08:54 +0000 |
|---|---|---|
| committer | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-11-20 17:08:54 +0000 |
| commit | 64f1268be9a06462fe9685107c949dbbad84212d (patch) | |
| tree | 52f1fef50b8e85b4730c878cf343e756384152b5 /scripts | |
| parent | 87314c6dbde26343d577423942d967b5acc37db5 (diff) | |
| download | genenetwork4-64f1268be9a06462fe9685107c949dbbad84212d.tar.gz | |
gemma: the genotype treatment and the lmdb store become workflow jobs
Both used to run on the API host before ravanan was invoked, cached by two
hand-rolled file keys -- one of which (the treatment) carried a version
constant that had to be bumped whenever the script changed what it wrote, and
the other (the store) keyed on a genotype file's path, size and mtime. As
workflow jobs they are scheduled on the cluster and cached by ravanan on
(script, inputs) like every other step, and both caches go away.
They are *separate* workflows, not steps inside the mapping one, because
ccwl's `pipe` is strictly linear: a step sees only the immediately preceding
step's unconsumed outputs, and GWA needs the prepared genotypes *and* the
kinship matrix -- a diamond ccwl cannot express (verified with a three-step
probe; ravanan implements no CWL `when` either, so an optional step is not an
option). So:
cwl/gemma/prepare.scm mode + BIMBAM pair (+ cross, individuals) -> pair
cwl/gemma/store.scm BIMBAM pair -> pangemma's lmdb store
cwl/gemma/manifest-artifacts.scm bash, coreutils, gawk, r-minimal,
r-qtl2, python, python-numpy, python-lmdb
and the server chains them: prepare when `impute` is not `none`, store when
the engine is pangemma, then the mapping workflow with the resulting paths.
Ravanan sets the manifest profile's search paths inside the job, so python3
there finds numpy and lmdb without the PYTHONPATH the API host needs.
Measured warm on BXD.8 trait 10001 (gemma / pangemma, rows):
none 21055 3.9 s / 10.3 s mean 21056 10.5 s / 16.5 s
hmm 20453 10.2 s / 16.5 s
Against 26.8 s for hmm through the host-side path before this.
Three things had to be right that were not:
- A step input cannot be optional here, so `cross` and `individuals_file` are
always passed -- an empty directory and an empty file for the modes that
ignore them.
- `cross` is a *path*, not a CWL Directory: ravanan's slurm-api backend does
not stage a Directory input (the staged path reached the job and R's setwd
failed; the same workflow under single-machine succeeded), so the server
copies the cross under its cache directory, which the nodes can see.
- `scripts/prepare-genotypes.sh --out` is now absolutized before use, because
qtl2-impute-bimbam.R does setwd(cross_dir) and writes <prefix>.* from there:
a relative prefix put the outputs inside the cross directory and the job's
output globs matched nothing. It also grew --impute-script (a staged script
is not beside its companion) and always writes <out>.individuals.txt, since
the caller needs the HMM's individual order to align trait values.
Also: a request that asked for a treatment no longer falls back to the
in-process wrapper when the Slurm route fails. The wrapper reads genotypes as
they stand, so falling back on `impute: hmm` answered 21,055 rows where the
request meant 20,453 -- a wrong answer under a "degraded" note. Treated
requests (and pangemma ones) now fail instead.
And ravanan's output may be one File or an array of them: a scattered step
reports an array, a single-step workflow one File, which is what "no store
array in ravanan's output" was.
Deployed and verified on the production instance: all six engine x mode
combinations answer 200 with the expected row counts, and
bin/monitor-gn4 --tier all is 50 ok / 0 failed.
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/prepare-genotypes.sh | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/scripts/prepare-genotypes.sh b/scripts/prepare-genotypes.sh index f26e8c7..e6042a5 100755 --- a/scripts/prepare-genotypes.sh +++ b/scripts/prepare-genotypes.sh @@ -17,13 +17,22 @@ # scripts/prepare-genotypes.sh --mode mean|hmm|none \ # --geno <bimbam geno> --snps <snps file> --out <prefix> \ # [--cross <qtl2 cross dir>] [--probs <probs.rds|->] [--minprob N] \ -# [--individuals-file <names, one per line>] +# [--individuals-file <names, one per line>] \ +# [--impute-script <qtl2-impute-bimbam.R>] +# +# A workflow job stages this script and the R one as separate inputs, so +# --impute-script is how it says where the R script landed; by hand it +# defaults to the file beside this one. # # Writes <prefix>.bimbam.txt and <prefix>.snps.txt and prints the prefix. # Exits 2 on bad arguments, 1 when a step fails. set -eu mode= geno= snps= out= cross_dir= probs= minprob=0 individuals_file= +# The HMM script normally sits beside this one. A caller that stages this +# script somewhere else (a workflow job, where it is a copied input and the R +# script is a second one) names it explicitly. +impute_script= while [ $# -gt 0 ]; do case $1 in --mode) mode=$2; shift 2 ;; @@ -34,6 +43,7 @@ while [ $# -gt 0 ]; do --probs) probs=$2; shift 2 ;; --minprob) minprob=$2; shift 2 ;; --individuals-file) individuals_file=$2; shift 2 ;; + --impute-script) impute_script=$2; shift 2 ;; -h|--help) sed -n '2,26p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;; *) echo "prepare-genotypes.sh: unknown argument $1" >&2; exit 2 ;; esac @@ -41,6 +51,15 @@ done case $mode in none|mean|hmm) ;; *) echo "prepare-genotypes.sh: --mode must be none, mean or hmm" >&2; exit 2 ;; esac [ -n "$out" ] || { echo "prepare-genotypes.sh: --out is required" >&2; exit 2; } +# Absolute, before anything moves: the HMM script does setwd(cross_dir) and +# writes <prefix>.* from there, so a relative prefix would put the outputs in +# the cross directory instead of the caller's -- which in a workflow job is the +# difference between the step's output globs matching and not (measured: the +# job answered "Type File mismatch for globbed paths"). +case $out in +/*) ;; +*) out=$(pwd)/$out ;; +esac mkdir -p "$(dirname "$out")" case $mode in @@ -68,7 +87,8 @@ hmm) { echo "prepare-genotypes.sh: $RSCRIPT is not on PATH (R with qtl2)" >&2; exit 1; } # R's own complaint last, so a caller that reports the final stderr line # reports the cause rather than our wrapper sentence. - if ! r_output=$("$RSCRIPT" "$(dirname "$0")/qtl2-impute-bimbam.R" \ + [ -n "$impute_script" ] || impute_script="$(dirname "$0")/qtl2-impute-bimbam.R" + if ! r_output=$("$RSCRIPT" "$impute_script" \ "$cross_dir" "${probs:--}" "$out" "$minprob" "$individuals_file" 2>&1); then echo "prepare-genotypes.sh: HMM imputation failed:" >&2 printf '%s\n' "$r_output" | tail -6 >&2 @@ -77,4 +97,18 @@ hmm) ;; esac +case $mode in +hmm) + # The R script writes <prefix>.individuals.txt itself: the HMM calls come + # from the cross, whose individual order is its own, and the caller aligns + # the trait values to that order. + ;; +*) + # The other modes keep the panel's order, so the caller's list is the + # answer -- copied rather than re-derived, because a BIMBAM file does not + # carry individual names at all. + [ -n "$individuals_file" ] && cp "$individuals_file" "$out.individuals.txt" + ;; +esac + printf '%s\n' "$out" |
