Skip to content

Commit

Permalink
IntervalKeepPairFilter now filters out single ended reads (#1252)
Browse files Browse the repository at this point in the history
* fix an exception when seeing unpaired reads
  • Loading branch information
meganshand authored and lbergelson committed Jan 7, 2019
1 parent 2737292 commit 2c97cce
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ public IntervalKeepPairFilter(final List<Interval> intervals) {
* overlaps the current interval using overlap detector. If yes, return
* false -> don't filter it out.
*
* If a read is secondary or supplementary, filter read out. Use
* {@link IntervalFilter} if you want to keep these reads, but NOTE: the
* If a read is secondary, supplementary, or single ended, filter read out.
* Use {@link IntervalFilter} if you want to keep these reads, but NOTE: the
* resulting bam may not be valid.
*
* @param record the SAMRecord to evaluate
* @return true if the SAMRecord matches the filter, otherwise false
*/
@Override
public boolean filterOut(final SAMRecord record) {
if (record.isSecondaryOrSupplementary()) {
if (record.isSecondaryOrSupplementary() || !record.getReadPairedFlag()) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public void setUp() {
builder.addFrag("mapped_pair_chr1", 0, 1, false, false, "151M", null, -1, true, false);
// Supplementary alignment are never kept by the interval filter.
builder.addFrag("mapped_pair_chr1", 0, 1, false, false, "151M", null, -1, false, true);
// Single ended read should never be kept by the interval filter.
builder.addFrag("single_ended", 0, 1, false);
}

@Test(dataProvider = "testData")
Expand Down Expand Up @@ -96,6 +98,21 @@ public void testNotPrimaryReads() {
Assert.assertFalse(notPrimary);
}

@Test
public void testSingleEndedReads() {
final List<Interval> intervalList = new ArrayList<>();
final Interval interval1 = new Interval("chr1", 1, 999);
intervalList.add(interval1);

final IntervalKeepPairFilter filter = new IntervalKeepPairFilter(intervalList);

boolean singleEnded = StreamSupport.stream(builder.spliterator(), false)
.filter(rec -> !filter.filterOut(rec))
.anyMatch(rec -> rec.getReadName().equals("single_ended"));

Assert.assertFalse(singleEnded);
}

@DataProvider(name = "testData")
private Object[][] testData() {
Interval interval = new Interval("chr1", 1, 999);
Expand Down

0 comments on commit 2c97cce

Please sign in to comment.