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

Genomic and Generic Assay bin counts endpoints #10964

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 @@ -9,6 +9,7 @@
import org.cbioportal.model.CopyNumberCountByGene;
import org.cbioportal.model.GenomicDataCountItem;
import org.cbioportal.model.GenomicDataCount;
import org.cbioportal.model.MolecularProfile;
import org.cbioportal.model.PatientTreatment;
import org.cbioportal.model.Sample;
import org.cbioportal.model.SampleTreatment;
Expand Down Expand Up @@ -67,4 +68,10 @@ public interface StudyViewRepository {
Map<String, Integer> getMutationCounts(StudyViewFilterContext studyViewFilterContext, GenomicDataFilter genomicDataFilter);

List<GenomicDataCountItem> getMutationCountsByType(StudyViewFilterContext studyViewFilterContext, List<GenomicDataFilter> genomicDataFilters);

List<ClinicalDataCount> getGenomicDataBinCounts(StudyViewFilterContext studyViewFilterContext, List<String> filteredAttributes);

List<ClinicalDataCount> getGenericAssayDataBinCounts(StudyViewFilterContext studyViewFilterContext, List<String> filteredAttributes);

List<MolecularProfile> getGenericAssayProfiles();
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.cbioportal.persistence.enums;

public enum ClinicalAttributeDataSource {
public enum DataSource {
PATIENT("PATIENT"),SAMPLE("SAMPLE");

private final String value;

ClinicalAttributeDataSource(String value) {
DataSource(String value) {
this.value = value;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,109 @@
package org.cbioportal.persistence.helper;

import org.cbioportal.model.MolecularProfile;
import org.cbioportal.persistence.enums.DataSource;
import org.cbioportal.web.parameter.ClinicalDataFilter;
import org.cbioportal.web.parameter.CategorizedGenericAssayDataCountFilter;
import org.cbioportal.web.parameter.CategorizedGenomicDataCountFilter;
import org.cbioportal.web.parameter.CustomSampleIdentifier;
import org.cbioportal.web.parameter.StudyViewFilter;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;

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

public final class StudyViewFilterHelper {
public static StudyViewFilterHelper build(@Nullable StudyViewFilter studyViewFilter,
@Nullable List<CustomSampleIdentifier> customDataSamples) {
@Nullable Map<DataSource, List<MolecularProfile>> genericAssayProfilesMap,
@Nullable List<CustomSampleIdentifier> customDataSamples) {
if (Objects.isNull(studyViewFilter)) {
studyViewFilter = new StudyViewFilter();
}
if (Objects.isNull(genericAssayProfilesMap)) {
genericAssayProfilesMap = new EnumMap<>(DataSource.class);
}
if (Objects.isNull(customDataSamples)) {
customDataSamples = new ArrayList<>();
}
return new StudyViewFilterHelper(studyViewFilter, customDataSamples);
return new StudyViewFilterHelper(studyViewFilter, genericAssayProfilesMap, customDataSamples);
}

private final StudyViewFilter studyViewFilter;
private final CategorizedGenomicDataCountFilter categorizedGenomicDataCountFilter;
private final CategorizedGenericAssayDataCountFilter categorizedGenericAssayDataCountFilter;
private final List<CustomSampleIdentifier> customDataSamples;

private StudyViewFilterHelper(@NonNull StudyViewFilter studyViewFilter,
@NonNull List<CustomSampleIdentifier> customDataSamples) {
private StudyViewFilterHelper(@NonNull StudyViewFilter studyViewFilter,
@NonNull Map<DataSource, List<MolecularProfile>> genericAssayProfilesMap,
@NonNull List<CustomSampleIdentifier> customDataSamples) {
this.studyViewFilter = studyViewFilter;

this.categorizedGenomicDataCountFilter = extractGenomicDataCountFilters(studyViewFilter);
this.categorizedGenericAssayDataCountFilter = extractGenericAssayDataCountFilters(studyViewFilter, genericAssayProfilesMap);
this.customDataSamples = customDataSamples;
}

public StudyViewFilter studyViewFilter() {
return studyViewFilter;
}

public CategorizedGenomicDataCountFilter categorizedGenomicDataCountFilter() {
return categorizedGenomicDataCountFilter;
}

public CategorizedGenericAssayDataCountFilter categorizedGenericAssayDataCountFilter() {
return categorizedGenericAssayDataCountFilter;
}

public List<CustomSampleIdentifier> customDataSamples() {
return this.customDataSamples;
}

private CategorizedGenomicDataCountFilter extractGenomicDataCountFilters(final StudyViewFilter studyViewFilter) {
if (studyViewFilter.getGenomicDataFilters() == null)
{
return CategorizedGenomicDataCountFilter.getBuilder().build();
}

CategorizedGenomicDataCountFilter.Builder builder = CategorizedGenomicDataCountFilter.getBuilder();

builder.setSampleNumericalGenomicDataFilters(studyViewFilter.getGenomicDataFilters().stream()
.filter(genomicDataFilter -> !genomicDataFilter.getProfileType().equals("cna") && !genomicDataFilter.getProfileType().equals("gistic"))
.toList());
builder.setSampleCategoricalGenomicDataFilters(studyViewFilter.getGenomicDataFilters().stream()
.filter(genomicDataFilter -> genomicDataFilter.getProfileType().equals("cna") || genomicDataFilter.getProfileType().equals("gistic"))
.toList());
return builder.build();
}

private CategorizedGenericAssayDataCountFilter extractGenericAssayDataCountFilters(final StudyViewFilter studyViewFilter, Map<DataSource, List<MolecularProfile>> genericAssayProfilesMap) {
if ((studyViewFilter.getGenericAssayDataFilters() == null || genericAssayProfilesMap.isEmpty()))
{
return CategorizedGenericAssayDataCountFilter.getBuilder().build();
}

CategorizedGenericAssayDataCountFilter.Builder builder = CategorizedGenericAssayDataCountFilter.getBuilder();

// TODO: Support patient level profiles and data filtering
List<String> sampleCategoricalProfileTypes = genericAssayProfilesMap.get(DataSource.SAMPLE)
.stream().filter(profile -> profile.getDatatype().equals("CATEGORICAL") || profile.getDatatype().equals("BINARY"))
.map(profile -> profile.getStableId().replace(profile.getCancerStudyIdentifier() + "_", ""))
.toList();
List<String> sampleNumericalProfileTypes = genericAssayProfilesMap.get(DataSource.SAMPLE)
.stream().filter(profile -> profile.getDatatype().equals("LIMIT-VALUE"))
.map(profile -> profile.getStableId().replace(profile.getCancerStudyIdentifier() + "_", ""))
.toList();
builder.setSampleNumericalGenericAssayDataFilters(studyViewFilter.getGenericAssayDataFilters().stream()
.filter(genericAssayDataFilter -> sampleNumericalProfileTypes.contains(genericAssayDataFilter.getProfileType()))
.toList());
builder.setSampleCategoricalGenericAssayDataFilters(studyViewFilter.getGenericAssayDataFilters().stream()
.filter(genericAssayDataFilter -> sampleCategoricalProfileTypes.contains(genericAssayDataFilter.getProfileType()))
.toList());
return builder.build();
}

public boolean isCategoricalClinicalDataFilter(ClinicalDataFilter clinicalDataFilter) {
var filterValue = clinicalDataFilter.getValues().getFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.cbioportal.model.GenomicDataCount;
import org.cbioportal.model.GenomicDataCountItem;
import org.cbioportal.model.PatientTreatment;
import org.cbioportal.model.MolecularProfile;
import org.cbioportal.model.Sample;
import org.cbioportal.model.SampleTreatment;
import org.cbioportal.persistence.helper.AlterationFilterHelper;
Expand Down Expand Up @@ -65,4 +66,9 @@ public interface StudyViewMapper {
Map<String, Integer> getMutationCounts(StudyViewFilterHelper studyViewFilterHelper, GenomicDataFilter genomicDataFilter);

List<GenomicDataCountItem> getMutationCountsByType(StudyViewFilterHelper studyViewFilterHelper, List<GenomicDataFilter> genomicDataFilters);

List<ClinicalDataCount> getGenomicDataBinCounts(StudyViewFilterHelper studyViewFilterHelper, List<String> attributeIds);
List<ClinicalDataCount> getGenericAssayDataBinCounts(StudyViewFilterHelper studyViewFilterHelper, List<String> attributeIds);

List<MolecularProfile> getGenericAssayProfiles();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
import org.cbioportal.model.GenomicDataCountItem;
import org.cbioportal.model.GenomicDataCount;
import org.cbioportal.model.CopyNumberCountByGene;
import org.cbioportal.model.MolecularProfile;
import org.cbioportal.model.PatientTreatment;
import org.cbioportal.model.Sample;
import org.cbioportal.model.SampleTreatment;
import org.cbioportal.model.StudyViewFilterContext;
import org.cbioportal.persistence.StudyViewRepository;
import org.cbioportal.persistence.enums.ClinicalAttributeDataSource;
import org.cbioportal.persistence.enums.DataSource;
import org.cbioportal.persistence.helper.AlterationFilterHelper;
import org.cbioportal.persistence.helper.StudyViewFilterHelper;
import org.cbioportal.web.parameter.ClinicalDataType;
Expand All @@ -24,6 +25,7 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -33,9 +35,9 @@
@Repository
public class StudyViewMyBatisRepository implements StudyViewRepository {

private Map<ClinicalAttributeDataSource, List<ClinicalAttribute>> clinicalAttributesMap = new HashMap<>();


private Map<DataSource, List<ClinicalAttribute>> clinicalAttributesMap = new EnumMap<>(DataSource.class);
private Map<DataSource, List<MolecularProfile>> genericAssayProfilesMap = new EnumMap<>(DataSource.class);
private static final List<String> FILTERED_CLINICAL_ATTR_VALUES = Collections.emptyList();
private final StudyViewMapper mapper;

Expand Down Expand Up @@ -101,14 +103,19 @@ public List<GenomicDataCount> getMolecularProfileSampleCounts(StudyViewFilterCon
}

public StudyViewFilterHelper createStudyViewFilterHelper(StudyViewFilterContext studyViewFilterContext) {
return StudyViewFilterHelper.build(studyViewFilterContext.studyViewFilter(), studyViewFilterContext.customDataFilterSamples());
return StudyViewFilterHelper.build(studyViewFilterContext.studyViewFilter() , getGenericAssayProfilesMap(), studyViewFilterContext.customDataFilterSamples());
}

@Override
public List<ClinicalAttribute> getClinicalAttributes() {
return mapper.getClinicalAttributes();
}

@Override
public List<MolecularProfile> getGenericAssayProfiles() {
return mapper.getGenericAssayProfiles();
}

@Override
public Map<String, ClinicalDataType> getClinicalAttributeDatatypeMap() {
if (clinicalAttributesMap.isEmpty()) {
Expand All @@ -118,11 +125,11 @@ public Map<String, ClinicalDataType> getClinicalAttributeDatatypeMap() {
Map<String, ClinicalDataType> attributeDatatypeMap = new HashMap<>();

clinicalAttributesMap
.get(ClinicalAttributeDataSource.SAMPLE)
.get(DataSource.SAMPLE)
.forEach(attribute -> attributeDatatypeMap.put(attribute.getAttrId(), ClinicalDataType.SAMPLE));

clinicalAttributesMap
.get(ClinicalAttributeDataSource.PATIENT)
.get(DataSource.PATIENT)
.forEach(attribute -> attributeDatatypeMap.put(attribute.getAttrId(), ClinicalDataType.PATIENT));

return attributeDatatypeMap;
Expand Down Expand Up @@ -199,18 +206,34 @@ public List<SampleTreatment> getSampleTreatments(StudyViewFilterContext studyVie
public int getTotalSampleTreatmentCount(StudyViewFilterContext studyViewFilterContext) {
return mapper.getTotalSampleTreatmentCounts(createStudyViewFilterHelper(studyViewFilterContext));
}

@Override
public List<ClinicalDataCount> getGenomicDataBinCounts(StudyViewFilterContext studyViewFilterContext, List<String> attributeIds) {
return mapper.getGenomicDataBinCounts(createStudyViewFilterHelper(studyViewFilterContext), attributeIds);
}

@Override
public List<ClinicalDataCount> getGenericAssayDataBinCounts(StudyViewFilterContext studyViewFilterContext, List<String> attributeIds) {
return mapper.getGenericAssayDataBinCounts(createStudyViewFilterHelper(studyViewFilterContext), attributeIds);
}

private void buildClinicalAttributeNameMap() {
clinicalAttributesMap = this.getClinicalAttributes()
.stream()
.collect(Collectors.groupingBy(ca -> ca.getPatientAttribute() ? ClinicalAttributeDataSource.PATIENT : ClinicalAttributeDataSource.SAMPLE));
.collect(Collectors.groupingBy(ca -> ca.getPatientAttribute().booleanValue() ? DataSource.PATIENT : DataSource.SAMPLE));
}

private Map<ClinicalAttributeDataSource, List<ClinicalAttribute>> getClinicalAttributeNameMap() {
if (clinicalAttributesMap.isEmpty()) {
buildClinicalAttributeNameMap();

private void buildGenericAssayProfilesMap() {
genericAssayProfilesMap = this.getGenericAssayProfiles()
.stream()
.collect(Collectors.groupingBy(ca -> ca.getPatientLevel().booleanValue() ? DataSource.PATIENT : DataSource.SAMPLE));
}

private Map<DataSource, List<MolecularProfile>> getGenericAssayProfilesMap() {
if (genericAssayProfilesMap.isEmpty()) {
buildGenericAssayProfilesMap();
}
return clinicalAttributesMap;
return genericAssayProfilesMap;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public interface StudyViewColumnarService {
List<GenomicDataCountItem> getCNACountsByGeneSpecific(StudyViewFilter studyViewFilter, List<GenomicDataFilter> genomicDataFilters);

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

List<ClinicalDataCountItem> getGenomicDataBinCounts(StudyViewFilter studyViewFilter, List<String> filteredAttributes);

List<ClinicalDataCountItem> getGenericAssayDataBinCounts(StudyViewFilter studyViewFilter, List<String> filteredAttributes);

List<GenomicDataCountItem> getMutationTypeCountsByGeneSpecific(StudyViewFilter studyViewFilter, List<GenomicDataFilter> genomicDataFilters);
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ public SampleTreatmentReport getSampleTreatmentReport(StudyViewFilter studyViewF
return treatmentCountReportService.getSampleTreatmentReport(createContext(studyViewFilter));
}

@Override
public List<ClinicalDataCountItem> getGenomicDataBinCounts(StudyViewFilter studyViewFilter, List<String> filteredAttributes) {
return generateDataCountItemsFromDataCounts(studyViewRepository.getGenomicDataBinCounts(createContext(studyViewFilter), filteredAttributes));
}

@Override
public List<ClinicalDataCountItem> getGenericAssayDataBinCounts(StudyViewFilter studyViewFilter, List<String> filteredAttributes) {
return generateDataCountItemsFromDataCounts(studyViewRepository.getGenericAssayDataBinCounts(createContext(studyViewFilter), filteredAttributes));
}

public List<CopyNumberCountByGene> getCnaGenes(StudyViewFilter studyViewFilter) {
return alterationCountService.getCnaGenes(createContext(studyViewFilter));
}
Expand All @@ -97,14 +107,7 @@ public Map<String, ClinicalDataType> getClinicalAttributeDatatypeMap() {

@Override
public List<ClinicalDataCountItem> getClinicalDataCounts(StudyViewFilter studyViewFilter, List<String> filteredAttributes) {
return studyViewRepository.getClinicalDataCounts(createContext(studyViewFilter), filteredAttributes)
.stream().collect(Collectors.groupingBy(ClinicalDataCount::getAttributeId))
.entrySet().parallelStream().map(e -> {
ClinicalDataCountItem item = new ClinicalDataCountItem();
item.setAttributeId(e.getKey());
item.setCounts(e.getValue());
return item;
}).collect(Collectors.toList());
return generateDataCountItemsFromDataCounts(studyViewRepository.getClinicalDataCounts(createContext(studyViewFilter), filteredAttributes));
}

@Override
Expand Down Expand Up @@ -156,8 +159,16 @@ private StudyViewFilterContext createContext(StudyViewFilter studyViewFilter) {
List<CustomSampleIdentifier> customSampleIdentifiers = customDataFilterUtil.extractCustomDataSamples(studyViewFilter);
return new StudyViewFilterContext(studyViewFilter, customSampleIdentifiers);
}



private List<ClinicalDataCountItem> generateDataCountItemsFromDataCounts(List<ClinicalDataCount> dataCounts) {
return dataCounts.stream().collect(Collectors.groupingBy(ClinicalDataCount::getAttributeId))
.entrySet().parallelStream().map(e -> {
ClinicalDataCountItem item = new ClinicalDataCountItem();
item.setAttributeId(e.getKey());
item.setCounts(e.getValue());
return item;
}).toList();
}

public static List<CaseListDataCount> mergeCaseListCounts(List<CaseListDataCount> counts) {
Map<String, List<CaseListDataCount>> countsPerListType = counts.stream()
Expand Down
Loading
Loading