nextflow-io / patterns

A curated collection of Nextflow implementation patterns
http://nextflow-io.github.io/patterns/
MIT License
332 stars 71 forks source link

Multiple optional inputs #48

Open shihabdider opened 11 months ago

shihabdider commented 11 months ago

The optional input pattern does not seem to work if a process has more than one optional input.

For example, the following test:

params.inputs = "$projectDir/data/sites.txt"
params.filter = "$projectDir/assets/NO_FILE"

process foo {
  debug true
  input:
  path seq
  path(opt)
  path(opt2)

  script:
  def filter = opt.name != 'NO_FILE' ? "--filter $opt" : ''
  def filter2 = opt2.name != 'NO_FILE' ? "--filter $opt" : ''
  """
  echo your_command --input $seq $filter $filter2
  """
}

workflow {
  prots_ch = Channel.fromPath(params.inputs, checkIfExists:true)
  opt_file = file(params.filter, checkIfExists:true)
  opt2_file = file(params.filter, checkIfExists:true)

  foo(prots_ch, opt_file, opt2_file)
}

Returns a collision error:

ERROR ~ Error executing process > 'foo (1)'
ERROR ~ Error executing process > 'foo (1)'

Caused by:                                                                                                             Process `foo` input file name collision -- There are multiple input files for each of the following file names: NO_FILE

Tip: view the complete command output by changing to the process work dir and entering the command `cat .command.out`

 -- Check '.nextflow.log' file for details

How should one generalize this pattern to handle multiple optional inputs?

cschu commented 11 months ago

I'd try making a second NO_FILE-file, e.g. NO_FILE2, use that as second input for the process and compare against it.