From 0c38de27014f9a7476f6784df30bd21f618b8b95 Mon Sep 17 00:00:00 2001 From: Paolo Di Tommaso Date: Wed, 28 Jan 2026 14:45:00 +0100 Subject: [PATCH] Add tools arguments ADR [ci skip] Introduces specification for typed tool arguments in module definitions: - Extend tools section in meta.yaml with args component - Argument attributes: type, enum, prefix, default, description - Script usage via tools implicit variable - Configuration and CLI override mechanisms - Migration guide from ext.args pattern Co-Authored-By: Claude Opus 4.5 Signed-off-by: Paolo Di Tommaso --- adr/20260128-tools-arguments.md | 357 ++++++++++++++++++++++++++++++++ 1 file changed, 357 insertions(+) create mode 100644 adr/20260128-tools-arguments.md diff --git a/adr/20260128-tools-arguments.md b/adr/20260128-tools-arguments.md new file mode 100644 index 0000000000..4e22cbfdef --- /dev/null +++ b/adr/20260128-tools-arguments.md @@ -0,0 +1,357 @@ +# Tools Arguments + +- Authors: Paolo Di Tommaso +- Status: draft +- Date: 2026-01-28 +- Tags: modules, tools, arguments, configuration + +## Context and Problem Statement + +The current adoption of `task.ext.args` for passing tool arguments in Nextflow modules is extremely convoluted. This pattern makes it impossible to have a consistent, programmatic definition for parameters exposed by a module. + +**Current approach (problematic):** +```groovy +process BWA_MEM { + script: + def args = task.ext.args ?: '' + """ + bwa mem $args -t $task.cpus $index $reads + """ +} +``` + +```groovy +// Configuration +withName: 'BWA_MEM' { + ext.args = '-K 100000000 -Y' +} +``` + +**Problems:** +- Arguments are opaque strings with no validation +- No documentation of available options +- No type safety or IDE support +- Easy to introduce typos or invalid combinations +- Impossible to programmatically introspect module capabilities + +## Decision + +Extend the `tools` definition in the module spec (`meta.yaml`) to support an `args` component that declares exposed tool command line arguments. + +**Key requirement:** The argument name must match the tool's actual option name. + +## Tool Arguments Specification + +### Definition in meta.yaml + +```yaml +tools: + - samtools: + description: SAMtools + homepage: http://www.htslib.org/ + args: + output_fmt: + type: string + enum: ["sam", "bam", "cram"] + description: "Output format" + + - bwa: + description: BWA aligner + homepage: http://bio-bwa.sourceforge.net/ + args: + K: + type: integer + description: "Process INT input bases in each batch" + prefix: '-' + Y: + type: boolean + description: "Use soft clipping for supplementary alignments" + prefix: '-' +``` + +### Argument Attributes + +| Attribute | Required | Default | Description | +|-----------|----------|---------|-------------| +| `type` | No | `string` | Data type: `boolean`, `integer`, `float`, `string` | +| `description` | No | - | Human-readable description | +| `enum` | No | - | List of allowed values | +| `prefix` | No | `'--'` | Command-line prefix for the argument | +| `default` | No | - | Default value if not configured | + +### Prefix Resolution + +The argument prefix determines how the argument is formatted on the command line: + +| Argument | Prefix | Value | Resolved | +|----------|--------|-------|----------| +| `output_fmt` | `--` (default) | `"cram"` | `--output_fmt cram` | +| `K` | `-` | `100000000` | `-K 100000000` | +| `Y` | `-` | `true` | `-Y` | + +**Boolean arguments:** When `type: boolean` and value is `true`, only the prefix+name is emitted (no value). + +## Script Usage + +In module scripts, access arguments via the `tools` implicit variable: + +```groovy +process BWA_MEM { + input: + tuple val(meta), path(reads) + path index + + output: + tuple val(meta), path("*.bam"), emit: aligned + + script: + // tools.bwa.args.K → "-K 100000000" + // tools.bwa.args.Y → "-Y" + // tools.bwa.args → "-K 100000000 -Y" (all args concatenated) + """ + bwa mem ${tools.bwa.args} -t $task.cpus $index $reads \ + | samtools sort ${tools.samtools.args} -o ${prefix}.bam - + """ +} +``` + +### Implicit Variable Reference + +| Expression | Description | Example Output | +|------------|-------------|----------------| +| `tools..args.` | Single formatted argument | `"-K 100000000"` | +| `tools..args` | All arguments concatenated | `"-K 100000000 -Y"` | + +## Configuration Usage + +Arguments are configured using `tools..args.`: + +```groovy +process { + withName: 'BWA_MEM' { + tools.bwa.args.K = 100000000 + tools.bwa.args.Y = true + tools.samtools.args.output_fmt = "cram" + } +} +``` + +## CLI Usage + +Arguments can be overridden via CLI: + +```bash +# For module run command +nextflow module run nf-core/bwa-align \ + --tools.bwa.K=100000000 \ + --tools.bwa.Y \ + --tools.samtools.output_fmt=cram + +# For standard workflow execution +nextflow run