From 640d9212597e2ff43ca3bd7fdb90d0a9dc5819ef Mon Sep 17 00:00:00 2001 From: jamesemery Date: Fri, 23 Dec 2022 15:51:21 -0500 Subject: [PATCH] Added a slightly more helpful error message to the reads filter (#7947) * added a summary line to the counting reads filter with totals. --- .../engine/filters/CountingReadFilter.java | 4 +++- .../filters/CountingReadFilterUnitTest.java | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/broadinstitute/hellbender/engine/filters/CountingReadFilter.java b/src/main/java/org/broadinstitute/hellbender/engine/filters/CountingReadFilter.java index 51662ebeb4d..cdaf4c0ddbc 100644 --- a/src/main/java/org/broadinstitute/hellbender/engine/filters/CountingReadFilter.java +++ b/src/main/java/org/broadinstitute/hellbender/engine/filters/CountingReadFilter.java @@ -201,6 +201,7 @@ public void resetFilteredCount() { protected static final class CountingAndReadFilter extends CountingBinopReadFilter { private static final long serialVersionUID = 1L; + protected long totalCount = 0; private CountingAndReadFilter(final CountingReadFilter lhs, final CountingReadFilter rhs) { super(lhs, rhs); @@ -212,6 +213,7 @@ public boolean test(final GATKRead read) { if (!accept) { filteredCount++; } + totalCount++; return accept; } @@ -249,7 +251,7 @@ private String getSummaryLineForLevelAllAndsSimplified() { } } - summaryLine.append(this.getFilteredCount() + " total reads filtered"); + summaryLine.append(this.getFilteredCount() + " total reads filtered out of "+ this.totalCount+ " reads processed"); return summaryLine.toString(); } diff --git a/src/test/java/org/broadinstitute/hellbender/engine/filters/CountingReadFilterUnitTest.java b/src/test/java/org/broadinstitute/hellbender/engine/filters/CountingReadFilterUnitTest.java index 9d8b649c0a4..b196b9b56b1 100644 --- a/src/test/java/org/broadinstitute/hellbender/engine/filters/CountingReadFilterUnitTest.java +++ b/src/test/java/org/broadinstitute/hellbender/engine/filters/CountingReadFilterUnitTest.java @@ -329,34 +329,37 @@ public Object[][] testAndFilterSummaryLineDataProvider() { final CountingReadFilter secondOfPair2 = new CountingReadFilter(ReadFilterLibrary.SECOND_OF_PAIR); secondOfPair2.filteredCount = 2; - final CountingReadFilter firstOfPair1AndSecondOfPair2 = firstOfPair1.and(secondOfPair2); + final CountingReadFilter.CountingAndReadFilter firstOfPair1AndSecondOfPair2 = (CountingReadFilter.CountingAndReadFilter)firstOfPair1.and(secondOfPair2); firstOfPair1AndSecondOfPair2.filteredCount = 3; + firstOfPair1AndSecondOfPair2.totalCount = 3; final String andWithCountsAbove0 = "1 read(s) filtered by: FirstOfPairReadFilter \n" + "2 read(s) filtered by: SecondOfPairReadFilter \n" - + "3 total reads filtered"; + + "3 total reads filtered out of 3 reads processed"; - final CountingReadFilter firstOfPair1AndMappingQuality0 = firstOfPair1.and(mappingQuality0); + final CountingReadFilter.CountingAndReadFilter firstOfPair1AndMappingQuality0 = (CountingReadFilter.CountingAndReadFilter)firstOfPair1.and(mappingQuality0); firstOfPair1AndMappingQuality0.filteredCount = 1; + firstOfPair1AndMappingQuality0.totalCount = 3; final String andWith1CountAbove0 = "1 read(s) filtered by: FirstOfPairReadFilter \n" + "0 read(s) filtered by: MappingQualityAvailableReadFilter \n" - + "1 total reads filtered"; + + "1 total reads filtered out of 3 reads processed"; - final CountingReadFilter mappingQuality0AndGoodCigar0 = mappingQuality0.and(goodCigar0); + final CountingReadFilter.CountingAndReadFilter mappingQuality0AndGoodCigar0 = (CountingReadFilter.CountingAndReadFilter)mappingQuality0.and(goodCigar0); mappingQuality0AndGoodCigar0.filteredCount = 0; final String andWithBoth0Counts = "0 read(s) filtered by: MappingQualityAvailableReadFilter \n" + "0 read(s) filtered by: GoodCigarReadFilter \n" - + "0 total reads filtered"; + + "0 total reads filtered out of 0 reads processed"; final CountingReadFilter firstOfPair1AndMappingQuality0AndGoodCigar0 = firstOfPair1AndMappingQuality0.and(goodCigar0); firstOfPair1AndMappingQuality0AndGoodCigar0.filteredCount = 1; - final CountingReadFilter firstOfPair1AndMappingQuality0AndGoodCigar0AndSecondOfPair2 = firstOfPair1AndMappingQuality0AndGoodCigar0.and(secondOfPair2); + final CountingReadFilter.CountingAndReadFilter firstOfPair1AndMappingQuality0AndGoodCigar0AndSecondOfPair2 = (CountingReadFilter.CountingAndReadFilter)firstOfPair1AndMappingQuality0AndGoodCigar0.and(secondOfPair2); firstOfPair1AndMappingQuality0AndGoodCigar0AndSecondOfPair2.filteredCount = 3; + firstOfPair1AndMappingQuality0AndGoodCigar0AndSecondOfPair2.totalCount = 5; final String multiAndWithMixCounts = "1 read(s) filtered by: FirstOfPairReadFilter \n" + "0 read(s) filtered by: MappingQualityAvailableReadFilter \n" + "0 read(s) filtered by: GoodCigarReadFilter \n" + "2 read(s) filtered by: SecondOfPairReadFilter \n" - + "3 total reads filtered"; + + "3 total reads filtered out of 5 reads processed"; final CountingReadFilter firstOfPair1AndMappingQuality0AndGoodCigar0OrSecondOfPair2 = firstOfPair1AndMappingQuality0AndGoodCigar0.or(secondOfPair2); firstOfPair1AndMappingQuality0AndGoodCigar0OrSecondOfPair2.filteredCount = 3;