Skip to content

Commit

Permalink
Merge genomic data bins working
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzhaoyuan authored and alisman committed Dec 3, 2024
1 parent b72ddaa commit 7cf0368
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ public List<GenomicDataCountItem> getMutationTypeCountsByGeneSpecific(StudyViewF


private StudyViewFilterContext createContext(StudyViewFilter studyViewFilter) {
studyViewFilter.mergeDataFilterNumericalValues();
List<CustomSampleIdentifier> customSampleIdentifiers = customDataFilterUtil.extractCustomDataSamples(studyViewFilter);
return new StudyViewFilterContext(studyViewFilter, customSampleIdentifiers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ public class DataFilterValue implements Serializable {
private BigDecimal end;
private String value;

public DataFilterValue() {}

public DataFilterValue(BigDecimal start, BigDecimal end, String value) {
this.start = start;
this.end = end;
this.value = value;
}

public BigDecimal getStart() {
return start;
}
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/org/cbioportal/web/parameter/StudyViewFilter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.cbioportal.web.parameter;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -41,6 +43,7 @@ public class StudyViewFilter implements Serializable {
private AlterationFilter alterationFilter;
private List<DataFilter> clinicalEventFilters;
private List<MutationDataFilter> mutationDataFilters;
private static boolean areBinsMerged = false;

@AssertTrue
private boolean isEitherSampleIdentifiersOrStudyIdsPresent() {
Expand Down Expand Up @@ -230,4 +233,46 @@ public void setClinicalEventFilters(List<DataFilter> clinicalEventFilters) {
public void setMutationDataFilters(List<MutationDataFilter> mutationDataFilters) {
this.mutationDataFilters = mutationDataFilters;
}

/**
* Merge the range of numerical values in DataFilters to reduce the number of scans that runs on the database.
* Variable 'areBinsMerged' is static so this method only gets run once.
*/
public void mergeDataFilterNumericalValues() {
if (areBinsMerged || this.genomicDataFilters == null || this.genomicDataFilters.isEmpty()) return;

List<GenomicDataFilter> mergedGenomicDataFilters = new ArrayList<>();

for (GenomicDataFilter genomicDataFilter : this.genomicDataFilters) {
GenomicDataFilter mergedGenomicDataFilter = new GenomicDataFilter(genomicDataFilter.getHugoGeneSymbol(), genomicDataFilter.getProfileType());
List<DataFilterValue> mergedValues = new ArrayList<>();

boolean hasNullStart = false, hasNullEnd = false;
BigDecimal mergedStart = null, mergedEnd = null;
for (DataFilterValue dataFilterValue : genomicDataFilter.getValues()) {
// filter non-numerical values and keep them intact
if (dataFilterValue.getValue() != null) {
mergedValues.add(dataFilterValue);
}
// record if numerical values have null start or end, otherwise record their start-end range
else {
if (dataFilterValue.getStart() == null) hasNullStart = true;
else if (mergedStart == null) mergedStart = dataFilterValue.getStart();
else if (dataFilterValue.getStart().compareTo(mergedStart) < 0) mergedStart = dataFilterValue.getStart();
if (dataFilterValue.getEnd() == null) hasNullEnd = true;
else if (mergedEnd == null) mergedEnd = dataFilterValue.getEnd();
else if (dataFilterValue.getEnd().compareTo(mergedEnd) > 0) mergedEnd = dataFilterValue.getEnd();
}
}
if (hasNullStart) mergedStart = null;
if (hasNullEnd) mergedEnd = null;

mergedValues.add(new DataFilterValue(mergedStart, mergedEnd, null));
mergedGenomicDataFilter.setValues(mergedValues);
mergedGenomicDataFilters.add(mergedGenomicDataFilter);
}

this.genomicDataFilters = mergedGenomicDataFilters;
areBinsMerged = true;
}
}

0 comments on commit 7cf0368

Please sign in to comment.