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

Fixing zero-length interval bug in IntervalList.merge #1318

Merged
merged 2 commits into from
Mar 11, 2019

Conversation

lbergelson
Copy link
Member

Checklist

  • Code compiles correctly
  • New tests covering changes and new functionality
  • All tests passing
  • Extended the README / documentation, if necessary
  • Is not backward compatible (breaks binary or source compatibility)

Copy link
Contributor

@yfarjoun yfarjoun left a comment

Choose a reason for hiding this comment

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

please add tests around zero-length intervals.

*/
static Interval merge(final Iterable<Interval> intervals, final boolean concatenateNames) {
final Interval first = intervals.iterator().next();
final String chrom = first.getContig();
int start = first.getStart();
int end = start;
int end = first.getEnd();
Copy link
Contributor

Choose a reason for hiding this comment

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

what should happen when we merge a zero-length interval with a non-zerolength one after it?

so,
10-9 merged with 11-15 should remain those two intervals
10-9 merged with 10-15 should become one interval 10-15
10-9 merged with 9-15 should become one interval 9-15

Copy link
Member Author

Choose a reason for hiding this comment

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

The first case, you mean it should become 10-15? Merge never leaves them separate.

Copy link
Contributor

Choose a reason for hiding this comment

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

no...I think that it should not become 10-15....since the size of the first interval is 0 it shouldn't change the total number of bases covered...

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that zero length intervals need to either be dropped when merging, or ignored...normal rules of merging do not apply.

*/
static Interval merge(final Iterable<Interval> intervals, final boolean concatenateNames) {
final Interval first = intervals.iterator().next();
final String chrom = first.getContig();
int start = first.getStart();
int end = start;
int end = first.getEnd();
Copy link
Contributor

Choose a reason for hiding this comment

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

nice catch. sorry.

Copy link
Member Author

Choose a reason for hiding this comment

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

I definitely didn't notice it in review. It makes sense, you can't have an end before start..

@codecov-io
Copy link

codecov-io commented Mar 6, 2019

Codecov Report

Merging #1318 into master will not change coverage.
The diff coverage is 100%.

@@             Coverage Diff             @@
##              master     #1318   +/-   ##
===========================================
  Coverage     67.635%   67.635%           
  Complexity      8230      8230           
===========================================
  Files            562       562           
  Lines          33617     33617           
  Branches        5642      5642           
===========================================
  Hits           22737     22737           
  Misses          8706      8706           
  Partials        2174      2174
Impacted Files Coverage Δ Complexity Δ
...c/main/java/htsjdk/samtools/util/IntervalList.java 74.754% <100%> (ø) 75 <0> (ø) ⬇️

@lbergelson lbergelson force-pushed the lb_fix_merge_for_zeroLength branch from 8b83dd9 to 198a2e1 Compare March 7, 2019 04:04
@lbergelson
Copy link
Member Author

I added some more test cases to cover the cases you mentioned

@lbergelson lbergelson requested a review from yfarjoun March 7, 2019 21:41
@lbergelson
Copy link
Member Author

@yfarjoun I added the tests I think you wanted. Is there anything else?

{Arrays.asList(zeroLengthInterval, interval600To601), true, interval600To625},
{Arrays.asList(interval600To601, new Interval(contig, 100, 200, false, "hasName")), true, new Interval(contig, 100, 601, false, "hasName")},
{Arrays.asList(interval600To601, new Interval(contig, 100, 200, false, "hasName")), false, new Interval(contig, 100, 601, false, "hasName")},
{Arrays.asList(zeroInterval10To9, new Interval(contig, 11, 15)), false, new Interval(contig, 10, 15)},
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that this is right. adding a zero-length interval shouldn't add bases to another interval.

* Fixing a bug in IntervalList.merge() that caused it to break when merging 0 length intervals
* Improving tests for merge
* The bug was introduced in #1265
@lbergelson lbergelson force-pushed the lb_fix_merge_for_zeroLength branch from 198a2e1 to 8cca313 Compare March 8, 2019 21:23
@lbergelson
Copy link
Member Author

@yfarjoun There exists problems with 0-length intervals... Unsurprisingly... I've opened a pr draft #1320 that shows some of them. I'm not going to resolve them in this PR.

@lbergelson lbergelson dismissed yfarjoun’s stale review March 8, 2019 21:45

Responded to comments as well as I can here, punting the rest to a new pr

@yfarjoun
Copy link
Contributor

yfarjoun commented Mar 9, 2019

👍

@lbergelson lbergelson merged commit fe27e66 into master Mar 11, 2019
@lbergelson lbergelson deleted the lb_fix_merge_for_zeroLength branch March 11, 2019 15:44
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.

3 participants