Skip to content

Commit

Permalink
make xy plot data cacheable (#11278)
Browse files Browse the repository at this point in the history
  • Loading branch information
onursumer authored Jan 10, 2025
1 parent fc6e424 commit 19599f2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@ public interface StudyViewColumnarService {
List<ClinicalDataCountItem> getGenericAssayDataBinCounts(StudyViewFilter studyViewFilter, List<GenericAssayDataBinFilter> genericAssayDataBinFilters);

List<GenomicDataCountItem> getMutationTypeCountsByGeneSpecific(StudyViewFilter studyViewFilter, List<GenomicDataFilter> genomicDataFilters);

List<ClinicalData> fetchClinicalDataForXyPlot(StudyViewFilter studyViewFilter, List<String> attributeIds, boolean shouldFilterNonEmptyClinicalData);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import static org.cbioportal.web.columnar.util.ClinicalDataXyPlotUtil.combineClinicalDataForXyPlot;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -273,6 +276,33 @@ public List<GenomicDataCountItem> getMutationTypeCountsByGeneSpecific(StudyViewF
return studyViewRepository.getMutationCountsByType(createContext(studyViewFilter), genomicDataFilters);
}

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfilteredQuery(#studyViewFilter)"
)
@Override
public List<ClinicalData> fetchClinicalDataForXyPlot(
StudyViewFilter studyViewFilter,
List<String> attributeIds,
boolean shouldFilterNonEmptyClinicalData
) {
List<ClinicalData> sampleClinicalDataList = this.getSampleClinicalData(studyViewFilter, attributeIds);
List<ClinicalData> patientClinicalDataList = this.getPatientClinicalData(studyViewFilter, attributeIds);
List<Sample> samples = Collections.emptyList();

if (!patientClinicalDataList.isEmpty()) {
// fetch samples for the given study view filter.
// we need this to construct the complete patient to sample map.
samples = this.getFilteredSamples(studyViewFilter);
}

return combineClinicalDataForXyPlot(
sampleClinicalDataList,
patientClinicalDataList,
samples,
shouldFilterNonEmptyClinicalData
);
}

private StudyViewFilterContext createContext(StudyViewFilter studyViewFilter) {
List<CustomSampleIdentifier> customSampleIdentifiers = customDataFilterUtil.extractCustomDataSamples(studyViewFilter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@
import java.util.Map;
import java.util.stream.Collectors;

import static org.cbioportal.web.columnar.util.ClinicalDataXyPlotUtil.fetchClinicalDataForXyPlot;

@InternalApi
@RestController()
@RequestMapping("/api")
Expand Down Expand Up @@ -307,8 +305,7 @@ public ResponseEntity<DensityPlotData> fetchClinicalDataDensityPlot(
.yAxisLogScale(yAxisLogScale)
.build();

List<ClinicalData> combinedClinicalDataList = fetchClinicalDataForXyPlot(
studyViewColumnarService,
List<ClinicalData> combinedClinicalDataList = studyViewColumnarService.fetchClinicalDataForXyPlot(
interceptedStudyViewFilter,
List.of(xAxisAttributeId, yAxisAttributeId),
false
Expand Down Expand Up @@ -369,8 +366,7 @@ public ResponseEntity<ClinicalViolinPlotData> fetchClinicalDataViolinPlots(
.ifPresent(f->interceptedStudyViewFilter.getClinicalDataFilters().remove(f));
}

List<ClinicalData> combinedClinicalDataList = fetchClinicalDataForXyPlot(
studyViewColumnarService,
List<ClinicalData> combinedClinicalDataList = studyViewColumnarService.fetchClinicalDataForXyPlot(
interceptedStudyViewFilter,
List.of(numericalAttributeId, categoricalAttributeId),
true // filter out clinical data with empty attribute values due to Clickhouse migration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import org.cbioportal.model.ClinicalData;
import org.cbioportal.model.Sample;
import org.cbioportal.service.StudyViewColumnarService;
import org.cbioportal.web.parameter.StudyViewFilter;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -12,15 +10,13 @@
import java.util.stream.Stream;

public class ClinicalDataXyPlotUtil {
public static List<ClinicalData> fetchClinicalDataForXyPlot(
StudyViewColumnarService studyViewColumnarService,
StudyViewFilter studyViewFilter,
List<String> attributeIds,
public static List<ClinicalData> combineClinicalDataForXyPlot(
List<ClinicalData> sampleClinicalDataList,
List<ClinicalData> patientClinicalDataList,
List<Sample> samples,
boolean shouldFilterNonEmptyClinicalData
) {
List<ClinicalData> combinedClinicalDataList;
List<ClinicalData> sampleClinicalDataList = studyViewColumnarService.getSampleClinicalData(studyViewFilter, attributeIds);
List<ClinicalData> patientClinicalDataList = studyViewColumnarService.getPatientClinicalData(studyViewFilter, attributeIds);

if (shouldFilterNonEmptyClinicalData) {
sampleClinicalDataList = filterNonEmptyClinicalData(sampleClinicalDataList);
Expand All @@ -30,10 +26,6 @@ public static List<ClinicalData> fetchClinicalDataForXyPlot(
if (patientClinicalDataList.isEmpty()) {
combinedClinicalDataList = sampleClinicalDataList;
} else {
// fetch samples for the given study view filter.
// we need this to construct the complete patient to sample map.
List<Sample> samples = studyViewColumnarService.getFilteredSamples(studyViewFilter);

combinedClinicalDataList = Stream.concat(
sampleClinicalDataList.stream(),
convertPatientClinicalDataToSampleClinicalData(patientClinicalDataList, samples).stream()
Expand Down

0 comments on commit 19599f2

Please sign in to comment.