Skip to content

Commit

Permalink
Implement generic-assay-data-counts endpoint in Clickhouse
Browse files Browse the repository at this point in the history
  • Loading branch information
alisman committed Jul 29, 2024
1 parent 8746a34 commit 47e387b
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/main/java/org/cbioportal/model/GenericAssayDataCount.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public class GenericAssayDataCount implements Serializable {

private String value;
private Integer count;
private String profileType;
private String stableId;

public String getValue() {
return value;
Expand All @@ -22,5 +24,12 @@ public Integer getCount() {
public void setCount(Integer count) {
this.count = count;
}

public void setProfileType(String profileType) { this.profileType = profileType; }
public String getProfileType() { return profileType; }

public void setStableId(String profileType) { this.stableId = profileType; }
public String getStableId() { return stableId; }

}

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.cbioportal.model.ClinicalDataCount;
import org.cbioportal.model.ClinicalEventTypeCount;
import org.cbioportal.model.CopyNumberCountByGene;
import org.cbioportal.model.GenericAssayDataCountItem;
import org.cbioportal.model.GenomicDataCount;
import org.cbioportal.model.PatientTreatment;
import org.cbioportal.model.PatientTreatmentReport;
Expand Down Expand Up @@ -51,6 +52,11 @@ public interface StudyViewRepository {
int getSampleProfileCountWithoutPanelData(StudyViewFilter studyViewFilter, String alterationType);

List<ClinicalEventTypeCount> getClinicalEventTypeCounts(StudyViewFilter studyViewFilter);

List<GenericAssayDataCountItem> getGenericAssayDataCounts(StudyViewFilter studyViewFilter,
List<String> stableId, List<String> profileType);



List<PatientTreatment> getPatientTreatments(StudyViewFilter studyViewFilter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import org.cbioportal.model.ClinicalEventTypeCount;
import org.cbioportal.model.CopyNumberCountByGene;
import org.cbioportal.model.GenePanelToGene;
import org.cbioportal.model.GenericAssayDataCount;
import org.cbioportal.model.GenomicDataCount;
import org.cbioportal.model.GenomicDataCountItem;
import org.cbioportal.model.PatientTreatment;
import org.cbioportal.model.PatientTreatmentReport;
import org.cbioportal.model.Sample;
Expand Down Expand Up @@ -57,6 +59,11 @@ List<ClinicalDataCount> getClinicalDataCounts(StudyViewFilter studyViewFilter, C
int getSampleProfileCountWithoutPanelData(StudyViewFilter studyViewFilter, CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter, boolean applyPatientIdFilters, String alterationType);

List<ClinicalEventTypeCount> getClinicalEventTypeCounts(StudyViewFilter studyViewFilter, CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter, boolean applyPatientIdFilters);

List<GenericAssayDataCount> getGenericAssayDataCounts(StudyViewFilter studyViewFilter, CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter, boolean applyPatientIdFilters, List<String> stableIds, List<String> profileTypes);




List<PatientTreatment> getPatientTreatments(StudyViewFilter studyViewFilter, CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter, boolean applyPatientIdFilters);
PatientTreatmentReport getPatientTreatmentCounts(StudyViewFilter studyViewFilter, CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter, boolean applyPatientIdFilters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.cbioportal.model.ClinicalDataCount;
import org.cbioportal.model.ClinicalEventTypeCount;
import org.cbioportal.model.GenePanelToGene;
import org.cbioportal.model.GenericAssayDataCount;
import org.cbioportal.model.GenericAssayDataCountItem;
import org.cbioportal.model.GenomicDataCount;
import org.cbioportal.model.CopyNumberCountByGene;
import org.cbioportal.model.PatientTreatment;
Expand All @@ -19,11 +21,15 @@
import org.cbioportal.web.parameter.StudyViewFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.stream.Collectors;

@Repository
Expand All @@ -44,7 +50,38 @@ public List<Sample> getFilteredSamples(StudyViewFilter studyViewFilter) {
CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter = extractClinicalDataCountFilters(studyViewFilter);
return mapper.getFilteredSamples(studyViewFilter, categorizedClinicalDataCountFilter, shouldApplyPatientIdFilters(studyViewFilter,categorizedClinicalDataCountFilter));
}



@Override
public List<GenericAssayDataCountItem> getGenericAssayDataCounts(StudyViewFilter studyViewFilter, List<String> stableIds, List<String> profileTypes) {

CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter = extractClinicalDataCountFilters(studyViewFilter);

List<GenericAssayDataCount> counts = mapper.getGenericAssayDataCounts(studyViewFilter,
categorizedClinicalDataCountFilter, shouldApplyPatientIdFilters(studyViewFilter,categorizedClinicalDataCountFilter),
stableIds, profileTypes);

List<GenericAssayDataCountItem> items = new ArrayList<GenericAssayDataCountItem>();

BiConsumer<String, List<GenericAssayDataCount>> biConsumer = (k, v) -> {
GenericAssayDataCountItem item = new GenericAssayDataCountItem();
item.setStableId(k);
item.setCounts(v);
items.add(item);
};

Map<String, List<GenericAssayDataCount>> countsGroupedByEntity =
counts.stream()
.collect(Collectors.groupingBy(GenericAssayDataCount::getStableId));

countsGroupedByEntity.forEach(biConsumer);

return items;

}



@Override
public List<AlterationCountByGene> getMutatedGenes(StudyViewFilter studyViewFilter) {
CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter = extractClinicalDataCountFilters(studyViewFilter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public RedissonClient getRedissonClient() {
config.useMasterSlaveServers()
.setMasterAddress(leaderAddress)
.addSlaveAddress(followerAddress)
.setDatabase(database)
.setPassword(password);
.setDatabase(database);
//.setPassword(password);

RedissonClient redissonClient = Redisson.create(config);
LOG.debug("Created Redisson Client: " + redissonClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import org.cbioportal.model.ClinicalData;
import org.cbioportal.model.ClinicalDataCountItem;
import org.cbioportal.model.ClinicalEventTypeCount;
import org.cbioportal.model.GenericAssayDataCountItem;
import org.cbioportal.model.GenomicDataCount;
import org.cbioportal.model.CopyNumberCountByGene;
import org.cbioportal.model.PatientTreatmentReport;
import org.cbioportal.model.Sample;
import org.cbioportal.web.parameter.ClinicalDataType;
import org.cbioportal.web.parameter.StudyViewFilter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

Expand All @@ -36,5 +38,8 @@ public interface StudyViewColumnarService {
List<GenomicDataCount> getGenomicDataCounts(StudyViewFilter studyViewFilter);

List<ClinicalEventTypeCount> getClinicalEventTypeCounts(StudyViewFilter studyViewFilter);

List<GenericAssayDataCountItem> getGenericAssayDataCounts(StudyViewFilter studyViewFilter,
List<String> stableIds, List<String> profileTypes);
PatientTreatmentReport getPatientTreatmentReport(StudyViewFilter studyViewFilter);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.cbioportal.model.ClinicalDataCountItem;
import org.cbioportal.model.ClinicalEventTypeCount;
import org.cbioportal.model.CopyNumberCountByGene;
import org.cbioportal.model.GenericAssayDataCount;
import org.cbioportal.model.GenericAssayDataCountItem;
import org.cbioportal.model.GenomicDataCount;
import org.cbioportal.model.PatientTreatmentReport;
import org.cbioportal.model.Sample;
Expand Down Expand Up @@ -48,6 +50,12 @@ public List<AlterationCountByGene> getMutatedGenes(StudyViewFilter studyViewFilt
return alterationCountService.getMutatedGenes(studyViewFilter);
}

@Override
public List<GenericAssayDataCountItem> getGenericAssayDataCounts(StudyViewFilter studyViewFilter, List<String> stableIds, List<String> profileTypes) {
return studyViewRepository.getGenericAssayDataCounts(studyViewFilter, stableIds, profileTypes);
}


@Override
public List<GenomicDataCount> getGenomicDataCounts(StudyViewFilter studyViewFilter) {
return studyViewRepository.getGenomicDataCounts(studyViewFilter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.cbioportal.model.ClinicalViolinPlotData;
import org.cbioportal.model.CopyNumberCountByGene;
import org.cbioportal.model.DensityPlotData;
import org.cbioportal.model.GenericAssayDataCount;
import org.cbioportal.model.GenericAssayDataCountItem;
import org.cbioportal.model.GenomicDataCount;
import org.cbioportal.model.PatientTreatmentReport;
import org.cbioportal.model.PatientTreatmentRow;
Expand All @@ -32,6 +34,9 @@
import org.cbioportal.web.parameter.ClinicalDataCountFilter;
import org.cbioportal.web.parameter.ClinicalDataFilter;
import org.cbioportal.web.parameter.DataBinMethod;
import org.cbioportal.web.parameter.GenericAssayDataCountFilter;
import org.cbioportal.web.parameter.GenericAssayDataFilter;
import org.cbioportal.web.parameter.SampleIdentifier;
import org.cbioportal.web.parameter.StudyViewFilter;
import org.cbioportal.web.util.DensityPlotParameters;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -52,6 +57,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -354,6 +360,44 @@ public ResponseEntity<List<ClinicalEventTypeCount>> getClinicalEventTypeCounts(
return new ResponseEntity<>(studyViewColumnarService.getClinicalEventTypeCounts(interceptedStudyViewFilter), HttpStatus.OK);
}


@PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection<CancerStudyId>', T(org.cbioportal.utils.security.AccessLevel).READ)")
@RequestMapping(value = "/column-store/generic-assay-data-counts/fetch", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(description = "Fetch generic assay data counts by study view filter")
@ApiResponse(responseCode = "200", description = "OK",
content = @Content(array = @ArraySchema(schema = @Schema(implementation = GenericAssayDataCountItem.class))))
public ResponseEntity<List<GenericAssayDataCountItem>> fetchGenericAssayDataCounts(
@Parameter(required = true, description = "Generic assay data count filter") @Valid @RequestBody(required = false) GenericAssayDataCountFilter genericAssayDataCountFilter,
@Parameter(hidden = true) // prevent reference to this attribute in the swagger-ui interface
@RequestAttribute(required = false, value = "involvedCancerStudies") Collection<String> involvedCancerStudies,
@Parameter(hidden = true) // prevent reference to this attribute in the swagger-ui interface. this
// attribute is needed for the @PreAuthorize tag above.
@Valid @RequestAttribute(required = false, value = "interceptedGenericAssayDataCountFilter") GenericAssayDataCountFilter interceptedGenericAssayDataCountFilter,
@Valid @RequestAttribute(required = false, value = "interceptedStudyViewFilter") StudyViewFilter interceptedStudyViewFilter
) {

List<GenericAssayDataFilter> gaFilters = interceptedGenericAssayDataCountFilter.getGenericAssayDataFilters();
StudyViewFilter studyViewFilter = interceptedGenericAssayDataCountFilter.getStudyViewFilter();
// when there is only one filter, it means study view is doing a single chart filter operation
// remove filter from studyViewFilter to return all data counts
// the reason we do this is to make sure after chart get filtered, user can still see unselected portion of the chart
if (gaFilters.size() == 1) {
NewStudyViewFilterUtil.removeSelfFromGenericAssayFilter(gaFilters.get(0).getStableId(), studyViewFilter);
}

List<String> gaStableIds = gaFilters.stream().map(GenericAssayDataFilter::getStableId).toList();
List<String> gaProfileTypes = gaFilters.stream().map(GenericAssayDataFilter::getProfileType).collect(Collectors.toList());

List<GenericAssayDataCountItem> res = studyViewColumnarService.getGenericAssayDataCounts(studyViewFilter,gaStableIds, gaProfileTypes);

return new ResponseEntity<>(res, HttpStatus.OK);
}






@PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection<CancerStudyId>', T(org.cbioportal.utils.security.AccessLevel).READ)")
@PostMapping(value = "/column-store/treatments/patient-counts/fetch", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(description = "Get all patient level treatments")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ public static void removeSelfFromFilter(String attributeId, StudyViewFilter stud
studyViewFilter.getClinicalDataFilters().removeIf(f -> f.getAttributeId().equals(attributeId));
}
}

public static void removeSelfFromGenericAssayFilter(String stableId, StudyViewFilter studyViewFilter) {
if (studyViewFilter != null && studyViewFilter.getGenericAssayDataFilters() != null) {
studyViewFilter.getGenericAssayDataFilters().removeIf(f -> f.getStableId().equals(stableId));
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.cbioportal.model.Gene;
import org.cbioportal.model.GenePanel;
import org.cbioportal.model.GenePanelToGene;
import org.cbioportal.model.GenericAssayDataCount;
import org.cbioportal.model.Geneset;
import org.cbioportal.model.GenesetCorrelation;
import org.cbioportal.model.GenesetMolecularData;
Expand Down Expand Up @@ -79,6 +80,7 @@
import org.cbioportal.web.mixin.GeneMixin;
import org.cbioportal.web.mixin.GenePanelMixin;
import org.cbioportal.web.mixin.GenePanelToGeneMixin;
import org.cbioportal.web.mixin.GenericAssayDataCountMixin;
import org.cbioportal.web.mixin.GenesetCorrelationMixin;
import org.cbioportal.web.mixin.GenesetMixin;
import org.cbioportal.web.mixin.GenesetMolecularDataMixin;
Expand Down Expand Up @@ -150,6 +152,7 @@ public CustomObjectMapper() {
mixinMap.put(VirtualStudyData.class, SessionDataMixin.class);
mixinMap.put(CustomAttributeWithData.class, SessionDataMixin.class);
mixinMap.put(CustomDataSession.class, SessionMixin.class);
mixinMap.put(GenericAssayDataCount.class, GenericAssayDataCountMixin.class);
super.setMixIns(mixinMap);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.cbioportal.web.mixin;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.cbioportal.model.TypeOfCancer;

import java.util.Date;

public class GenericAssayDataCountMixin {
@JsonIgnore
private Integer profileType;

@JsonIgnore
private Integer stableId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,23 @@
GROUP BY event_type;
</select>

<select id="getGenericAssayDataCounts" resultType="org.cbioportal.model.GenericAssayDataCount">
SELECT value, entity_stable_id as stableId, generic_assay_type as profileType, count(value) as count
FROM generic_assay_data_derived coog
<where>
<include refid="applyStudyViewFilter">
<property name="filter_type" value="'SAMPLE_ID_ONLY'"/>
</include>
AND
<foreach item="profileType" collection="profileTypes" open="(" separator="OR" close=")">
<foreach item="stableId" collection="stableIds" open="(" separator="OR" close=")">
(entity_stable_id='${stableId}' AND generic_assay_type=upper('${profileType}'))
</foreach>
</foreach>
</where>
GROUP BY (value, entity_stable_id, generic_assay_type)
</select>

<resultMap id="PatientTreatmentReport" type="org.cbioportal.model.PatientTreatmentReport">
<constructor>
<arg column="totalPatients" javaType="_int"/>
Expand Down

0 comments on commit 47e387b

Please sign in to comment.