2017-08-10 3 views
0

特定のルールが失敗してもスニーク・ワークフローを継続して実行したいと考えています。shell/Rエラーでsnakemakeが失敗するのを防ぐうまい方法は何でしょうか?

たとえば、ChIP-seqデータのピークコールを実行するために、さまざまなツールを使用しています。しかし、特定のプログラムは、ピークを特定できないときにエラーを出します。そのような場合に空の出力ファイルを作成し、snakemakeが失敗しないようにしたいと考えています(いくつかのピーク時の呼び出し元がすでに行っているように)。

「シェル」と「実行」キーワードを使用して、このようなケースを処理するスネークメイクのような方法はありますか?

おかげshellコマンドについて

答えて

1

は、あなたは常に、||を条件付き「または」利用することができます:

rule some_rule: 
    output: 
     "outfile" 
    shell: 
     """ 
     command_that_errors || true 
     """ 

# or... 

rule some_rule: 
    output: 
     "outfile" 
    run: 
     shell("command_that_errors || true") 

ゼロの通常終了コード(0)成功を意味し、何でも非ゼロを示し失敗。 || trueを含めると、コマンドがゼロ以外の終了コード(trueは常に0を返す)で終了すると正常終了します。

特定のゼロ以外の終了コードを許可する必要がある場合は、シェルまたはPythonを使用してコードをチェックできます。 Pythonの場合、次のようなものになります。 shlex.split()モジュールが使用されているため、シェルコマンドを引数の配列として渡す必要はありません。シェルスクリプトで

import shlex 

rule some_rule: 
    output: 
     "outfile" 
    run: 
     try: 
      proc_output = subprocess.check_output(shlex.split("command_that_errors {output}"), shell=True)      
     # an exception is raised by check_output() for non-zero exit codes (usually returned to indicate failure) 
     except subprocess.CalledProcessError as exc: 
      if exc.returncode == 2: # 2 is an allowed exit code 
       # this exit code is OK 
       pass 
      else: 
       # for all others, re-raise the exception 
       raise 

rule some_rule: 
    output: 
     "outfile" 
    run: 
     shell("command_that_errors {output} || rc=$?; if [[ $rc == 2 ]]; then exit 0; else exit $?; fi") 
関連する問題