Skip to content

Commit

Permalink
Genomic and Generic Assay bin counts endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
dippindots committed Aug 29, 2024
1 parent b36bffb commit 415cb1a
Show file tree
Hide file tree
Showing 18 changed files with 968 additions and 83 deletions.
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,6 +1,7 @@
package org.cbioportal.persistence.helper;

import org.cbioportal.model.ClinicalAttribute;
import org.cbioportal.model.MolecularProfile;
import org.cbioportal.persistence.enums.ClinicalAttributeDataSource;
import org.cbioportal.web.parameter.CategorizedClinicalDataCountFilter;
import org.cbioportal.web.parameter.CustomSampleIdentifier;
Expand All @@ -13,21 +14,26 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

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

private final StudyViewFilter studyViewFilter;
Expand All @@ -37,9 +43,10 @@ public static StudyViewFilterHelper build(@Nullable StudyViewFilter studyViewFil


private StudyViewFilterHelper(@NonNull StudyViewFilter studyViewFilter, @NonNull Map<ClinicalAttributeDataSource, List<ClinicalAttribute>> clinicalAttributesMap,
@NonNull Map<ClinicalAttributeDataSource, List<MolecularProfile>> genericAssayProfilesMap,
@NonNull List<CustomSampleIdentifier> customDataSamples) {
this.studyViewFilter = studyViewFilter;
this.categorizedClinicalDataCountFilter = extractClinicalDataCountFilters(studyViewFilter, clinicalAttributesMap);
this.categorizedClinicalDataCountFilter = extractClinicalDataCountFilters(studyViewFilter, clinicalAttributesMap, genericAssayProfilesMap);
this.customDataSamples = customDataSamples;
this.applyPatientIdFilters = shouldApplyPatientIdFilters();
}
Expand All @@ -56,46 +63,77 @@ public List<CustomSampleIdentifier> customDataSamples() {
return this.customDataSamples;
}

private CategorizedClinicalDataCountFilter extractClinicalDataCountFilters(final StudyViewFilter studyViewFilter, Map<ClinicalAttributeDataSource, List<ClinicalAttribute>> clinicalAttributesMap) {

if (studyViewFilter.getClinicalDataFilters() == null || clinicalAttributesMap.isEmpty()) {
private CategorizedClinicalDataCountFilter extractClinicalDataCountFilters(final StudyViewFilter studyViewFilter, Map<ClinicalAttributeDataSource, List<ClinicalAttribute>> clinicalAttributesMap, Map<ClinicalAttributeDataSource, List<MolecularProfile>> genericAssayProfilesMap) {
if ((studyViewFilter.getClinicalDataFilters() == null || clinicalAttributesMap.isEmpty()) &&
(studyViewFilter.getGenericAssayDataFilters() == null || genericAssayProfilesMap.isEmpty()) &&
studyViewFilter.getGenomicDataFilters() == null)
{
return CategorizedClinicalDataCountFilter.getBuilder().build();
}

List<String> patientCategoricalAttributes = clinicalAttributesMap.get(ClinicalAttributeDataSource.PATIENT)
.stream().filter(ca -> ca.getDatatype().equals("STRING"))
.map(ClinicalAttribute::getAttrId)
.toList();
CategorizedClinicalDataCountFilter.Builder builder = CategorizedClinicalDataCountFilter.getBuilder();

if (studyViewFilter.getClinicalDataFilters() != null) {
List<String> patientCategoricalAttributes = clinicalAttributesMap.get(ClinicalAttributeDataSource.PATIENT)
.stream().filter(ca -> ca.getDatatype().equals("STRING"))
.map(ClinicalAttribute::getAttrId)
.toList();

List<String> patientNumericalAttributes = clinicalAttributesMap.get(ClinicalAttributeDataSource.PATIENT)
.stream().filter(ca -> ca.getDatatype().equals("NUMBER"))
.map(ClinicalAttribute::getAttrId)
.toList();
List<String> patientNumericalAttributes = clinicalAttributesMap.get(ClinicalAttributeDataSource.PATIENT)
.stream().filter(ca -> ca.getDatatype().equals("NUMBER"))
.map(ClinicalAttribute::getAttrId)
.toList();

List<String> sampleCategoricalAttributes = clinicalAttributesMap.get(ClinicalAttributeDataSource.SAMPLE)
.stream().filter(ca -> ca.getDatatype().equals("STRING"))
.map(ClinicalAttribute::getAttrId)
.toList();
List<String> sampleCategoricalAttributes = clinicalAttributesMap.get(ClinicalAttributeDataSource.SAMPLE)
.stream().filter(ca -> ca.getDatatype().equals("STRING"))
.map(ClinicalAttribute::getAttrId)
.toList();

List<String> sampleNumericalAttributes = clinicalAttributesMap.get(ClinicalAttributeDataSource.SAMPLE)
.stream().filter(ca -> ca.getDatatype().equals("NUMBER"))
.map(ClinicalAttribute::getAttrId)
.toList();
List<String> sampleNumericalAttributes = clinicalAttributesMap.get(ClinicalAttributeDataSource.SAMPLE)
.stream().filter(ca -> ca.getDatatype().equals("NUMBER"))
.map(ClinicalAttribute::getAttrId)
.toList();

builder.setPatientCategoricalClinicalDataFilters(studyViewFilter.getClinicalDataFilters()
.stream().filter(clinicalDataFilter -> patientCategoricalAttributes.contains(clinicalDataFilter.getAttributeId()))
.collect(Collectors.toList()))
.setPatientNumericalClinicalDataFilters(studyViewFilter.getClinicalDataFilters().stream()
.filter(clinicalDataFilter -> patientNumericalAttributes.contains(clinicalDataFilter.getAttributeId()))
.collect(Collectors.toList()))
.setSampleCategoricalClinicalDataFilters(studyViewFilter.getClinicalDataFilters().stream()
.filter(clinicalDataFilter -> sampleCategoricalAttributes.contains(clinicalDataFilter.getAttributeId()))
.collect(Collectors.toList()))
.setSampleNumericalClinicalDataFilters(studyViewFilter.getClinicalDataFilters().stream()
.filter(clinicalDataFilter -> sampleNumericalAttributes.contains(clinicalDataFilter.getAttributeId()))
.collect(Collectors.toList()));
}
if (studyViewFilter.getGenomicDataFilters() != null) {
builder.setSampleNumericalGenomicDataFilters(studyViewFilter.getGenomicDataFilters().stream()
.filter(genomicDataFilter -> !genomicDataFilter.getProfileType().equals("cna") && !genomicDataFilter.getProfileType().equals("gistic"))
.collect(Collectors.toList()));
builder.setSampleCategoricalGenomicDataFilters(studyViewFilter.getGenomicDataFilters().stream()
.filter(genomicDataFilter -> genomicDataFilter.getProfileType().equals("cna") || genomicDataFilter.getProfileType().equals("gistic"))
.collect(Collectors.toList()));
}
if (studyViewFilter.getGenericAssayDataFilters() != null) {
// TODO: Support patient level profiles and data filtering
List<String> sampleCategoricalProfileTypes = genericAssayProfilesMap.get(ClinicalAttributeDataSource.SAMPLE)
.stream().filter(profile -> profile.getDatatype().equals("CATEGORICAL") || profile.getDatatype().equals("BINARY"))
.map(profile -> profile.getStableId().replace(profile.getCancerStudyIdentifier() + "_", ""))
.toList();

return CategorizedClinicalDataCountFilter.getBuilder()
.setPatientCategoricalClinicalDataFilters(studyViewFilter.getClinicalDataFilters()
.stream().filter(clinicalDataFilter -> patientCategoricalAttributes.contains(clinicalDataFilter.getAttributeId()))
.toList())
.setPatientNumericalClinicalDataFilters(studyViewFilter.getClinicalDataFilters().stream()
.filter(clinicalDataFilter -> patientNumericalAttributes.contains(clinicalDataFilter.getAttributeId()))
.toList())
.setSampleCategoricalClinicalDataFilters(studyViewFilter.getClinicalDataFilters().stream()
.filter(clinicalDataFilter -> sampleCategoricalAttributes.contains(clinicalDataFilter.getAttributeId()))
.toList())
.setSampleNumericalClinicalDataFilters(studyViewFilter.getClinicalDataFilters().stream()
.filter(clinicalDataFilter -> sampleNumericalAttributes.contains(clinicalDataFilter.getAttributeId()))
.toList())
.build();
List<String> sampleNumericalProfileTypes = genericAssayProfilesMap.get(ClinicalAttributeDataSource.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()))
.collect(Collectors.toList()));
builder.setSampleCategoricalGenericAssayDataFilters(studyViewFilter.getGenericAssayDataFilters().stream()
.filter(genericAssayDataFilter -> sampleCategoricalProfileTypes.contains(genericAssayDataFilter.getProfileType()))
.collect(Collectors.toList()));
}
return builder.build();
}

public boolean shouldApplyPatientIdFilters() {
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,6 +9,7 @@
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;
Expand All @@ -17,8 +18,10 @@
import org.cbioportal.persistence.enums.ClinicalAttributeDataSource;
import org.cbioportal.persistence.helper.AlterationFilterHelper;
import org.cbioportal.persistence.helper.StudyViewFilterHelper;
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 All @@ -34,6 +37,7 @@
public class StudyViewMyBatisRepository implements StudyViewRepository {

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


private static final List<String> FILTERED_CLINICAL_ATTR_VALUES = Collections.emptyList();
Expand Down Expand Up @@ -101,14 +105,19 @@ public List<GenomicDataCount> getMolecularProfileSampleCounts(StudyViewFilterCon
}

public StudyViewFilterHelper createStudyViewFilterHelper(StudyViewFilterContext studyViewFilterContext) {
return StudyViewFilterHelper.build(studyViewFilterContext.studyViewFilter(), getClinicalAttributeNameMap(), studyViewFilterContext.customDataFilterSamples());
return StudyViewFilterHelper.build(studyViewFilterContext.studyViewFilter(), getClinicalAttributeNameMap(), 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 Down Expand Up @@ -199,19 +208,42 @@ 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));
}

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

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

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

@Override
public List<GenomicDataCountItem> getCNACounts(StudyViewFilterContext studyViewFilterContext, List<GenomicDataFilter> genomicDataFilters) {
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,30 @@ public SampleTreatmentReport getSampleTreatmentReport(StudyViewFilter studyViewF
return treatmentCountReportService.getSampleTreatmentReport(createContext(studyViewFilter));
}

@Override
public List<ClinicalDataCountItem> getGenomicDataBinCounts(StudyViewFilter studyViewFilter, List<String> filteredAttributes) {
return studyViewRepository.getGenomicDataBinCounts(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());
}

@Override
public List<ClinicalDataCountItem> getGenericAssayDataBinCounts(StudyViewFilter studyViewFilter, List<String> filteredAttributes) {
return studyViewRepository.getGenericAssayDataBinCounts(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());
}

public List<CopyNumberCountByGene> getCnaGenes(StudyViewFilter studyViewFilter) {
return alterationCountService.getCnaGenes(createContext(studyViewFilter));
}
Expand Down
Loading

0 comments on commit 415cb1a

Please sign in to comment.