Skip to content

Commit

Permalink
Demo rfc80 poc mutation data count unit tests (cBioPortal#10981)
Browse files Browse the repository at this point in the history
* Fix CNA table definition
  • Loading branch information
fuzhaoyuan authored Sep 12, 2024
1 parent 59d84c9 commit 092773e
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ public class GenomicDataFilter extends DataFilter implements Serializable {
private String hugoGeneSymbol;
private String profileType;

public GenomicDataFilter() {}

public GenomicDataFilter(String hugoGeneSymbol, String profileType) {
this.hugoGeneSymbol = hugoGeneSymbol;
this.profileType = profileType;
}

public String getHugoGeneSymbol() {
return hugoGeneSymbol;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/db-scripts/clickhouse/clickhouse.sql
Original file line number Diff line number Diff line change
Expand Up @@ -298,18 +298,18 @@ SELECT
sample_unique_id,
cancer_study_identifier,
hugo_gene_symbol,
profile_type,
replaceOne(stable_id, concat(sd.cancer_study_identifier, '_'), '') as profile_type,
alteration_value
FROM
(SELECT
sample_id,
hugo_gene_symbol,
profile_type,
stable_id,
alteration_value
FROM
(SELECT
g.hugo_gene_symbol AS hugo_gene_symbol,
arrayElement(splitByString('_', assumeNotNull(gp.stable_id)), -1) AS profile_type,
gp.stable_id as stable_id,
arrayMap(x -> (x = '' ? NULL : x), splitByString(',', assumeNotNull(trim(trailing ',' from ga.values)))) AS alteration_value,
arrayMap(x -> (x = '' ? NULL : toInt32(x)), splitByString(',', assumeNotNull(trim(trailing ',' from gps.ordered_sample_list)))) AS sample_id
FROM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@
#{studyId}
</foreach>
AND gpg.gene = #{mutationDataFilter.hugoGeneSymbol}
AND sgp.alteration_type = 'MUTATION_EXTENDED'
),
mutated_samples AS (
SELECT DISTINCT sample_unique_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
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}
AND sgp.alteration_type = 'MUTATION_EXTENDED'
),
mutated_count as (
SELECT count(distinct sample_unique_id)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package org.cbioportal.persistence.mybatisclickhouse;

import org.cbioportal.model.GenomicDataCount;
import org.cbioportal.model.GenomicDataCountItem;
import org.cbioportal.persistence.helper.StudyViewFilterHelper;
import org.cbioportal.persistence.mybatisclickhouse.config.MyBatisConfig;
import org.cbioportal.web.parameter.GenomicDataFilter;
import org.cbioportal.web.parameter.StudyViewFilter;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.context.annotation.Import;
import org.springframework.test.annotation.DirtiesContext;
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;

@RunWith(SpringRunner.class)
@Import(MyBatisConfig.class)
@DataJpaTest
@DirtiesContext
@AutoConfigureTestDatabase(replace= AutoConfigureTestDatabase.Replace.NONE)
@ContextConfiguration(initializers = AbstractTestcontainers.Initializer.class)
public class GenomicDataFilterTest extends AbstractTestcontainers {

private static final String STUDY_TCGA_PUB = "study_tcga_pub";
private static final String STUDY_ACC_TCGA = "acc_tcga";

@Autowired
private StudyViewMapper studyViewMapper;

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

GenomicDataFilter genomicDataFilterCNA = new GenomicDataFilter("AKT1", "cna");
List<GenomicDataCountItem> actualCountsCNA = studyViewMapper.getCNACounts(StudyViewFilterHelper.build(studyViewFilter, null), List.of(genomicDataFilterCNA));
List<GenomicDataCountItem> expectedCountsCNA = List.of(
new GenomicDataCountItem("AKT1", "cna", List.of(
new GenomicDataCount("Homozygously deleted", "-2", 2),
new GenomicDataCount("Heterozygously deleted", "-1", 2),
new GenomicDataCount("Diploid", "0", 2),
new GenomicDataCount("Gained", "1", 2),
new GenomicDataCount("Amplified", "2", 2),
new GenomicDataCount("NA", "NA", 5)
)));
assertThat(actualCountsCNA)
.usingRecursiveComparison()
.ignoringCollectionOrder()
.isEqualTo(expectedCountsCNA);

GenomicDataFilter genomicDataFilterGISTIC = new GenomicDataFilter("AKT1", "gistic");
List<GenomicDataCountItem> actualCountsGISTIC = studyViewMapper.getCNACounts(StudyViewFilterHelper.build(studyViewFilter, null), List.of(genomicDataFilterGISTIC));
List<GenomicDataCountItem> expectedCountsGISTIC = List.of(
new GenomicDataCountItem("AKT1", "gistic", List.of(
new GenomicDataCount("Homozygously deleted", "-2", 2),
new GenomicDataCount("Heterozygously deleted", "-1", 3),
new GenomicDataCount("Diploid", "0", 3),
new GenomicDataCount("Gained", "1", 3),
new GenomicDataCount("Amplified", "2", 3),
new GenomicDataCount("NA", "NA", 1)
)));
assertThat(actualCountsGISTIC)
.usingRecursiveComparison()
.ignoringCollectionOrder()
.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), 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();
studyViewFilter.setStudyIds(List.of(STUDY_TCGA_PUB));

GenomicDataFilter genomicDataFilterMutation = new GenomicDataFilter("AKT1", "mutation");
List<GenomicDataCountItem> actualMutationCountsByType = studyViewMapper.getMutationCountsByType(StudyViewFilterHelper.build(studyViewFilter, null), List.of(genomicDataFilterMutation));
List<GenomicDataCountItem> expectedMutationCountsByType = List.of(
new GenomicDataCountItem("AKT1", "mutations", List.of(
new GenomicDataCount("nonsense mutation", "nonsense_mutation", 1, 1),
new GenomicDataCount("missense mutation", "missense_mutation", 1, 1)
)));
assertThat(actualMutationCountsByType)
.usingRecursiveComparison()
.ignoringCollectionOrder()
.isEqualTo(expectedMutationCountsByType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void getMutatedGenes() {
AlterationFilterHelper.build(studyViewFilter.getAlterationFilter()));
assertEquals(3, alterationCountByGenes.size());

var testBrca1AlterationCount = alterationCountByGenes.stream().filter(a -> Objects.equals(a.getHugoGeneSymbol(), "brca1")).findFirst();
var testBrca1AlterationCount = alterationCountByGenes.stream().filter(a -> Objects.equals(a.getHugoGeneSymbol(), "BRCA1")).findFirst();
assert (testBrca1AlterationCount.isPresent());
assertEquals(Integer.valueOf(5), testBrca1AlterationCount.get().getTotalCount());
}
Expand Down Expand Up @@ -118,7 +118,7 @@ public void getTotalProfiledCountsByGene() {

assertEquals(3, totalProfiledCountsMap.size());

var akt2TotalProfiledCounts = totalProfiledCountsMap.stream().filter(c -> c.getHugoGeneSymbol().equals("akt2")).findFirst();
var akt2TotalProfiledCounts = totalProfiledCountsMap.stream().filter(c -> c.getHugoGeneSymbol().equals("AKT2")).findFirst();
assertTrue(akt2TotalProfiledCounts.isPresent());
assertEquals(4, akt2TotalProfiledCounts.get().getNumberOfProfiledCases().intValue());
}
Expand Down
Loading

0 comments on commit 092773e

Please sign in to comment.