Skip to content

Commit

Permalink
make xy plot data cacheable
Browse files Browse the repository at this point in the history
  • Loading branch information
onursumer committed Dec 12, 2024
1 parent fa1e4f3 commit 6109444
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 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 @@ -28,13 +28,14 @@
import org.cbioportal.web.parameter.GenericAssayDataFilter;
import org.cbioportal.web.parameter.GenomicDataBinFilter;
import org.cbioportal.web.parameter.GenomicDataFilter;
import org.cbioportal.web.parameter.SampleIdentifier;
import org.cbioportal.web.parameter.StudyViewFilter;
import org.cbioportal.web.columnar.util.CustomDataFilterUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

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

import java.util.*;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -276,6 +277,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 @@ -12,15 +12,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 +28,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 6109444

Please sign in to comment.