SparseVariantFilterRunner implements VariantFilterRunner { @Override public List<VariantEvaluation> run(VariantFilter filter, List<VariantEvaluation> variantEvaluations) { for (VariantEvaluation variantEvaluation : variantEvaluations) { if (variantEvaluation.passedFilters()) { run(filter, variantEvaluation); } } return passedFilteredVariants(variantEvaluations); }  @Override List<VariantEvaluation> run(VariantFilter filter, List<VariantEvaluation> variantEvaluations);  }
@Test public void testRunOnlyReturnsVariantPassingAllFilters() { List<VariantFilter> filters = new ArrayList<>(); filters.add(pathogenicityFilter); filters.add(variantEffectFilter); filters.add(qualityFilter); filters.add(frequencyFilter); filters.forEach(filter -> instance.run(filter, variantEvaluations)); assertThat(passesAllFilters.passedFilters(), is(true)); assertThat(passesAllFilters.passedFilter(FilterType.VARIANT_EFFECT_FILTER), is(true)); assertThat(passesAllFilters.passedFilter(FilterType.QUALITY_FILTER), is(true)); assertThat(passesAllFilters.passedFilter(FilterType.FREQUENCY_FILTER), is(true)); assertThat(passesAllFilters.passedFilter(FilterType.PATHOGENICITY_FILTER), is(true)); assertThat(passesAllFilters.passedFilter(FilterType.ENTREZ_GENE_ID_FILTER), is(false)); assertThat(passesQualityFrequencyFilter.passedFilters(), is(false)); assertThat(passesQualityFrequencyFilter.getPassedFilterTypes().isEmpty(), is(true)); assertThat(passesTargetQualityFilter.passedFilters(), is(false)); assertThat(passesTargetQualityFilter.getPassedFilterTypes().isEmpty(), is(true)); assertThat(failsAllFilters.passedFilters(), is(false)); assertThat(failsAllFilters.getPassedFilterTypes().isEmpty(), is(true)); }
@Test public void testRunOnlyReturnsVariantPassingAllFiltersDifferentOrder() { List<VariantFilter> filters = new ArrayList<>(); filters.add(variantEffectFilter); filters.add(qualityFilter); filters.add(frequencyFilter); filters.add(pathogenicityFilter); filters.forEach(filter -> instance.run(filter, variantEvaluations)); assertThat(passesAllFilters.passedFilters(), is(true)); assertThat(passesAllFilters.getPassedFilterTypes(), equalTo(EnumSet.of(FilterType.VARIANT_EFFECT_FILTER, FilterType.QUALITY_FILTER, FilterType.FREQUENCY_FILTER, FilterType.PATHOGENICITY_FILTER))); assertThat(passesAllFilters.passedFilter(FilterType.ENTREZ_GENE_ID_FILTER), is(false)); assertThat(passesQualityFrequencyFilter.passedFilters(), is(false)); assertThat(passesQualityFrequencyFilter.getPassedFilterTypes().isEmpty(), is(true)); assertThat(passesTargetQualityFilter.passedFilters(), is(false)); assertThat(passesTargetQualityFilter.getPassedFilterTypes(), equalTo(EnumSet.of(FilterType.VARIANT_EFFECT_FILTER, FilterType.QUALITY_FILTER))); assertThat(failsAllFilters.passedFilters(), is(false)); assertThat(failsAllFilters.getPassedFilterTypes().isEmpty(), is(true)); }
@Test public void testRunReturnsVariantsPassingVariantEffectAndQualityFilters() { List<VariantFilter> filters = new ArrayList<>(); filters.add(variantEffectFilter); filters.add(qualityFilter); filters.forEach(filter -> instance.run(filter, variantEvaluations)); assertThat(passesAllFilters.passedFilters(), is(true)); assertThat(passesAllFilters.getPassedFilterTypes(), equalTo(EnumSet.of(FilterType.VARIANT_EFFECT_FILTER, FilterType.QUALITY_FILTER))); assertThat(passesAllFilters.passedFilter(FilterType.ENTREZ_GENE_ID_FILTER), is(false)); assertThat(passesQualityFrequencyFilter.passedFilters(), is(false)); assertThat(passesQualityFrequencyFilter.getPassedFilterTypes().isEmpty(), is(true)); assertThat(passesTargetQualityFilter.passedFilters(), is(true)); assertThat(passesTargetQualityFilter.getPassedFilterTypes(), equalTo(EnumSet.of(FilterType.VARIANT_EFFECT_FILTER, FilterType.QUALITY_FILTER))); assertThat(failsAllFilters.passedFilters(), is(false)); assertThat(failsAllFilters.getPassedFilterTypes().isEmpty(), is(true)); }
@Test public void testRunReturnsVariantsPassingQualityAndVariantEffectFilters() { List<VariantFilter> filters = new ArrayList<>(); filters.add(qualityFilter); filters.add(variantEffectFilter); filters.forEach(filter -> instance.run(filter, variantEvaluations)); assertThat(passesAllFilters.passedFilters(), is(true)); assertThat(passesAllFilters.getPassedFilterTypes(), equalTo(EnumSet.of(FilterType.VARIANT_EFFECT_FILTER, FilterType.QUALITY_FILTER))); assertThat(passesAllFilters.passedFilter(FilterType.ENTREZ_GENE_ID_FILTER), is(false)); assertThat(passesQualityFrequencyFilter.passedFilters(), is(false)); assertThat(passesQualityFrequencyFilter.getPassedFilterTypes(), equalTo(EnumSet.of(FilterType.QUALITY_FILTER))); assertThat(passesTargetQualityFilter.passedFilters(), is(true)); assertThat(passesTargetQualityFilter.getPassedFilterTypes(), equalTo(EnumSet.of(FilterType.VARIANT_EFFECT_FILTER, FilterType.QUALITY_FILTER))); assertThat(failsAllFilters.passedFilters(), is(false)); assertThat(failsAllFilters.getPassedFilterTypes().isEmpty(), is(true)); }
@Test public void testRunWithOneFilterOnlyReturnsVariantPassingAllFilters() { VariantFilter filterToPass = qualityFilter; List<VariantEvaluation> expResult = new ArrayList<>(); expResult.add(passesTargetQualityFilter); expResult.add(passesQualityFrequencyFilter); expResult.add(passesAllFilters); List<VariantEvaluation> result = instance.run(filterToPass, variantEvaluations); assertThat(result, equalTo(expResult)); for (VariantEvaluation variantEvaluation : result) { assertPassedFilterAndFailedAllOthers(variantEvaluation, filterToPass); } }
@Test public void testRunWithOneFilterUsingStreamOnlyReturnsVariantPassingAllFilters() { VariantFilter filterToPass = qualityFilter; List<VariantEvaluation> expResult = new ArrayList<>(); expResult.add(passesTargetQualityFilter); expResult.add(passesQualityFrequencyFilter); expResult.add(passesAllFilters); List<VariantEvaluation> result = variantEvaluations.stream() .filter(variantEvaluation -> { instance.run(filterToPass, variantEvaluation); return variantEvaluation.passedFilters(); }) .collect(toList()); assertThat(result, equalTo(expResult)); for (VariantEvaluation variantEvaluation : result) { assertPassedFilterAndFailedAllOthers(variantEvaluation, filterToPass); } }