pythonbedtools

pybedtools bam_to_bed() bedpe


I'm feeling dumb, but I can't figure out the syntax below, and I've been googling the w/o success for a while.

Very easy, I have a bam I want to convert to bedpe with pybedtools within a script.

The following works great:

pybed_BAM = pybedtools.BedTool("path/to/sorted/bam")
bedpe = pybed_BAM.bam_to_bed().to_dataframe()

however, of course, it results in a normal bed file. If I try to add the bedpe argument as either pybed_BAM.bam_to_bed("-bedpe") or pybed_BAM.bam_to_bed("bedpe") it fails with:

TypeError: handle_kwargs() keywords must be strings

Unfortunately the bam_to_bed() page doesn't provide syntax explanation but is simply a copy-paste of the command-line tool help. The above attempts are trying to borrow the syntax from other pybedtools functions but are obviously incorrect. What am I missing?

PS the file is fine as the conversion from commandline with bedtools bamtobed works fine.

PPS I'd like to avoid subprocess pipes and use pybedtools


Solution

  • with an hint from Patrick Artner's suggestion I found the solution

    pybed_BAM.bam_to_bed(bedpe=True) does the job!