【问题标题】:scriptExit 1 with pybedtools venn_mpl - snakemake 5.2.4scriptExit 1 与 pybedtools venn_mpl - snakemake 5.2.4
【发布时间】:2019-05-24 06:50:01
【问题描述】:

我想用 pybedtools 创建 VennDiagramms。有一个使用 matplotlib 的特殊脚本,称为 venn_mpl。当我在我的 jupyter notebook 中试用它时,它可以完美运行。您可以使用 python 或使用 shell 命令来完成。

不幸的是,当我想在我的蛇文件中使用它时出了点问题,我真的不知道问题出在哪里。

首先,这是脚本:venn_mpl.py

#!/gnu/store/3w3nz0h93h7jif9d9c3hdfyimgkpx1a4-python-wrapper-3.7.0/bin/python
"""
Given 3 files, creates a 3-way Venn diagram of intersections using matplotlib; \
see :mod:`pybedtools.contrib.venn_maker` for more flexibility.

Numbers are placed on the diagram.  If you don't have matplotlib installed.
try venn_gchart.py to use the Google Chart API instead.

The values in the diagram assume:

    * unstranded intersections
    * no features that are nested inside larger features
"""

import argparse
import sys
import os
import pybedtools

def venn_mpl(a, b, c, colors=None, outfn='out.png', labels=None):
    """
    *a*, *b*, and *c* are filenames to BED-like files.

    *colors* is a list of matplotlib colors for the Venn diagram circles.

    *outfn* is the resulting output file.  This is passed directly to
    fig.savefig(), so you can supply extensions of .png, .pdf, or whatever your
    matplotlib installation supports.

    *labels* is a list of labels to use for each of the files; by default the
    labels are ['a','b','c']
    """
    try:
        import matplotlib.pyplot as plt
        from matplotlib.patches import Circle
    except ImportError:
        sys.stderr.write('matplotlib is required to make a Venn diagram with %s\n' % os.path.basename(sys.argv[0]))
        sys.exit(1)

    a = pybedtools.BedTool(a)
    b = pybedtools.BedTool(b)
    c = pybedtools.BedTool(c)

    if colors is None:
        colors = ['r','b','g']

    radius = 6.0
    center = 0.0
    offset = radius / 2

    if labels is None:
        labels = ['a','b','c']

然后是我的代码:

rule venndiagramm_data:
     input:
         data = expand("bed_files/{sample}_peaks.narrowPeak", sample=config["samples"]["data"])
     output:
         "figures/Venn_PR1_PR2_GUI_data.png"
     run:
         col = ['g','k','b']
         lab = ['PR1_data','PR2_data','GUI_data']
         venn_mpl(input.data[0], input.data[1], input.data[2], colors = col, labels = lab, outfn = output)

错误是:

SystemExit in line 62 of snakemake_generatingVennDiagramm.py:
1

snakemake-log 只给我:

rule venndiagramm_data:
    input: bed_files/A_peaks.narrowPeak,bed_files/B_peaks.narrowPeak, bed_files/C_peaks.narrowPeak
    output: figures/Venn_PR1_PR2_GUI_data.png
    jobid: 2

Shutting down, this might take some time.
Exiting because a job execution failed. Look above for error message

我已经尝试按照文档中的说明添加:

rule error:
  shell:
    """
    set +e
    somecommand ...
    exitcode=$?
    if [ $exitcode -eq 1 ]
    then
        exit 1
    else
        exit 0
    fi
    """

但这并没有改变。

然后我的下一个想法是在使用我之前也测试过并且运行良好的 shell 命令时这样做。但是后来我得到了一个不同但我认为非常相似的错误消息,我也没有找到合适的解决方案:

rule venndiagramm_data_shell:
    input:
        data = expand("bed_files/{sample}_peaks.narrowPeak", sample=config["samples"]["data"])
    output:
        "figures/Venn_PR1_PR2_GUI_data.png"
    shell:
        "venn_mpl.py -a {input.data[0]} -b {input.data[1]} -c {input.data[2]} --color 'g,k,b' --labels 'PR1_data,PR2_data,GUI_data'"
The snakemake log:

[Thu May 23 16:37:27 2019]
rule venndiagramm_data_shell:
    input: bed_files/A_peaks.narrowPeak, bed_files/B_peaks.narrowPeak, bed_files/C_peaks.narrowPeak
    output: figures/Venn_PR1_PR2_GUI_data.png
    jobid: 1

[Thu May 23 16:37:29 2019]
Error in rule venndiagramm_data_shell:
    jobid: 1
    output: figures/Venn_PR1_PR2_GUI_data.png

RuleException:
CalledProcessError in line 45 of snakemake_generatingVennDiagramm.py:
Command ' set -euo pipefail;  venn_mpl.py -a input.data[0] -b input.data[1] -c input.data[2] --color 'g,k,b' --labels 'PR1_data,PR2_data,GUI_data' ' returned non-zero exit status 1.

有谁知道这可能是什么原因以及如何解决它?

仅供参考:我说我测试了它,但没有使用蛇形程序运行它。这是我的工作代码:

from snakemake.io import expand
import yaml
import pybedtools
from pybedtools.scripts.venn_mpl import venn_mpl

config_text_real = """ 
samples:
    data:
    - A
    - B
    - C
    control:
    - A_input 
    - B_input
    - C_input
"""
config_vennDiagramm = yaml.load(config_text_real)
config = config_vennDiagramm

data = expand("{sample}_peaks.narrowPeak", sample=config["samples"]["data"])
col = ['g','k','b']
lab = ['PR1_data','PR2_data','GUI_data']
venn_mpl(data[0], data[1], data[2], colors = col, labels = lab, outfn = 'Venn_PR1_PR2_GUI_data.png')

control = expand("{sample}_peaks.narrowPeak", sample=config["samples"]["control"])
lab = ['PR1_control','PR2_control','GUI_control']
venn_mpl(control[0], control[1], control[2], colors = col, labels = lab, outfn = 'Venn_PR1_PR2_GUI_control.png')

在我的 shell 的 jupyter notebook 中:

!A='../path/to/file/A_peaks.narrowPeak'
!B='../path/to/file/B_peaks.narrowPeak'
!C='../path/to/file/C_peaks.narrowPeak'
!col=g,k,b
!lab='PR1_data, PR2_data, GUI_data'
!venn_mpl.py -a ../path/to/file/A_peaks.narrowPeak -b ../path/to/file/B_peaks.narrowPeak -c ../path/to/file/C_peaks.narrowPeak --color "g,k,b" --labels "PR1_data, PR2_data, GUI_data"

我使用完整路径而不是变量的原因是,由于某种原因,代码无法使用 "$A" 调用变量。

【问题讨论】:

  • 请提供更多数据。首先,看起来问题出在脚本 venn_mpl.py 中,而不是 Snakefile 本身。如果没有看到这个脚本的代码,我们不能说什么具体的。接下来,如果配置文件中的样本数量与脚本期望的数量不同,则可能会出现问题。应该至少有 3 个文件,但这是真的吗? input.data[0], input.data[1], input.data[2]
  • 输入文件数正确。正如错误消息中所见,每个文件也被正确解释
  • 我编辑了帖子并在顶部提供了脚本的代码。不是我自己写的。它是 pyBedTools 包的一部分。

标签: python snakemake matplotlib-venn


【解决方案1】:

不确定这是否能解决问题,但我注意到的一件事是:

shell:
    "venn_mpl.py -a input.data[0] -b input.data[1] -c input.data[2]..." 

应该是:

shell:
    "venn_mpl.py -a {input.data[0]} -b {input.data[1]} -c {input.data[2]}..." 

【讨论】:

  • 谢谢! Ideed 这是 shell 版本的问题。但还有别的东西。但不幸的是,它仍然给我同样的错误。
  • 我更新了帖子并给了你在snakemake之外对我有用的代码
  • 还有一件事...您的 shell 命令不包含输出文件。应该是:venn_mpl.py -o {output} -a {input.data[0]} ...。实际上,由于未生成请求的输出figures/Venn_PR1_PR2_GUI_data.png,它会使snakemake 失败。但这不太可能是您的问题的原因。你能显示你执行的snakemake命令吗?此外,将-p/--printshellcmds 添加到其中,这样您就可以确切地看到snakemake 正在执行什么,将venn_mpl.py ... 命令复制并粘贴到Sheel 并检查错误和退出代码(完成后立即使用echo $?
  • 非常感谢使用 -p 的提示。这很有帮助!好吧,在这种情况下,它给了我“matplotlib 需要使用 .venn_mpl.py-real 制作维恩图”。这很奇怪,原因有两个:在snakemake文件的开头我有“import matplotlib”,其次,当我在我的jupyter笔记本中将它作为shell命令运行时,它可以工作。为了执行,我使用 jupyter notebook 中的终端和“snakemake -s snakefile.py”
  • matplotlib is required ... 可能是执行venn_mpl.py(即shebang行中的那个)的python版本与你的不同在你的 PATH 上,它没有安装 matplotlib。试试python /path/to/venn_mpl.py ... 和/或python3 ...。还要检查哪个 python 可执行文件运行 jupiter 并使用那个。 (只是猜测......)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-07
  • 1970-01-01
相关资源
最近更新 更多