How to stop/exit workflow?

Hi there,
Is there a way to stop/exit workflow after a process?
For e.g., using exit keyword or something?

workflow wes {

def csvFile = params.input_csvFile //def csvFile = file($params.input_csvFile)
  
  Channel
        .fromPath( csvFile )
        .splitCsv( )
		.multiMap { row ->
            def tumor_reads = tuple( file( row[3]) ,file(row[4]))
            def normal_reads = tuple(file(row[1]),file(row[2]) )
            
            tumor:
                tuple( row[0], tumor_reads )
            normal:
                tuple( row[0], normal_reads )
        }
        .set { samples }
		
	FASTP(samples.tumor, samples.normal)
step2(FASTP.out)
step3(step2.out)
///exit/stop here how do I do?
step4()
step5()
step6()
step7()
step8()
step9()
step10()
}

I’d like to stop processing at step3 without commenting out remaining lines.
How do I achieve it?

When I’m developing a pipeline and want to see how things are going up to a certain point, I add return at the following line, and the pipeline will end there. It’s a useful little trick, though less valuable than live debugging with a fully powered IDE.

When talking about a proper exit during a pipeline run, there’s a Nextflow function specific to that named error. It’ll throw an exception. Let’s run the Nextflow pipeline below:

process FOO {
  debug true

  input:
  val x

  output:
  stdout

  script:
  """
  echo FOO process ${x}
  """
}

process BAR {
  debug true

  input:
  val x

  output:
  stdout

  script:
  """
  echo BAR process ${x}
  """
}

workflow {
  Channel
    .of(1..4)
    .set { my_ch }
  FOO(my_ch)
  BAR(my_ch)
}

The output:

Now, let’s add an error call before the line with BAR(my_ch).

...

workflow {
  Channel
    .of(1..4)
    .set { my_ch }
  FOO(my_ch)
  error("Some issue occurred. A useful message here :)")
  BAR(my_ch)
}

Output:

As you can see, though, it’s an abrupt error. It doesn’t really care what’s going on, as soon as the error call is evaluated, the pipeline is terminated. The best way to handle such situations is to use errorStrategy (more info here). As for skipping processes, there’s a snippet I posted earlier today that works out-of-the-box for nf-core pipelines, but can also be made to work in your own pipelines with a bit of work. Check it here.

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