Nextflow examples don't show expected output

62 Views Asked by At

This example is from the nextflow docs

process basicExample {
  input:
  val x

  "echo process job $x"
}

workflow {
  def num = Channel.of(1,2,3)
  basicExample(num)
}

It says output should be similar to:

process job 3
process job 1
process job 2

However, I only see one of these outputs. For example: process job 2 when I look in .command.out. Note, that there is only one folder in db/9217e2 folder with one .command.out file.

$> find  "work/db/"  -name ".command.out"                                                                                                                      
work/db/9217e2451637514ea8ab5791fbcca4/.command.out
N E X T F L O W  ~  version 23.10.0
Launching `../../nextflow/channelexample.nf` [festering_stonebraker] DSL2 - revision: 110bfce0a9
executor >  local (3)
[db/9217e2] process > basicExample (3) [100%] 3 of 3 ✔
2

There are 2 best solutions below

0
On

Nextflow defaults to iterating each process over a list of inputs. So each process will only have 1 output, and your input will be in a random order.

If you want to use all inputs in one process it would be something like this:

process basicExample {
  input:
  val x

  script:
  def echo_all = x.collect{ "echo process job $it" }.join('\n')
  """
  ${echo_all}
  """  

}

workflow {
  def num = Channel.of(1,2,3).collect()
  basicExample(num)
}

And another way to better monitor your jobs if you're iterating over a list is to use tag.

process basicExample {
  tag "$x"

  input:
  val x

  "echo process job $x"
}

This will then put your output to something like this, where x is the value of $x the process is using:

[81/a571ca] process > basicExample (x) [0%] 0 of 3
2
On

You're looking for .command.out in one work directory. Nextflow made 3 seperate directories inside the work directory, one for each instance of the basicExample process that was called. If you look in the other workfolders, you will see the other outputs.