deeptools / pyBigWig

A python extension for quick access to bigWig and bigBed files
MIT License
212 stars 48 forks source link

Stats Sum Not Working as Expected #146

Closed atancoder closed 6 months ago

atancoder commented 6 months ago

I'm using the latest version of pyBigWig and the 'sum' stat doesn't seem to work properly. It returns different results than if i were to sum up the values myself.

>>> from pyBigWig import open as open_bigwig
>>> import pyBigWig
>>> pyBigWig.__version__
'0.3.22'
>>> f = '/oak/stanford/groups/engreitz/Users/atan5133/atac_to_dnase/input_data/DNase.bigwig'
>>> bw = open_bigwig(f)
>>> bw.stats('chr1', 3774743, 3775877, type='sum')
[10.811250448226929]
>>> sum(bw.values('chr1', 3774743, 3775877))
6294.481561243534
>>> bw.stats('chr1', 3774743, 3775877, type='max')
[12.645500183105469]
>>> max(bw.values('chr1', 3774743, 3775877))
12.645500183105469

max works as expected. Am I misunderstanding how sum is supposed to work here?

edit: perhaps it's due to https://github.com/deeptools/pyBigWig?tab=readme-ov-file#a-note-on-statistics-and-zoom-levels ? But weird how the approximation is quite off