1

I'm working on a bioinformatics pipeline and one of the rule is to perform genome assembly using SPAdes (https://github.com/ablab/spades):

rule perform_de_novo_assembly_using_spades:
  input:
    bam = input.bam
  output:
    spades_contigs = directory(_RESULTS_DIR + "assembled_spades/")
  threads:
    _NBR_CPUS
  run:
    out_dir = _RESULTS_DIR + "assembled_spades/"
    command = "spades.py -t " + str(threads) + " --12 " + input.bam + " -o " + out_dir
    shell(command + " || true")

... More rules

onsuccess: print("Pipeline completed successfully!")
onerror: print("One or more errors occurred. Please refer to log file.")

The problem is sometimes for some problematic input files SPAdes can fail, resulting in my workflow being terminated. Therefore I added " || true " to the shell command to run SPAdes (according to this post: What would be an elegant way of preventing snakemake from failing upon shell/R error?) so that workflow will continue despite SPAdes failing. However right now my pipeline will run and still gives the "Pipeline completed successfully!" onsuccess message at the end. Ideally I want to it to print the onerror message "One or more errors occurred. Please refer to log file." Is there a way to make my workflow continue to the end despite SPAdes giving a runtime error and snakemake catching the error so that it displays the onerror message at the end?

user9367574
  • 91
  • 1
  • 7
  • Maybe the `--keep-going` option is what you need. It will allow independent jobs to continue and will result in onfailure triggering. – Troy Comi Nov 09 '20 at 19:56
  • You could add a `final_check` rule that checks the output of `perform_de_novo_assembly_using_spades` and fails when this output reveals that SPAdes failed. In order not to make the pipeline fail prematurely, this rule should have as input all inputs that your top driving rule currently has, and its output would then be the only input of your top driving rule. Or maybe just adding a run section that does the checking to the top driving rule works ? – bli Nov 26 '20 at 08:13

0 Answers0