Snakemake如何忽略RuntimeWarning?

时间:2019-06-11 17:29:06

标签: python snakemake

与默认的Python行为不同,Snakemake在numpy抛出RuntimeWarnings时停止执行。

/a-path/site-packages/numpy/lib/function_base.py:3250: RuntimeWarning: All-NaN slice encountered
Exiting because a job execution failed. Look above for error message


使用下面的代码配置numpy.seterr没有帮助。

import numpy as np
np.seterr(all='print')

我如何简单地告诉snakemake不要终止警告规则?

注意:我正在使用snakemake中的run:选项来抛出RuntimeWarning的规则。

1 个答案:

答案 0 :(得分:1)

也许您在其他地方有实际错误。在5.4.2上,警告似乎还可以:

rule all:
    input:
        'foo.txt',

rule one:
    output:
        touch('foo.txt'),
    run:
        import numpy as np
        np.nanmax([np.nan, np.nan])

执行:

snakemake

Building DAG of jobs...
Using shell: /bin/bash
Provided cores: 1
Rules claiming more threads will be scaled down.
Job counts:
    count   jobs
    1   all
    1   one
    2

[Tue Jun 11 21:09:47 2019]
rule one:
    output: foo.txt
    jobid: 1

Job counts:
    count   jobs
    1   one
    1
/home/dario/miniconda3/lib/python3.6/site-packages/snakemake/workflow.py:19: RuntimeWarning: All-NaN axis encountered
  from snakemake.logging import logger, format_resources, format_resource_names
Touching output file foo.txt.
[Tue Jun 11 21:09:47 2019]
Finished job 1.
1 of 2 steps (50%) done

[Tue Jun 11 21:09:47 2019]
localrule all:
    input: foo.txt
    jobid: 0

[Tue Jun 11 21:09:47 2019]
Finished job 0.
2 of 2 steps (100%) done
Complete log: /home/dario/Tritume/.snakemake/log/2019-06-11T210947.007675.snakemake.log

在任何情况下,您都可以通过以下方式使错误消失

import warnings
warnings.filterwarnings('ignore')