diff --git a/src/main/resources/db-scripts/clickhouse/clickhouse.sql b/src/main/resources/db-scripts/clickhouse/clickhouse.sql index 88aa4ca8cbe..4b155562c08 100644 --- a/src/main/resources/db-scripts/clickhouse/clickhouse.sql +++ b/src/main/resources/db-scripts/clickhouse/clickhouse.sql @@ -110,13 +110,17 @@ SELECT concat(cs.cancer_study_identifier, '_', sample.stable_id) AS sample_uniqu me.protein_change AS mutation_variant, me.mutation_type AS mutation_type, mutation.mutation_status AS mutation_status, - 'NA' AS driver_filter, + ada.driver_filter AS driver_filter, 'NA' AS drivet_tiers_filter, NULL AS cna_alteration, '' AS cna_cytoband, '' AS sv_event_info, concat(cs.cancer_study_identifier, '_', patient.stable_id) AS patient_unique_id FROM mutation + INNER JOIN alteration_driver_annotation ada + ON mutation.mutation_event_id = ada.alteration_event_id + AND mutation.sample_id = ada.sample_id + AND mutation.genetic_profile_id = ada.genetic_profile_id INNER JOIN mutation_event AS me ON mutation.mutation_event_id = me.mutation_event_id INNER JOIN sample_profile sp ON mutation.sample_id = sp.sample_id AND mutation.genetic_profile_id = sp.genetic_profile_id diff --git a/src/test/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapperTest.java b/src/test/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapperTest.java index 3d77bbb3492..e3c845207f7 100644 --- a/src/test/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapperTest.java +++ b/src/test/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapperTest.java @@ -123,6 +123,104 @@ public void getMutatedGenesWithAlterationFilter() { var alterationCountByGenes2 = studyViewMapper.getMutatedGenes(StudyViewFilterHelper.build(studyViewFilter, null, null), AlterationFilterHelper.build(onlyMutationStatusFilter)); assertEquals(1, alterationCountByGenes2.size()); + + // Testing custom driver filter + AlterationFilter onlyDriverFilter = new AlterationFilter(); + onlyDriverFilter.setIncludeDriver(true); + onlyDriverFilter.setIncludeVUS(false); + onlyDriverFilter.setIncludeUnknownOncogenicity(false); + + var alterationCountByGenes3 = studyViewMapper.getMutatedGenes(StudyViewFilterHelper.build(studyViewFilter, null, null), + AlterationFilterHelper.build(onlyDriverFilter)); + assertEquals(2, alterationCountByGenes3.size()); + + var akt1AlteredCounts3 = alterationCountByGenes3.stream().filter(c -> c.getHugoGeneSymbol().equals("AKT1")) + .mapToInt(c -> c.getNumberOfAlteredCases().intValue()) + .sum(); + assertEquals(1, akt1AlteredCounts3); + var akt2AlteredCounts3 = alterationCountByGenes3.stream().filter(c -> c.getHugoGeneSymbol().equals("AKT2")) + .mapToInt(c -> c.getNumberOfAlteredCases().intValue()) + .sum(); + assertEquals(0, akt2AlteredCounts3); + var brca1AlteredCounts3 = alterationCountByGenes3.stream().filter(c -> c.getHugoGeneSymbol().equals("BRCA1")) + .mapToInt(c -> c.getNumberOfAlteredCases().intValue()) + .sum(); + assertEquals(3, brca1AlteredCounts3); + + AlterationFilter onlyVUSFilter = new AlterationFilter(); + onlyVUSFilter.setIncludeDriver(false); + onlyVUSFilter.setIncludeVUS(true); + onlyVUSFilter.setIncludeUnknownOncogenicity(false); + + var alterationCountByGenes4 = studyViewMapper.getMutatedGenes(StudyViewFilterHelper.build(studyViewFilter, null, null), + AlterationFilterHelper.build(onlyVUSFilter)); + assertEquals(3, alterationCountByGenes4.size()); + + var akt1AlteredCounts4 = alterationCountByGenes4.stream().filter(c -> c.getHugoGeneSymbol().equals("AKT1")) + .mapToInt(c -> c.getNumberOfAlteredCases().intValue()) + .sum(); + assertEquals(1, akt1AlteredCounts4); + var akt2AlteredCounts4 = alterationCountByGenes4.stream().filter(c -> c.getHugoGeneSymbol().equals("AKT2")) + .mapToInt(c -> c.getNumberOfAlteredCases().intValue()) + .sum(); + assertEquals(1, akt2AlteredCounts4); + var brca1AlteredCounts4 = alterationCountByGenes4.stream().filter(c -> c.getHugoGeneSymbol().equals("BRCA1")) + .mapToInt(c -> c.getNumberOfAlteredCases().intValue()) + .sum(); + assertEquals(2, brca1AlteredCounts4); + + AlterationFilter onlyUnknownOncogenicityFilter = new AlterationFilter(); + onlyUnknownOncogenicityFilter.setIncludeDriver(false); + onlyUnknownOncogenicityFilter.setIncludeVUS(false); + onlyUnknownOncogenicityFilter.setIncludeUnknownOncogenicity(true); + + var alterationCountByGenes5 = studyViewMapper.getMutatedGenes(StudyViewFilterHelper.build(studyViewFilter, null, null), + AlterationFilterHelper.build(onlyUnknownOncogenicityFilter)); + assertEquals(0, alterationCountByGenes5.size()); + } + + @Test + public void getCnaGenesWithAlterationFilter() { + StudyViewFilter studyViewFilter = new StudyViewFilter(); + studyViewFilter.setStudyIds(List.of(STUDY_TCGA_PUB)); + + // Create AlterationFilter + // Testing custom driver filter + AlterationFilter onlyDriverFilter = new AlterationFilter(); + onlyDriverFilter.setIncludeDriver(true); + onlyDriverFilter.setIncludeVUS(false); + onlyDriverFilter.setIncludeUnknownOncogenicity(false); + + var alterationCountByGenes = studyViewMapper.getCnaGenes(StudyViewFilterHelper.build(studyViewFilter, null, null), + AlterationFilterHelper.build(onlyDriverFilter)); + assertEquals(0, alterationCountByGenes.size()); + + AlterationFilter onlyVUSFilter = new AlterationFilter(); + onlyVUSFilter.setIncludeDriver(false); + onlyVUSFilter.setIncludeVUS(true); + onlyVUSFilter.setIncludeUnknownOncogenicity(false); + + var alterationCountByGenes1 = studyViewMapper.getCnaGenes(StudyViewFilterHelper.build(studyViewFilter, null, null), + AlterationFilterHelper.build(onlyVUSFilter)); + assertEquals(0, alterationCountByGenes1.size()); + + AlterationFilter onlyUnknownOncogenicityFilter = new AlterationFilter(); + onlyUnknownOncogenicityFilter.setIncludeDriver(false); + onlyUnknownOncogenicityFilter.setIncludeVUS(false); + onlyUnknownOncogenicityFilter.setIncludeUnknownOncogenicity(true); + + var alterationCountByGenes2 = studyViewMapper.getCnaGenes(StudyViewFilterHelper.build(studyViewFilter, null, null), + AlterationFilterHelper.build(onlyUnknownOncogenicityFilter)); + assertEquals(3, alterationCountByGenes2.size()); + + var akt1AlteredCounts2 = alterationCountByGenes2.stream().filter(c -> c.getHugoGeneSymbol().equals("AKT1")) + .mapToInt(c -> c.getNumberOfAlteredCases().intValue()) + .sum(); + assertEquals(2, akt1AlteredCounts2); + var akt2AlteredCounts2 = alterationCountByGenes2.stream().filter(c -> c.getHugoGeneSymbol().equals("AKT2")) + .mapToInt(c -> c.getNumberOfAlteredCases().intValue()) + .sum(); + assertEquals(1, akt2AlteredCounts2); } @Test