@Test public void deleteSuperRegion() { GenomeLoc e = genomeLocParser.createGenomeLoc(contigOneName, 10, 20); GenomeLoc g = genomeLocParser.createGenomeLoc(contigOneName, 70, 100); mSortedSet.add(g); mSortedSet.addRegion(e); assertTrue(mSortedSet.size() == 2); // now delete a region GenomeLoc d = genomeLocParser.createGenomeLoc(contigOneName, 15, 75); mSortedSet = mSortedSet.subtractRegions(new GenomeLocSortedSet(genomeLocParser, d)); Iterator<GenomeLoc> iter = mSortedSet.iterator(); GenomeLoc loc = iter.next(); assertTrue(loc.getStart() == 10); assertTrue(loc.getStop() == 14); assertTrue(loc.getContigIndex() == 1); loc = iter.next(); assertTrue(loc.getStart() == 76); assertTrue(loc.getStop() == 100); assertTrue(loc.getContigIndex() == 1); }
/** * Adds a GenomeLoc to the collection, merging it if it overlaps another region. If it's not * overlapping then we add it in sorted order. * * @param e the GenomeLoc to add to the collection * @return true, if the GenomeLoc could be added to the collection */ public boolean addRegion(GenomeLoc e) { if (e == null) { return false; } // have we added it to the collection? boolean haveAdded = false; /** * check if the specified element overlaps any current locations, if so we should merge the two. */ for (GenomeLoc g : mArray) { if (g.contiguousP(e)) { GenomeLoc c = g.merge(e); mArray.set(mArray.indexOf(g), c); haveAdded = true; } else if ((g.getContigIndex() == e.getContigIndex()) && (e.getStart() < g.getStart()) && !haveAdded) { mArray.add(mArray.indexOf(g), e); return true; } else if (haveAdded && ((e.getContigIndex() > e.getContigIndex()) || (g.getContigIndex() == e.getContigIndex() && e.getStart() > g.getStart()))) { return true; } } /** * we're at the end and we haven't found locations that should fall after it, so we'll put it at * the end */ if (!haveAdded) { mArray.add(e); } return true; }
@Test public void fromSequenceDictionary() { mSortedSet = GenomeLocSortedSet.createSetFromSequenceDictionary(this.header.getSequenceDictionary()); // we should have sequence assertTrue(mSortedSet.size() == GenomeLocSortedSetUnitTest.NUMBER_OF_CHROMOSOMES); int seqNumber = 0; for (GenomeLoc loc : mSortedSet) { assertTrue(loc.getStart() == 1); assertTrue(loc.getStop() == GenomeLocSortedSetUnitTest.CHROMOSOME_SIZE); assertTrue(loc.getContigIndex() == seqNumber); ++seqNumber; } assertTrue(seqNumber == GenomeLocSortedSetUnitTest.NUMBER_OF_CHROMOSOMES); }
@Test public void mergingOverlappingAbove() { GenomeLoc e = genomeLocParser.createGenomeLoc(contigOneName, 0, 50); GenomeLoc g = genomeLocParser.createGenomeLoc(contigOneName, 49, 100); assertTrue(mSortedSet.size() == 0); mSortedSet.add(g); assertTrue(mSortedSet.size() == 1); mSortedSet.addRegion(e); assertTrue(mSortedSet.size() == 1); Iterator<GenomeLoc> iter = mSortedSet.iterator(); GenomeLoc loc = iter.next(); assertEquals(loc.getStart(), 0); assertEquals(loc.getStop(), 100); assertEquals(loc.getContigIndex(), 1); }