Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration tests for clickhouse endpoints cna and sv genes #11221

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
<choose>
<when test="alterationFilterHelper.getCnaTypeList.hasNone()">NULL</when>
<when test="!alterationFilterHelper.getCnaTypeList.hasAll()">
cna_event.ALTERATION IN
<foreach item="type" collection="cnaTypes" open="("
AND
genomic_event_derived.cna_alteration IN
<foreach item="type" collection="alterationFilterHelper.getCnaTypeList()" open="("
separator="," close=")">
#{type}
</foreach>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.cbioportal.persistence.mybatisclickhouse;

import org.cbioportal.model.AlterationFilter;
import org.cbioportal.model.CNA;
import org.cbioportal.persistence.helper.AlterationFilterHelper;
import org.cbioportal.persistence.helper.StudyViewFilterHelper;
import org.cbioportal.persistence.mybatisclickhouse.config.MyBatisConfig;
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 java.util.Objects;

import static org.junit.Assert.assertEquals;

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

private static final String STUDY_TCGA_PUB = "study_tcga_pub";

@Autowired
private StudyViewMapper studyViewMapper;

@Test
public void getCnaGenes() {
StudyViewFilter studyViewFilter = new StudyViewFilter();
studyViewFilter.setStudyIds(List.of(STUDY_TCGA_PUB));
var alterationCountByGenes = studyViewMapper.getCnaGenes(StudyViewFilterHelper.build(studyViewFilter, null, null),
AlterationFilterHelper.build(studyViewFilter.getAlterationFilter()));
assertEquals(3, alterationCountByGenes.size());

// Test cna count for akt1
var testAKT1AlterationCount = alterationCountByGenes.stream().filter(a -> Objects.equals(a.getHugoGeneSymbol(), "AKT1"))
.mapToInt(c -> c.getTotalCount().intValue())
.sum();
assertEquals(3, testAKT1AlterationCount);
}

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

// Create AlterationFilter
AlterationFilter alterationFilter = new AlterationFilter();
Map<CNA, Boolean> cnaEventTypeFilterMap = new HashMap<>();
cnaEventTypeFilterMap.put(CNA.HOMDEL, false);
cnaEventTypeFilterMap.put(CNA.AMP, true);
alterationFilter.setCopyNumberAlterationEventTypes(cnaEventTypeFilterMap);

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

// Test cna count for akt1 filtering for AMP
var testAKT1AlterationCount = alterationCountByGenes.stream().filter(a -> Objects.equals(a.getHugoGeneSymbol(), "AKT1"))
.mapToInt(c -> c.getTotalCount().intValue())
.sum();
assertEquals(2, testAKT1AlterationCount);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.cbioportal.persistence.mybatisclickhouse;

import org.cbioportal.persistence.helper.AlterationFilterHelper;
import org.cbioportal.persistence.helper.StudyViewFilterHelper;
import org.cbioportal.persistence.mybatisclickhouse.config.MyBatisConfig;
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.List;
import java.util.Objects;

import static org.junit.Assert.assertEquals;

@RunWith(SpringRunner.class)
@Import(MyBatisConfig.class)
@DataJpaTest
@DirtiesContext
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@ContextConfiguration(initializers = AbstractTestcontainers.Initializer.class)
public class StructuralVariantGenesTest 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 getStructuralVariantGenes() {
StudyViewFilter studyViewFilter = new StudyViewFilter();
studyViewFilter.setStudyIds(List.of(STUDY_TCGA_PUB, STUDY_ACC_TCGA));
var alterationCountByGenes = studyViewMapper.getStructuralVariantGenes(StudyViewFilterHelper.build(studyViewFilter, null, null),
AlterationFilterHelper.build(studyViewFilter.getAlterationFilter()));
assertEquals(8, alterationCountByGenes.size());

// Test sv count for eml4 which is in one study
var testeml4AlterationCount = alterationCountByGenes.stream().filter(a -> Objects.equals(a.getHugoGeneSymbol(), "eml4"))
.mapToInt(c -> c.getTotalCount().intValue())
.sum();
assertEquals(1, testeml4AlterationCount);

// Test sv count for ncoa4 which is in both studies
var testncoa4AlterationCount = alterationCountByGenes.stream().filter(a -> Objects.equals(a.getHugoGeneSymbol(), "ncoa4"))
.mapToInt(c -> c.getTotalCount().intValue())
.sum();
assertEquals(3, testncoa4AlterationCount);
}
}
2 changes: 2 additions & 0 deletions src/test/resources/clickhouse_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ insert into sample_profile (sample_id,genetic_profile_id,panel_id) values (1,3,1
insert into sample_profile (sample_id,genetic_profile_id,panel_id) values (1,4,null);
insert into sample_profile (sample_id,genetic_profile_id,panel_id) values (1,6,2);
insert into sample_profile (sample_id,genetic_profile_id,panel_id) values (1,6,1);
insert into sample_profile (sample_id,genetic_profile_id,panel_id) values (1,7,null);
insert into sample_profile (sample_id,genetic_profile_id,panel_id) values (2,2,1);
insert into sample_profile (sample_id,genetic_profile_id,panel_id) values (2,2,2);
insert into sample_profile (sample_id,genetic_profile_id,panel_id) values (2,3,1);
Expand Down Expand Up @@ -275,6 +276,7 @@ insert into sample_profile (sample_id,genetic_profile_id,panel_id) values (13,4,
insert into sample_profile (sample_id,genetic_profile_id,panel_id) values (13,6,null);
insert into sample_profile (sample_id,genetic_profile_id,panel_id) values (14,2,null);
insert into sample_profile (sample_id,genetic_profile_id,panel_id) values (14,4,null);
insert into sample_profile (sample_id,genetic_profile_id,panel_id) values (15,13,null);
insert into sample_profile (sample_id,genetic_profile_id,panel_id) values (301,16,3);
insert into sample_profile (sample_id,genetic_profile_id,panel_id) values (301,17,3);
insert into sample_profile (sample_id,genetic_profile_id,panel_id) values (302,16,3);
Expand Down
Loading