about summary refs log tree commit diff
path: root/src/gemma.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/gemma.rs')
-rw-r--r--src/gemma.rs56
1 files changed, 41 insertions, 15 deletions
diff --git a/src/gemma.rs b/src/gemma.rs
index 860ef9e..51e3fce 100644
--- a/src/gemma.rs
+++ b/src/gemma.rs
@@ -462,7 +462,7 @@ pub async fn compute(
 /// Read a scattered `File[]` output's list of `path`s from ravanan's
 /// stdout (the CWL outputs record for a scattered output:
 /// `{"<output id>": [{"class": "File", "path": ..., ...}, ...], ...}`,
-/// one entry per `cwl/gemma/gemma-loco.cwl` chromosome).
+/// one entry per `cwl/gemma/gemma-loco.scm` chromosome).
 fn ravanan_output_paths<'a>(outputs: &'a Value, id: &str) -> Result<Vec<&'a str>, GemmaError> {
     let files = outputs
         .get(id)
@@ -484,7 +484,7 @@ fn ravanan_output_paths<'a>(outputs: &'a Value, id: &str) -> Result<Vec<&'a str>
 /// `compute_ravanan`'s `chromosomes` scatter input (CWL's `scatter`
 /// needs a concrete array at invocation time, which can't be
 /// discovered by a step inside the workflow itself without another
-/// round of plumbing -- see `cwl/gemma/gemma-loco.cwl`'s own doc
+/// round of plumbing -- see `cwl/gemma/gemma-loco.scm`'s own doc
 /// comment on this input).
 fn chromosomes_in(snps_file: &str) -> Result<Vec<String>, GemmaError> {
     let contents = std::fs::read_to_string(snps_file).map_err(GemmaError::Io)?;
@@ -502,7 +502,8 @@ fn chromosomes_in(snps_file: &str) -> Result<Vec<String>, GemmaError> {
 
 /// The same GEMMA `--loco` kinship-then-GWA computation as `compute`,
 /// but run via `ravanan` (https://github.com/vepiteski/ravanan) driving
-/// the CWL workflow at `workflow_path` (see `cwl/gemma/gemma-loco.cwl`)
+/// a CWL workflow compiled from the ccwl (https://ccwl.systemreboot.net/)
+/// source at `workflow_scm_path` (see `cwl/gemma/gemma-loco.scm`)
 /// instead of this module's own direct subprocess calls: one
 /// gemma-wrapper invocation per chromosome, scattered by ravanan
 /// itself (`--chromosomes`/`--no-parallel`, see
@@ -512,7 +513,8 @@ fn chromosomes_in(snps_file: &str) -> Result<Vec<String>, GemmaError> {
 /// Backs `POST /compute/gemma/ravanan`.
 pub async fn compute_ravanan(
     ravanan_cmd: &str,
-    workflow_path: &str,
+    ccwl_cmd: &str,
+    workflow_scm_path: &str,
     manifest_path: &str,
     cache_dir: &str,
     genotype_file: &str,
@@ -528,6 +530,26 @@ pub async fn compute_ravanan(
 
     let log_path = streaming::create_run_log(cache_dir, run_id)?;
 
+    // gemma-loco.scm is the maintained source; the CWL ravanan actually
+    // runs is a generated, throwaway artifact compiled fresh on every
+    // call (cheap: ccwl compile is pure macro expansion, no Guix build
+    // involved) and never checked into the repo -- see the doc comment
+    // on Config::gemma_ravanan_workflow.
+    let compiled_workflow_path =
+        Path::new(cache_dir).join(format!("{unique}-gemma-loco.cwl"));
+    let ccwl_output_arg = format!("--output={}", compiled_workflow_path.display());
+    let ccwl_args = vec!["compile", ccwl_output_arg.as_str(), workflow_scm_path];
+    let ccwl_output = streaming::run_streaming(ccwl_cmd, &ccwl_args, None, &[])
+        .await
+        .map_err(GemmaError::Io)?;
+    if !ccwl_output.status.success() {
+        return Err(GemmaError::CommandFailed {
+            step: "ccwl compile",
+            stderr: String::from_utf8_lossy(&ccwl_output.stderr).into_owned(),
+        });
+    }
+    let compiled_workflow_arg = compiled_workflow_path.to_string_lossy().into_owned();
+
     let store_dir = Path::new(cache_dir).join("ravanan-store");
     // ravanan's --store needs these three subdirectories to already
     // exist; it does not create them itself.
@@ -584,19 +606,19 @@ pub async fn compute_ravanan(
     let store_arg = format!("--store={}", store_dir.display());
     let manifest_arg = format!("--guix-manifest={manifest_path}");
     let inputs_yaml_arg = inputs_yaml_path.to_string_lossy().into_owned();
-    // No --output-directory: gwa.cwl's per-chromosome archive outputs
-    // all share gemma-wrapper's own content-hash basename (its hash
-    // doesn't vary with --chromosomes), and ravanan's --output-directory
-    // step symlinks every scattered output into one flat directory by
-    // basename, which collides across chromosomes -- a ravanan/
-    // gemma-wrapper interaction bug, not something fixable on either
-    // side alone. Harmless to skip: it's optional, and this code reads
-    // paths straight out of ravanan's own --store via its stdout
-    // output record, never through --output-directory.
+    // No --output-directory: the gwa step's per-chromosome archive
+    // outputs all share gemma-wrapper's own content-hash basename (its
+    // hash doesn't vary with --chromosomes), and ravanan's
+    // --output-directory step symlinks every scattered output into one
+    // flat directory by basename, which collides across chromosomes --
+    // a ravanan/gemma-wrapper interaction bug, not something fixable
+    // on either side alone. Harmless to skip: it's optional, and this
+    // code reads paths straight out of ravanan's own --store via its
+    // stdout output record, never through --output-directory.
     let args = vec![
         store_arg.as_str(),
         manifest_arg.as_str(),
-        workflow_path,
+        compiled_workflow_arg.as_str(),
         inputs_yaml_arg.as_str(),
     ];
     let ravanan_note = format!("ravanan: {ravanan_cmd} {}", args.join(" "));
@@ -677,7 +699,11 @@ pub async fn compute_ravanan(
     Ok(GemmaOutput {
         columns,
         rows: Value::Array(rows),
-        notes: vec![ravanan_note, chromosomes_note, format!("workflow: {workflow_path}")],
+        notes: vec![
+            ravanan_note,
+            chromosomes_note,
+            format!("workflow: {workflow_scm_path} (compiled to {compiled_workflow_arg})"),
+        ],
     })
 }