Skip to content

Fix bigWig zoom summaries across sparse gaps - #103

Open
Rehpotsirhc-z wants to merge 1 commit into
jackh726:masterfrom
Rehpotsirhc-z:fix-bigwig-zoom-gaps
Open

Fix bigWig zoom summaries across sparse gaps#103
Rehpotsirhc-z wants to merge 1 commit into
jackh726:masterfrom
Rehpotsirhc-z:fix-bigwig-zoom-gaps

Conversation

@Rehpotsirhc-z

Copy link
Copy Markdown

The bigWig writer can produce zoom summaries for regions where no data was written. In this example, I use pybigtools, but the main bigtools writer is also affected. The full-resolution records correctly show an empty gap, but the zoomed query reports values throughout it.

import pybigtools

starts = list(range(10_000, 11_000)) + list(range(900_000, 901_000))
vals = [5.0] * 1000 + [7.0] * 1000
pybigtools.open("t.bw", "w").write(
    {"chr1": 1_000_000},
    (("chr1", s, s + 1, v) for s, v in zip(starts, vals)),
)

b = pybigtools.open("t.bw")
list(b.records("chr1", 11_000, 900_000))
# []
b.values("chr1", 200_000, 800_000, bins=5, summary="max", exact=True)
# array([nan, nan, nan, nan, nan])
b.values("chr1", 200_000, 800_000, bins=5, summary="max", exact=False)
# array([7., 7., 7., 7., 7.])

I also wrote the same sparse input using pyBigWig for comparison, along with pybigtools before and after the patch in this PR. Here's what it looks like in IGV, where pybigtools shows signal across the gaps:

igv-zoom-bug

This PR clamps add_start to at least current_val.start, which matches the equivalent logic already used in the bigBed writer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant