This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Collapse bed and only sum overlapping parts

Hi,

I have a bed that looks something like this:

chr1    150000    170000    feature    10    +
chr1    160000    180000    feature    10    +

I want a way to sum the scores in only the overlapping regions, like this:

chr1    150000    160000    feature    10    +
chr1    160000    170000    feature    20    +
chr1    170000    180000    feature    10    +

Does anyone have any ideas how to do this? I wrote a super chunky python script, but its super computationally intensive and there must be a better way.

Thanks!

bed rna-seq alignment

1 answer

Figured out a bedops bedmap option:

bedops --partition my.bed |  bedmap --echo --sum --delim '\t' - my.bed

Input bed needs to be sorted first.

Log in to answer this question.