Skip to content

Commit

Permalink
Demo rfc80 poc mutation data counts & genomic data counts (cBioPortal…
Browse files Browse the repository at this point in the history
…#10807)

Clickhouse implementations of mutation data counts & genomic data counts services

---------

Co-authored-by: Qi-Xuan Lu <[email protected]>
  • Loading branch information
fuzhaoyuan and qlu-cls authored Aug 13, 2024
1 parent d7af5e5 commit 956fb33
Show file tree
Hide file tree
Showing 13 changed files with 470 additions and 31 deletions.
15 changes: 15 additions & 0 deletions src/main/java/org/cbioportal/model/GenomicDataCount.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ public class GenomicDataCount implements Serializable {
private Integer count;
private Integer uniqueCount;

public GenomicDataCount() {}

public GenomicDataCount(String label, String value, Integer count) {
this.label = label;
this.value = value;
this.count = count;
}

public GenomicDataCount(String label, String value, Integer count, Integer uniqueCount) {
this.label = label;
this.value = value;
this.count = count;
this.uniqueCount = uniqueCount;
}

public String getLabel() {
return label;
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/cbioportal/model/GenomicDataCountItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ public class GenomicDataCountItem implements Serializable {
private String profileType;
private List<GenomicDataCount> counts;

public GenomicDataCountItem() {}

public GenomicDataCountItem(String hugoGeneSymbol, String profileType, List<GenomicDataCount> counts) {
this.hugoGeneSymbol = hugoGeneSymbol;
this.profileType = profileType;
this.counts = counts;
}

public String getHugoGeneSymbol() {
return hugoGeneSymbol;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import org.cbioportal.model.ClinicalDataCount;
import org.cbioportal.model.ClinicalEventTypeCount;
import org.cbioportal.model.CopyNumberCountByGene;
import org.cbioportal.model.GenomicDataCountItem;
import org.cbioportal.model.GenomicDataCount;
import org.cbioportal.model.PatientTreatment;
import org.cbioportal.model.Sample;
import org.cbioportal.model.SampleTreatment;
import org.cbioportal.web.parameter.ClinicalDataType;
import org.cbioportal.web.parameter.GenomicDataFilter;
import org.cbioportal.web.parameter.StudyViewFilter;

import java.util.List;
Expand Down Expand Up @@ -59,4 +61,10 @@ public interface StudyViewRepository {
List<SampleTreatment> getSampleTreatments(StudyViewFilter studyViewFilter);

int getTotalSampleTreatmentCount(StudyViewFilter studyViewFilter);

List<GenomicDataCountItem> getCNACounts(StudyViewFilter studyViewFilter, List<GenomicDataFilter> genomicDataFilters);

Map<String, Integer> getMutationCounts(StudyViewFilter studyViewFilter, GenomicDataFilter genomicDataFilter);

List<GenomicDataCountItem> getMutationCountsByType(StudyViewFilter studyViewFilter, List<GenomicDataFilter> genomicDataFilters);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
import org.cbioportal.model.CopyNumberCountByGene;
import org.cbioportal.model.GenePanelToGene;
import org.cbioportal.model.GenomicDataCount;
import org.cbioportal.model.GenomicDataCountItem;
import org.cbioportal.model.PatientTreatment;
import org.cbioportal.model.Sample;
import org.cbioportal.model.SampleTreatment;
import org.cbioportal.persistence.helper.AlterationFilterHelper;
import org.cbioportal.web.parameter.CategorizedClinicalDataCountFilter;
import org.cbioportal.web.parameter.GenomicDataFilter;
import org.cbioportal.web.parameter.StudyViewFilter;

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


public interface StudyViewMapper {
Expand Down Expand Up @@ -60,4 +63,10 @@ List<ClinicalDataCount> getClinicalDataCounts(StudyViewFilter studyViewFilter, C
int getPatientTreatmentCounts(StudyViewFilter studyViewFilter, CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter, boolean applyPatientIdFilters);
List<SampleTreatment> getSampleTreatmentCounts(StudyViewFilter studyViewFilter, CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter, boolean applyPatientIdFilters);
int getTotalSampleTreatmentCounts(StudyViewFilter studyViewFilter, CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter, boolean applyPatientIdFilters);

List<GenomicDataCountItem> getCNACounts(StudyViewFilter studyViewFilter, CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter, List<GenomicDataFilter> genomicDataFilters);

Map<String, Integer> getMutationCounts(StudyViewFilter studyViewFilter, CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter, GenomicDataFilter genomicDataFilter);

List<GenomicDataCountItem> getMutationCountsByType(StudyViewFilter studyViewFilter, CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter, List<GenomicDataFilter> genomicDataFilters);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.cbioportal.model.ClinicalDataCount;
import org.cbioportal.model.ClinicalEventTypeCount;
import org.cbioportal.model.GenePanelToGene;
import org.cbioportal.model.GenomicDataCountItem;
import org.cbioportal.model.GenomicDataCount;
import org.cbioportal.model.CopyNumberCountByGene;
import org.cbioportal.model.PatientTreatment;
Expand All @@ -16,6 +17,7 @@
import org.cbioportal.persistence.helper.AlterationFilterHelper;
import org.cbioportal.web.parameter.CategorizedClinicalDataCountFilter;
import org.cbioportal.web.parameter.ClinicalDataType;
import org.cbioportal.web.parameter.GenomicDataFilter;
import org.cbioportal.web.parameter.StudyViewFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
Expand Down Expand Up @@ -293,5 +295,20 @@ private CategorizedClinicalDataCountFilter extractClinicalDataCountFilters(final
.build();
}

@Override
public List<GenomicDataCountItem> getCNACounts(StudyViewFilter studyViewFilter, List<GenomicDataFilter> genomicDataFilters) {
CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter = extractClinicalDataCountFilters(studyViewFilter);
return mapper.getCNACounts(studyViewFilter, categorizedClinicalDataCountFilter, genomicDataFilters);
}

public Map<String, Integer> getMutationCounts(StudyViewFilter studyViewFilter, GenomicDataFilter genomicDataFilter) {
CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter = extractClinicalDataCountFilters(studyViewFilter);
return mapper.getMutationCounts(studyViewFilter, categorizedClinicalDataCountFilter, genomicDataFilter);
}

public List<GenomicDataCountItem> getMutationCountsByType(StudyViewFilter studyViewFilter, List<GenomicDataFilter> genomicDataFilters) {
CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter = extractClinicalDataCountFilters(studyViewFilter);
return mapper.getMutationCountsByType(studyViewFilter, categorizedClinicalDataCountFilter, genomicDataFilters);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import org.cbioportal.model.ClinicalData;
import org.cbioportal.model.ClinicalDataCountItem;
import org.cbioportal.model.ClinicalEventTypeCount;
import org.cbioportal.model.GenomicDataCountItem;
import org.cbioportal.model.GenomicDataCount;
import org.cbioportal.model.CopyNumberCountByGene;
import org.cbioportal.model.PatientTreatmentReport;
import org.cbioportal.model.Sample;
import org.cbioportal.model.SampleTreatmentReport;
import org.cbioportal.web.parameter.ClinicalDataType;
import org.cbioportal.web.parameter.GenomicDataFilter;
import org.cbioportal.web.parameter.StudyViewFilter;

import java.util.List;
Expand Down Expand Up @@ -39,4 +41,10 @@ public interface StudyViewColumnarService {
List<ClinicalEventTypeCount> getClinicalEventTypeCounts(StudyViewFilter studyViewFilter);
PatientTreatmentReport getPatientTreatmentReport(StudyViewFilter studyViewFilter);
SampleTreatmentReport getSampleTreatmentReport(StudyViewFilter studyViewFilter);

List<GenomicDataCountItem> getCNACountsByGeneSpecific(StudyViewFilter studyViewFilter, List<GenomicDataFilter> genomicDataFilters);

List<GenomicDataCountItem> getMutationCountsByGeneSpecific(StudyViewFilter studyViewFilter, List<GenomicDataFilter> genomicDataFilters);

List<GenomicDataCountItem> getMutationTypeCountsByGeneSpecific(StudyViewFilter studyViewFilter, List<GenomicDataFilter> genomicDataFilters);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@
import org.cbioportal.model.CopyNumberCountByGene;
import org.cbioportal.model.GenomicDataCount;
import org.cbioportal.model.PatientTreatmentReport;
import org.cbioportal.model.GenomicDataCountItem;
import org.cbioportal.model.Sample;
import org.cbioportal.model.SampleTreatmentReport;
import org.cbioportal.persistence.StudyViewRepository;
import org.cbioportal.service.AlterationCountService;
import org.cbioportal.service.StudyViewColumnarService;
import org.cbioportal.service.treatment.TreatmentCountReportService;
import org.cbioportal.web.parameter.ClinicalDataType;
import org.cbioportal.web.parameter.GenomicDataFilter;
import org.cbioportal.web.parameter.StudyViewFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -115,4 +118,32 @@ public List<ClinicalData> getPatientClinicalData(StudyViewFilter studyViewFilter
public List<ClinicalData> getSampleClinicalData(StudyViewFilter studyViewFilter, List<String> attributeIds) {
return studyViewRepository.getSampleClinicalData(studyViewFilter, attributeIds);
}

@Override
public List<GenomicDataCountItem> getCNACountsByGeneSpecific(StudyViewFilter studyViewFilter, List<GenomicDataFilter> genomicDataFilters) {
return studyViewRepository.getCNACounts(studyViewFilter, genomicDataFilters);
}

@Override
public List<GenomicDataCountItem> getMutationCountsByGeneSpecific(StudyViewFilter studyViewFilter, List<GenomicDataFilter> genomicDataFilters) {
List<GenomicDataCountItem> genomicDataCountItemList = new ArrayList<>();
for (GenomicDataFilter genomicDataFilter : genomicDataFilters) {
Map<String, Integer> counts = studyViewRepository.getMutationCounts(studyViewFilter, genomicDataFilter);
List<GenomicDataCount> genomicDataCountList = new ArrayList<>();
if (counts.getOrDefault("mutatedCount", 0) > 0)
genomicDataCountList.add(new GenomicDataCount("Mutated", "MUTATED", counts.get("mutatedCount"), counts.get("mutatedCount")));
if (counts.getOrDefault("notMutatedCount", 0) > 0)
genomicDataCountList.add(new GenomicDataCount("Not Mutated", "NOT_MUTATED", counts.get("notMutatedCount"), counts.get("notMutatedCount")));
if (counts.getOrDefault("notProfiledCount", 0) > 0)
genomicDataCountList.add(new GenomicDataCount("Not Profiled", "NOT_PROFILED", counts.get("notProfiledCount"), counts.get("notProfiledCount")));
genomicDataCountItemList.add(new GenomicDataCountItem(genomicDataFilter.getHugoGeneSymbol(), "mutations", genomicDataCountList));
}
return genomicDataCountItemList;
}

@Override
public List<GenomicDataCountItem> getMutationTypeCountsByGeneSpecific(StudyViewFilter studyViewFilter, List<GenomicDataFilter> genomicDataFilters) {
return studyViewRepository.getMutationCountsByType(studyViewFilter, genomicDataFilters);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ public List<GenomicDataCountItem> getMutationCountsByGeneSpecific(List<String> s

return genomicDataFilters
.stream()
.flatMap(gdFilter -> {
.flatMap(genomicDataFilter -> {
GenomicDataCountItem genomicDataCountItem = new GenomicDataCountItem();
String hugoGeneSymbol = gdFilter.getKey();
String profileType = gdFilter.getValue();
String hugoGeneSymbol = genomicDataFilter.getKey();
String profileType = genomicDataFilter.getValue();
genomicDataCountItem.setHugoGeneSymbol(hugoGeneSymbol);
genomicDataCountItem.setProfileType(profileType);

Expand Down Expand Up @@ -234,9 +234,9 @@ public List<GenomicDataCountItem> getMutationTypeCountsByGeneSpecific(List<Strin

return genomicDataFilters
.stream()
.flatMap(gdFilter -> {
String hugoGeneSymbol = gdFilter.getKey();
String profileType = gdFilter.getValue();
.flatMap(genomicDataFilter -> {
String hugoGeneSymbol = genomicDataFilter.getKey();
String profileType = genomicDataFilter.getValue();

List<Integer> stableIds = Collections.singletonList(geneSymbolIdMap.get(hugoGeneSymbol));

Expand Down Expand Up @@ -359,10 +359,10 @@ public List<GenomicDataCountItem> getCNAAlterationCountsByGeneSpecific(List<Stri

return genomicDataFilters
.stream()
.flatMap(gdFilter -> {
.flatMap(genomicDataFilter -> {
GenomicDataCountItem genomicDataCountItem = new GenomicDataCountItem();
String hugoGeneSymbol = gdFilter.getKey();
String profileType = gdFilter.getValue();
String hugoGeneSymbol = genomicDataFilter.getKey();
String profileType = genomicDataFilter.getValue();
genomicDataCountItem.setHugoGeneSymbol(hugoGeneSymbol);
genomicDataCountItem.setProfileType(profileType);

Expand Down
24 changes: 12 additions & 12 deletions src/main/java/org/cbioportal/web/StudyViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -956,15 +956,15 @@ public ResponseEntity<List<GenomicDataCountItem>> fetchGenomicDataCounts(
@Parameter(required = true, description = "Intercepted Genomic Data Count Filter")
@Valid @RequestAttribute(required = false, value = "interceptedGenomicDataCountFilter") GenomicDataCountFilter interceptedGenomicDataCountFilter
) throws StudyNotFoundException {
List<GenomicDataFilter> gdFilters = interceptedGenomicDataCountFilter.getGenomicDataFilters();
List<GenomicDataFilter> genomicDataFilters = interceptedGenomicDataCountFilter.getGenomicDataFilters();
StudyViewFilter studyViewFilter = interceptedGenomicDataCountFilter.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 (gdFilters.size() == 1) {
if (genomicDataFilters.size() == 1) {
studyViewFilterUtil.removeSelfFromGenomicDataFilter(
gdFilters.get(0).getHugoGeneSymbol(),
gdFilters.get(0).getProfileType(),
genomicDataFilters.get(0).getHugoGeneSymbol(),
genomicDataFilters.get(0).getProfileType(),
studyViewFilter);
}
List<SampleIdentifier> filteredSampleIdentifiers = studyViewFilterApplier.apply(studyViewFilter);
Expand All @@ -980,7 +980,7 @@ public ResponseEntity<List<GenomicDataCountItem>> fetchGenomicDataCounts(
List<GenomicDataCountItem> result = studyViewService.getCNAAlterationCountsByGeneSpecific(
studyIds,
sampleIds,
gdFilters.stream().map(gdFilter -> new Pair<>(gdFilter.getHugoGeneSymbol(), gdFilter.getProfileType())).collect(Collectors.toList()));
genomicDataFilters.stream().map(genomicDataFilter -> new Pair<>(genomicDataFilter.getHugoGeneSymbol(), genomicDataFilter.getProfileType())).collect(Collectors.toList()));

return new ResponseEntity<>(result, HttpStatus.OK);
}
Expand Down Expand Up @@ -1182,15 +1182,15 @@ public ResponseEntity<List<GenomicDataCountItem>> fetchMutationDataCounts(
@Parameter(hidden = true) // prevent reference to this attribute in the swagger-ui interface
@Valid @RequestAttribute(required = false, value = "interceptedGenomicDataCountFilter") GenomicDataCountFilter interceptedGenomicDataCountFilter
) {
List<GenomicDataFilter> gdFilters = interceptedGenomicDataCountFilter.getGenomicDataFilters();
List<GenomicDataFilter> genomicDataFilters = interceptedGenomicDataCountFilter.getGenomicDataFilters();
StudyViewFilter studyViewFilter = interceptedGenomicDataCountFilter.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 (gdFilters.size() == 1 && projection == Projection.SUMMARY) {
if (genomicDataFilters.size() == 1 && projection == Projection.SUMMARY) {
studyViewFilterUtil.removeSelfFromMutationDataFilter(
gdFilters.get(0).getHugoGeneSymbol(),
gdFilters.get(0).getProfileType(),
genomicDataFilters.get(0).getHugoGeneSymbol(),
genomicDataFilters.get(0).getProfileType(),
MutationOption.MUTATED,
studyViewFilter);
}
Expand All @@ -1211,13 +1211,13 @@ public ResponseEntity<List<GenomicDataCountItem>> fetchMutationDataCounts(
studyViewService.getMutationCountsByGeneSpecific(
studyIds,
sampleIds,
gdFilters.stream().map(gdFilter -> new Pair<>(gdFilter.getHugoGeneSymbol(), gdFilter.getProfileType())).toList(),
genomicDataFilters.stream().map(genomicDataFilter -> new Pair<>(genomicDataFilter.getHugoGeneSymbol(), genomicDataFilter.getProfileType())).toList(),
studyViewFilter.getAlterationFilter()
) :
) :
studyViewService.getMutationTypeCountsByGeneSpecific(
studyIds,
sampleIds,
gdFilters.stream().map(gdFilter -> new Pair<>(gdFilter.getHugoGeneSymbol(), gdFilter.getProfileType())).toList()
genomicDataFilters.stream().map(genomicDataFilter -> new Pair<>(genomicDataFilter.getHugoGeneSymbol(), genomicDataFilter.getProfileType())).toList()
);

return new ResponseEntity<>(result, HttpStatus.OK);
Expand Down
Loading

0 comments on commit 956fb33

Please sign in to comment.