Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with wrong values for overlapping bed-ranges #84

Merged
merged 4 commits into from
Aug 26, 2024

Conversation

Jakob37
Copy link
Contributor

@Jakob37 Jakob37 commented Aug 23, 2024

As a part of testing #83, we realized that some values were used multiple times in calculations.

Tracking this down, it seems that in track.rs, same ranges were used multiple times. This is the part of the code I recently updated to fix a separate issue, and might have been a new bug caused by solving the old.

I have prepared a 10nt d4 file mapped with two reads to test this:

$ d4tools show input_10nt.d4
chr     0       3       0
chr     3       4       1
chr     4       7       2
chr     7       9       1
chr     9       10      0

Expected total coverage would be (3 * 2 + 3 * 1) / 10 = 0.9

Before the update:

$ d4tools stat -s mean -r input_10nt.overlapping_ranges.bed input_10nt.d4
chr     0       10      1.2
chr     4       5       2

After the change:

$ d4tools stat -s mean -r input_10nt.overlapping_ranges.bed input_10nt.d4
chr     0       10      0.9
chr     4       5       2

I have prepared a unit test based on this as part of the PR. This and other tests are succeeding, except two remote-view tests (which I don't think are related to this change).

tests_2

Would you be able to review @brentp ?

@@ -83,7 +88,12 @@ where
if let Some(handle) = handle {
handle.init();
if let Some(top) = active_heap.first() {
let this_begin = top.get_range().0;
let this_begin;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let this_begin = top.get_range().0.max(last_end)

@@ -70,7 +70,12 @@ where
}

if this_end != last_end {
let this_begin = top.get_range().0;
let this_begin;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let this_begin = top.get_range().0.max(last_end)

@Jakob37 Jakob37 requested a review from brentp August 26, 2024 06:07
@Jakob37
Copy link
Contributor Author

Jakob37 commented Aug 26, 2024

Thank you for the review @brentp ! Makes much sense to do more careful testing.

I added a more extensive case and simplified the code as suggested.

Ready for re-review.

@brentp brentp merged commit 31cd8d6 into 38:master Aug 26, 2024
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.

2 participants