Skip to content

Commit

Permalink
Fix tests, compilation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ramari16 committed Mar 27, 2024
1 parent 275e316 commit acec7bc
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public Map<String, FileBackedByteIndexedInfoStore> mergeVariantIndexes() throws
String[] variantIndex2 = variantStore2.getVariantSpecIndex();

Map<String, Integer> variantSpecToIndexMap = new HashMap<>();
LinkedList<String> variantSpecList = new LinkedList<>(Arrays.asList(variantIndex1));
LinkedList<String> variantSpecList = new LinkedList<>(List.of(variantIndex1));
for (int i = 0; i < variantIndex1.length; i++) {
variantSpecToIndexMap.put(variantIndex1[i], i);
}
Expand Down Expand Up @@ -251,13 +251,13 @@ public FileBackedJsonIndexStorage<Integer, ConcurrentHashMap<String, VariableVar
log.info("Mask 2: " + Optional.ofNullable(variantMasks2.heterozygousMask).map(VariantMask::toString).orElse("empty"));
log.info("Merged mask: " + Optional.ofNullable(mergeResult.heterozygousMask).map(VariantMask::toString).orElse("empty"));

Set<Integer> patientIds1 = VariableVariantMasks.patientMaskToPatientIdSet(Optional.ofNullable(entry.getValue().heterozygousMask).orElse(VariantMask.emptyInstance()), Arrays.asList(variantStore1.getPatientIds()));
Set<Integer> patientIds1 = Optional.ofNullable(entry.getValue().heterozygousMask).orElse(VariantMask.emptyInstance()).patientMaskToPatientIdSet(List.of(variantStore1.getPatientIds()));
log.info("Patients 1: " + Joiner.on(",").join(patientIds1));

Set<Integer> patientIds2 = VariableVariantMasks.patientMaskToPatientIdSet(Optional.ofNullable(variantMasks2.heterozygousMask).orElse(VariantMask.emptyInstance()), Arrays.asList(variantStore2.getPatientIds()));
Set<Integer> patientIds2 = Optional.ofNullable(variantMasks2.heterozygousMask).orElse(VariantMask.emptyInstance()).patientMaskToPatientIdSet(List.of(variantStore2.getPatientIds()));
log.info("Patients 2: " + Joiner.on(",").join(patientIds2));

Set<Integer> mergedPatientIds = VariableVariantMasks.patientMaskToPatientIdSet(Optional.ofNullable(mergeResult.heterozygousMask).orElse(VariantMask.emptyInstance()), Arrays.asList(mergedVariantStore.getPatientIds()));
Set<Integer> mergedPatientIds = Optional.ofNullable(mergeResult.heterozygousMask).orElse(VariantMask.emptyInstance()).patientMaskToPatientIdSet(List.of(mergedVariantStore.getPatientIds()));
log.info("Merged patient ids: " + Joiner.on(",").join(mergedPatientIds));
}
mergedMasks.put(entry.getKey(), mergeResult);
Expand Down Expand Up @@ -301,7 +301,7 @@ public FileBackedJsonIndexStorage<Integer, ConcurrentHashMap<String, VariableVar
maskMap.keySet().stream().sorted().limit(5).forEach(variantSpec -> {
VariableVariantMasks variableVariantMasks = maskMap.get(variantSpec);
VariantMask heteroMask = Optional.ofNullable(variableVariantMasks.heterozygousMask).orElse(VariantMask.emptyInstance());
Set<Integer> patientsWithVariant = VariableVariantMasks.patientMaskToPatientIdSet(heteroMask, Arrays.asList(mergedVariantStore.getPatientIds()));
Set<Integer> patientsWithVariant = heteroMask.patientMaskToPatientIdSet(List.of(mergedVariantStore.getPatientIds()));
log.trace("Patients with variant [" + variantSpec + "]: " + Joiner.on(",").join(patientsWithVariant));
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public VariantMask runGetPatientMask(DistributableQuery distributableQuery) {

@Override
public Set<Integer> patientMaskToPatientIdSet(VariantMask patientMask) {
return VariableVariantMasks.patientMaskToPatientIdSet(patientMask, getPatientIds());
return patientMask.patientMaskToPatientIdSet(getPatientIds());
}

private List<VariantIndex> getVariantsMatchingFilters(Query.VariantInfoFilter filter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Mono<VariantMask> getPatientMask(DistributableQuery distributableQuery) {

@Override
public Set<Integer> patientMaskToPatientIdSet(VariantMask patientMask) {
return VariableVariantMasks.patientMaskToPatientIdSet(patientMask, getPatientIds());
return patientMask.patientMaskToPatientIdSet(getPatientIds());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public SizedVariantMask appendMask(SizedVariantMask mask1, SizedVariantMask mask

@Override
public Set<Integer> patientMaskToPatientIdSet(VariantMask patientMask) {
return VariableVariantMasks.patientMaskToPatientIdSet(patientMask, getPatientIds());
return patientMask.patientMaskToPatientIdSet(getPatientIds());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void getPatientMask_validResponses_returnMerged() {
when(mockProcessor2.getPatientMask(distributableQuery)).thenReturn(Mono.just(new VariantMaskBitmaskImpl(new BigInteger("110001100011", 2))));
when(mockProcessor3.getPatientMask(distributableQuery)).thenReturn(Mono.just(new VariantMaskBitmaskImpl(new BigInteger("11000111", 2))));
VariantMask patientMask = patientMergingParent.getPatientMask(distributableQuery).block();
VariantMask expectedPatientMask = new VariantMaskBitmaskImpl(new BigInteger("11011000011000000111", 2));
VariantMask expectedPatientMask = new VariantMaskBitmaskImpl(new BigInteger("11000100011000011011", 2));
assertEquals(expectedPatientMask, patientMask);
}

Expand All @@ -54,7 +54,7 @@ public void getPatientMask_noPatientResponses_returnMerged() {
when(mockProcessor2.getPatientMask(distributableQuery)).thenReturn(Mono.just(new VariantMaskBitmaskImpl(new BigInteger("110000000011", 2))));
when(mockProcessor3.getPatientMask(distributableQuery)).thenReturn(Mono.just(new VariantMaskBitmaskImpl(new BigInteger("11000011", 2))));
VariantMask patientMask = patientMergingParent.getPatientMask(distributableQuery).block();
VariantMask expectedPatientMask = new VariantMaskBitmaskImpl(new BigInteger("11011000000000000011", 2));
VariantMask expectedPatientMask = new VariantMaskBitmaskImpl(new BigInteger("11000000000000011011", 2));
assertEquals(expectedPatientMask, patientMask);
}

Expand All @@ -65,7 +65,7 @@ public void getPatientMask_emptyResponses_returnMerged() {
when(mockProcessor2.getPatientMask(distributableQuery)).thenReturn(Mono.just(new VariantMaskBitmaskImpl(new BigInteger("1111", 2))));
when(mockProcessor3.getPatientMask(distributableQuery)).thenReturn(Mono.just(new VariantMaskBitmaskImpl(new BigInteger("11000111", 2))));
VariantMask patientMask = patientMergingParent.getPatientMask(distributableQuery).block();
VariantMask expectedPatientMask = new VariantMaskBitmaskImpl(new BigInteger("110110000111", 2));
VariantMask expectedPatientMask = new VariantMaskBitmaskImpl(new BigInteger("110001011011", 2));
assertEquals(expectedPatientMask, patientMask);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class PatientVariantJoinHandlerTest {

public static final String[] PATIENT_IDS = {"101", "102", "103", "104", "105", "106", "107", "108"};
public static final Set<Integer> PATIENT_IDS_INTEGERS = Set.of(PATIENT_IDS).stream().map(Integer::parseInt).collect(Collectors.toSet());
public static final String[] VARIANT_INDEX = {"16,61642243,A,T", "16,61642252,A,G", "16,61642256,C,T", "16,61642257,G,A", "16,61642258,G,A", "16,61642259,G,A", "16,61642260,G,A", "16,61642261,G,A"};
public static final String[] VARIANT_INDEX = {"16,61642243,A,T,ABC,consequence1", "16,61642252,A,G,ABC,consequence1", "16,61642256,C,T,ABC,consequence2", "16,61642257,G,A,ABC,consequence3", "16,61642258,G,A,ABC,consequence3", "16,61642259,G,A,ABC,consequence1", "16,61642260,G,A,ABC,consequence1", "16,61642261,G,A,ABC,consequence1"};

public PatientVariantJoinHandlerTest(@Mock VariantService variantService) {
this.variantService = variantService;
Expand All @@ -54,7 +54,7 @@ public void getPatientIdsForIntersectionOfVariantSets_allPatientsMatchOneVariant
when(variantService.getMasks(eq(VARIANT_INDEX[2]), any())).thenReturn(Optional.of(emptyVariantMasks));
when(variantService.getMasks(eq(VARIANT_INDEX[4]), any())).thenReturn(Optional.of(emptyVariantMasks));

Set<Integer> patientIdsForIntersectionOfVariantSets = VariableVariantMasks.patientMaskToPatientIdSet(patientVariantJoinHandler.getPatientIdsForIntersectionOfVariantSets(null, intersectionOfInfoFilters), List.of(PATIENT_IDS));
Set<Integer> patientIdsForIntersectionOfVariantSets = patientVariantJoinHandler.getPatientIdsForIntersectionOfVariantSets(null, intersectionOfInfoFilters).patientMaskToPatientIdSet(List.of(PATIENT_IDS));
// this should be all patients, as all patients match one of the variants
assertEquals(PATIENT_IDS_INTEGERS, patientIdsForIntersectionOfVariantSets);
}
Expand All @@ -76,7 +76,7 @@ public void getPatientIdsForIntersectionOfVariantSets_allPatientsMatchOneVariant
when(variantService.getMasks(eq(VARIANT_INDEX[2]), any())).thenReturn(Optional.empty());
when(variantService.getMasks(eq(VARIANT_INDEX[4]), any())).thenReturn(Optional.empty());

Set<Integer> patientIdsForIntersectionOfVariantSets = VariableVariantMasks.patientMaskToPatientIdSet(patientVariantJoinHandler.getPatientIdsForIntersectionOfVariantSets(null, intersectionOfInfoFilters), List.of(PATIENT_IDS));
Set<Integer> patientIdsForIntersectionOfVariantSets = patientVariantJoinHandler.getPatientIdsForIntersectionOfVariantSets(null, intersectionOfInfoFilters).patientMaskToPatientIdSet(List.of(PATIENT_IDS));
// this should be all patients, as all patients match one of the variants
assertEquals(PATIENT_IDS_INTEGERS, patientIdsForIntersectionOfVariantSets);
}
Expand All @@ -94,7 +94,7 @@ public void getPatientIdsForIntersectionOfVariantSets_noPatientsMatchVariants()
when(variantService.getMasks(eq(VARIANT_INDEX[2]), any())).thenReturn(Optional.of(emptyVariantMasks));
when(variantService.getMasks(eq(VARIANT_INDEX[4]), any())).thenReturn(Optional.of(emptyVariantMasks));

Set<Integer> patientIdsForIntersectionOfVariantSets = VariableVariantMasks.patientMaskToPatientIdSet(patientVariantJoinHandler.getPatientIdsForIntersectionOfVariantSets(Set.of(), intersectionOfInfoFilters), List.of(PATIENT_IDS));
Set<Integer> patientIdsForIntersectionOfVariantSets = patientVariantJoinHandler.getPatientIdsForIntersectionOfVariantSets(Set.of(), intersectionOfInfoFilters).patientMaskToPatientIdSet(List.of(PATIENT_IDS));
// this should be empty because all variants masks have no matching patients
assertEquals(Set.of(), patientIdsForIntersectionOfVariantSets);
}
Expand All @@ -114,7 +114,7 @@ public void getPatientIdsForIntersectionOfVariantSets_somePatientsMatchVariants(
when(variantService.getMasks(eq(VARIANT_INDEX[0]), any())).thenReturn(Optional.of(variantMasks));
when(variantService.getMasks(eq(VARIANT_INDEX[2]), any())).thenReturn(Optional.of(variantMasks2));

Set<Integer> patientIdsForIntersectionOfVariantSets = VariableVariantMasks.patientMaskToPatientIdSet(patientVariantJoinHandler.getPatientIdsForIntersectionOfVariantSets(null, intersectionOfInfoFilters), List.of(PATIENT_IDS));
Set<Integer> patientIdsForIntersectionOfVariantSets = patientVariantJoinHandler.getPatientIdsForIntersectionOfVariantSets(null, intersectionOfInfoFilters).patientMaskToPatientIdSet(List.of(PATIENT_IDS));
// this should be all patients who match at least one variant
assertEquals(Set.of(101, 103, 105), patientIdsForIntersectionOfVariantSets);
}
Expand All @@ -124,7 +124,7 @@ public void getPatientIdsForIntersectionOfVariantSets_noVariants() {
VariantIndex intersectionOfInfoFilters = VariantIndex.empty();
when(variantService.getPatientIds()).thenReturn(PATIENT_IDS);

Set<Integer> patientIdsForIntersectionOfVariantSets = VariableVariantMasks.patientMaskToPatientIdSet(patientVariantJoinHandler.getPatientIdsForIntersectionOfVariantSets(null, intersectionOfInfoFilters), List.of(PATIENT_IDS));
Set<Integer> patientIdsForIntersectionOfVariantSets = patientVariantJoinHandler.getPatientIdsForIntersectionOfVariantSets(null, intersectionOfInfoFilters).patientMaskToPatientIdSet(List.of(PATIENT_IDS));
// this should be empty, as there are no variants
assertEquals(Set.of(), patientIdsForIntersectionOfVariantSets);
}
Expand All @@ -144,7 +144,7 @@ public void getPatientIdsForIntersectionOfVariantSets_patientSubsetPassed() {
when(variantService.getMasks(eq(VARIANT_INDEX[0]), any())).thenReturn(Optional.of(variantMasks));
when(variantService.getMasks(eq(VARIANT_INDEX[2]), any())).thenReturn(Optional.of(variantMasks2));

Set<Integer> patientIdsForIntersectionOfVariantSets = VariableVariantMasks.patientMaskToPatientIdSet(patientVariantJoinHandler.getPatientIdsForIntersectionOfVariantSets(Set.of(102, 103, 104, 105, 106), intersectionOfInfoFilters), List.of(PATIENT_IDS));
Set<Integer> patientIdsForIntersectionOfVariantSets = patientVariantJoinHandler.getPatientIdsForIntersectionOfVariantSets(Set.of(102, 103, 104, 105, 106), intersectionOfInfoFilters).patientMaskToPatientIdSet(List.of(PATIENT_IDS));
// this should be the union of patients matching variants (101, 103, 105, 107), intersected with the patient subset parameter (103, 104, 105) which is (103, 105)
assertEquals(Set.of(103, 105), patientIdsForIntersectionOfVariantSets);
}
Expand Down

0 comments on commit acec7bc

Please sign in to comment.