4

我正在尝试运行一个简单的单规则蛇形文件,如下所示:

resources_dir='resources'

rule downloadReference:
    output:
        fa = resources_dir+'/human_g1k_v37.fasta',
        fai = resources_dir+'/human_g1k_v37.fasta.fai',
    shell:
        ('mkdir -p '+resources_dir+'; cd '+resources_dir+'; ' +
        'wget ftp://ftp-trace.ncbi.nih.gov/1000genomes/ftp/technical/reference/human_g1k_v37.fasta.gz; gunzip human_g1k_v37.fasta.gz; ' +
        'wget ftp://ftp-trace.ncbi.nih.gov/1000genomes/ftp/technical/reference/human_g1k_v37.fasta.fai;')

但我得到一个错误:

    Error in job downloadReference while creating output files 
    resources/human_g1k_v37.fasta, resources/human_g1k_v37.fasta.fai.
    RuleException:
    CalledProcessError in line 10 of 
    /lustre4/home/masih/projects/NGS_pipeline/snake_test:
    Command 'mkdir -p resources; cd resources; wget ftp://ftp-
  trace.ncbi.nih.gov/1000genomes/ftp/technical/reference/human_g1k_v37.fasta.gz; gunzip human_g1k_v37.fasta.gz; wget ftp://ftp-trace.ncbi.nih.gov/1000genomes/ftp/technical/reference/human_g1k_v37.fasta.fai;' returned non-zero exit status 2.
      File "/lustre4/home/masih/projects/NGS_pipeline/snake_test", line 10, in __rule_downloadReference
      File "/home/masih/miniconda3/lib/python3.6/concurrent/futures/thread.py", line 55, in run
    Removing output files of failed job downloadReference since they might be corrupted:
    resources/human_g1k_v37.fasta
    Will exit after finishing currently running jobs.
    Exiting because a job execution failed. Look above for error message

我没有在snakemake 中使用threads 选项。我不知道这与thread.py有什么关系。有人有这个错误的经验吗?

4

1 回答 1

4

当 shell 命令失败时,它的退出状态不是 0。这就是“返回的非零退出状态 2”所表示的。

您的其中一个 shell 命令失败了,并且该失败传播到了snakemake。threads.py我想snakemake 使用线程,并且失败在文件1中的某些代码级别表现出来。

为了更好地理解发生了什么,我们可以使用||运算符捕获第一个错误,然后是一个发出错误消息的函数:

# Define functions to be used in shell portions
shell.prefix("""
# http://linuxcommand.org/wss0150.php
PROGNAME=$(basename $0)

function error_exit
{{
#   ----------------------------------------------------------------
#   Function for exit due to fatal program error
#       Accepts 1 argument:
#           string containing descriptive error message
#   ----------------------------------------------------------------
    echo "${{PROGNAME}}: ${{1:-"Unknown Error"}}" 1>&2
    exit 1
}}
""")

resources_dir='resources'

rule downloadReference:
    output:
        fa = resources_dir+'/human_g1k_v37.fasta',
        fai = resources_dir+'/human_g1k_v37.fasta.fai',
    params:
        resources_dir = resources_dir
    shell:
        """
        mkdir -p {params.resources_dir}
        cd {params.resources_dir}
        wget ftp://ftp-trace.ncbi.nih.gov/1000genomes/ftp/technical/reference/human_g1k_v37.fasta.gz || error_exit "fasta download failed"
        gunzip human_g1k_v37.fasta.gz || error_exit "fasta gunzip failed"
        wget ftp://ftp-trace.ncbi.nih.gov/1000genomes/ftp/technical/reference/human_g1k_v37.fasta.fai || error_exit "fai download failed"
        """

当我运行它时,我在第一次下载的消息之后收到以下消息:

gzip: human_g1k_v37.fasta.gz: decompression OK, trailing garbage ignored
bash: fasta gunzip failed

事实证明,gzip在出现警告时使用非零退出代码:

退出状态通常为0;如果发生错误,退出状态为 1。如果出现警告,退出状态为 2。

(来自诊断部分man gzip

如果我删除 error-capturing || error_exit "fasta gunzip failed",则工作流程能够完成。所以我不明白你为什么首先会出现这个错误。

我很惊讶gzip作者决定在简单警告的情况下使用非零状态。由于尾随零的存在,他们添加了-q关闭此特定警告的选项,但奇怪的是,使用此选项时退出状态仍然非零。


1根据蛇形的作者 Johannes Köster 所说:

对不起,误导 thread.py 的事情,这只是 snakemake 检测到问题的地方。真正的问题是您的命令以退出代码 2 退出,这表明与 Snakemake 无关的错误

于 2017-06-19T08:45:54.753 回答