Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dippindots committed Aug 30, 2024
1 parent 415cb1a commit 030e7f1
Show file tree
Hide file tree
Showing 11 changed files with 365 additions and 284 deletions.
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
Expand Up @@ -2,8 +2,10 @@

import org.cbioportal.model.ClinicalAttribute;
import org.cbioportal.model.MolecularProfile;
import org.cbioportal.persistence.enums.ClinicalAttributeDataSource;
import org.cbioportal.persistence.enums.DataSource;
import org.cbioportal.web.parameter.CategorizedClinicalDataCountFilter;
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;
Expand All @@ -18,17 +20,17 @@

public final class StudyViewFilterHelper {
public static StudyViewFilterHelper build(@Nullable StudyViewFilter studyViewFilter,
@Nullable Map<ClinicalAttributeDataSource, List<ClinicalAttribute>> clinicalAttributesMap,
@Nullable Map<ClinicalAttributeDataSource, List<MolecularProfile>> genericAssayProfilesMap,
@Nullable Map<DataSource, List<ClinicalAttribute>> clinicalAttributesMap,
@Nullable Map<DataSource, List<MolecularProfile>> genericAssayProfilesMap,
@Nullable List<CustomSampleIdentifier> customDataSamples) {
if (Objects.isNull(studyViewFilter)) {
studyViewFilter = new StudyViewFilter();
}
if (Objects.isNull(clinicalAttributesMap)) {
clinicalAttributesMap = new EnumMap<>(ClinicalAttributeDataSource.class);
clinicalAttributesMap = new EnumMap<>(DataSource.class);
}
if (Objects.isNull(genericAssayProfilesMap)) {
genericAssayProfilesMap = new EnumMap<>(ClinicalAttributeDataSource.class);
genericAssayProfilesMap = new EnumMap<>(DataSource.class);
}
if (Objects.isNull(customDataSamples)) {
customDataSamples = new ArrayList<>();
Expand All @@ -38,15 +40,22 @@ public static StudyViewFilterHelper build(@Nullable StudyViewFilter studyViewFil

private final StudyViewFilter studyViewFilter;
private final CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter;

private final CategorizedGenomicDataCountFilter categorizedGenomicDataCountFilter;

private final CategorizedGenericAssayDataCountFilter categorizedGenericAssayDataCountFilter;

private final List<CustomSampleIdentifier> customDataSamples;
private final boolean applyPatientIdFilters;


private StudyViewFilterHelper(@NonNull StudyViewFilter studyViewFilter, @NonNull Map<ClinicalAttributeDataSource, List<ClinicalAttribute>> clinicalAttributesMap,
@NonNull Map<ClinicalAttributeDataSource, List<MolecularProfile>> genericAssayProfilesMap,
private StudyViewFilterHelper(@NonNull StudyViewFilter studyViewFilter, @NonNull Map<DataSource, List<ClinicalAttribute>> clinicalAttributesMap,
@NonNull Map<DataSource, List<MolecularProfile>> genericAssayProfilesMap,
@NonNull List<CustomSampleIdentifier> customDataSamples) {
this.studyViewFilter = studyViewFilter;
this.categorizedClinicalDataCountFilter = extractClinicalDataCountFilters(studyViewFilter, clinicalAttributesMap, genericAssayProfilesMap);
this.categorizedGenomicDataCountFilter = extractGenomicDataCountFilters(studyViewFilter);
this.categorizedGenericAssayDataCountFilter = extractGenericAssayDataCountFilters(studyViewFilter, genericAssayProfilesMap);
this.customDataSamples = customDataSamples;
this.applyPatientIdFilters = shouldApplyPatientIdFilters();
}
Expand All @@ -58,81 +67,104 @@ public StudyViewFilter studyViewFilter() {
public CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter() {
return categorizedClinicalDataCountFilter;
}

public CategorizedGenomicDataCountFilter categorizedGenomicDataCountFilter() {
return categorizedGenomicDataCountFilter;
}

public CategorizedGenericAssayDataCountFilter categorizedGenericAssayDataCountFilter() {
return categorizedGenericAssayDataCountFilter;
}

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

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)
private CategorizedClinicalDataCountFilter extractClinicalDataCountFilters(final StudyViewFilter studyViewFilter, Map<DataSource, List<ClinicalAttribute>> clinicalAttributesMap, Map<DataSource, List<MolecularProfile>> genericAssayProfilesMap) {
if ((studyViewFilter.getClinicalDataFilters() == null || clinicalAttributesMap.isEmpty()))
{
return CategorizedClinicalDataCountFilter.getBuilder().build();
}

CategorizedClinicalDataCountFilter.Builder builder = CategorizedClinicalDataCountFilter.getBuilder();

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

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

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

List<String> sampleNumericalAttributes = clinicalAttributesMap.get(ClinicalAttributeDataSource.SAMPLE)
List<String> sampleNumericalAttributes = clinicalAttributesMap.get(DataSource.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()))
.toList())
.setPatientNumericalClinicalDataFilters(studyViewFilter.getClinicalDataFilters().stream()
.filter(clinicalDataFilter -> patientNumericalAttributes.contains(clinicalDataFilter.getAttributeId()))
.collect(Collectors.toList()))
.toList())
.setSampleCategoricalClinicalDataFilters(studyViewFilter.getClinicalDataFilters().stream()
.filter(clinicalDataFilter -> sampleCategoricalAttributes.contains(clinicalDataFilter.getAttributeId()))
.collect(Collectors.toList()))
.toList())
.setSampleNumericalClinicalDataFilters(studyViewFilter.getClinicalDataFilters().stream()
.filter(clinicalDataFilter -> sampleNumericalAttributes.contains(clinicalDataFilter.getAttributeId()))
.collect(Collectors.toList()));
.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()));
return builder.build();
}

private CategorizedGenomicDataCountFilter extractGenomicDataCountFilters(final StudyViewFilter studyViewFilter) {
if (studyViewFilter.getGenomicDataFilters() == null)
{
return CategorizedGenomicDataCountFilter.getBuilder().build();
}
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();

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()));
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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@
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.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;

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 @@ -36,8 +35,8 @@
@Repository
public class StudyViewMyBatisRepository implements StudyViewRepository {

private Map<ClinicalAttributeDataSource, List<ClinicalAttribute>> clinicalAttributesMap = new HashMap<>();
private Map<ClinicalAttributeDataSource, List<MolecularProfile>> genericAssayProfilesMap = 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();
Expand Down Expand Up @@ -127,11 +126,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 @@ -222,23 +221,23 @@ public List<ClinicalDataCount> getGenericAssayDataBinCounts(StudyViewFilterConte
private void buildClinicalAttributeNameMap() {
clinicalAttributesMap = this.getClinicalAttributes()
.stream()
.collect(Collectors.groupingBy(ca -> ca.getPatientAttribute() ? ClinicalAttributeDataSource.PATIENT : ClinicalAttributeDataSource.SAMPLE));
.collect(Collectors.groupingBy(ca -> ca.getPatientAttribute() ? DataSource.PATIENT : DataSource.SAMPLE));
}

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

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

private Map<ClinicalAttributeDataSource, List<MolecularProfile>> getGenericAssayProfilesMap() {
private Map<DataSource, List<MolecularProfile>> getGenericAssayProfilesMap() {
if (genericAssayProfilesMap.isEmpty()) {
buildGenericAssayProfilesMap();
}
Expand Down
Loading

0 comments on commit 030e7f1

Please sign in to comment.