-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make BAMFileReader and some related classes public, and expose (#786)
methods for iterating over a part of a BAM file (needed for Hadoop-BAM, which processes BAM files in parallel). Also, add BAMFileSpan#removeContentsAfter method to mirror removeContentsBefore.
- Loading branch information
Showing
4 changed files
with
160 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package htsjdk.samtools; | ||
|
||
import java.util.Arrays; | ||
import org.testng.Assert; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
public class BAMFileSpanTest { | ||
@Test(dataProvider = "testRemoveContentsBeforeProvider") | ||
public void testRemoveContentsBefore(BAMFileSpan originalSpan, BAMFileSpan cutoff, | ||
BAMFileSpan expectedSpan) { | ||
// only start value in cutoff is used | ||
Assert.assertEquals( | ||
((BAMFileSpan) originalSpan.removeContentsBefore(cutoff)).getChunks(), | ||
expectedSpan.getChunks()); | ||
} | ||
|
||
@DataProvider(name = "testRemoveContentsBeforeProvider") | ||
private Object[][] testRemoveContentsBeforeProvider() { | ||
return new Object[][] { | ||
{ span(chunk(6,10), chunk(11,15)), null, span(chunk(6,10), chunk(11,15)) }, | ||
{ span(chunk(6,10), chunk(11,15)), span(), span(chunk(6,10), chunk(11,15)) }, | ||
{ span(chunk(6,10), chunk(11,15)), span(chunk(6,0)), span(chunk(6,10), chunk(11,15)) }, | ||
{ span(chunk(6,10), chunk(11,15)), span(chunk(7,0)), span(chunk(7,10), chunk(11,15)) }, | ||
{ span(chunk(6,10), chunk(11,15)), span(chunk(9,0)), span(chunk(9,10), chunk(11,15)) }, | ||
{ span(chunk(6,10), chunk(11,15)), span(chunk(10,0)), span(chunk(11,15)) }, | ||
{ span(chunk(6,10), chunk(11,15)), span(chunk(11,0)), span(chunk(11,15)) }, | ||
{ span(chunk(6,10), chunk(11,15)), span(chunk(12,0)), span(chunk(12,15)) }, | ||
{ span(chunk(6,10), chunk(11,15)), span(chunk(15,0)), span() }, | ||
{ span(chunk(6,10), chunk(11,15)), span(chunk(16,0)), span() }, | ||
{ span(chunk(6,10), chunk(11,15)), span(chunk(6,10), chunk(7,16)), span(chunk(6, 10), chunk(11,15)) }, | ||
{ span(chunk(6,10), chunk(11,15)), span(chunk(16,17), chunk(18,19)), span() }, | ||
}; | ||
} | ||
|
||
@Test(dataProvider = "testRemoveContentsAfterProvider") | ||
public void testRemoveContentsAfter(BAMFileSpan originalSpan, BAMFileSpan cutoff, | ||
BAMFileSpan expectedSpan) { | ||
// only end value in cutoff is used | ||
Assert.assertEquals( | ||
((BAMFileSpan) originalSpan.removeContentsAfter(cutoff)).getChunks(), | ||
expectedSpan.getChunks()); | ||
} | ||
|
||
@DataProvider(name = "testRemoveContentsAfterProvider") | ||
private Object[][] testRemoveContentsAfterProvider() { | ||
return new Object[][] { | ||
{ span(chunk(6,10), chunk(11,15)), null, span(chunk(6,10), chunk(11,15)) }, | ||
{ span(chunk(6,10), chunk(11,15)), span(), span(chunk(6,10), chunk(11,15)) }, | ||
{ span(chunk(6,10), chunk(11,15)), span(chunk(0,6)), span() }, | ||
{ span(chunk(6,10), chunk(11,15)), span(chunk(0,7)), span(chunk(6,7)) }, | ||
{ span(chunk(6,10), chunk(11,15)), span(chunk(0,9)), span(chunk(6,9)) }, | ||
{ span(chunk(6,10), chunk(11,15)), span(chunk(0,10)), span(chunk(6,10)) }, | ||
{ span(chunk(6,10), chunk(11,15)), span(chunk(0,11)), span(chunk(6,10)) }, | ||
{ span(chunk(6,10), chunk(11,15)), span(chunk(0,12)), span(chunk(6,10), chunk(11,12)) }, | ||
{ span(chunk(6,10), chunk(11,15)), span(chunk(0,15)), span(chunk(6,10), chunk(11,15)) }, | ||
{ span(chunk(6,10), chunk(11,15)), span(chunk(0,16)), span(chunk(6,10), chunk(11,15)) }, | ||
{ span(chunk(6,10), chunk(11,15)), span(chunk(0,6), chunk(7,10)), span(chunk(6, 10)) }, | ||
{ span(chunk(6,10), chunk(11,15)), span(chunk(0,6), chunk(7,16)), span(chunk(6, 10), chunk(11,15)) }, | ||
}; | ||
} | ||
|
||
private BAMFileSpan span(Chunk... chunks) { | ||
return new BAMFileSpan(Arrays.asList(chunks)); | ||
} | ||
|
||
private Chunk chunk(long start, long end) { | ||
return new Chunk(start, end); | ||
} | ||
} |