Skip to content

Commit

Permalink
Put non-numerical values to the end
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzhaoyuan authored and alisman committed Dec 6, 2024
1 parent 31a3b0d commit ceb19a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public static StudyViewFilterHelper build(@Nullable StudyViewFilter studyViewFil
List<GenomicDataFilter> mergedGenomicDataFilters = mergeDataFilters(studyViewFilter.getGenomicDataFilters());
studyViewFilter.setGenomicDataFilters(mergedGenomicDataFilters);
}
if (studyViewFilter.getClinicalDataFilters() != null && !studyViewFilter.getClinicalDataFilters().isEmpty()) {
List<ClinicalDataFilter> mergedClinicalDataFilters = mergeDataFilters(studyViewFilter.getClinicalDataFilters());
studyViewFilter.setClinicalDataFilters(mergedClinicalDataFilters);
}
if (studyViewFilter.getGenericAssayDataFilters() != null && !studyViewFilter.getGenericAssayDataFilters().isEmpty()) {
List<GenericAssayDataFilter> mergedGenericAssayDataFilters = mergeDataFilters(studyViewFilter.getGenericAssayDataFilters());
studyViewFilter.setGenericAssayDataFilters(mergedGenericAssayDataFilters);
Expand Down Expand Up @@ -114,13 +118,14 @@ public static <T extends DataFilter> List<T> mergeDataFilters(List<T> filters) {

for (T filter : filters) {
List<DataFilterValue> mergedValues = new ArrayList<>();
List<DataFilterValue> nonNumericalValues = new ArrayList<>();

BigDecimal mergedStart = null;
BigDecimal mergedEnd = null;
for (DataFilterValue dataFilterValue : filter.getValues()) {
// leave non-numerical values as they are
if (dataFilterValue.getValue() != null) {
mergedValues.add(dataFilterValue);
nonNumericalValues.add(dataFilterValue);
}
// merge adjacent numerical bins
else {
Expand All @@ -142,6 +147,7 @@ else if (mergedEnd.equals(start)) {
}

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 @@ -73,7 +73,7 @@ public void testMergeDataFilterNumericalInfiniteValues() {
assertNull(end);
}

// (-2.5, -2.25], (-2.25, -2], "NA" -> "NA", (-2.5, -1.75]
// (-2.5, -2.25], (-2.25, -2], "NA" -> (-2.5, -1.75], "NA"
@Test
public void testMergeDataFilterNumericalNonNumericalValues() {
List<GenomicDataFilter> genomicDataFilters = new ArrayList<>();
Expand All @@ -85,11 +85,11 @@ public void testMergeDataFilterNumericalNonNumericalValues() {

List<GenomicDataFilter> mergedGenomicDataFilters = StudyViewFilterHelper.mergeDataFilters(genomicDataFilters);
List<DataFilterValue> mergedDataFilterValues = mergedGenomicDataFilters.getFirst().getValues();
String value = mergedDataFilterValues.getFirst().getValue();
BigDecimal start = mergedDataFilterValues.get(1).getStart();
BigDecimal end = mergedDataFilterValues.get(1).getEnd();
assertEquals("NA", value);
BigDecimal start = mergedDataFilterValues.getFirst().getStart();
BigDecimal end = mergedDataFilterValues.getFirst().getEnd();
String value = mergedDataFilterValues.get(1).getValue();
assertEquals(0, BigDecimal.valueOf(-2.5).compareTo(start));
assertEquals(0, BigDecimal.valueOf(-2).compareTo(end));
assertEquals("NA", value);
}
}

0 comments on commit ceb19a5

Please sign in to comment.