Skip to content

Commit

Permalink
address issues besides NA counts
Browse files Browse the repository at this point in the history
  • Loading branch information
dippindots committed Aug 29, 2024
1 parent 7b4dd2a commit e4fd443
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 500 deletions.
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 @@ -68,10 +68,8 @@ public interface StudyViewMapper {
List<GenomicDataCountItem> getMutationCountsByType(StudyViewFilterHelper studyViewFilterHelper, List<GenomicDataFilter> genomicDataFilters);

// TODO: update this with new parameters
List<ClinicalDataCount> getGenomicDataBinCounts(StudyViewFilter studyViewFilter, CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter,
boolean applyPatientIdFilters, List<String> attributeIds, List<String> filteredAttributeValues);
List<ClinicalDataCount> getGenericAssayDataBinCounts(StudyViewFilter studyViewFilter, CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter,
boolean applyPatientIdFilters, List<String> attributeIds, List<String> filteredAttributeValues);
List<ClinicalDataCount> getGenomicDataBinCounts(StudyViewFilterHelper studyViewFilterHelper, List<String> attributeIds);
List<ClinicalDataCount> getGenericAssayDataBinCounts(StudyViewFilterHelper studyViewFilterHelper, List<String> attributeIds);

List<MolecularProfile> getGenericAssayProfiles();
}
Loading

0 comments on commit e4fd443

Please sign in to comment.