Skip to content

Commit

Permalink
Add isUnfiltered condition to cacheable clickhouse methods (#11120)
Browse files Browse the repository at this point in the history
* add singleStudyUnfiltered condition to cacheable clickhouse methods

* add condition for density and violin plot data methods

* change singleStudyUnfiltered to just unfiltered

---------

Co-authored-by: Bryan Lai <[email protected]>
  • Loading branch information
gblaih and Bryan Lai authored Oct 28, 2024
1 parent 6d87467 commit d4fece4
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import org.cbioportal.model.ClinicalData;
import org.cbioportal.model.DensityPlotData;
import org.cbioportal.web.parameter.StudyViewFilter;
import org.cbioportal.web.util.DensityPlotParameters;

import java.math.BigDecimal;
import java.util.List;

public interface ClinicalDataDensityPlotService {
DensityPlotData getDensityPlotData(List<ClinicalData> filteredClinicalData, DensityPlotParameters densityPlotParameters);
DensityPlotData getDensityPlotData(List<ClinicalData> filteredClinicalData, DensityPlotParameters densityPlotParameters, StudyViewFilter studyViewFilter);
}
4 changes: 3 additions & 1 deletion src/main/java/org/cbioportal/service/ViolinPlotService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.cbioportal.model.ClinicalData;
import org.cbioportal.model.ClinicalViolinPlotData;
import org.cbioportal.model.Sample;
import org.cbioportal.web.parameter.StudyViewFilter;

import java.math.BigDecimal;
import java.util.List;
Expand All @@ -15,6 +16,7 @@ ClinicalViolinPlotData getClinicalViolinPlotData(
BigDecimal axisEnd,
BigDecimal numCurvePoints,
Boolean useLogScale,
BigDecimal sigmaMultiplier
BigDecimal sigmaMultiplier,
StudyViewFilter studyViewFilter
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.cbioportal.model.DensityPlotData;
import org.cbioportal.service.ClinicalDataDensityPlotService;
import org.cbioportal.web.columnar.StudyViewColumnStoreController;
import org.cbioportal.web.parameter.StudyViewFilter;
import org.cbioportal.web.util.DensityPlotParameters;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
Expand All @@ -25,10 +26,10 @@ public class ClinicalDataDensityPlotServiceImpl implements ClinicalDataDensityPl

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfiltered(#studyViewFilter)"
)
@Override
public DensityPlotData getDensityPlotData(List<ClinicalData> sampleClinicalData, DensityPlotParameters densityPlotParameters) {
public DensityPlotData getDensityPlotData(List<ClinicalData> sampleClinicalData, DensityPlotParameters densityPlotParameters, StudyViewFilter studyViewFilter) {
DensityPlotData result = new DensityPlotData();
result.setBins(new ArrayList<>());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ public StudyViewColumnarServiceImpl(StudyViewRepository studyViewRepository, Alt
this.treatmentCountReportService = treatmentCountReportService;
this.customDataFilterUtil = customDataFilterUtil;
}

// should condition = "@cacheEnabledConfig.getEnabledClickhouse() && #singleStudyUnfiltered"

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfiltered(#studyViewFilter)"
)
@Override
public List<Sample> getFilteredSamples(StudyViewFilter studyViewFilter) {
Expand All @@ -65,7 +64,7 @@ public List<Sample> getFilteredSamples(StudyViewFilter studyViewFilter) {

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfiltered(#studyViewFilter)"
)
@Override
public List<AlterationCountByGene> getMutatedGenes(StudyViewFilter studyViewFilter) throws StudyNotFoundException {
Expand All @@ -74,7 +73,7 @@ public List<AlterationCountByGene> getMutatedGenes(StudyViewFilter studyViewFilt

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfiltered(#studyViewFilter)"
)
@Override
public List<GenomicDataCount> getMolecularProfileSampleCounts(StudyViewFilter studyViewFilter) {
Expand All @@ -83,7 +82,7 @@ public List<GenomicDataCount> getMolecularProfileSampleCounts(StudyViewFilter st

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfiltered(#studyViewFilter)"
)
@Override
public List<ClinicalEventTypeCount> getClinicalEventTypeCounts(StudyViewFilter studyViewFilter) {
Expand All @@ -92,7 +91,7 @@ public List<ClinicalEventTypeCount> getClinicalEventTypeCounts(StudyViewFilter s

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfiltered(#studyViewFilter)"
)
@Override
public PatientTreatmentReport getPatientTreatmentReport(StudyViewFilter studyViewFilter) {
Expand All @@ -101,7 +100,7 @@ public PatientTreatmentReport getPatientTreatmentReport(StudyViewFilter studyVie

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfiltered(#studyViewFilter)"
)
@Override
public SampleTreatmentReport getSampleTreatmentReport(StudyViewFilter studyViewFilter) {
Expand All @@ -110,7 +109,7 @@ public SampleTreatmentReport getSampleTreatmentReport(StudyViewFilter studyViewF

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfiltered(#studyViewFilter)"
)
@Override
public List<ClinicalDataCountItem> getGenomicDataBinCounts(StudyViewFilter studyViewFilter, List<GenomicDataBinFilter> genomicDataBinFilters) {
Expand All @@ -119,7 +118,7 @@ public List<ClinicalDataCountItem> getGenomicDataBinCounts(StudyViewFilter study

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfiltered(#studyViewFilter)"
)
@Override
public List<ClinicalDataCountItem> getGenericAssayDataBinCounts(StudyViewFilter studyViewFilter, List<GenericAssayDataBinFilter> genericAssayDataBinFilters) {
Expand All @@ -132,7 +131,7 @@ public List<CopyNumberCountByGene> getCnaGenes(StudyViewFilter studyViewFilter)

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfiltered(#studyViewFilter)"
)
@Override
public List<AlterationCountByGene> getStructuralVariantGenes(StudyViewFilter studyViewFilter) throws StudyNotFoundException {
Expand All @@ -141,7 +140,7 @@ public List<AlterationCountByGene> getStructuralVariantGenes(StudyViewFilter stu

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfiltered(#studyViewFilter)"
)
@Override
public Map<String, ClinicalDataType> getClinicalAttributeDatatypeMap() {
Expand All @@ -150,7 +149,7 @@ public Map<String, ClinicalDataType> getClinicalAttributeDatatypeMap() {

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfiltered(#studyViewFilter)"
)
@Override
public List<ClinicalDataCountItem> getClinicalDataCounts(StudyViewFilter studyViewFilter, List<String> filteredAttributes) {
Expand All @@ -169,7 +168,7 @@ public List<ClinicalDataCountItem> getClinicalDataCounts(StudyViewFilter studyVi

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfiltered(#studyViewFilter)"
)
@Override
public List<CaseListDataCount> getCaseListDataCounts(StudyViewFilter studyViewFilter) {
Expand All @@ -181,7 +180,7 @@ public List<CaseListDataCount> getCaseListDataCounts(StudyViewFilter studyViewFi

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfiltered(#studyViewFilter)"
)
@Override
public List<ClinicalData> getPatientClinicalData(StudyViewFilter studyViewFilter, List<String> attributeIds) {
Expand All @@ -190,7 +189,7 @@ public List<ClinicalData> getPatientClinicalData(StudyViewFilter studyViewFilter

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfiltered(#studyViewFilter)"
)
@Override
public List<ClinicalData> getSampleClinicalData(StudyViewFilter studyViewFilter, List<String> attributeIds) {
Expand All @@ -199,7 +198,7 @@ public List<ClinicalData> getSampleClinicalData(StudyViewFilter studyViewFilter,

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfiltered(#studyViewFilter)"
)
@Override
public List<GenomicDataCountItem> getCNACountsByGeneSpecific(StudyViewFilter studyViewFilter, List<GenomicDataFilter> genomicDataFilters) {
Expand All @@ -208,7 +207,7 @@ public List<GenomicDataCountItem> getCNACountsByGeneSpecific(StudyViewFilter stu

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfiltered(#studyViewFilter)"
)
@Override
public List<GenericAssayDataCountItem> getGenericAssayDataCounts(StudyViewFilter studyViewFilter, List<GenericAssayDataFilter> genericAssayDataFilters) {
Expand All @@ -217,7 +216,7 @@ public List<GenericAssayDataCountItem> getGenericAssayDataCounts(StudyViewFilter

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfiltered(#studyViewFilter)"
)
@Override
public List<GenomicDataCountItem> getMutationCountsByGeneSpecific(StudyViewFilter studyViewFilter, List<GenomicDataFilter> genomicDataFilters) {
Expand All @@ -238,7 +237,7 @@ public List<GenomicDataCountItem> getMutationCountsByGeneSpecific(StudyViewFilte

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfiltered(#studyViewFilter)"
)
@Override
public List<GenomicDataCountItem> getMutationTypeCountsByGeneSpecific(StudyViewFilter studyViewFilter, List<GenomicDataFilter> genomicDataFilters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.apache.commons.math3.stat.descriptive.rank.Percentile;
import org.cbioportal.model.*;
import org.cbioportal.service.ViolinPlotService;
import org.cbioportal.web.parameter.StudyViewFilter;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

Expand All @@ -20,7 +21,7 @@ public class ViolinPlotServiceImpl implements ViolinPlotService {

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
condition = "@cacheEnabledConfig.getEnabledClickhouse() && @studyViewFilterUtil.isUnfiltered(#studyViewFilter)"
)
public ClinicalViolinPlotData getClinicalViolinPlotData(
List<ClinicalData> sampleClinicalDataForViolinPlot,
Expand All @@ -29,7 +30,8 @@ public ClinicalViolinPlotData getClinicalViolinPlotData(
BigDecimal axisEnd,
BigDecimal numCurvePoints,
Boolean useLogScale,
BigDecimal sigmaMultiplier
BigDecimal sigmaMultiplier,
StudyViewFilter studyViewFilter
) {
ClinicalViolinPlotData result = new ClinicalViolinPlotData();
result.setAxisStart(Double.POSITIVE_INFINITY);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/cbioportal/web/StudyViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,8 @@ public ResponseEntity<ClinicalViolinPlotData> fetchClinicalDataViolinPlots(
axisEnd,
numCurvePoints,
useLogScale,
sigmaMultiplier
sigmaMultiplier,
interceptedStudyViewFilter
);

return new ResponseEntity<>(result, HttpStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public ResponseEntity<DensityPlotData> fetchClinicalDataDensityPlot(
.build();

List<ClinicalData> sampleClinicalDataList = studyViewColumnarService.getSampleClinicalData(interceptedStudyViewFilter, xyAttributeId);
DensityPlotData result = clinicalDataDensityPlotService.getDensityPlotData(sampleClinicalDataList, densityPlotParameters);
DensityPlotData result = clinicalDataDensityPlotService.getDensityPlotData(sampleClinicalDataList, densityPlotParameters, interceptedStudyViewFilter);

return new ResponseEntity<>(result, HttpStatus.OK);
}
Expand Down Expand Up @@ -378,7 +378,8 @@ public ResponseEntity<ClinicalViolinPlotData> fetchClinicalDataViolinPlots(
axisEnd,
numCurvePoints,
useLogScale,
sigmaMultiplier
sigmaMultiplier,
interceptedStudyViewFilter
);

return new ResponseEntity<>(result, HttpStatus.OK);
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/cbioportal/web/util/StudyViewFilterUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,16 @@ public List<ClinicalDataCountItem> getClinicalDataCountsFromCustomData(Collectio
}

public boolean isSingleStudyUnfiltered(StudyViewFilter filter) {
return isSingleStudy(filter) && isUnfiltered(filter);
}

public boolean isSingleStudy(StudyViewFilter filter) {
return filter.getStudyIds() != null &&
filter.getStudyIds().size() == 1;
}

public boolean isUnfiltered(StudyViewFilter filter) {
return filter.getStudyIds() != null &&
filter.getStudyIds().size() == 1 &&
(filter.getClinicalDataFilters() == null || filter.getClinicalDataFilters().isEmpty()) &&
(filter.getGeneFilters() == null || filter.getGeneFilters().isEmpty()) &&
(filter.getSampleTreatmentFilters() == null || filter.getSampleTreatmentFilters().getFilters().isEmpty()) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.cbioportal.model.ClinicalViolinPlotData;
import org.cbioportal.model.ClinicalViolinPlotRowData;
import org.cbioportal.model.Sample;
import org.cbioportal.web.parameter.StudyViewFilter;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -77,7 +78,8 @@ public void getClinicalViolinPlotData() throws Exception {
new BigDecimal(1),
new BigDecimal(NUM_CURVE_POINTS),
false,
new BigDecimal(1)
new BigDecimal(1),
new StudyViewFilter()
);


Expand Down

0 comments on commit d4fece4

Please sign in to comment.