This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How Can I Merge Intervals ?

I want to merge intervals using weighted means instead of sum or average. Thanks for taking your time to read this file.

My input data: data format: chrFileA startFileA endFile1 chrFile2 startFile2 endFile2 value TheLengthOfOverlap

   chr1    12000    13000    chr1    12984    13164    3    16
   chr1    13000    14000    chr1    12984    13164    3    164

My output data: data format: chrFileA startFileA WeightedMeanValues

   chr1    12000    13000    16/(13164-12984)*3
   chr1    13000    14000    164/(13164-12984)*3

Any help would be great grateful.

sequencing

2 answers

I think pandas and numpy models are suit for our analysis.

I know how to calculate this one. Just using groupby function and pd object. df.groupby(col2 and col3).apply(lambda x: np.average(col7, weights=col8))

Log in to answer this question.