Generating a bedgraph from a scored bed file
3
2
Entering edit mode
7.3 years ago
Matt Corley ▴ 40

Bedtools has a function, genomecov, that will output a bedgraph from a BAM file:

I have a slightly different use case, where I'd like to generate a bedgraph file from a scored bed file. That is, instead of each interval representing a count of '1', each interval can represent an arbitrary count. In the case of overlapping intervals, I'd like to report the mean in the bedgraph output. Graphically:

Does anybody know a way to accomplish this using bedtools? I'll also accept non-bedtools solutions, provided they can be implemented in Python (e.g., other tools with a Python API or fully implemented in Python).

bedgraph ChIP-Seq coverage bedtools genome • 2.9k views
1
Entering edit mode
7.3 years ago

I think what you want to do can be accomplished using bedtools map.

1
Entering edit mode
7.3 years ago

You could either use bedops --partition followed by bedtools map, or simply use bedtools unionbedg and post-process its output. If you're using pybedtools, the latter option is probably easiest. There may also be a way to do all of this with bedops.