/** * Gets the constituent chunks stored in this span. * @return An unmodifiable list of chunks. */ public List<GATKChunk> getGATKChunks() { List<GATKChunk> gatkChunks = new ArrayList<GATKChunk>(); for(Chunk chunk: getChunks()) gatkChunks.add(new GATKChunk(chunk)); return gatkChunks; }
@Override public GATKChunk clone() { return new GATKChunk(getChunkStart(),getChunkEnd()); }
@Test public void testUnionAllFileSpansAdded() { GATKBAMFileSpan regionOne = new GATKBAMFileSpan(new GATKChunk[] { new GATKChunk(0,1<<16), new GATKChunk(2<<16,3<<16), new GATKChunk(20<<16,21<<16) }); GATKBAMFileSpan regionTwo = new GATKBAMFileSpan(new GATKChunk(1<<16,2<<16)); GATKBAMFileSpan union = regionOne.union(regionTwo); Assert.assertEquals(union.getGATKChunks().size(),2,"Elements to be merged were not."); Assert.assertEquals(union.getGATKChunks().get(0),new GATKChunk(0,3<<16)); Assert.assertEquals(union.getGATKChunks().get(1),new GATKChunk(20<<16,21<<16)); }
@Test public void testUnionOfStringOfFileSpans() { GATKBAMFileSpan regionOne = new GATKBAMFileSpan(new GATKChunk[] { new GATKChunk(0,1<<16), new GATKChunk(2<<16,3<<16) }); GATKBAMFileSpan regionTwo = new GATKBAMFileSpan(new GATKChunk(1<<16,2<<16)); GATKBAMFileSpan union = regionOne.union(regionTwo); Assert.assertEquals(union.getGATKChunks().size(),1,"Elements to be merged were not."); Assert.assertEquals(union.getGATKChunks().get(0),new GATKChunk(0,3<<16)); }
@Test public void testUnionOfFileSpansFirstRegionEndsAfterSecondRegionEnd() { // Region 1 ends after Region 2 end: // |---2----| // |---1---------------| GATKBAMFileSpan regionOne = new GATKBAMFileSpan(new GATKChunk(0,(1<<16)|65535)); GATKBAMFileSpan regionTwo = new GATKBAMFileSpan(new GATKChunk(1<<16,(1<<16)|32767)); GATKBAMFileSpan union = regionOne.union(regionTwo); Assert.assertEquals(union.getGATKChunks().size(),1,"Elements to be merged were not."); Assert.assertEquals(union.getGATKChunks().get(0),new GATKChunk(0,(1<<16)|65535)); }
@Test public void testSubtractionOfPartialOverlap() { GATKBAMFileSpan regionOne = new GATKBAMFileSpan(new GATKChunk(0,2<<16)); GATKBAMFileSpan regionTwo = new GATKBAMFileSpan(new GATKChunk(1<<16,3<<16)); GATKBAMFileSpan subtraction = regionOne.minus(regionTwo); Assert.assertEquals(subtraction.getGATKChunks().size(),1,"Incorrect size in partial subset subtraction of region"); Assert.assertEquals(subtraction.getGATKChunks().get(0),new GATKChunk(0<<16,1<<16),"Determined subtraction is incorrect."); } }
@Test public void testUnionOfFileSpansFirstRegionEndsWithinSecondRegion() { // Region 1 ends within Region 2: // |---2----| // |---1----| GATKBAMFileSpan regionOne = new GATKBAMFileSpan(new GATKChunk(0,(1<<16)|32767)); GATKBAMFileSpan regionTwo = new GATKBAMFileSpan(new GATKChunk(1<<16,(1<<16)|65535)); GATKBAMFileSpan union = regionOne.union(regionTwo); Assert.assertEquals(union.getGATKChunks().size(),1,"Elements to be merged were not."); Assert.assertEquals(union.getGATKChunks().get(0),new GATKChunk(0,(1<<16)|65535)); }
@Test public void testUnionOfFileSpansFirstRegionEndsAtSecondRegionEnd() { // Region 1 ends at Region 2 end: // |---2----| // |---1-----------| GATKBAMFileSpan regionOne = new GATKBAMFileSpan(new GATKChunk(0,(1<<16)|65535)); GATKBAMFileSpan regionTwo = new GATKBAMFileSpan(new GATKChunk(1<<16,(1<<16)|65535)); GATKBAMFileSpan union = regionOne.union(regionTwo); Assert.assertEquals(union.getGATKChunks().size(),1,"Elements to be merged were not."); Assert.assertEquals(union.getGATKChunks().get(0),new GATKChunk(0,(1<<16)|65535)); }
@Test public void testSizeOfChunkWithinSingleBlock() { GATKChunk chunk = new GATKChunk(0,FULL_BLOCK_UNCOMPRESSED_SIZE-1); Assert.assertEquals(chunk.size(),FULL_BLOCK_UNCOMPRESSED_SIZE-1,"Chunk spanning limits of block is returning wrong size."); chunk = new GATKChunk(0,HALF_BLOCK_UNCOMPRESSED_SIZE); Assert.assertEquals(chunk.size(),HALF_BLOCK_UNCOMPRESSED_SIZE,"Chunk spanning 1/2 block is returning the wrong size."); }
@Test public void testUnionOfContiguousFileSpans() { // Region 1 ends at position adjacent to Region 2 start: // |---1----|---2----| GATKBAMFileSpan regionOne = new GATKBAMFileSpan(new GATKChunk(0,1<<16)); GATKBAMFileSpan regionTwo = new GATKBAMFileSpan(new GATKChunk(1<<16,(1<<16)|65535)); GATKBAMFileSpan union = regionOne.union(regionTwo); Assert.assertEquals(union.getGATKChunks().size(),1,"Elements to be merged were not."); Assert.assertEquals(union.getGATKChunks().get(0),new GATKChunk(0,(1<<16)|65535)); }
@Test public void testUnionOfFileSpansFirstRegionStartsAtSecondRegionStart() { // Region 1 starts at Region 2 start, but ends before Region 2: // |---2--------| // |---1----| GATKBAMFileSpan regionOne = new GATKBAMFileSpan(new GATKChunk(1<<16,(1<<16)|32767)); GATKBAMFileSpan regionTwo = new GATKBAMFileSpan(new GATKChunk(1<<16,(1<<16)|65535)); GATKBAMFileSpan union = regionOne.union(regionTwo); Assert.assertEquals(union.getGATKChunks().size(),1,"Elements to be merged were not."); Assert.assertEquals(union.getGATKChunks().get(0),new GATKChunk(1<<16,(1<<16)|65535)); }
@Test public void testIntersectionOfNonOverlappingFileSpans() { GATKBAMFileSpan regionOne = new GATKBAMFileSpan(new GATKChunk(0,1<<16)); GATKBAMFileSpan regionTwo = new GATKBAMFileSpan(new GATKChunk(1<<16,2<<16)); GATKBAMFileSpan intersection = regionOne.intersection(regionTwo); Assert.assertEquals(intersection.getGATKChunks().size(),0,"Elements inserted in intersection of two non-intersecting filespans"); }
/** * Create a new GATKBAMFileSpan from an existing BAMFileSpan. * @param sourceFileSpan */ public GATKBAMFileSpan(SAMFileSpan sourceFileSpan) { if(!(sourceFileSpan instanceof BAMFileSpan)) throw new SAMException("Unable to create GATKBAMFileSpan from a SAMFileSpan. Please submit a BAMFileSpan instead"); BAMFileSpan sourceBAMFileSpan = (BAMFileSpan)sourceFileSpan; for(Chunk chunk: sourceBAMFileSpan.getChunks()) add(chunk instanceof GATKChunk ? chunk : new GATKChunk(chunk)); }
@Test public void testSizeOfSingleBlock() { GATKChunk chunk = new GATKChunk(0,FULL_BLOCK_COMPRESSED_SIZE<<16); Assert.assertEquals(chunk.size(),FULL_BLOCK_UNCOMPRESSED_SIZE,"Chunk spanning complete block returns incorrect size."); }
@Test public void testUnionOfFileSpansFirstRegionEqualToSecondRegion() { // Region 1 and Region 2 represent the same region: // |---2----| // |---1----| GATKBAMFileSpan regionOne = new GATKBAMFileSpan(new GATKChunk(1<<16,(1<<16)|65535)); GATKBAMFileSpan regionTwo = new GATKBAMFileSpan(new GATKChunk(1<<16,(1<<16)|65535)); GATKBAMFileSpan union = regionOne.union(regionTwo); Assert.assertEquals(union.getGATKChunks().size(),1,"Elements to be merged were not."); Assert.assertEquals(union.getGATKChunks().get(0),new GATKChunk(1<<16,(1<<16)|65535)); }
@Test public void testSubtractionOfStrictSubset() { GATKBAMFileSpan regionOne = new GATKBAMFileSpan(new GATKChunk(0,2<<16)); GATKBAMFileSpan regionTwo = new GATKBAMFileSpan(new GATKChunk(0,1<<16)); GATKBAMFileSpan subtraction = regionOne.minus(regionTwo); Assert.assertEquals(subtraction.getGATKChunks().size(),1,"Incorrect size in strict subset subtraction of region"); Assert.assertEquals(subtraction.getGATKChunks().get(0),new GATKChunk(1<<16,2<<16),"Determined subtraction is incorrect."); }
@Test public void testSizeOfBlockAndAHalf() { GATKChunk chunk = new GATKChunk(0,(FULL_BLOCK_COMPRESSED_SIZE<<16)+HALF_BLOCK_UNCOMPRESSED_SIZE); Assert.assertEquals(chunk.size(),FULL_BLOCK_UNCOMPRESSED_SIZE+HALF_BLOCK_UNCOMPRESSED_SIZE,"Chunk spanning 1.5 blocks returns incorrect size."); }
@Test public void testSizeOfHalfBlock() { GATKChunk chunk = new GATKChunk(HALF_BLOCK_UNCOMPRESSED_SIZE,FULL_BLOCK_COMPRESSED_SIZE<<16); Assert.assertEquals(chunk.size(),HALF_BLOCK_UNCOMPRESSED_SIZE,"Chunk spanning 0.5 blocks returns incorrect size."); } }
@Test public void testUnionOfNonOverlappingFileSpans() { GATKBAMFileSpan regionOne = new GATKBAMFileSpan(new GATKChunk(0,65535)); GATKBAMFileSpan regionTwo = new GATKBAMFileSpan(new GATKChunk(1<<16,(1<<16)|65535)); GATKBAMFileSpan union = regionOne.union(regionTwo); Assert.assertEquals(union.getGATKChunks().size(),2,"Discontiguous elements were merged"); Assert.assertEquals(union.getGATKChunks().get(0),regionOne.getGATKChunks().get(0),"Wrong chunk was first in list"); Assert.assertEquals(union.getGATKChunks().get(1),regionTwo.getGATKChunks().get(0),"Wrong chunk was second in list"); }
@Test public void testFilePointerCombineOneSided() { FilePointer filePointer = new FilePointer(IntervalMergingRule.ALL, genomeLocParser.createGenomeLoc("chr1",1,5)); filePointer.addFileSpans(readerID,new GATKBAMFileSpan(new GATKChunk(0,1))); FilePointer empty = new FilePointer(IntervalMergingRule.ALL, genomeLocParser.createGenomeLoc("chr1",6,10)); // Do not add file spans to empty result FilePointer result = new FilePointer(IntervalMergingRule.ALL, genomeLocParser.createGenomeLoc("chr1",1,10)); result.addFileSpans(readerID,new GATKBAMFileSpan(new GATKChunk(0,1))); Assert.assertEquals(filePointer.combine(genomeLocParser,empty),result,"Combination of two file pointers is incorrect"); Assert.assertEquals(empty.combine(genomeLocParser,filePointer),result,"Combination of two file pointers is incorrect"); } }