Skip to content

Commit

Permalink
Fix on mutation counts
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzhaoyuan committed Aug 28, 2024
1 parent bf5f8bf commit ea7e6e0
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ public interface StudyViewRepository {
int getTotalSampleTreatmentCount(StudyViewFilterContext studyViewFilterContext);

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

Map<String, Integer> getMutationCounts(StudyViewFilterContext studyViewFilterContext, GenomicDataFilter genomicDataFilter);

List<GenomicDataCountItem> getMutationCountsByType(StudyViewFilterContext studyViewFilterContext, List<GenomicDataFilter> genomicDataFilters);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.cbioportal.web.parameter.GenomicDataFilter;

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


public interface StudyViewMapper {
Expand Down Expand Up @@ -62,7 +61,5 @@ public interface StudyViewMapper {

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

Map<String, Integer> getMutationCounts(StudyViewFilterHelper studyViewFilterHelper, GenomicDataFilter genomicDataFilter);

List<GenomicDataCountItem> getMutationCountsByType(StudyViewFilterHelper studyViewFilterHelper, List<GenomicDataFilter> genomicDataFilters);
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,6 @@ public List<GenomicDataCountItem> getCNACounts(StudyViewFilterContext studyViewF

return mapper.getCNACounts(createStudyViewFilterHelper(studyViewFilterContext), genomicDataFilters);
}

public Map<String, Integer> getMutationCounts(StudyViewFilterContext studyViewFilterContext, GenomicDataFilter genomicDataFilter) {

return mapper.getMutationCounts(createStudyViewFilterHelper(studyViewFilterContext), genomicDataFilter);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,19 @@ public List<GenomicDataCountItem> getCNACountsByGeneSpecific(StudyViewFilter stu
@Override
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) {
Map<String, Integer> counts = studyViewRepository.getMutationCounts(createContext(studyViewFilter), genomicDataFilter);
AlterationCountByGene filteredAlterationCount = alterationCountByGenes.stream()
.filter(g -> g.getHugoGeneSymbol().equals(genomicDataFilter.getHugoGeneSymbol()))
.findFirst()
.orElse(new AlterationCountByGene());
int mutatedCount = filteredAlterationCount.getNumberOfAlteredCases();
int profiledCount = filteredAlterationCount.getNumberOfProfiledCases();
List<GenomicDataCount> genomicDataCountList = new ArrayList<>();
if (counts.getOrDefault("mutatedCount", 0) > 0)
genomicDataCountList.add(new GenomicDataCount("Mutated", "MUTATED", counts.get("mutatedCount"), counts.get("mutatedCount")));
if (counts.getOrDefault("notMutatedCount", 0) > 0)
genomicDataCountList.add(new GenomicDataCount("Not Mutated", "NOT_MUTATED", counts.get("notMutatedCount"), counts.get("notMutatedCount")));
if (counts.getOrDefault("notProfiledCount", 0) > 0)
genomicDataCountList.add(new GenomicDataCount("Not Profiled", "NOT_PROFILED", counts.get("notProfiledCount"), counts.get("notProfiledCount")));
genomicDataCountList.add(new GenomicDataCount("Mutated", "MUTATED", mutatedCount, mutatedCount));
genomicDataCountList.add(new GenomicDataCount("Not Mutated", "NOT_MUTATED", profiledCount - mutatedCount, profiledCount - mutatedCount));
genomicDataCountList.add(new GenomicDataCount("Not Profiled", "NOT_PROFILED", totalCount - profiledCount, totalCount - profiledCount));
genomicDataCountItemList.add(new GenomicDataCountItem(genomicDataFilter.getHugoGeneSymbol(), "mutations", genomicDataCountList));
}
return genomicDataCountItemList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,28 +270,6 @@
FROM cna_sum
</select>

<!-- for /mutation-data-counts/fetch (returns GenomicDataCountItem objects) mutation counts pie chart part -->
<select id="getMutationCounts">
WITH profiled_count as (
SELECT count(distinct sgp.sample_unique_id)
FROM sample_to_gene_panel_derived sgp
JOIN gene_panel_to_gene_derived gpg ON sgp.gene_panel_id = gpg.gene_panel_id
WHERE sample_unique_id IN (<include refid="sampleUniqueIdsFromStudyViewFilter"/>)
AND gpg.gene = #{genomicDataFilter.hugoGeneSymbol}
),
mutated_count as (
SELECT count(distinct sample_unique_id)
FROM genomic_event_derived
WHERE sample_unique_id IN (<include refid="sampleUniqueIdsFromStudyViewFilter"/>)
AND hugo_gene_symbol = #{genomicDataFilter.hugoGeneSymbol}
AND variant_type = 'mutation'
)
SELECT
cast((SELECT * FROM mutated_count) as INTEGER) as mutatedCount,
cast(((SELECT * FROM profiled_count) - (SELECT * FROM mutated_count)) as INTEGER) as notMutatedCount,
cast(((SELECT * FROM (<include refid="getTotalSampleCount"/>)) - (SELECT * FROM profiled_count)) as INTEGER) as notProfiledCount
</select>

<!-- for /mutation-data-counts/fetch - (returns GenomicDataCountItem objects) mutation type counts table part-->
<select id="getMutationCountsByType" resultMap="GenomicDataCountItemResultMap">
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

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

import static org.assertj.core.api.Assertions.assertThat;

Expand Down Expand Up @@ -74,23 +72,6 @@ public void getCNACounts() {
.isEqualTo(expectedCountsGISTIC);
}

@Test
public void getMutationCounts() {
StudyViewFilter studyViewFilter = new StudyViewFilter();
studyViewFilter.setStudyIds(List.of(STUDY_TCGA_PUB));

GenomicDataFilter genomicDataFilterMutation = new GenomicDataFilter("AKT1", "cna");
Map<String, Integer> actualMutationCounts = studyViewMapper.getMutationCounts(StudyViewFilterHelper.build(studyViewFilter, null, null), genomicDataFilterMutation);
Map<String, Integer> expectedMutationCounts = new HashMap<>();
expectedMutationCounts.put("mutatedCount", 2);
expectedMutationCounts.put("notMutatedCount", 2);
expectedMutationCounts.put("notProfiledCount", 11);
assertThat(actualMutationCounts)
.usingRecursiveComparison()
.ignoringCollectionOrder()
.isEqualTo(expectedMutationCounts);
}

@Test
public void getMutationCountsByType() {
StudyViewFilter studyViewFilter = new StudyViewFilter();
Expand Down

0 comments on commit ea7e6e0

Please sign in to comment.