Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make XY plot data cacheable #11278

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading