From 5baf906c28d3653dac8d775e89f5c7da71eade89 Mon Sep 17 00:00:00 2001 From: David Roazen Date: Mon, 1 Apr 2013 15:32:40 -0400 Subject: [PATCH] Intervals: fix bug where we could fail to find the intersection of unsorted/missorted interval lists -The algorithm for finding the intersection of two sets of intervals relies on the sortedness of the intervals within each set, but the engine was not sorting the intervals before attempting to find the intersection. -The result was that if one or both interval lists was unsorted / lexicographically sorted, we would often fail to find the intersection correctly. -Now the IntervalBinding sorts all sets of intervals before returning them, solving the problem. -Added an integration test for this case. GSA-909 #resolve --- .../sting/commandline/IntervalBinding.java | 1 + .../utils/interval/IntervalIntegrationTest.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/public/java/src/org/broadinstitute/sting/commandline/IntervalBinding.java b/public/java/src/org/broadinstitute/sting/commandline/IntervalBinding.java index 7f419abb2..9253e1ee5 100644 --- a/public/java/src/org/broadinstitute/sting/commandline/IntervalBinding.java +++ b/public/java/src/org/broadinstitute/sting/commandline/IntervalBinding.java @@ -98,6 +98,7 @@ public final class IntervalBinding { intervals = IntervalUtils.parseIntervalArguments(genomeLocParser, stringIntervals); } + Collections.sort(intervals); return intervals; } diff --git a/public/java/test/org/broadinstitute/sting/utils/interval/IntervalIntegrationTest.java b/public/java/test/org/broadinstitute/sting/utils/interval/IntervalIntegrationTest.java index 98ecd0f43..69466d163 100644 --- a/public/java/test/org/broadinstitute/sting/utils/interval/IntervalIntegrationTest.java +++ b/public/java/test/org/broadinstitute/sting/utils/interval/IntervalIntegrationTest.java @@ -285,4 +285,20 @@ public class IntervalIntegrationTest extends WalkerTest { Arrays.asList(md5)); executeTest("testSymbolicAlleles", spec); } + + @Test + public void testIntersectionOfLexicographicallySortedIntervals() { + final String md5 = "18be9375e5a753f766616a51eb6131f0"; + WalkerTest.WalkerTestSpec spec = new WalkerTest.WalkerTestSpec( + " -T CountLoci" + + " -I " + privateTestDir + "NA12878.4.snippet.bam" + + " -R " + b37KGReference + + " -L " + privateTestDir + "lexicographicallySortedIntervals.bed" + + " -L 4" + + " -isr INTERSECTION" + + " -o %s", + 1, // just one output file + Arrays.asList(md5)); + executeTest("testIntersectionOfLexicographicallySortedIntervals", spec); + } }