Skip to content

Commit

Permalink
separate mutated and mutation types service
Browse files Browse the repository at this point in the history
  • Loading branch information
qlu-cls committed Dec 19, 2023
1 parent c483c96 commit 6a37817
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 110 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,7 +12,7 @@ public enum MutationFilterOption {
this.mutationFilterOption = mutationFilterOption;
}

public String getMutationType() {
public String getMutationFilterOption() {
return mutationFilterOption;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface StudyViewService {
List<AlterationCountByGene> getMutationAlterationCountByGenes(List<String> studyIds, List<String> sampleIds, AlterationFilter annotationFilter)
throws StudyNotFoundException;

List<GenomicDataCountItem> getMutationCountsByGeneSpecific(List<String> studyIds, List<String> sampleIds, List<Pair<String, String>> genomicDataFilters, AlterationFilter annotationFilter, String projection);
List<GenomicDataCountItem> getMutationCountsByGeneSpecific(List<String> studyIds, List<String> sampleIds, List<Pair<String, String>> genomicDataFilters, AlterationFilter annotationFilter);

List<GenomicDataCountItem> getMutationTypeCountsByGeneSpecific(List<String> studyIds, List<String> sampleIds, List<Pair<String, String>> genomicDataFilters);

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -112,8 +111,7 @@ public List<AlterationCountByGene> getMutationAlterationCountByGenes(List<String
public List<GenomicDataCountItem> getMutationCountsByGeneSpecific(List<String> studyIds,
List<String> sampleIds,
List<Pair<String, String>> genomicDataFilters,
AlterationFilter alterationFilter,
String projection) {
AlterationFilter alterationFilter) {
List<MolecularProfileCaseIdentifier> caseIdentifiers =
molecularProfileService.getMutationProfileCaseIdentifiers(studyIds, sampleIds);

Expand All @@ -134,13 +132,6 @@ public List<GenomicDataCountItem> getMutationCountsByGeneSpecific(List<String> s
false,
alterationFilter).getFirst();

List<GenomicDataCountItem> mutationTypeCountItems;
if (projection.equals("DETAILED")) {
mutationTypeCountItems = getMutationTypeCountsByGeneSpecific(studyIds, sampleIds, genomicDataFilters);
} else {
mutationTypeCountItems = new ArrayList<>();
}

return genomicDataFilters
.stream()
.flatMap(gdFilter -> {
Expand All @@ -164,33 +155,24 @@ public List<GenomicDataCountItem> getMutationCountsByGeneSpecific(List<String> s
int totalCount = sampleIds.size();

List<GenomicDataCount> genomicDataCounts = new ArrayList<>();

if (CollectionUtils.isNotEmpty(mutationTypeCountItems)) {
Optional<GenomicDataCountItem> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,37 +235,11 @@ public void getMutationCountsByGeneSpecific() {
List<Pair<String, String>> genomicDataFilters = new ArrayList<>();
Pair<String, String> 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<GenomicDataCount> 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<GenomicDataCountItem> 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
Expand Down
21 changes: 14 additions & 7 deletions web/src/main/java/org/cbioportal/web/StudyViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -1113,13 +1113,20 @@ public ResponseEntity<List<GenomicDataCountItem>> fetchMutationDataCounts(
List<String> sampleIds = new ArrayList<>();
studyViewFilterUtil.extractStudyAndSampleIds(filteredSampleIdentifiers, studyIds, sampleIds);

List<GenomicDataCountItem> result = studyViewService.getMutationCountsByGeneSpecific(
studyIds,
sampleIds,
gdFilters.stream().map(gdFilter -> new Pair<>(gdFilter.getHugoGeneSymbol(), gdFilter.getProfileType())).collect(Collectors.toList()),
studyViewFilter.getAlterationFilter(),
projection.name()
);
List<GenomicDataCountItem> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1056,42 +1056,18 @@ private List<ClinicalData> fetchMutationDataAndTransformToClinicalDataList(
.stream().collect(Collectors.toMap(MolecularProfile::getCancerStudyIdentifier,
MolecularProfile::getStableId));

Stream<ClinicalData> res = Stream.of();
List<DataFilterValue> 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<ClinicalData> res1 = fetchMutatedAndProfiledMutationData(
sampleIdentifiers, geneNameIdMap, mutationDataFilter,
studyIdToMolecularProfileIdMap);
res = Stream.concat(res, res1);
}
return res;
}).collect(Collectors.toList());
}
private <S extends DataFilter> List<ClinicalDataFilter> transformToClinicalDataFilter(List<S> dataFilters) {
Expand Down Expand Up @@ -1191,7 +1167,7 @@ private List<SampleIdentifier> fetchMutationOptionDataByGene(List<String> studyI
return newSampleIdentifiers;
}

private Stream<ClinicalData> fetchMutatedAndProfiledMutationData(
private Stream<ClinicalData> fetchMutatedAndWildTypeData(
List<SampleIdentifier> sampleIdentifiers, Map<String, Integer> geneNameIdMap, MutationDataFilter mutationDataFilter,
Map<String, String> studyIdToMolecularProfileIdMap) {
List<String> studyIds = new ArrayList<>();
Expand Down Expand Up @@ -1223,7 +1199,7 @@ private Stream<ClinicalData> fetchMutatedAndProfiledMutationData(
List<ClinicalData> notProfiledClinicalDatas = transformSampleIdentifiersToClinicalData(
notProfiledSampleIdentifiers,
studyViewFilterUtil.getMutationDataFilterUniqueKey(mutationDataFilter),
MutationFilterOption.NOT_PROFILED.name()
MutationFilterOption.NA.name()
);

clinicalDatas.addAll(notProfiledClinicalDatas);
Expand All @@ -1237,7 +1213,7 @@ private Stream<ClinicalData> fetchMutatedAndProfiledMutationData(
List<ClinicalData> notMutatedClinicalDatas = transformSampleIdentifiersToClinicalData(
notMutatedSampleIdentifiers,
studyViewFilterUtil.getMutationDataFilterUniqueKey(mutationDataFilter),
MutationFilterOption.NOT_MUTATED.name()
MutationFilterOption.WILD_TYPE.name()
);

clinicalDatas.addAll(notMutatedClinicalDatas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6a37817

Please sign in to comment.