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).