Skip to content

Commit

Permalink
Overload methods
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzhaoyuan committed Sep 5, 2024
1 parent 942e443 commit a73857b
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public interface StudyViewRepository {

List<ClinicalData> getPatientClinicalData(StudyViewFilterContext studyViewFilterContext, List<String> attributeIds);

List<AlterationCountByGene> getMutatedGenes(StudyViewFilterContext studyViewFilterContext, String specificHugoGeneSymbol);
List<AlterationCountByGene> getMutatedGenes(StudyViewFilterContext studyViewFilterContext);

List<AlterationCountByGene> getMutatedGenes(StudyViewFilterContext studyViewFilterContext, List<String> hugoGeneSymbols);

List<AlterationCountByGene> getStructuralVariantGenes(StudyViewFilterContext studyViewFilterContext);
List<CopyNumberCountByGene> getCnaGenes(StudyViewFilterContext studyViewFilterContext);
Expand All @@ -42,11 +44,15 @@ public interface StudyViewRepository {

List<CaseListDataCount> getCaseListDataCountsPerStudy(StudyViewFilterContext studyViewFilterContext);

Map<String, Integer> getTotalProfiledCounts(StudyViewFilterContext studyViewFilterContext, String alterationType, String specificHugoGeneSymbol);
Map<String, Integer> getTotalProfiledCounts(StudyViewFilterContext studyViewFilterContext, String alterationType);

Map<String, Integer> getTotalProfiledCounts(StudyViewFilterContext studyViewFilterContext, String alterationType, List<String> hugoGeneSymbols);

int getFilteredSamplesCount(StudyViewFilterContext studyViewFilterContext);

Map<String, Set<String>> getMatchingGenePanelIds(StudyViewFilterContext studyViewFilterContext, String alterationType, String specificHugoGeneSymbol);
Map<String, Set<String>> getMatchingGenePanelIds(StudyViewFilterContext studyViewFilterContext, String alterationType);

Map<String, Set<String>> getMatchingGenePanelIds(StudyViewFilterContext studyViewFilterContext, String alterationType, List<String> hugoGeneSymbols);

int getTotalProfiledCountsByAlterationType(StudyViewFilterContext studyViewFilterContext, String alterationType);

Expand All @@ -65,6 +71,4 @@ public interface StudyViewRepository {
List<GenomicDataCountItem> getCNACounts(StudyViewFilterContext studyViewFilterContext, List<GenomicDataFilter> genomicDataFilters);

List<GenomicDataCountItem> getMutationCountsByType(StudyViewFilterContext studyViewFilterContext, List<GenomicDataFilter> genomicDataFilters);

AlterationCountByGene getMutatedGene(StudyViewFilterContext studyViewFilterContext, String specificHugoGeneSymbol);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface StudyViewMapper {

List<GenomicDataCount> getMolecularProfileSampleCounts(@Param("studyViewFilterHelper") StudyViewFilterHelper studyViewFilterHelper);

List<AlterationCountByGene> getMutatedGenes(StudyViewFilterHelper studyViewFilterHelper, AlterationFilterHelper alterationFilterHelper, String specificHugoGeneSymbol);
List<AlterationCountByGene> getMutatedGenes(StudyViewFilterHelper studyViewFilterHelper, AlterationFilterHelper alterationFilterHelper, List<String> hugoGeneSymbols);

List<CopyNumberCountByGene> getCnaGenes(StudyViewFilterHelper studyViewFilterHelper, AlterationFilterHelper alterationFilterHelper);

Expand All @@ -42,11 +42,11 @@ public interface StudyViewMapper {

List<ClinicalData> getPatientClinicalDataFromStudyViewFilter(StudyViewFilterHelper studyViewFilterHelper, List<String> attributeIds);

List<AlterationCountByGene> getTotalProfiledCounts(StudyViewFilterHelper studyViewFilterHelper, String alterationType, String specificHugoGeneSymbol);
List<AlterationCountByGene> getTotalProfiledCounts(StudyViewFilterHelper studyViewFilterHelper, String alterationType, List<String> hugoGeneSymbols);

int getFilteredSamplesCount(@Param("studyViewFilterHelper") StudyViewFilterHelper studyViewFilterHelper);

List<GenePanelToGene> getMatchingGenePanelIds(StudyViewFilterHelper studyViewFilterHelper, String alterationType, String specificHugoGeneSymbol);
List<GenePanelToGene> getMatchingGenePanelIds(StudyViewFilterHelper studyViewFilterHelper, String alterationType, List<String> hugoGeneSymbols);

int getTotalProfiledCountByAlterationType(StudyViewFilterHelper studyViewFilterHelper, String alterationType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ public List<Sample> getFilteredSamples(StudyViewFilterContext studyViewFilterCon
}

@Override
public List<AlterationCountByGene> getMutatedGenes(StudyViewFilterContext studyViewFilterContext, String specificHugoGeneSymbol) {
public List<AlterationCountByGene> getMutatedGenes(StudyViewFilterContext studyViewFilterContext) {
return mapper.getMutatedGenes(createStudyViewFilterHelper(studyViewFilterContext),
AlterationFilterHelper.build(studyViewFilterContext.studyViewFilter().getAlterationFilter()), specificHugoGeneSymbol);
AlterationFilterHelper.build(studyViewFilterContext.studyViewFilter().getAlterationFilter()), null);
}

@Override
public List<AlterationCountByGene> getMutatedGenes(StudyViewFilterContext studyViewFilterContext, List<String> hugoGeneSymbols) {
return mapper.getMutatedGenes(createStudyViewFilterHelper(studyViewFilterContext),
AlterationFilterHelper.build(studyViewFilterContext.studyViewFilter().getAlterationFilter()), hugoGeneSymbols);
}

@Override
Expand Down Expand Up @@ -142,10 +148,18 @@ public List<ClinicalData> getSampleClinicalData(StudyViewFilterContext studyView
public List<ClinicalData> getPatientClinicalData(StudyViewFilterContext studyViewFilterContext, List<String> attributeIds) {
return mapper.getPatientClinicalDataFromStudyViewFilter(createStudyViewFilterHelper(studyViewFilterContext), attributeIds);
}

@Override
public Map<String, Integer> getTotalProfiledCounts(StudyViewFilterContext studyViewFilterContext, String alterationType) {
return mapper.getTotalProfiledCounts(createStudyViewFilterHelper(studyViewFilterContext), alterationType, null)
.stream()
.collect(Collectors.groupingBy(AlterationCountByGene::getHugoGeneSymbol,
Collectors.mapping(AlterationCountByGene::getNumberOfProfiledCases, Collectors.summingInt(Integer::intValue))));
}

@Override
public Map<String, Integer> getTotalProfiledCounts(StudyViewFilterContext studyViewFilterContext, String alterationType, String specificHugoGeneSymbol) {
return mapper.getTotalProfiledCounts(createStudyViewFilterHelper(studyViewFilterContext), alterationType, specificHugoGeneSymbol)
public Map<String, Integer> getTotalProfiledCounts(StudyViewFilterContext studyViewFilterContext, String alterationType, List<String> hugoGeneSymbols) {
return mapper.getTotalProfiledCounts(createStudyViewFilterHelper(studyViewFilterContext), alterationType, hugoGeneSymbols)
.stream()
.collect(Collectors.groupingBy(AlterationCountByGene::getHugoGeneSymbol,
Collectors.mapping(AlterationCountByGene::getNumberOfProfiledCases, Collectors.summingInt(Integer::intValue))));
Expand All @@ -157,8 +171,16 @@ public int getFilteredSamplesCount(StudyViewFilterContext studyViewFilterContext
}

@Override
public Map<String, Set<String>> getMatchingGenePanelIds(StudyViewFilterContext studyViewFilterContext, String alterationType, String specificHugoGeneSymbol) {
return mapper.getMatchingGenePanelIds(createStudyViewFilterHelper(studyViewFilterContext), alterationType, specificHugoGeneSymbol)
public Map<String, Set<String>> getMatchingGenePanelIds(StudyViewFilterContext studyViewFilterContext, String alterationType) {
return mapper.getMatchingGenePanelIds(createStudyViewFilterHelper(studyViewFilterContext), alterationType, null)
.stream()
.collect(Collectors.groupingBy(GenePanelToGene::getHugoGeneSymbol,
Collectors.mapping(GenePanelToGene::getGenePanelId, Collectors.toSet())));
}

@Override
public Map<String, Set<String>> getMatchingGenePanelIds(StudyViewFilterContext studyViewFilterContext, String alterationType, List<String> hugoGeneSymbols) {
return mapper.getMatchingGenePanelIds(createStudyViewFilterHelper(studyViewFilterContext), alterationType, hugoGeneSymbols)
.stream()
.collect(Collectors.groupingBy(GenePanelToGene::getHugoGeneSymbol,
Collectors.mapping(GenePanelToGene::getGenePanelId, Collectors.toSet())));
Expand Down Expand Up @@ -224,10 +246,4 @@ public List<GenomicDataCountItem> getMutationCountsByType(StudyViewFilterContext
return mapper.getMutationCountsByType(createStudyViewFilterHelper(studyViewFilterContext), genomicDataFilters);
}

@Override
public AlterationCountByGene getMutatedGene(StudyViewFilterContext studyViewFilterContext, String specificHugoGeneSymbol) {
return mapper.getMutatedGene(createStudyViewFilterHelper(studyViewFilterContext),
AlterationFilterHelper.build(studyViewFilterContext.studyViewFilter().getAlterationFilter()), specificHugoGeneSymbol);
}

}
17 changes: 10 additions & 7 deletions src/main/java/org/cbioportal/service/AlterationCountService.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package org.cbioportal.service;

import org.apache.commons.math3.util.Pair;
import org.cbioportal.model.*;
import org.cbioportal.model.AlterationCountByGene;
import org.cbioportal.model.AlterationCountByStructuralVariant;
import org.cbioportal.model.AlterationFilter;
import org.cbioportal.model.CopyNumberCountByGene;
import org.cbioportal.model.MolecularProfileCaseIdentifier;
import org.cbioportal.model.StudyViewFilterContext;
import org.cbioportal.model.util.Select;
import org.cbioportal.web.parameter.CategorizedClinicalDataCountFilter;
import org.cbioportal.web.parameter.CustomSampleIdentifier;
import org.cbioportal.web.parameter.SampleIdentifier;
import org.cbioportal.web.parameter.StudyViewFilter;

import java.util.List;
import java.util.Map;

public interface AlterationCountService {

Expand Down Expand Up @@ -80,9 +82,10 @@ Pair<List<CopyNumberCountByGene>, Long> getPatientCnaGeneCounts(List<MolecularPr
AlterationFilter alterationFilter);

List<AlterationCountByGene> getMutatedGenes(StudyViewFilterContext studyViewFilterContext);

Map<String, AlterationCountByGene> getMutatedGenes(StudyViewFilterContext studyViewFilterContext, List<String> hugoGeneSymbols);

List<CopyNumberCountByGene> getCnaGenes(StudyViewFilterContext studyViewFilterContext);

List<AlterationCountByGene> getStructuralVariantGenes(StudyViewFilterContext studyViewFilterContext);

AlterationCountByGene getMutatedGene(StudyViewFilterContext studyViewFilterContext, String specificHugoGeneSymbol);
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public Pair<List<CopyNumberCountByGene>, Long> getPatientCnaGeneCounts(List<Mole

@Override
public List<AlterationCountByGene> getMutatedGenes(StudyViewFilterContext studyViewFilterContext) {
var alterationCountByGenes = studyViewRepository.getMutatedGenes(studyViewFilterContext, null);
var alterationCountByGenes = studyViewRepository.getMutatedGenes(studyViewFilterContext);
return populateAlterationCounts(alterationCountByGenes, studyViewFilterContext, AlterationType.MUTATION_EXTENDED, null);
}

Expand All @@ -271,10 +271,10 @@ public List<AlterationCountByGene> getStructuralVariantGenes(StudyViewFilterCont

private < T extends AlterationCountByGene> List<T> populateAlterationCounts(@NonNull List<T> alterationCounts,
@NonNull StudyViewFilterContext studyViewFilterContext,
@NonNull AlterationType alterationType, String specificHugoGeneSymbol) {
@NonNull AlterationType alterationType, List<String> hugoGeneSymbols) {
final int profiledCountWithoutGenePanelData = studyViewRepository.getTotalProfiledCountsByAlterationType(studyViewFilterContext, alterationType.toString());
var profiledCountsMap = studyViewRepository.getTotalProfiledCounts(studyViewFilterContext, alterationType.toString(), specificHugoGeneSymbol);
final var matchingGenePanelIdsMap = studyViewRepository.getMatchingGenePanelIds(studyViewFilterContext, alterationType.toString(), specificHugoGeneSymbol);
var profiledCountsMap = hugoGeneSymbols == null ? studyViewRepository.getTotalProfiledCounts(studyViewFilterContext, alterationType.toString()) : studyViewRepository.getTotalProfiledCounts(studyViewFilterContext, alterationType.toString(), hugoGeneSymbols);
final var matchingGenePanelIdsMap = hugoGeneSymbols == null ? studyViewRepository.getMatchingGenePanelIds(studyViewFilterContext, alterationType.toString()) : studyViewRepository.getMatchingGenePanelIds(studyViewFilterContext, alterationType.toString(), hugoGeneSymbols);
final int sampleProfileCountWithoutGenePanelData = studyViewRepository.getSampleProfileCountWithoutPanelData(studyViewFilterContext, alterationType.toString());

alterationCounts.parallelStream()
Expand All @@ -295,9 +295,15 @@ private < T extends AlterationCountByGene> List<T> populateAlterationCounts(@Non
}

@Override
public AlterationCountByGene getMutatedGene(StudyViewFilterContext studyViewFilterContext, String specificHugoGeneSymbol) {
List<AlterationCountByGene> alterationCountByGenes = studyViewRepository.getMutatedGenes(studyViewFilterContext, specificHugoGeneSymbol);
return populateAlterationCounts(alterationCountByGenes, studyViewFilterContext, AlterationType.MUTATION_EXTENDED, specificHugoGeneSymbol).getFirst();
public Map<String, AlterationCountByGene> getMutatedGenes(StudyViewFilterContext studyViewFilterContext, List<String> hugoGeneSymbols) {
List<AlterationCountByGene> alterationCounts = studyViewRepository.getMutatedGenes(studyViewFilterContext, hugoGeneSymbols);
List<AlterationCountByGene> alterationCountByGenes = populateAlterationCounts(alterationCounts, studyViewFilterContext, AlterationType.MUTATION_EXTENDED, hugoGeneSymbols);
return alterationCountByGenes.stream()
.collect(Collectors.toMap(
AlterationCountByGene::getHugoGeneSymbol,
alterationCountByGene -> alterationCountByGene,
(existing, replacement) -> existing
));
}

private boolean hasGenePanelData(@NonNull Set<String> matchingGenePanelIds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@ public List<GenomicDataCountItem> getCNACountsByGeneSpecific(StudyViewFilter stu
public List<GenomicDataCountItem> getMutationCountsByGeneSpecific(StudyViewFilter studyViewFilter, List<GenomicDataFilter> genomicDataFilters) {
List<GenomicDataCountItem> genomicDataCountItemList = new ArrayList<>();
int totalCount = studyViewRepository.getFilteredSamplesCount(createContext(studyViewFilter));
List<String> hugoGeneSymbols = genomicDataFilters.stream()
.map(GenomicDataFilter::getHugoGeneSymbol)
.toList();
Map<String, AlterationCountByGene> alterationCountByGenes = alterationCountService.getMutatedGenes(createContext(studyViewFilter), hugoGeneSymbols);
for (GenomicDataFilter genomicDataFilter : genomicDataFilters) {
AlterationCountByGene filteredAlterationCount = alterationCountService.getMutatedGene(createContext(studyViewFilter), genomicDataFilter.getHugoGeneSymbol());
AlterationCountByGene filteredAlterationCount = alterationCountByGenes.getOrDefault(genomicDataFilter.getHugoGeneSymbol(), new AlterationCountByGene());
int mutatedCount = filteredAlterationCount.getNumberOfAlteredCases();
int profiledCount = filteredAlterationCount.getNumberOfProfiledCases();
List<GenomicDataCount> genomicDataCountList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@
FROM genomic_event_derived
<where>
variant_type = 'mutation' AND
<if test="specificHugoGeneSymbol != null">
hugo_gene_symbol = #{specificHugoGeneSymbol} AND
<if test="hugoGeneSymbols != null">
hugo_gene_symbol IN
<foreach item="hugoGeneSymbol" collection="hugoGeneSymbols" open="(" separator="," close=")">
#{hugoGeneSymbol}
</foreach>
AND
</if>
<include refid="applyStudyViewFilter">
<property name="filter_type" value="'SAMPLE_AND_PATIENT_ID'"/>
Expand Down Expand Up @@ -339,8 +343,11 @@
INNER JOIN gene_panel_to_gene_derived gptg on stgp.gene_panel_id = gptg.gene_panel_id
<where>
stgp.alteration_type = '${alterationType}'
<if test="specificHugoGeneSymbol != null">
AND gptg.gene = #{specificHugoGeneSymbol}
<if test="hugoGeneSymbols != null">
AND gptg.gene IN
<foreach item="hugoGeneSymbol" collection="hugoGeneSymbols" open="(" separator="," close=")">
#{hugoGeneSymbol}
</foreach>
</if>
AND stgp.gene_panel_id != 'WES'
AND
Expand Down Expand Up @@ -401,8 +408,11 @@
</include>
</where>
)
<if test="specificHugoGeneSymbol != null">
AND gene = #{specificHugoGeneSymbol}
<if test="hugoGeneSymbols != null">
AND gene IN
<foreach item="hugoGeneSymbol" collection="hugoGeneSymbols" open="(" separator="," close=")">
#{hugoGeneSymbol}
</foreach>
</if>
</where>
GROUP BY gene, gene_panel_id;
Expand Down

0 comments on commit a73857b

Please sign in to comment.