Migrate to topic channels
Topic channels are a new feature in Nextflow that allow for more flexible and efficient handling of version outputs across modules and pipelines. Instead of collecting versions through YAML files, topic channels enable direct version tracking through structured channel outputs.
This migration guide provides step-by-step instructions for three different scenarios:
- Updating modules: For standard modules that generate version outputs in scripts
- Updating modules with templates: For modules that use template scripts to generate version information
- Updating pipelines: For pipelines that consume modules with topic channels
You will need the following to get started:
- nf-core tools version 3.5.0 or later
- A clone of the
nf-core/modulesrepository (for module updates) - Nextflow version 25.04.0 or later
Migrate modules
To migrate a module to use topic channels for version outputs:
-
Open the module
main.nffile. -
Identify the code that looks similar to the following:
main.nf cat <<-END_VERSIONS > versions.yml "${task.process}": <tool1>: \$(tool1 --version) <tool2>: \$(tool2 --version) END_VERSIONS -
Remove the
versions.ymlfile from theoutputblock. -
Add outputs for each tool in the module:
tuple val("${task.process}"), val('<tool1>'), eval('tool1 --version'), emit: versions_tool1, topic: versionsReplace
<tool1>andtool1 --versionwith the tool name and version command.- Repeat this for each tool used in the module.
-
Run
nf-core modules lint <module_name> --fixto migrate themeta.ymlfile with the new topic outputs. -
Add a
typeanddescriptionfor each field in the versions output:meta.yml versions_<tool>: - - ${task.process}: type: string description: The process the versions were collected from - <tool>: type: string description: The tool name - <versions_command>: type: string description: The version of the toolUpdate
<tool>and<versions_command>to the output channel values. -
Add the topics block to the
meta.ymlfile below the outputs section:meta.yml topics: - versions: - - process: type: string description: The process the versions were collected from - tool: type: string description: The tool name - version: type: string description: The version of the tool -
Update the
main.nf.testfile to check for the new version outputs.- If the test runs on all process output (
snapshot(process.out).match()), do nothing. - If the test checks for specific outputs, update it to check for the new version outputs.
process.out.versionsshould be changed toprocess.out.findAll { key, val -> key.startsWith('versions') }.
- If the test runs on all process output (
-
Run tests to regenerate the snapshots:
nf-core modules test <module_name> --update -
Check that the snapshot is correct and that all versions are being captured correctly.
- If not, return to step 3 and migrate any incorrect information in the module.
-
Commit and push changes to your fork.
-
Open a pull request to the main
nf-core/modulesrepository.
Migrate modules with template scripts
To migrate modules that use template scripts to use topic channels for version outputs:
-
Open the modules
main.nffile. -
Update the
path "versions.yml", emit: versionsline:main.nf path "versions.yml", emit: versions, topic: versions -
Add the following to the
meta.ymlfile below the outputs section:meta.yml versions: - versions.yml: type: file description: YAML file containing versions of tools used in the module -
Commit and push changes to your fork.
-
Open a pull request to the main
nf-core/modulesrepository.
Migrate pipelines
To migrate a pipelines to use topic channels for version outputs:
-
Update the pipeline template a version that includes support for topic channels (version 3.5.0 or later).
-
Run
nf-core modules updateto pull the latest changes. -
Find and remove instances in the pipeline code where
versionsis referenced as an invalid process output. These outputs are now handled by topic channels and should be removed.You may encounter errors like this:
ERROR ~ No such variable: Exception evaluating property 'versions' for nextflow.script.ChannelOut, Reason: groovy.lang.MissingPropertyException: No such property: versions for class: groovyx.gpars.dataflow.DataflowBroadcastExample: A workflow using the
samtools/sortmodule might have code like this:SAMTOOLS_SORT(input) ch_versions = ch_versions.mix(SAMTOOLS_SORT.out.versions)Fix: Remove the line referencing
SAMTOOLS_SORT.out.versions:SAMTOOLS_SORT(input) -ch_versions = ch_versions.mix(SAMTOOLS_SORT.out.versions)