Skip to content

Commit

Permalink
Merge branch 'demo-rfc80-poc' into rfc80/clinical-data-counts-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
alisman authored Nov 6, 2024
2 parents 9c534e8 + 9782432 commit fcba20d
Show file tree
Hide file tree
Showing 30 changed files with 407 additions and 125 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.cbioportal.model;

public class ClinicalViolinPlotBoxData {
import java.io.Serializable;

public class ClinicalViolinPlotBoxData implements Serializable {
private double whiskerLower;
private double whiskerUpper;
private double median;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.cbioportal.model;

import java.io.Serializable;
import java.util.List;

public class ClinicalViolinPlotData {
public class ClinicalViolinPlotData implements Serializable {
private List<ClinicalViolinPlotRowData> rows;
private Double axisStart;
private Double axisEnd;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.cbioportal.model;

public class ClinicalViolinPlotIndividualPoint {
import java.io.Serializable;

public class ClinicalViolinPlotIndividualPoint implements Serializable {
private String sampleId;
private String studyId;
private double value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.cbioportal.model;

import java.io.Serializable;
import java.util.List;

public class ClinicalViolinPlotRowData {
public class ClinicalViolinPlotRowData implements Serializable {
private String category;
private Integer numSamples;
private List<Double> curveData;
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/org/cbioportal/persistence/CacheEnabledConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ public class CacheEnabledConfig {

@Value("${persistence.cache_type:no-cache}")
private String cacheType;
@Value("${persistence.cache_type_clickhouse:no-cache}")
private String cacheTypeClickhouse;

private boolean enabled;
private boolean enabledClickhouse;

public static final String EHCACHE_DISK = "ehcache-disk";
public static final String EHCACHE_HEAP = "ehcache-heap";
Expand All @@ -30,6 +33,8 @@ public class CacheEnabledConfig {
public void init() {
this.enabled = enableCache(cacheType);
LOG.info("Cache is enabled: " + this.enabled);
this.enabledClickhouse = enableCache(cacheTypeClickhouse);
LOG.info("Cache is enabled for clickhouse: " + this.enabledClickhouse);
}

public static boolean enableCache(String cacheType) {
Expand All @@ -53,4 +58,16 @@ public boolean isEnabled() {
return enabled;
}

public String getEnabledClickhouse() {
if (enabledClickhouse) {
return "true";
} else {
return "false";
}
}

public boolean isEnabledClickhouse() {
return enabledClickhouse;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
public interface StudyViewRepository {
List<Sample> getFilteredSamples(StudyViewFilterContext studyViewFilterContext);

List<String> getFilteredStudyIds(StudyViewFilterContext studyViewFilterContext);

List<ClinicalData> getSampleClinicalData(StudyViewFilterContext studyViewFilterContext, List<String> attributeIds);

List<ClinicalData> getPatientClinicalData(StudyViewFilterContext studyViewFilterContext, List<String> attributeIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public class SpringManagedCacheMapUtil implements CacheMapUtil {

@Value("${persistence.cache_type:no-cache}")
private String cacheType;
@Value("${persistence.cache_type_clickhouse:no-cache}")
private String cacheTypeClickhouse;

@Value("${cache.cache-map-utils.spring-managed}")
private boolean springManagedCacheMapUtils;
Expand All @@ -67,7 +69,7 @@ public class SpringManagedCacheMapUtil implements CacheMapUtil {
@PostConstruct
public void init() {
// Make sure the user does not have a conflicting configuration. Explode if there is.
if (cacheType.equals("no-cache") && springManagedCacheMapUtils) {
if (cacheType.equals("no-cache") && cacheTypeClickhouse.equals("no-cache") && springManagedCacheMapUtils) {
throw new RuntimeException("cache.cache-map-utils.spring-managed property is set to 'true' but the portal is not " +
"configured with a cache-implementation (persistence.cache_type property is 'no-cache'). Please set to 'false'" +
" or configure the cache.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import org.cbioportal.persistence.util.CustomKeyGenerator;
import org.cbioportal.persistence.util.CustomRedisCachingProvider;
import org.cbioportal.persistence.util.LoggingCacheErrorHandler;
import org.cbioportal.utils.config.annotation.ConditionalOnProperty;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
Expand All @@ -18,7 +18,9 @@

@Configuration
@EnableCaching
@ConditionalOnProperty(name = "persistence.cache_type", havingValue = {"redis"})
@ConditionalOnExpression(
"#{environment['persistence.cache_type'] == 'redis' or environment['persistence.cache_type_clickhouse'] == 'redis'}"
)
public class RedisConfig extends CachingConfigurerSupport {

@Value("${redis.name:cbioportal}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

public interface StudyViewMapper {
List<Sample> getFilteredSamples(@Param("studyViewFilterHelper") StudyViewFilterHelper studyViewFilterHelper);

List<String> getFilteredStudyIds(@Param("studyViewFilterHelper") StudyViewFilterHelper studyViewFilterHelper);

List<GenomicDataCount> getMolecularProfileSampleCounts(@Param("studyViewFilterHelper") StudyViewFilterHelper studyViewFilterHelper);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ public StudyViewMyBatisRepository(StudyViewMapper mapper) {
public List<Sample> getFilteredSamples(StudyViewFilterContext studyViewFilterContext) {
return mapper.getFilteredSamples(createStudyViewFilterHelper(studyViewFilterContext));
}


@Override
public List<String> getFilteredStudyIds(StudyViewFilterContext studyViewFilterContext) {
return mapper.getFilteredStudyIds(createStudyViewFilterHelper(studyViewFilterContext));
}

@Override
public List<AlterationCountByGene> getMutatedGenes(StudyViewFilterContext studyViewFilterContext) {
return mapper.getMutatedGenes(createStudyViewFilterHelper(studyViewFilterContext),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class CustomKeyGenerator implements KeyGenerator {
private static final Logger LOG = LoggerFactory.getLogger(CustomKeyGenerator.class);

public Object generate(Object target, Method method, Object... params) {
if (!cacheEnabledConfig.isEnabled()) {
if (!cacheEnabledConfig.isEnabled() && !cacheEnabledConfig.isEnabledClickhouse()) {
return "";
}
String key = target.getClass().getSimpleName() + CACHE_KEY_PARAM_DELIMITER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import static org.cbioportal.persistence.util.CustomRedisCache.DELIMITER;


import org.cbioportal.utils.config.annotation.ConditionalOnProperty;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Component;
Expand All @@ -14,7 +14,9 @@
import java.util.stream.Collectors;

@Component
@ConditionalOnProperty(name = "persistence.cache_type", havingValue = "redis")
@ConditionalOnExpression(
"#{environment['persistence.cache_type'] == 'redis' or environment['persistence.cache_type_clickhouse'] == 'redis'}"
)
public class RedisCacheUtils implements CacheUtils {

@Autowired
Expand Down
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 @@ -391,7 +391,7 @@ private boolean hasGenePanelData(@NonNull Set<String> matchingGenePanelIds) {
}

private Map<String, MutSig> getMutSigs(StudyViewFilterContext studyViewFilterContext) throws StudyNotFoundException {
var distinctStudyIds = new HashSet<>(studyViewFilterContext.studyViewFilter().getStudyIds()).stream().toList();
var distinctStudyIds = studyViewRepository.getFilteredStudyIds(studyViewFilterContext);
Map<String, MutSig> mutSigs = new HashMap<>();
if (distinctStudyIds.size() == 1) {
var studyId = distinctStudyIds.getFirst();
Expand All @@ -409,7 +409,7 @@ private Map<String, MutSig> getMutSigs(StudyViewFilterContext studyViewFilterCon
}

private Map<Pair<String, Integer>, Gistic> getGisticMap(StudyViewFilterContext studyViewFilterContext) throws StudyNotFoundException {
var distinctStudyIds = new HashSet<>(studyViewFilterContext.studyViewFilter().getStudyIds()).stream().toList();
var distinctStudyIds = studyViewRepository.getFilteredStudyIds(studyViewFilterContext);
Map<Pair<String, Integer>, Gistic> gisticMap = new HashMap<>();
if (distinctStudyIds.size() == 1) {
var studyId = distinctStudyIds.getFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
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;

import java.math.BigDecimal;
Expand All @@ -18,15 +20,21 @@
import java.util.Map;
import java.util.stream.Collectors;


@Service
public class ClinicalDataDensityPlotServiceImpl implements ClinicalDataDensityPlotService {

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
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<>());

Map<String, List<ClinicalData>> clinicalDataGroupedBySampleId = sampleClinicalData.stream().
collect(Collectors.groupingBy(ClinicalData::getSampleId));
collect(Collectors.groupingBy(c -> c.getStudyId() + "_" + c.getSampleId()));

List<ClinicalData> extractedXYClinicalData = clinicalDataGroupedBySampleId.entrySet().stream()
.filter(entry -> entry.getValue().size() == 2 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.cbioportal.utils.config.annotation.ConditionalOnProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.security.access.AccessDeniedException;
Expand All @@ -19,7 +20,9 @@
import java.util.stream.Collectors;

@Service
@ConditionalOnProperty(name = "persistence.cache_type", havingValue = {"redis"})
@ConditionalOnExpression(
"#{environment['persistence.cache_type'] == 'redis' or environment['persistence.cache_type_clickhouse'] == 'redis'}"
)
public class RedisCacheStatisticsServiceImpl implements CacheStatisticsService {

@Autowired
Expand Down
Loading

0 comments on commit fcba20d

Please sign in to comment.