Skip to content

Commit

Permalink
Add optional specific gene parameter for populateAlterationCounts
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzhaoyuan committed Sep 4, 2024
1 parent ea7e6e0 commit 942e443
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface StudyViewRepository {

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

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

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

List<CaseListDataCount> getCaseListDataCountsPerStudy(StudyViewFilterContext studyViewFilterContext);

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

int getFilteredSamplesCount(StudyViewFilterContext studyViewFilterContext);

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

int getTotalProfiledCountsByAlterationType(StudyViewFilterContext studyViewFilterContext, String alterationType);

Expand All @@ -65,4 +65,6 @@ 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);
List<AlterationCountByGene> getMutatedGenes(StudyViewFilterHelper studyViewFilterHelper, AlterationFilterHelper alterationFilterHelper, String specificHugoGeneSymbol);

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);
List<AlterationCountByGene> getTotalProfiledCounts(StudyViewFilterHelper studyViewFilterHelper, String alterationType, String specificHugoGeneSymbol);

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

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

int getTotalProfiledCountByAlterationType(StudyViewFilterHelper studyViewFilterHelper, String alterationType);

Expand All @@ -62,4 +62,6 @@ public interface StudyViewMapper {
List<GenomicDataCountItem> getCNACounts(StudyViewFilterHelper studyViewFilterHelper, List<GenomicDataFilter> genomicDataFilters);

List<GenomicDataCountItem> getMutationCountsByType(StudyViewFilterHelper studyViewFilterHelper, List<GenomicDataFilter> genomicDataFilters);

AlterationCountByGene getMutatedGene(StudyViewFilterHelper studyViewFilterHelper, AlterationFilterHelper alterationFilterHelper, String specificHugoGeneSymbol);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public List<Sample> getFilteredSamples(StudyViewFilterContext studyViewFilterCon
}

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

@Override
Expand Down Expand Up @@ -144,8 +144,8 @@ public List<ClinicalData> getPatientClinicalData(StudyViewFilterContext studyVie
}

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

@Override
public Map<String, Set<String>> getMatchingGenePanelIds(StudyViewFilterContext studyViewFilterContext, String alterationType) {
return mapper.getMatchingGenePanelIds(createStudyViewFilterHelper(studyViewFilterContext), alterationType)
public Map<String, Set<String>> getMatchingGenePanelIds(StudyViewFilterContext studyViewFilterContext, String alterationType, String specificHugoGeneSymbol) {
return mapper.getMatchingGenePanelIds(createStudyViewFilterHelper(studyViewFilterContext), alterationType, specificHugoGeneSymbol)
.stream()
.collect(Collectors.groupingBy(GenePanelToGene::getHugoGeneSymbol,
Collectors.mapping(GenePanelToGene::getGenePanelId, Collectors.toSet())));
Expand Down Expand Up @@ -224,4 +224,10 @@ 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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ Pair<List<CopyNumberCountByGene>, Long> getPatientCnaGeneCounts(List<MolecularPr

List<AlterationCountByGene> getStructuralVariantGenes(StudyViewFilterContext studyViewFilterContext);

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

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

public List<CopyNumberCountByGene> getCnaGenes(StudyViewFilterContext studyViewFilterContext) {
var copyNumberCountByGenes = studyViewRepository.getCnaGenes(studyViewFilterContext);
return populateAlterationCounts(copyNumberCountByGenes, studyViewFilterContext, AlterationType.COPY_NUMBER_ALTERATION);
return populateAlterationCounts(copyNumberCountByGenes, studyViewFilterContext, AlterationType.COPY_NUMBER_ALTERATION, null);
}

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

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

alterationCounts.parallelStream()
Expand All @@ -294,6 +294,11 @@ private < T extends AlterationCountByGene> List<T> populateAlterationCounts(@Non
return alterationCounts;
}

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

private boolean hasGenePanelData(@NonNull Set<String> matchingGenePanelIds) {
return matchingGenePanelIds.contains(WHOLE_EXOME_SEQUENCING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,8 @@ 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<AlterationCountByGene> alterationCountByGenes = alterationCountService.getMutatedGenes(createContext(studyViewFilter));
for (GenomicDataFilter genomicDataFilter : genomicDataFilters) {
AlterationCountByGene filteredAlterationCount = alterationCountByGenes.stream()
.filter(g -> g.getHugoGeneSymbol().equals(genomicDataFilter.getHugoGeneSymbol()))
.findFirst()
.orElse(new AlterationCountByGene());
AlterationCountByGene filteredAlterationCount = alterationCountService.getMutatedGene(createContext(studyViewFilter), genomicDataFilter.getHugoGeneSymbol());
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,6 +30,9 @@
FROM genomic_event_derived
<where>
variant_type = 'mutation' AND
<if test="specificHugoGeneSymbol != null">
hugo_gene_symbol = #{specificHugoGeneSymbol} AND
</if>
<include refid="applyStudyViewFilter">
<property name="filter_type" value="'SAMPLE_AND_PATIENT_ID'"/>
</include>
Expand Down Expand Up @@ -336,6 +339,9 @@
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>
AND stgp.gene_panel_id != 'WES'
AND
<include refid="applyStudyViewFilter">
Expand Down Expand Up @@ -395,6 +401,9 @@
</include>
</where>
)
<if test="specificHugoGeneSymbol != null">
AND gene = #{specificHugoGeneSymbol}
</if>
</where>
GROUP BY gene, gene_panel_id;
</select>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void getMutatedGenes() {
StudyViewFilter studyViewFilter = new StudyViewFilter();
studyViewFilter.setStudyIds(List.of(STUDY_TCGA_PUB));
var alterationCountByGenes = studyViewMapper.getMutatedGenes(StudyViewFilterHelper.build(studyViewFilter, null, null),
AlterationFilterHelper.build(studyViewFilter.getAlterationFilter()));
AlterationFilterHelper.build(studyViewFilter.getAlterationFilter()), null);
assertEquals(3, alterationCountByGenes.size());

var testBrca1AlterationCount = alterationCountByGenes.stream().filter(a -> Objects.equals(a.getHugoGeneSymbol(), "BRCA1")).findFirst();
Expand All @@ -83,7 +83,7 @@ public void getMutatedGenesWithAlterationFilter() {
alterationFilter.setMutationEventTypes(mutationEventTypeFilterMap);

var alterationCountByGenes = studyViewMapper.getMutatedGenes(StudyViewFilterHelper.build(studyViewFilter, null, null),
AlterationFilterHelper.build(alterationFilter));
AlterationFilterHelper.build(alterationFilter), null);
assertEquals(2, alterationCountByGenes.size());

AlterationFilter onlyMutationStatusFilter = new AlterationFilter();
Expand All @@ -93,7 +93,7 @@ public void getMutatedGenesWithAlterationFilter() {
onlyMutationStatusFilter.setIncludeUnknownStatus(true);

var alterationCountByGenes1 = studyViewMapper.getMutatedGenes(StudyViewFilterHelper.build(studyViewFilter, null, null),
AlterationFilterHelper.build(onlyMutationStatusFilter));
AlterationFilterHelper.build(onlyMutationStatusFilter), null);
assertEquals(1, alterationCountByGenes1.size());

AlterationFilter mutationTypeAndStatusFilter = new AlterationFilter();
Expand All @@ -104,7 +104,7 @@ public void getMutatedGenesWithAlterationFilter() {
mutationTypeAndStatusFilter.setIncludeUnknownStatus(true);

var alterationCountByGenes2 = studyViewMapper.getMutatedGenes(StudyViewFilterHelper.build(studyViewFilter, null, null),
AlterationFilterHelper.build(onlyMutationStatusFilter));
AlterationFilterHelper.build(onlyMutationStatusFilter), null);
assertEquals(1, alterationCountByGenes2.size());
}

Expand All @@ -114,7 +114,7 @@ public void getTotalProfiledCountsByGene() {
studyViewFilter.setStudyIds(List.of(STUDY_TCGA_PUB));

var totalProfiledCountsMap = studyViewMapper.getTotalProfiledCounts(StudyViewFilterHelper.build(studyViewFilter, null, null),
"MUTATION_EXTENDED");
"MUTATION_EXTENDED", null);

assertEquals(3, totalProfiledCountsMap.size());

Expand Down

0 comments on commit 942e443

Please sign in to comment.