Skip to content

Commit

Permalink
Add empty variant index
Browse files Browse the repository at this point in the history
  • Loading branch information
ramari16 committed Jan 3, 2024
1 parent 882b68c commit 69c56bb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public BigInteger runGetPatientMask(DistributableQuery distributableQuery) {
List<VariantIndex> variantSets = getVariantsMatchingFilters(filter);
log.info("Found " + variantSets.size() + " groups of sets for patient identification");
if(!variantSets.isEmpty()) {
VariantIndex unionOfVariantSets = new SparseVariantIndex(Set.of());
VariantIndex unionOfVariantSets = VariantIndex.empty();
for(VariantIndex variantSet : variantSets) {
unionOfVariantSets = unionOfVariantSets.union(variantSet);
}
Expand All @@ -100,8 +100,7 @@ public BigInteger runGetPatientMask(DistributableQuery distributableQuery) {
intersectionOfInfoFilters = intersectionOfInfoFilters.intersection(unionOfVariantSets);
}
} else {
// todo: create an empty variant index implementation
intersectionOfInfoFilters = new SparseVariantIndex(Set.of());
intersectionOfInfoFilters = VariantIndex.empty();
}
}
// todo: handle empty getVariantInfoFilters()
Expand Down Expand Up @@ -194,14 +193,14 @@ private VariantIndex getComputedVariantIndexForCategoryFilter(Map.Entry<String,
.reduce(VariantIndex::union)
.orElseGet(() -> {
log.info("No variant index computed for category filter. This should never happen");
return new SparseVariantIndex(Set.of());
return VariantIndex.empty();
});
} else if(infoKeys.size() == 1) {
return variantIndexCache.get(column, infoKeys.get(0));
} else { // infoKeys.size() == 0
log.info("No indexes found for column [" + column + "] for values [" + Joiner.on(",").join(values) + "]");
// todo: test this case. should this be empty list or a list with an empty VariantIndex?
return new SparseVariantIndex(Set.of());
return VariantIndex.empty();
}
}

Expand Down Expand Up @@ -249,7 +248,7 @@ public Collection<String> runGetVariantList(DistributableQuery query) {
!variantInfoFilter.categoryVariantInfoFilters.isEmpty() || !variantInfoFilter.numericVariantInfoFilters.isEmpty()
);
if(queryContainsVariantInfoFilters) {
VariantIndex unionOfInfoFilters = new SparseVariantIndex(Set.of());
VariantIndex unionOfInfoFilters = VariantIndex.empty();

// todo: are these not the same thing?
if(query.getVariantInfoFilters().size()>1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ protected VariantIndex intersection(SparseVariantIndex sparseVariantIndex, Dense
.collect(Collectors.toSet());
return new SparseVariantIndex(intersection);
}

public static VariantIndex empty() {
return new SparseVariantIndex(Set.of());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void getPatientIdsForIntersectionOfVariantSets_somePatientsMatchVariants(

@Test
public void getPatientIdsForIntersectionOfVariantSets_noVariants() {
VariantIndex intersectionOfInfoFilters = new SparseVariantIndex(Set.of());
VariantIndex intersectionOfInfoFilters = VariantIndex.empty();

Set<Integer> patientIdsForIntersectionOfVariantSets = patientMaskToPatientIdSet(patientVariantJoinHandler.getPatientIdsForIntersectionOfVariantSets(Set.of(), intersectionOfInfoFilters));
// this should be empty, as there are no variants
Expand Down

0 comments on commit 69c56bb

Please sign in to comment.