Difference between workflow and module in Nextflow?
2
0
Entering edit mode
3.8 years ago

I was wondering if anyone with Nextflow experience could tell me the difference between a workflow and a module? After reading the documentation, I am still confused.

alignment • 1.5k views
ADD COMMENT
0
Entering edit mode

a module is a piece of workflow that can be imported/included in the main workflow.

include foo from './some/module'
ADD REPLY
3
Entering edit mode
18 months ago

A long time has passed since you asked this question and I think today is a good time to answer that. Mostly with the results of the latest nf-core Hackathon last week, I think a lot of progress has been made regarding modules, workflows, and subworkflows. Before explaining what each of these words mean, I think it's important to make sure some nextflow-lingo is clear.

In Nextflow, a process is the basic computing primitive to execute foreign functions, such as custom scripts or tools. The process definition starts with the keyword process, followed by the process name, and finally, the process body delimited by curly brackets. You've probably have run into a snippet like:

process FOO {
  input:
    val x
  output:
    stdout
  script:
  """
  echo $x
  """
}

A workflow, is a block of code just like the process but it describes how the whole pipeline will behave. What processes will be called, in what order, and so on. Something like:

workflow {
  FOO(Channel.of(1, 2, 3))
}

Ever since DSL2, you can have other workflow blocks in your Nextflow script, as long as at least one has no name (like the one above) and the others are named, such as:

workflow BIGGER {
  FOO(Channel.of(4, 5, 6))
}

This way, you can decide which workflow you want to invoke with nextflow run script.nf -entry BIGGER.

Modules are Nextflow script files only with processes. You include them in your main Nextflow script file, but write your own workflow block. It's like you'd like to use tool X, would have to write a process block for that but instead, you can simply import the Nextflow module for X that has already been created. One example is the tool bamtobed from bedtools that you can check here.

Subworkflows, on the other hand, make use of modules, just like you would when writing your pipelines, but then it comes with a workflow block. You can check an example of bam_qc_picard here.

Let's now try to combine all these concepts. You're writing your pipeline to do something and you realize that a few steps of your pipeline have already been written as a subworkflow, that includes modules of a few tools required for these few steps. What do you do? You include this subworkflow in your Nextflow script (that will as a consequence include the modules for the tools). Then you write your workflow block, or workflow blocks if you prefer, deciding on which to call later through the -entry option of the Nextflow command line interface.

More info can be found in the official documentation here.

ADD COMMENT
0
Entering edit mode
3.2 years ago

module can be a process or workflow. workflow can contain one or more process.

ADD COMMENT

Login before adding your answer.

Traffic: 1474 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6