From 6a37817f0a17216dc909ded9f4618a5ba02a7abf Mon Sep 17 00:00:00 2001 From: Qi-Xuan Lu Date: Tue, 19 Dec 2023 14:08:42 +0100 Subject: [PATCH] separate mutated and mutation types service --- .../model/MutationFilterOption.java | 8 +-- .../cbioportal/service/StudyViewService.java | 2 +- .../service/impl/StudyViewServiceImpl.java | 52 ++++++------------- .../impl/StudyViewServiceImplTest.java | 30 +---------- .../cbioportal/web/StudyViewController.java | 21 +++++--- .../web/util/StudyViewFilterApplier.java | 42 ++++----------- .../web/StudyViewControllerTest.java | 9 +++- 7 files changed, 54 insertions(+), 110 deletions(-) diff --git a/model/src/main/java/org/cbioportal/model/MutationFilterOption.java b/model/src/main/java/org/cbioportal/model/MutationFilterOption.java index 0ab49b62722..30b16234be3 100644 --- a/model/src/main/java/org/cbioportal/model/MutationFilterOption.java +++ b/model/src/main/java/org/cbioportal/model/MutationFilterOption.java @@ -1,9 +1,9 @@ package org.cbioportal.model; public enum MutationFilterOption { - MUTATED("Mutated"), - NOT_MUTATED("Not Mutated"), - NOT_PROFILED("Not Profiled"), + MUTATED("Mutated vs. Wild Type"), + WILD_TYPE("Wild Type"), + NA("NA"), ; private final String mutationFilterOption; @@ -12,7 +12,7 @@ public enum MutationFilterOption { this.mutationFilterOption = mutationFilterOption; } - public String getMutationType() { + public String getMutationFilterOption() { return mutationFilterOption; } } diff --git a/service/src/main/java/org/cbioportal/service/StudyViewService.java b/service/src/main/java/org/cbioportal/service/StudyViewService.java index bdb383191db..93645a36dc7 100644 --- a/service/src/main/java/org/cbioportal/service/StudyViewService.java +++ b/service/src/main/java/org/cbioportal/service/StudyViewService.java @@ -12,7 +12,7 @@ public interface StudyViewService { List getMutationAlterationCountByGenes(List studyIds, List sampleIds, AlterationFilter annotationFilter) throws StudyNotFoundException; - List getMutationCountsByGeneSpecific(List studyIds, List sampleIds, List> genomicDataFilters, AlterationFilter annotationFilter, String projection); + List getMutationCountsByGeneSpecific(List studyIds, List sampleIds, List> genomicDataFilters, AlterationFilter annotationFilter); List getMutationTypeCountsByGeneSpecific(List studyIds, List sampleIds, List> genomicDataFilters); diff --git a/service/src/main/java/org/cbioportal/service/impl/StudyViewServiceImpl.java b/service/src/main/java/org/cbioportal/service/impl/StudyViewServiceImpl.java index 8517f5e6dcf..dbcb40e8993 100644 --- a/service/src/main/java/org/cbioportal/service/impl/StudyViewServiceImpl.java +++ b/service/src/main/java/org/cbioportal/service/impl/StudyViewServiceImpl.java @@ -1,6 +1,5 @@ package org.cbioportal.service.impl; -import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.map.MultiKeyMap; import org.apache.commons.lang3.StringUtils; import org.apache.commons.math3.util.Pair; @@ -112,8 +111,7 @@ public List getMutationAlterationCountByGenes(List getMutationCountsByGeneSpecific(List studyIds, List sampleIds, List> genomicDataFilters, - AlterationFilter alterationFilter, - String projection) { + AlterationFilter alterationFilter) { List caseIdentifiers = molecularProfileService.getMutationProfileCaseIdentifiers(studyIds, sampleIds); @@ -134,13 +132,6 @@ public List getMutationCountsByGeneSpecific(List s false, alterationFilter).getFirst(); - List mutationTypeCountItems; - if (projection.equals("DETAILED")) { - mutationTypeCountItems = getMutationTypeCountsByGeneSpecific(studyIds, sampleIds, genomicDataFilters); - } else { - mutationTypeCountItems = new ArrayList<>(); - } - return genomicDataFilters .stream() .flatMap(gdFilter -> { @@ -164,33 +155,24 @@ public List getMutationCountsByGeneSpecific(List s int totalCount = sampleIds.size(); List genomicDataCounts = new ArrayList<>(); - - if (CollectionUtils.isNotEmpty(mutationTypeCountItems)) { - Optional genomicDataCountItemType = mutationTypeCountItems.stream() - .filter(item -> item.getHugoGeneSymbol().equals(hugoGeneSymbol) && item.getProfileType().equals(profileType)) - .findFirst(); - genomicDataCountItemType.ifPresent(dataCountItem -> genomicDataCounts.addAll(dataCountItem.getCounts())); - } - - if (CollectionUtils.isEmpty(genomicDataCounts)) { - GenomicDataCount genomicDataCountMutated = new GenomicDataCount(); - genomicDataCountMutated.setLabel(MutationFilterOption.MUTATED.getMutationType()); - genomicDataCountMutated.setValue(MutationFilterOption.MUTATED.name()); - genomicDataCountMutated.setCount(mutatedCount); - genomicDataCountMutated.setUniqueCount(mutatedCount); - if (genomicDataCountMutated.getCount() > 0) genomicDataCounts.add(genomicDataCountMutated); - } - - GenomicDataCount genomicDataCountNotMutated = new GenomicDataCount(); - genomicDataCountNotMutated.setLabel(MutationFilterOption.NOT_MUTATED.getMutationType()); - genomicDataCountNotMutated.setValue(MutationFilterOption.NOT_MUTATED.name()); - genomicDataCountNotMutated.setCount(profiledCount - mutatedCount); - genomicDataCountNotMutated.setUniqueCount(profiledCount - mutatedCount); - if (genomicDataCountNotMutated.getCount() > 0) genomicDataCounts.add(genomicDataCountNotMutated); + + GenomicDataCount genomicDataCountMutated = new GenomicDataCount(); + genomicDataCountMutated.setLabel(MutationFilterOption.MUTATED.getMutationFilterOption()); + genomicDataCountMutated.setValue(MutationFilterOption.MUTATED.name()); + genomicDataCountMutated.setCount(mutatedCount); + genomicDataCountMutated.setUniqueCount(mutatedCount); + if (genomicDataCountMutated.getCount() > 0) genomicDataCounts.add(genomicDataCountMutated); + + GenomicDataCount genomicDataCountWildType = new GenomicDataCount(); + genomicDataCountWildType.setLabel(MutationFilterOption.WILD_TYPE.getMutationFilterOption()); + genomicDataCountWildType.setValue(MutationFilterOption.WILD_TYPE.name()); + genomicDataCountWildType.setCount(profiledCount - mutatedCount); + genomicDataCountWildType.setUniqueCount(profiledCount - mutatedCount); + if (genomicDataCountWildType.getCount() > 0) genomicDataCounts.add(genomicDataCountWildType); GenomicDataCount genomicDataCountNotProfiled = new GenomicDataCount(); - genomicDataCountNotProfiled.setLabel(MutationFilterOption.NOT_PROFILED.getMutationType()); - genomicDataCountNotProfiled.setValue(MutationFilterOption.NOT_PROFILED.name()); + genomicDataCountNotProfiled.setLabel(MutationFilterOption.NA.getMutationFilterOption()); + genomicDataCountNotProfiled.setValue(MutationFilterOption.NA.name()); genomicDataCountNotProfiled.setCount(totalCount - profiledCount); genomicDataCountNotProfiled.setUniqueCount(totalCount - profiledCount); if (genomicDataCountNotProfiled.getCount() > 0) genomicDataCounts.add(genomicDataCountNotProfiled); diff --git a/service/src/test/java/org/cbioportal/service/impl/StudyViewServiceImplTest.java b/service/src/test/java/org/cbioportal/service/impl/StudyViewServiceImplTest.java index 820bf525052..193a6cf7cb7 100644 --- a/service/src/test/java/org/cbioportal/service/impl/StudyViewServiceImplTest.java +++ b/service/src/test/java/org/cbioportal/service/impl/StudyViewServiceImplTest.java @@ -235,37 +235,11 @@ public void getMutationCountsByGeneSpecific() { List> genomicDataFilters = new ArrayList<>(); Pair genomicDataFilter = new Pair<>(BaseServiceImplTest.HUGO_GENE_SYMBOL_1, BaseServiceImplTest.PROFILE_TYPE_1); genomicDataFilters.add(genomicDataFilter); - - GenomicDataCountItem genomicDataCountItem = new GenomicDataCountItem(); - genomicDataCountItem.setHugoGeneSymbol(BaseServiceImplTest.HUGO_GENE_SYMBOL_1); - genomicDataCountItem.setProfileType(BaseServiceImplTest.PROFILE_TYPE_1); - List genomicDataCounts = new ArrayList<>(); - GenomicDataCount genomicDataCount1 = new GenomicDataCount(); - genomicDataCount1.setLabel(MutationEventType.missense_mutation.getMutationType()); - genomicDataCount1.setValue(MutationEventType.missense_mutation.getMutationType()); - genomicDataCount1.setCount(2); - genomicDataCount1.setUniqueCount(1); - genomicDataCounts.add(genomicDataCount1); - GenomicDataCount genomicDataCount2 = new GenomicDataCount(); - genomicDataCount2.setLabel(MutationEventType.splice_site_indel.getMutationType()); - genomicDataCount2.setValue(MutationEventType.splice_site_indel.getMutationType()); - genomicDataCount2.setCount(2); - genomicDataCount2.setUniqueCount(1); - genomicDataCounts.add(genomicDataCount2); - genomicDataCountItem.setCounts(genomicDataCounts); - - Mockito.doReturn(Collections.singletonList(genomicDataCountItem)) - .when(studyViewService).getMutationTypeCountsByGeneSpecific(anyList(), anyList(), anyList()); List result = studyViewService.getMutationCountsByGeneSpecific( - studyIds, sampleIds, genomicDataFilters, alterationFilter, "SUMMARY"); - Assert.assertEquals(1, result.size()); - Assert.assertEquals(3, result.get(0).getCounts().size()); - - result = studyViewService.getMutationCountsByGeneSpecific( - studyIds, sampleIds, genomicDataFilters, alterationFilter, "DETAILED"); + studyIds, sampleIds, genomicDataFilters, alterationFilter); Assert.assertEquals(1, result.size()); - Assert.assertEquals(4, result.get(0).getCounts().size()); + Assert.assertEquals(1, result.get(0).getCounts().size()); } @Test diff --git a/web/src/main/java/org/cbioportal/web/StudyViewController.java b/web/src/main/java/org/cbioportal/web/StudyViewController.java index 33f31f899b0..1f549358742 100644 --- a/web/src/main/java/org/cbioportal/web/StudyViewController.java +++ b/web/src/main/java/org/cbioportal/web/StudyViewController.java @@ -1113,13 +1113,20 @@ public ResponseEntity> fetchMutationDataCounts( List sampleIds = new ArrayList<>(); studyViewFilterUtil.extractStudyAndSampleIds(filteredSampleIdentifiers, studyIds, sampleIds); - List result = studyViewService.getMutationCountsByGeneSpecific( - studyIds, - sampleIds, - gdFilters.stream().map(gdFilter -> new Pair<>(gdFilter.getHugoGeneSymbol(), gdFilter.getProfileType())).collect(Collectors.toList()), - studyViewFilter.getAlterationFilter(), - projection.name() - ); + List result; + + result = projection == Projection.SUMMARY ? + studyViewService.getMutationCountsByGeneSpecific( + studyIds, + sampleIds, + gdFilters.stream().map(gdFilter -> new Pair<>(gdFilter.getHugoGeneSymbol(), gdFilter.getProfileType())).collect(Collectors.toList()), + studyViewFilter.getAlterationFilter() + ) : + studyViewService.getMutationTypeCountsByGeneSpecific( + studyIds, + sampleIds, + gdFilters.stream().map(gdFilter -> new Pair<>(gdFilter.getHugoGeneSymbol(), gdFilter.getProfileType())).collect(Collectors.toList()) + ); return new ResponseEntity<>(result, HttpStatus.OK); } diff --git a/web/src/main/java/org/cbioportal/web/util/StudyViewFilterApplier.java b/web/src/main/java/org/cbioportal/web/util/StudyViewFilterApplier.java index 92f5626823a..34e07201ef9 100644 --- a/web/src/main/java/org/cbioportal/web/util/StudyViewFilterApplier.java +++ b/web/src/main/java/org/cbioportal/web/util/StudyViewFilterApplier.java @@ -1056,42 +1056,18 @@ private List fetchMutationDataAndTransformToClinicalDataList( .stream().collect(Collectors.toMap(MolecularProfile::getCancerStudyIdentifier, MolecularProfile::getStableId)); - Stream res = Stream.of(); - List customFilters = new ArrayList<>(); - - if (mutationDataFilter.getCategorization() == MutationOption.EVENT) { - customFilters = mutationDataFilter.getValues() - .stream() - .flatMap(value -> - value.stream().filter(x -> x.getValue().equalsIgnoreCase(MutationFilterOption. - MUTATED - .name()) || - x.getValue().equalsIgnoreCase(MutationFilterOption. - NOT_PROFILED - .name()) || - x.getValue().equalsIgnoreCase(MutationFilterOption. - NOT_MUTATED - .name())) - ).collect(Collectors.toList()); - - + if (mutationDataFilter.getCategorization() == MutationOption.MUTATED) { + return fetchMutatedAndWildTypeData( + sampleIdentifiers, geneNameIdMap, mutationDataFilter, + studyIdToMolecularProfileIdMap); + } else { // fetch mutation type data - res = invokeDataFunc(sampleIds, studyIds, Collections.singletonList( + return invokeDataFunc(sampleIds, studyIds, Collections.singletonList( geneNameIdMap.get(mutationDataFilter.getHugoGeneSymbol()).toString()), studyIdToMolecularProfileIdMap, studyViewFilterUtil.getMutationDataFilterUniqueKey(mutationDataFilter), fetchMutationData); - - } - if (mutationDataFilter.getCategorization() == MutationOption.MUTATED || - CollectionUtils.isNotEmpty(customFilters)) { - - Stream res1 = fetchMutatedAndProfiledMutationData( - sampleIdentifiers, geneNameIdMap, mutationDataFilter, - studyIdToMolecularProfileIdMap); - res = Stream.concat(res, res1); } - return res; }).collect(Collectors.toList()); } private List transformToClinicalDataFilter(List dataFilters) { @@ -1191,7 +1167,7 @@ private List fetchMutationOptionDataByGene(List studyI return newSampleIdentifiers; } - private Stream fetchMutatedAndProfiledMutationData( + private Stream fetchMutatedAndWildTypeData( List sampleIdentifiers, Map geneNameIdMap, MutationDataFilter mutationDataFilter, Map studyIdToMolecularProfileIdMap) { List studyIds = new ArrayList<>(); @@ -1223,7 +1199,7 @@ private Stream fetchMutatedAndProfiledMutationData( List notProfiledClinicalDatas = transformSampleIdentifiersToClinicalData( notProfiledSampleIdentifiers, studyViewFilterUtil.getMutationDataFilterUniqueKey(mutationDataFilter), - MutationFilterOption.NOT_PROFILED.name() + MutationFilterOption.NA.name() ); clinicalDatas.addAll(notProfiledClinicalDatas); @@ -1237,7 +1213,7 @@ private Stream fetchMutatedAndProfiledMutationData( List notMutatedClinicalDatas = transformSampleIdentifiersToClinicalData( notMutatedSampleIdentifiers, studyViewFilterUtil.getMutationDataFilterUniqueKey(mutationDataFilter), - MutationFilterOption.NOT_MUTATED.name() + MutationFilterOption.WILD_TYPE.name() ); clinicalDatas.addAll(notMutatedClinicalDatas); diff --git a/web/src/test/java/org/cbioportal/web/StudyViewControllerTest.java b/web/src/test/java/org/cbioportal/web/StudyViewControllerTest.java index ce967ecf23b..4aff1812225 100644 --- a/web/src/test/java/org/cbioportal/web/StudyViewControllerTest.java +++ b/web/src/test/java/org/cbioportal/web/StudyViewControllerTest.java @@ -1117,8 +1117,13 @@ public void fetchMutationDataCounts() throws Exception { anyList(), anyList(), anyList(), - any(AlterationFilter.class), - anyString())) + any(AlterationFilter.class))) + .thenReturn(genomicDataCountItems); + + when(studyViewService.getMutationTypeCountsByGeneSpecific( + anyList(), + anyList(), + anyList())) .thenReturn(genomicDataCountItems); GenomicDataCountFilter genomicDataCountFilter = new GenomicDataCountFilter();