agentleFS
nextflow-ionextflow-io/agent-skills/skills/migrate-nextflow-code/SKILL.md

migrate-nextflow-code

Skill25 starsChanged 48 days agoApache-2.0Archived repositoryView on GitHub

Migrate a Nextflow pipeline to new language patterns.

The file

Show its rules and text

We split this skill into the rules it gives an agent

19 rules. About 0 are common, 4 are distinctive, and 15 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 15

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Update a pipeline to comply with nextflow lint.

    line 25
  2. Very specific:

    Run the linter over the entire project: nextflow lint -o concise .

    line 27
  3. Very specific:

    Delete the ch_versions plumbing.

    line 41
  4. Distinctive:

    Use destructured record inputs/outputs in processes.

    line 72
  5. Very specific:

    Check carefully whether a process path input/output should be a single file (Path) or a file collection (List<Path>, Set<Path>, etc).

    line 73
  6. Distinctive:

    Every process should output a single wide record.

    line 74
  7. Distinctive:

    Use record types to describe channel inputs/outputs for workflows.

    line 75
  8. Very specific:

    If the pipeline uses the nf-schema plugin, update it to version 2.7.2 or later to avoid runtime issues with static typing.

    line 76
  9. Very specific:

    Use type coercion (x as Type) only when the type is genuinely unknown, such as channel.topic().

    line 79
  10. Very specific:

    Add a top-level output block with a declaration and path directive for each published channel.

    line 96
  11. Very specific:

    Delete the publishDir directives.

    line 98
  12. Very specific:

    Prefer one combined per-sample output over many per-tool outputs.

    line 102
  13. Very specific:

    If the pipeline hasn't been migrated to static typing, or doesn't have the params and output blocks, stop and warn the user about this.

    line 117
  14. Very specific:

    Check for global params usage.

    line 121
  15. Very specific:

    Check for project-level assets (projectDir, bin, lib).

    line 123
  16. Very specific:

    Check for process configuration (conf/modules, ext.args, withName).

    line 125
  17. Very specific:

    Use helper functions to separate complex ext settings from workflow logic.

    line 132
  18. Distinctive:

    After each migration, verify behavior against baseline using the project's test suite.

    line 141
  19. Very specific:

    Run before/after with test profile: nextflow run .

    line 143

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Migrate Nextflow Code

Migrate a Nextflow pipeline to new language patterns. Follow best practices from the Nextflow docs. Use nextflow lint to validate code as you go. Verify that the pipeline produces the same results before/after migration.

Requirements

Requires Nextflow 26.10 or later for the nextflow lint command with type checking.

Requires nf-core template 3.0.0 or later, if applicable. If the pipeline has a .nf-core.yml, check which version of nf-core/tools last generated its template. If nf_core_version is unspecified or less than 3.0.0, stop and tell the user to upgrade their template first. This will resolve syntax errors in the template code and provide a cleaner baseline.

Migrations

Apply each migration requested by the user, one at a time, in the following order. Each migration requires the ones before it.

Each migration links the relevant docs. Consult these docs when you aren't sure how to do something. For example, which type to use, which method to use for a given type, or how to use a specific channel operator. Don't just guess or try to work from past knowledge. The linter can guide you, but the docs provide examples and best practices.

Strict syntax

Update a pipeline to comply with nextflow lint. Pipelines written before the introduction of the strict syntax parser may contain patterns that are no longer valid.

  1. Run the linter over the entire project: nextflow lint -o concise .
  2. Fix each issue without changing behavior. Keep changes minimal.
  3. Re-run the linter as needed and iterate until there are no errors.

Reference:

Topic channels

Replace the ch_versions plumbing in a pipeline with a versions topic channel.

  1. Send process version outputs to the versions topic. Replace emit: versions with topic: versions. Replace the YAML versions file with a tuple of process name, tool name, and eval command.
  2. Consume the versions topic with channel.topic('versions') when writing the versions file. Group elements by process.
  3. Delete the ch_versions plumbing.
// before
output:
path "versions.yml", emit: versions

// after
output:
tuple val("${task.process}"), val('bash'), eval('bash --version'), topic: versions

// after (typed)
topic:
tuple(task.process, 'bash', eval('bash --version')) >> 'versions'

Any process downstream of the topic channel must not emit to that topic, or else the pipeline deadlocks.

Reference:

Static typing

Migrate a pipeline to use typed processes, typed workflows, typed parameters, and records. Migrate components from the bottom up. Use nextflow lint to type-check as you go.

  1. Migrate processes to typed processes
  2. Migrate workflows to typed workflows
  3. Migrate the pipeline parameters to typed parameters
  4. Re-run the linter as needed until there are no errors.

Rules:

  • Use destructured record inputs/outputs in processes.
  • Check carefully whether a process path input/output should be a single file (Path) or a file collection (List<Path>, Set<Path>, etc).
  • Every process should output a single wide record. Every workflow should join related outputs into a wide record channel. This makes it easier to migrate to workflow outputs.
  • Use record types to describe channel inputs/outputs for workflows. Define record types with their workflow, not a shared types module.
  • If the pipeline uses the nf-schema plugin, update it to version 2.7.2 or later to avoid runtime issues with static typing.
  • Params used by the script must be declared in the script. Params that only affect config settings should be declared in the config file. Config can override script param defaults, but ideally in a profile (e.g. test).
  • The global params record should only be used in the entry workflow. Pass params to processes and workflows as explicit inputs. Bundle related params into a single workflow input with a record type (e.g. workflow ALIGNER -> record AlignerParams) so that you can pass params directly from the entry workflow.
  • Use type coercion (x as Type) only when the type is genuinely unknown, such as channel.topic().

Reference:

Workflow outputs

Migrate a pipeline to use workflow outputs. Replace all publishDir directives with a top-level output block that produces the same output directory tree.

If the pipeline hasn't been migrated to static typing and records, stop and warn the user about this. The output block requires process outputs to be propagated to the entry workflow, which leads to an excessive number of workflow emits if the pipeline still uses narrow tuples (e.g. (meta, file)). Combining narrow tuple channels into wide record channels makes it feasible to publish channels through the output block.

  1. Identify all publishDir directives in processes and config files.
  2. For each publisher, determine: which process(es) are targeted, which files are published, and where they are published.
  3. For each published output, propagate the corresponding process outputs to the entry workflow (via emit:) and publish them (via publish:).
  4. Add a top-level output block with a declaration and path directive for each published channel.
  5. Define global publishing behavior in config (outputDir, workflow.output.mode, etc). Override publish settings in the output block as needed.
  6. Delete the publishDir directives.

Rules:

  • Consult the docs to learn the publishDir options, output path directive, and workflow.output options. Figure out how to map the former to the latter.
  • Prefer one combined per-sample output over many per-tool outputs. Create an index file only if the pipeline already does it (see collectFile below).
  • You don't need to manually extract or flatten files when publishing a channel. Nextflow automatically extracts files from published values (lists, maps, records, tuples).
  • The collectFile operator with storeDir: is another way to publish a file. Remove storeDir: and publish it to the output block instead. You might even be able to replace it with an output index directive, e.g. if it is a samplesheet of the per-sample outputs.
  • Some pipelines have a catch-all publishDir in the main config. This can likely be deleted.

Reference:

Pipeline composition

Make a pipeline composable, so that it can be executed directly or included by another pipeline.

If the pipeline hasn't been migrated to static typing, or doesn't have the params and output blocks, stop and warn the user about this. Pipeline composition depends heavily on these language features.

  1. Review the params block. Determine which params can be refactored as dataflow types. A samplesheet input can be refactored as a channel of records (Channel<Sample>). An index file input can be wrapped as a dataflow value (Value<Path>). Unless the user says otherwise, refactor samplesheet inputs and leave the rest.
  2. Check for global params usage. The pipeline should not use global params outside the entry workflow and output block. It should already be publishing all outputs through the output block instead of publishDir directives.
  3. Check for project-level assets (projectDir, bin, lib). The pipeline should avoid these in favor of composable alternatives (params, module resources/ and moduleDir, helper functions).
  4. Check for process configuration (conf/modules, ext.args, withName). Refactor it by moving it into pipeline code (see below).

The biggest issue you will likely encounter is ext config. nf-core modules use ext for certain inputs such as tool args and filename prefix/suffix. Users can then override these settings easily from config. A pipeline may specify its own defaults in config with process selectors. This makes the pipeline harder to compose.

The solution is to refactor the pipeline's ext config as pipeline code:

  • Modules take args / prefix / suffix as explicit inputs and resolve them as task.ext.<name> ?: <input> ?: <default>. Users can still override any tool at runtime with config.
  • Each ext setting moves into pipeline code. Add the setting to each sample record with map or combine depending on whether it varies per-sample.
  • Use helper functions to separate complex ext settings from workflow logic. Build an options map first, then render it to a CLI string with a separate cli() helper.

Reference:

Validation

After each migration, verify behavior against baseline using the project's test suite. For example:

  • Run before/after with test profile: nextflow run . -profile test,docker
  • nf-test: nf-test test
  • Stub run: nextflow run . -stub

Critical Rules

  1. One migration at a time. Finish one migration before starting another one.
  2. Read the docs. Consult the linked docs when you aren't sure how to do something.
  3. Preserve behavior. The pipeline should produce the same outputs before/after the migration.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.