Statements cannot be mixed with script declarations error

Hi, I am very new to Nextflow and still looking at the training materials and workshops (sorry if this seems like a really straight forward problem to solve!). I have found this page with some really useful explanations Nextflow Processes . I have recently installed the nextflow extension in VScode to try and replicate these scripts and implement them into my own pipeline.

However, I wanted to ask about a particular part of tutorial in the “input values” section:

//process_input_value.nf
nextflow.enable.dsl=2

process PRINTCHR {

  input:
  val chr

  script:
  """
  echo processing chromosome ${chr}
  """
}

chr_ch = Channel.of( 1..22,'X','Y' )

workflow {

  PRINTCHR( chr_ch )
}

When I copy this into my vscode .nf file it comes up with an error message for the line: chr_ch = Channel.of( 1..22,‘X’,‘Y’ )

“Statements cannot be mixed with script declarations – move statements into a process or workflow”

I wanted to ask if this was previously part of DSL1 and doesn’t work in DSL2? (although I see nextflow.enable.dsl=2 at the top) I was wondering where the best place would be to move this line and avoid this error? Thank you!!

Yes, this was DSL1 syntax. DSL1 didn’t have the workflow block so channel operations were defined outside any block, like in your example.

The fix is to move channel operations inside the workflow block:

//process_input_value.nf

process PRINTCHR {

  input:
  val chr

  script:
  """
  echo processing chromosome ${chr}
  """
}

workflow {
  chr_ch = Channel.of( 1..22,'X','Y' )

  PRINTCHR( chr_ch )
}

It used to be valid DSL2 as well, but lately the syntax has been becoming stricter which makes for simpler and more readable code.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.