From 1eb5f972550f7e467ac67d66b70160c34683d1f7 Mon Sep 17 00:00:00 2001 From: aaron Date: Fri, 12 Mar 2010 19:14:21 +0000 Subject: [PATCH] fixed dropping single base intervals from deleteRegion, moving onto performance fixes. (stop - start is length-1 on closed intervals, so we need to check greater than OR equals to zero) git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2990 348d0f76-0448-11de-a6fe-93d51630548a --- .../sting/utils/GenomeLocSortedSet.java | 4 ++-- .../sting/utils/GenomeLocSortedSetTest.java | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/java/src/org/broadinstitute/sting/utils/GenomeLocSortedSet.java b/java/src/org/broadinstitute/sting/utils/GenomeLocSortedSet.java index 03b410878..22aeeae65 100755 --- a/java/src/org/broadinstitute/sting/utils/GenomeLocSortedSet.java +++ b/java/src/org/broadinstitute/sting/utils/GenomeLocSortedSet.java @@ -174,10 +174,10 @@ public class GenomeLocSortedSet extends AbstractSet { GenomeLoc before = GenomeLocParser.createGenomeLoc(g.getContigIndex(), g.getStart(), e.getStart() - 1); GenomeLoc after = GenomeLocParser.createGenomeLoc(g.getContigIndex(), e.getStop() + 1, g.getStop()); int index = mArray.indexOf(g); - if (after.getStop() - after.getStart() > 0) { + if (after.getStop() - after.getStart() >= 0) { mArray.add(index, after); } - if (before.getStop() - before.getStart() > 0) { + if (before.getStop() - before.getStart() >= 0) { mArray.add(index, before); } mArray.remove(mArray.indexOf(g)); diff --git a/java/test/org/broadinstitute/sting/utils/GenomeLocSortedSetTest.java b/java/test/org/broadinstitute/sting/utils/GenomeLocSortedSetTest.java index 111265045..528a153c8 100755 --- a/java/test/org/broadinstitute/sting/utils/GenomeLocSortedSetTest.java +++ b/java/test/org/broadinstitute/sting/utils/GenomeLocSortedSetTest.java @@ -142,6 +142,30 @@ public class GenomeLocSortedSetTest extends BaseTest { assertTrue(loc.getContigIndex() == 1); } + @Test + public void deleteAllButTwoEndBases() { + GenomeLoc e = GenomeLocParser.createGenomeLoc(1, 1, 50); + mSortedSet.add(e); + + // now delete the region + GenomeLoc d = GenomeLocParser.createGenomeLoc(1, 2, 49); + mSortedSet.removeRegion(d); + Iterator iter = mSortedSet.iterator(); + + // we expect to find the two end bases only, this was added because we were + // dropping intervals that were of size one. + GenomeLoc loc = iter.next(); + assertTrue(loc.getStart() == 1); + assertTrue(loc.getStop() == 1); + assertTrue(loc.getContigIndex() == 1); + + loc = iter.next(); + assertTrue(loc.getStart() == 50); + assertTrue(loc.getStop() == 50); + assertTrue(loc.getContigIndex() == 1); + } + + @Test public void deleteAllByRegion() { GenomeLoc e = GenomeLocParser.createGenomeLoc(1, 1, 100);