diff --git a/src/main/java/org/cbioportal/persistence/StudyViewRepository.java b/src/main/java/org/cbioportal/persistence/StudyViewRepository.java index 27b75170b15..5c3ee61a9c3 100644 --- a/src/main/java/org/cbioportal/persistence/StudyViewRepository.java +++ b/src/main/java/org/cbioportal/persistence/StudyViewRepository.java @@ -5,6 +5,7 @@ import org.cbioportal.model.CaseListDataCount; import org.cbioportal.model.ClinicalData; import org.cbioportal.model.ClinicalDataCount; +import org.cbioportal.model.ClinicalDataCountItem; import org.cbioportal.model.ClinicalEventTypeCount; import org.cbioportal.model.CopyNumberCountByGene; import org.cbioportal.model.GenericAssayDataCountItem; @@ -39,7 +40,7 @@ public interface StudyViewRepository { List getStructuralVariantGenes(StudyViewFilterContext studyViewFilterContext); List getCnaGenes(StudyViewFilterContext studyViewFilterContext); - List getClinicalDataCounts(StudyViewFilterContext studyViewFilterContext, List filteredAttributes); + List getClinicalDataCounts(StudyViewFilterContext studyViewFilterContext, List filteredAttributes); List getMolecularProfileSampleCounts(StudyViewFilterContext studyViewFilterContext); diff --git a/src/main/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapper.java b/src/main/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapper.java index 1662980258f..97419bcf06b 100644 --- a/src/main/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapper.java +++ b/src/main/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapper.java @@ -6,6 +6,7 @@ import org.cbioportal.model.ClinicalAttribute; import org.cbioportal.model.ClinicalData; import org.cbioportal.model.ClinicalDataCount; +import org.cbioportal.model.ClinicalDataCountItem; import org.cbioportal.model.ClinicalEventTypeCount; import org.cbioportal.model.CopyNumberCountByGene; import org.cbioportal.model.GenePanelToGene; @@ -40,7 +41,7 @@ public interface StudyViewMapper { List getStructuralVariantGenes(StudyViewFilterHelper studyViewFilterHelper, AlterationFilterHelper alterationFilterHelper); - List getClinicalDataCounts(StudyViewFilterHelper studyViewFilterHelper, List attributeIds, List filteredAttributeValues); + List getClinicalDataCounts(StudyViewFilterHelper studyViewFilterHelper, List attributeIds, List filteredAttributeValues); List getCaseListDataCountsPerStudy(@Param("studyViewFilterHelper") StudyViewFilterHelper studyViewFilterHelper); diff --git a/src/main/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMyBatisRepository.java b/src/main/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMyBatisRepository.java index 0ee1d0a60f9..74affd393db 100644 --- a/src/main/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMyBatisRepository.java +++ b/src/main/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMyBatisRepository.java @@ -4,6 +4,7 @@ import org.cbioportal.model.CaseListDataCount; import org.cbioportal.model.ClinicalData; import org.cbioportal.model.ClinicalDataCount; +import org.cbioportal.model.ClinicalDataCountItem; import org.cbioportal.model.ClinicalEventTypeCount; import org.cbioportal.model.GenePanelToGene; import org.cbioportal.model.GenericAssayDataCountItem; @@ -79,7 +80,7 @@ public List getStructuralVariantGenes(StudyViewFilterCont } @Override - public List getClinicalDataCounts(StudyViewFilterContext studyViewFilterContext, List filteredAttributes) { + public List getClinicalDataCounts(StudyViewFilterContext studyViewFilterContext, List filteredAttributes) { return mapper.getClinicalDataCounts(createStudyViewFilterHelper(studyViewFilterContext), filteredAttributes, FILTERED_CLINICAL_ATTR_VALUES); } diff --git a/src/main/java/org/cbioportal/service/impl/StudyViewColumnarServiceImpl.java b/src/main/java/org/cbioportal/service/impl/StudyViewColumnarServiceImpl.java index 5402ddc6584..2dc8881d6df 100644 --- a/src/main/java/org/cbioportal/service/impl/StudyViewColumnarServiceImpl.java +++ b/src/main/java/org/cbioportal/service/impl/StudyViewColumnarServiceImpl.java @@ -153,17 +153,7 @@ public Map getClinicalAttributeDatatypeMap() { ) @Override public List getClinicalDataCounts(StudyViewFilter studyViewFilter, List filteredAttributes) { - StudyViewFilterContext studyViewFilterContext = createContext(studyViewFilter); - List dataCounts = studyViewRepository.getClinicalDataCounts(studyViewFilterContext, filteredAttributes); - List clinicalDataCountItems = generateDataCountItemsFromDataCounts(dataCounts); - - return calculateMissingNaCountsForClinicalDataCountItems( - clinicalDataCountItems, - filteredAttributes.stream().distinct().toList(), - this.getClinicalAttributeDatatypeMap(), - studyViewRepository.getFilteredSamplesCount(studyViewFilterContext), - studyViewRepository.getFilteredPatientCount(studyViewFilterContext) - ); + return studyViewRepository.getClinicalDataCounts(createContext(studyViewFilter), filteredAttributes); } @Cacheable( @@ -311,83 +301,6 @@ private List normalizeDataCounts(List data return new ArrayList<>(normalizedDataCounts); } - public static List calculateMissingNaCountsForClinicalDataCountItems( - List clinicalDataCountItems, - List filteredAttributes, - Map clinicalAttributeDatatypeMap, - int filteredSamplesCount, - int filteredPatientsCount - ) { - // Postprocess clinical data count items to adjust NA counts - List combinedClinicalDataCountItems = new ArrayList<>(); - - Map clinicalDataCountItemMap = clinicalDataCountItems - .stream() - .collect(Collectors.toMap( - ClinicalDataCountItem::getAttributeId, - item -> item - )); - - // go over all filtered attributes, not just attributes found in clinicalDataCountItems - for (String attributeId: filteredAttributes) { - ClinicalDataCountItem clinicalDataCountItem = clinicalDataCountItemMap.get(attributeId); - boolean isItemMissing = false; - - if (clinicalDataCountItem == null) { - isItemMissing = true; - clinicalDataCountItem = new ClinicalDataCountItem(); - clinicalDataCountItem.setAttributeId(attributeId); - clinicalDataCountItem.setCounts(new ArrayList<>()); - } - - Integer totalClinicalDataCount = clinicalDataCountItem - .getCounts() - .stream() - .map(ClinicalDataCount::getCount) - .reduce(0, Integer::sum); - // depending on clinical data type we either use filtered sample count or filtered patient count - int filteredCount = clinicalAttributeDatatypeMap.get(clinicalDataCountItem.getAttributeId()) == ClinicalDataType.SAMPLE ? - filteredSamplesCount: filteredPatientsCount; - int casesWithoutClinicalData = filteredCount - totalClinicalDataCount; - - if (casesWithoutClinicalData > 0) { - // some of these attributes may be completely missing in clinicalDataCountItem - // in case the only attribute value is NA. - // we need to manually add those missing items to make sure we have NA counts. - if (isItemMissing) { - combinedClinicalDataCountItems.add(clinicalDataCountItem); - } - - // find "NA" or else create a new one - Optional naClinicalDataCountOptional = clinicalDataCountItem - .getCounts() - .stream() - .filter(c -> c.getValue().equals("NA")) - .findFirst(); - - ClinicalDataCount naClinicalDataCount = naClinicalDataCountOptional - .orElseGet(() -> { - // this should only happen when there are multiple studies - ClinicalDataCount count = new ClinicalDataCount(); - count.setAttributeId(attributeId); - count.setValue("NA"); - count.setCount(0); - return count; - }); - - // if not present we need to add naClinicalDataCount to the existing counts - if (naClinicalDataCountOptional.isEmpty()) { - clinicalDataCountItem.getCounts().add(naClinicalDataCount); - } - - naClinicalDataCount.setCount(naClinicalDataCount.getCount() + casesWithoutClinicalData); - } - } - - combinedClinicalDataCountItems.addAll(clinicalDataCountItems); - return combinedClinicalDataCountItems; - } - public static List mergeCaseListCounts(List counts) { Map> countsPerListType = counts.stream() .collect((Collectors.groupingBy(CaseListDataCount::getValue))); diff --git a/src/main/java/org/cbioportal/web/columnar/StudyViewColumnStoreController.java b/src/main/java/org/cbioportal/web/columnar/StudyViewColumnStoreController.java index 32d32ce8a7b..bd360e50f0a 100644 --- a/src/main/java/org/cbioportal/web/columnar/StudyViewColumnStoreController.java +++ b/src/main/java/org/cbioportal/web/columnar/StudyViewColumnStoreController.java @@ -208,12 +208,10 @@ public ResponseEntity> fetchClinicalDataCounts( StudyViewFilter studyViewFilter = interceptedClinicalDataCountFilter.getStudyViewFilter(); if (attributes.size() == 1) { - NewStudyViewFilterUtil.removeSelfFromFilter(attributes.get(0).getAttributeId(), studyViewFilter); + NewStudyViewFilterUtil.removeClinicalDataFilter(attributes.getFirst().getAttributeId(), studyViewFilter.getClinicalDataFilters()); } - // boolean singleStudyUnfiltered = studyViewFilterUtil.isSingleStudyUnfiltered(studyViewFilter); List result = studyViewColumnarService.getClinicalDataCounts(studyViewFilter, attributes.stream().map(ClinicalDataFilter::getAttributeId).collect(Collectors.toList())); - //studyIds, sampleIds, attributes.stream().map(a -> a.getAttributeId()).collect(Collectors.toList())); return new ResponseEntity<>(result, HttpStatus.OK); } @@ -576,7 +574,7 @@ public ResponseEntity> fetchCustomDataCounts( List attributes = interceptedClinicalDataCountFilter.getAttributes(); StudyViewFilter studyViewFilter = interceptedClinicalDataCountFilter.getStudyViewFilter(); if (attributes.size() == 1) { - NewStudyViewFilterUtil.removeSelfCustomDataFromFilter(attributes.get(0).getAttributeId(), studyViewFilter); + NewStudyViewFilterUtil.removeClinicalDataFilter(attributes.getFirst().getAttributeId(), studyViewFilter.getCustomDataFilters()); } List filteredSampleIdentifiers = studyViewColumnarService.getFilteredSamples(studyViewFilter).stream().map(sample -> studyViewFilterUtil.buildSampleIdentifier(sample.getCancerStudyIdentifier(), sample.getStableId())).toList(); diff --git a/src/main/java/org/cbioportal/web/columnar/util/NewClinicalDataBinUtil.java b/src/main/java/org/cbioportal/web/columnar/util/NewClinicalDataBinUtil.java index b89066fc758..df1b9524c6e 100644 --- a/src/main/java/org/cbioportal/web/columnar/util/NewClinicalDataBinUtil.java +++ b/src/main/java/org/cbioportal/web/columnar/util/NewClinicalDataBinUtil.java @@ -25,7 +25,7 @@ public static StudyViewFilter removeSelfFromFilter(ClinicalDataBinCountFilter da StudyViewFilter studyViewFilter = dataBinCountFilter.getStudyViewFilter(); if (attributes.size() == 1) { - NewStudyViewFilterUtil.removeSelfFromFilter(attributes.get(0).getAttributeId(), studyViewFilter); + NewStudyViewFilterUtil.removeClinicalDataFilter(attributes.getFirst().getAttributeId(), studyViewFilter.getClinicalDataFilters()); } return studyViewFilter; @@ -36,7 +36,7 @@ public static StudyViewFilter removeSelfCustomDataFromFilter(ClinicalDataBinCoun StudyViewFilter studyViewFilter = dataBinCountFilter.getStudyViewFilter(); if (attributes.size() == 1) { - NewStudyViewFilterUtil.removeSelfCustomDataFromFilter(attributes.get(0).getAttributeId(), studyViewFilter); + NewStudyViewFilterUtil.removeClinicalDataFilter(attributes.getFirst().getAttributeId(), studyViewFilter.getCustomDataFilters()); } return studyViewFilter; diff --git a/src/main/java/org/cbioportal/web/columnar/util/NewStudyViewFilterUtil.java b/src/main/java/org/cbioportal/web/columnar/util/NewStudyViewFilterUtil.java index 305a7ce5bae..5363802afe2 100644 --- a/src/main/java/org/cbioportal/web/columnar/util/NewStudyViewFilterUtil.java +++ b/src/main/java/org/cbioportal/web/columnar/util/NewStudyViewFilterUtil.java @@ -1,19 +1,15 @@ package org.cbioportal.web.columnar.util; -import org.cbioportal.web.parameter.StudyViewFilter; +import org.cbioportal.web.parameter.ClinicalDataFilter; -public class NewStudyViewFilterUtil { +import java.util.List; - public static void removeSelfFromFilter(String attributeId, StudyViewFilter studyViewFilter) { - if (studyViewFilter!= null && studyViewFilter.getClinicalDataFilters() != null) { - studyViewFilter.getClinicalDataFilters().removeIf(f -> f.getAttributeId().equals(attributeId)); - } - } +public class NewStudyViewFilterUtil { - public static void removeSelfCustomDataFromFilter(String attributeId, StudyViewFilter studyViewFilter) { - if (studyViewFilter != null && studyViewFilter.getCustomDataFilters() != null) { - studyViewFilter.getCustomDataFilters().removeIf(f -> f.getAttributeId().equals(attributeId)); + public static void removeClinicalDataFilter(String attributeId, List dataFilterList ) { + if (dataFilterList != null) { + dataFilterList.removeIf(f -> f.getAttributeId().equals(attributeId)); } } } diff --git a/src/main/resources/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapper.xml b/src/main/resources/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapper.xml index fea1eb9853f..56074802351 100644 --- a/src/main/resources/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapper.xml +++ b/src/main/resources/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapper.xml @@ -136,10 +136,14 @@ - + + + UNION ALL - + + + @@ -179,63 +183,63 @@ GROUP BY s.cancer_study_identifier, sl.stable_id, sl.name - - + + ( + WITH clinical_data_query AS ( SELECT - attribute_name as attributeId, - - - as value, - count(value) as count + attribute_name AS attributeId, + upper(attribute_value) AS value, + cast(count(*) AS INTEGER) as count FROM clinical_data_derived - type='sample' AND - - + type='${type}' + AND + + - - AND UPPER(value) NOT IN - - #{filteredAttributeValue} - - + != 'NA' + AND + + + + + + + + + + + + AND attribute_name IN #{attributeId} - GROUP BY attribute_name, - value - - - - SELECT - attribute_name as attributeId, - - - as value, - count(value) as count - FROM clinical_data_derived + GROUP BY attribute_name, value ), + clinical_data_sum AS (SELECT attributeId, sum(count) AS sum FROM clinical_data_query GROUP BY attributeId) + + SELECT * FROM clinical_data_query + UNION ALL + SELECT attributeId, + 'NA' AS value, + (( + + + + + + + + + ) - clinical_data_sum.sum) AS count + FROM clinical_data_sum - type='patient' AND - - - - - AND UPPER(value) NOT IN - - #{filteredAttributeValue} - - - AND attribute_name IN - - #{attributeId} - + count > 0 - GROUP BY attribute_name, - value + ) - + SELECT count(distinct sample_unique_id) as count FROM sample_derived @@ -409,6 +413,15 @@ + + + + + + + + + SELECT patient_unique_id diff --git a/src/test/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapperClinicalDataCountTest.java b/src/test/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapperClinicalDataCountTest.java index 26a5466ace7..0760a81407e 100644 --- a/src/test/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapperClinicalDataCountTest.java +++ b/src/test/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapperClinicalDataCountTest.java @@ -21,6 +21,7 @@ import java.util.List; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; @RunWith(SpringRunner.class) @Import(MyBatisConfig.class) @@ -40,12 +41,18 @@ public void getMutationCounts() { StudyViewFilter studyViewFilter = new StudyViewFilter(); studyViewFilter.setStudyIds(List.of(STUDY_GENIE_PUB)); - var mutationsCounts = studyViewMapper.getClinicalDataCounts( + var clinicalDataCountItems = studyViewMapper.getClinicalDataCounts( StudyViewFilterHelper.build(studyViewFilter, null, null), List.of("mutation_count"), Collections.emptyList() ); + var mutationsCountsOptional = clinicalDataCountItems.stream() + .filter(c -> c.getAttributeId().equals("mutation_count")).findFirst(); + + assertTrue(mutationsCountsOptional.isPresent()); + var mutationsCounts = mutationsCountsOptional.get().getCounts(); + assertEquals(6, mutationsCounts.size()); assertEquals(1, findClinicaDataCount(mutationsCounts, "11")); assertEquals(1, findClinicaDataCount(mutationsCounts, "6")); @@ -61,19 +68,25 @@ public void getCenterCounts() { StudyViewFilter studyViewFilter = new StudyViewFilter(); studyViewFilter.setStudyIds(List.of(STUDY_GENIE_PUB)); - var categoricalClinicalDataCounts = studyViewMapper.getClinicalDataCounts( + var clinicalDataCounts = studyViewMapper.getClinicalDataCounts( StudyViewFilterHelper.build(studyViewFilter, null, null), List.of("center"), Collections.emptyList() ); + var categoricalClinicalDataCountsOptional = clinicalDataCounts.stream() + .filter(c -> c.getAttributeId().equals("center")).findFirst(); + + assertTrue(categoricalClinicalDataCountsOptional.isPresent()); + var categoricalClinicalDataCounts = categoricalClinicalDataCountsOptional.get().getCounts(); + assertEquals(7, categoricalClinicalDataCounts.size()); - assertEquals(3, findClinicaDataCount(categoricalClinicalDataCounts, "msk")); - assertEquals(2, findClinicaDataCount(categoricalClinicalDataCounts, "dfci")); - assertEquals(2, findClinicaDataCount(categoricalClinicalDataCounts, "chop")); - assertEquals(1, findClinicaDataCount(categoricalClinicalDataCounts, "mda")); - assertEquals(1, findClinicaDataCount(categoricalClinicalDataCounts, "ohsu")); - assertEquals(1, findClinicaDataCount(categoricalClinicalDataCounts, "ucsf")); + assertEquals(3, findClinicaDataCount(categoricalClinicalDataCounts, "MSK")); + assertEquals(2, findClinicaDataCount(categoricalClinicalDataCounts, "DFCI")); + assertEquals(2, findClinicaDataCount(categoricalClinicalDataCounts, "CHOP")); + assertEquals(1, findClinicaDataCount(categoricalClinicalDataCounts, "MDA")); + assertEquals(1, findClinicaDataCount(categoricalClinicalDataCounts, "OHSU")); + assertEquals(1, findClinicaDataCount(categoricalClinicalDataCounts, "UCSF")); // 1 empty string + 1 'NA' + 11 samples with no data assertEquals(13, findClinicaDataCount(categoricalClinicalDataCounts, "NA")); } @@ -83,22 +96,24 @@ public void getDeadCounts() { StudyViewFilter studyViewFilter = new StudyViewFilter(); studyViewFilter.setStudyIds(List.of(STUDY_GENIE_PUB)); - var categoricalClinicalDataCounts = studyViewMapper.getClinicalDataCounts( + var clinicalDataCounts = studyViewMapper.getClinicalDataCounts( StudyViewFilterHelper.build(studyViewFilter, null, null), List.of("dead"), Collections.emptyList() ); - assertEquals(10, categoricalClinicalDataCounts.size()); - assertEquals(1, findClinicaDataCount(categoricalClinicalDataCounts, "True")); - assertEquals(1, findClinicaDataCount(categoricalClinicalDataCounts, "TRUE")); - assertEquals(1, findClinicaDataCount(categoricalClinicalDataCounts, "true")); - assertEquals(1, findClinicaDataCount(categoricalClinicalDataCounts, "False")); - assertEquals(2, findClinicaDataCount(categoricalClinicalDataCounts, "FALSE")); - assertEquals(1, findClinicaDataCount(categoricalClinicalDataCounts, "false")); - assertEquals(1, findClinicaDataCount(categoricalClinicalDataCounts, "Not Released")); - assertEquals(1, findClinicaDataCount(categoricalClinicalDataCounts, "Not Collected")); - assertEquals(1, findClinicaDataCount(categoricalClinicalDataCounts, "Unknown")); + var categoricalClinicalDataCountsOptional = clinicalDataCounts.stream() + .filter(c -> c.getAttributeId().equals("dead")).findFirst(); + + assertTrue(categoricalClinicalDataCountsOptional.isPresent()); + var categoricalClinicalDataCounts = categoricalClinicalDataCountsOptional.get().getCounts(); + + assertEquals(6, categoricalClinicalDataCounts.size()); + assertEquals(3, findClinicaDataCount(categoricalClinicalDataCounts, "TRUE")); + assertEquals(4, findClinicaDataCount(categoricalClinicalDataCounts, "FALSE")); + assertEquals(1, findClinicaDataCount(categoricalClinicalDataCounts, "NOT RELEASED")); + assertEquals(1, findClinicaDataCount(categoricalClinicalDataCounts, "NOT COLLECTED")); + assertEquals(1, findClinicaDataCount(categoricalClinicalDataCounts, "UNKNOWN")); // 1 empty string + 1 'N/A' + 11 samples with no data assertEquals(13, findClinicaDataCount(categoricalClinicalDataCounts, "NA")); } @@ -114,7 +129,7 @@ public void getMutationAndCenterCounts() { Collections.emptyList() ); - assertEquals(13, combinedClinicalDataCounts.size()); + assertEquals(2, combinedClinicalDataCounts.size()); } @Test @@ -122,12 +137,18 @@ public void getAgeCounts() { StudyViewFilter studyViewFilter = new StudyViewFilter(); studyViewFilter.setStudyIds(List.of(STUDY_GENIE_PUB)); - var ageCounts = studyViewMapper.getClinicalDataCounts( + var clinicalDataCountItems = studyViewMapper.getClinicalDataCounts( StudyViewFilterHelper.build(studyViewFilter, null, null), List.of("age"), Collections.emptyList() ); + var ageCountsOptional = clinicalDataCountItems.stream() + .filter(c -> c.getAttributeId().equals("age")).findFirst(); + + assertTrue(ageCountsOptional.isPresent()); + var ageCounts = ageCountsOptional.get().getCounts(); + assertAgeCounts(ageCounts); // 1 empty string + 1 'NAN' + 1 'N/A' + 1 patient without data @@ -139,20 +160,24 @@ public void getAgeCountsForMultipleStudies() { StudyViewFilter studyViewFilter = new StudyViewFilter(); studyViewFilter.setStudyIds(List.of(STUDY_GENIE_PUB, STUDY_ACC_TCGA)); - var ageCounts = studyViewMapper.getClinicalDataCounts( + var clinicalDataCountItems = studyViewMapper.getClinicalDataCounts( StudyViewFilterHelper.build(studyViewFilter, null, null), List.of("age"), Collections.emptyList() ); + var ageCountsOptional = clinicalDataCountItems.stream() + .filter(c -> c.getAttributeId().equals("age")).findFirst(); + + assertTrue(ageCountsOptional.isPresent()); + var ageCounts = ageCountsOptional.get().getCounts(); + // everything should be exactly the same as single study (STUDY_GENIE_PUB) filter // except NA counts assertAgeCounts(ageCounts); - // TODO this fails because of a known issue - // (https://github.com/cBioPortal/rfc80-team/issues/39) // 1 empty string + 1 'NAN' + 1 'N/A' + 1 GENIE_PUB patient without data + 4 ACC_TCGA data without data - // assertEquals(8, findClinicaDataCount(ageCounts, "NA")); + assertEquals(8, findClinicaDataCount(ageCounts, "NA")); } private void assertAgeCounts(List ageCounts) { @@ -184,12 +209,18 @@ public void getMutationCountsFilteredByAge() { ClinicalDataFilter filter = buildClinicalDataFilter("age", 20, 70); studyViewFilter.setClinicalDataFilters(List.of(filter)); - var mutationCountsFiltered = studyViewMapper.getClinicalDataCounts( + var clinicalDataCountItems = studyViewMapper.getClinicalDataCounts( StudyViewFilterHelper.build(studyViewFilter, null, null), List.of("mutation_count"), Collections.emptyList() ); + var mutationsCountsOptional = clinicalDataCountItems.stream() + .filter(c -> c.getAttributeId().equals("mutation_count")).findFirst(); + + assertTrue(mutationsCountsOptional.isPresent()); + var mutationCountsFiltered = mutationsCountsOptional.get().getCounts(); + assertEquals(3, mutationCountsFiltered.size()); assertEquals(2, findClinicaDataCount(mutationCountsFiltered, "2")); assertEquals(2, findClinicaDataCount(mutationCountsFiltered, "1")); @@ -206,12 +237,18 @@ public void getMutationCountsFilteredByAgeWithOpenStartValues() { ClinicalDataFilter filter = buildClinicalDataFilter("age", null, 20); studyViewFilter.setClinicalDataFilters(List.of(filter)); - var mutationCountsFiltered = studyViewMapper.getClinicalDataCounts( + var clinicalDataCountItems = studyViewMapper.getClinicalDataCounts( StudyViewFilterHelper.build(studyViewFilter, null, null), List.of("mutation_count"), Collections.emptyList() ); + var mutationsCountsOptional = clinicalDataCountItems.stream() + .filter(c -> c.getAttributeId().equals("mutation_count")).findFirst(); + + assertTrue(mutationsCountsOptional.isPresent()); + var mutationCountsFiltered = mutationsCountsOptional.get().getCounts(); + assertEquals(4, mutationCountsFiltered.size()); assertEquals(1, findClinicaDataCount(mutationCountsFiltered, "11")); // patient 301 assertEquals(1, findClinicaDataCount(mutationCountsFiltered, "6")); // patient 302 @@ -232,12 +269,18 @@ public void getMutationCountsFilteredByAgeWithOpenEndValues() { ClinicalDataFilter filter = buildClinicalDataFilter("age", 80, null); studyViewFilter.setClinicalDataFilters(List.of(filter)); - var mutationCountsFiltered = studyViewMapper.getClinicalDataCounts( + var clinicalDataCountItems = studyViewMapper.getClinicalDataCounts( StudyViewFilterHelper.build(studyViewFilter, null, null), List.of("mutation_count"), Collections.emptyList() ); + var mutationsCountsOptional = clinicalDataCountItems.stream() + .filter(c -> c.getAttributeId().equals("mutation_count")).findFirst(); + + assertTrue(mutationsCountsOptional.isPresent()); + var mutationCountsFiltered = mutationsCountsOptional.get().getCounts(); + assertEquals(3, mutationCountsFiltered.size()); assertEquals(1, findClinicaDataCount(mutationCountsFiltered, "4")); // patient 304 assertEquals(1, findClinicaDataCount(mutationCountsFiltered, "2")); // patient 305