daler / pybedtools

Python wrapper -- and more -- for BEDTools (bioinformatics tools for "genome arithmetic")
http://daler.github.io/pybedtools
Other
300 stars 102 forks source link

venn_mpl does not work #90

Closed iiiir closed 11 years ago

iiiir commented 11 years ago

i have made three three-columns bed file named a.bed, b.bed and c.bed, and try to run the following test scripts which get an error:

import pybedtools import pybedtools.scripts.venn_mpl

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

pybedtools.scripts.venn_mpl.venn_mpl(a,b,c)

error message: Traceback (most recent call last): File "/lab01/Projects/piRNA/Analysis_Feb202013/lincRNA_SW/exome/test.py", line 14, in pybedtools.scripts.venn_mpl.venn_mpl(a,b,c) File "/usr/lib64/python2.6/site-packages/pybedtools/scripts/venn_mpl.py", line 97, in venn_mpl fig.savefig(outfn) File "/usr/lib64/python2.6/site-packages/matplotlib/figure.py", line 1363, in savefig self.canvas.print_figure(_args, *_kwargs) File "/usr/lib64/python2.6/site-packages/matplotlib/backend_bases.py", line 2093, in print_figure **kwargs) File "/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_agg.py", line 503, in print_png filename_or_obj, self.figure.dpi) TypeError: Object does not appear to be a 8-bit string path or a Python file-like object

daler commented 11 years ago

When using it as a library as you do here, the output arg to venn_mpl defaults to None, so it doesn't know where to save the figure. I just pushed a fix so that it defaults to out.png.

Instead of venn_mpl, I'd strongly recommend using pybedtools.contrib.venn_maker, which is much more flexible. It creates a script to run the VennDiagram package in R (which needs to also be installed). For example,

from pybedtools.contrib.venn_maker import venn_maker
venn_maker(['a.bed', 'b.bed', 'c.bed'], run=True, figure_filename='out.tiff')