NextflowSnippets icon indicating copy to clipboard operation
NextflowSnippets copied to clipboard

This repository hosts a large collection of Nextflow snippets

Nextflow Snippets

Snippet is a programming term for a small region of re-usable source code, machine code, or text, and Nextflow is both a Domain-Specific Language for writing data pipelines and a pipeline orchestrator. For more information about Nextflow, check the official site and documentation. For community training material, this link is a greaaaaaat place to start! :smiley:

This repository contains a collection of numerous solutions I have worked on throughout the past months as a Nextflow and nf-core Developer Advocate at Seqera Labs providing community support to numerous users around the world. I haven't saved all the snippets I created, but as I have now answered over 500 questions in this period, there are indeed quite a few I have kept when I found the solution interesting enough :satisfied:

List of snippets by category

Below, you'll find links to Markdown documents in this repository explaining the issue followed by the snippet that solves it.

Using Channel Operators

  • Get first N elements from a channel
  • Get last N elements from a channel
  • Filter items within a list in tuples within your channels
  • Filter tuples within your channel
  • Flatten multiple-item tuple to 2-item tuple keeping key
  • Recreate countBy operator for channels consisting of single elements or tuples
  • Set operations with channels
  • Filter output channel elements based on file size or file content
  • Sort lexicographically paths in a list within a tuple
  • Provide multiple paths from a channel as a string to a command
  • Guarantee tuple structure in a channel
  • Group based on two keys, sort based on another one

Misc

  • Prepare assets without running the pipeline
  • Organize output files according to some pattern, and organize everything else in a different path
  • Capture multiple values provided with a pipeline parameter
  • Query attributes of objects
  • Piping with multiple processes at the same time
  • Get the publishDir paths for a specific task
  • Request the maximum number of available CPU cores for a process
  • Pass config settings as a command line argument instead of a config file
  • Multiple instances of the same file provided to the same task
  • Save configuration files used in a specific run
  • Compose configurations in the nextflow.config file
  • Run some processes outside containers
  • Run containers of specific processes without root access

Nextflow Patterns

If you're looking for more snippets, you can find plenty at Nextflow Patterns.