.. _nextflow_4-page: ******************* 4 Nextflow ******************* Modules and how to re-use the code ================================== A great advantage of the Nextflow is to allow the **modularization of the code**. In particular, you can move a named workflow within a module and keep it aside for being accessed by different pipelines. The **test4** folder provides an example of using modules. .. literalinclude:: ../nextflow/test4/test4.nf :language: groovy We now include two modules, named **fastqc** and **multiqc**, from ```${projectDir}/modules/fastqc.nf``` and ```${projectDir}/modules/multiqc.nf```. Let's inspect the **multiQC** module: .. literalinclude:: ../nextflow/test4/modules/multiqc.nf :language: groovy The module **multiqc** takes as **input** a channel with files containing reads and produces as **output** the files generated by the multiqc program. The module contains the directive **publishDir**, the tag, and the container to be used and has a similar input, output, and script session as the fastqc process in **test3.nf**. A module can have hardcoded information such as the label and the container, but you can also specify some of them via `nextflow.config`. In this example, we have the hardcoded labels, output director, and label: .. literalinclude:: ../nextflow/test4/modules/fastqc.nf :language: groovy :emphasize-lines: 8-10 In the multiqc module, we don't specify the container. We indicate it via `nextflow.config` file using the **withName** selector. .. literalinclude:: ../nextflow/nextflow.config :language: groovy :emphasize-lines: 19-21,40-43,63-66 Here you see that we are not using our own image, but rather we use the image provided by **biocontainers** in `quay <://quay.io/>`__. .. note:: IMPORTANT: You have to specify a default image to run nextflow -with-docker or -with-singularity and you have to have a container(s) defined inside modules. Reporting and graphical interface =================================== Nextflow has an embedded function for reporting information about the resources requested for each job and the timing; to generate a html report, run Nextflow with the `-with-report` parameter : .. code-block:: console nextflow run test5.nf -with-docker -bg -with-report > log .. image:: images/report.png :width: 800 **Nextflow Seqera Platform (formerly known as Tower)** is an open-source monitoring and management platform for Nextflow workflows. There are two versions: - Open source for monitoring of single pipelines. - Commercial one for workflow management, monitoring, and resource optimization. We will show the open-source one. First, you need to access the `Seqera platform <://cloud.seqera.io/>`__ website and login. .. image:: images/tower.png :width: 800 We recommend using either Google or GitHub for login. .. image:: images/tower0.png :width: 800 Once you are signed in you will see a page like this: .. image:: images/tower2.png :width: 800 You can generate your token at `://cloud.seqera.io/tokens <://cloud.seqera.io/tokens>`__ and copy-paste it into your pipeline using this snippet in the configuration file: .. code-block:: groovy tower { accessToken = '' enabled = true } or exporting those environmental variables: .. code-block:: groovy export TOWER_ACCESS_TOKEN=*******YOUR***TOKEN*****HERE******* Now we can launch the pipeline: .. code-block:: console nextflow run test5.nf -with-singularity -with-tower -params-file params.yaml -bg > log CAPSULE: Downloading dependency io.nextflow:nf-tower:jar:20.09.1-edge CAPSULE: Downloading dependency org.codehaus.groovy:groovy-nio:jar:3.0.5 CAPSULE: Downloading dependency io.nextflow:nextflow:jar:20.09.1-edge CAPSULE: Downloading dependency io.nextflow:nf-httpfs:jar:20.09.1-edge CAPSULE: Downloading dependency org.codehaus.groovy:groovy-json:jar:3.0.5 CAPSULE: Downloading dependency org.codehaus.groovy:groovy:jar:3.0.5 CAPSULE: Downloading dependency io.nextflow:nf-amazon:jar:20.09.1-edge CAPSULE: Downloading dependency org.codehaus.groovy:groovy-templates:jar:3.0.5 CAPSULE: Downloading dependency org.codehaus.groovy:groovy-xml:jar:3.0.5 and go to the tower website again: .. image:: images/tower3.png :width: 800 Once the pipeline is finished, you can also receive a mail. .. image:: images/tower4.png :width: 800