Skip to content

Commit

Permalink
Fix non-numerical value only list
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzhaoyuan authored and alisman committed Dec 6, 2024
1 parent ceb19a5 commit 803f257
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public boolean isCategoricalClinicalDataFilter(ClinicalDataFilter clinicalDataFi
* Merge the range of numerical bins in DataFilters to reduce the number of scans that runs on the database when filtering.
*/
public static <T extends DataFilter> List<T> mergeDataFilters(List<T> filters) {
boolean isNonNumericalOnly = true;
List<T> mergedDataFilters = new ArrayList<>();

for (T filter : filters) {
Expand All @@ -129,6 +130,7 @@ public static <T extends DataFilter> List<T> mergeDataFilters(List<T> filters) {
}
// merge adjacent numerical bins
else {
isNonNumericalOnly = false;
BigDecimal start = dataFilterValue.getStart();
BigDecimal end = dataFilterValue.getEnd();

Expand All @@ -146,7 +148,9 @@ else if (mergedEnd.equals(start)) {
}
}

mergedValues.add(new DataFilterValue(mergedStart, mergedEnd, null));
if (!isNonNumericalOnly) {
mergedValues.add(new DataFilterValue(mergedStart, mergedEnd, null));
}
mergedValues.addAll(nonNumericalValues);
filter.setValues(mergedValues);
mergedDataFilters.add(filter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void testMergeDataFilterNumericalInfiniteValues() {
}

// (-2.5, -2.25], (-2.25, -2], "NA" -> (-2.5, -1.75], "NA"
// This test also ensures the non-numerical values gets moved to the end
@Test
public void testMergeDataFilterNumericalNonNumericalValues() {
List<GenomicDataFilter> genomicDataFilters = new ArrayList<>();
Expand All @@ -92,4 +93,18 @@ public void testMergeDataFilterNumericalNonNumericalValues() {
assertEquals(0, BigDecimal.valueOf(-2).compareTo(end));
assertEquals("NA", value);
}

// "NA" -> "NA"
@Test
public void testMergeDataFilterNonNumericalOnlyValues() {
List<GenomicDataFilter> genomicDataFilters = new ArrayList<>();
List<DataFilterValue> values = new ArrayList<>();
values.add(new DataFilterValue(null, null, "NA"));
genomicDataFilters.add(new GenomicDataFilter(null, null, values));

List<GenomicDataFilter> mergedGenomicDataFilters = StudyViewFilterHelper.mergeDataFilters(genomicDataFilters);
List<DataFilterValue> mergedDataFilterValues = mergedGenomicDataFilters.getFirst().getValues();
String value = mergedDataFilterValues.getFirst().getValue();
assertEquals("NA", value);
}
}

0 comments on commit 803f257

Please sign in to comment.