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 testing for clickhouse sql #44

Closed
wants to merge 3 commits into from
Closed
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
121 changes: 121 additions & 0 deletions db-scripts/src/main/resources/clickhouse-test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
create table cna_discrete
(
sample_unique_id varchar(255),
alteration int(11),
hugo_gene_symbol varchar(255),
gene_panel_stable_id varchar(255),
cancer_study_identifier varchar(255),
genetic_profile_stable_id varchar(255),
PRIMARY KEY (sample_unique_id, alteration, hugo_gene_symbol, cancer_study_identifier)
);

create table genetic_profile
(
sample_unique_id varchar(255),
genetic_alteration_type varchar(255),
datatype varchar(255),
value varchar(255),
cancer_study_identifier varchar(255),
PRIMARY KEY (sample_unique_id, genetic_alteration_type, datatype, value, cancer_study_identifier)
);

create table genetic_profile_counts
(
sample_unique_id varchar(255),
profile_name varchar(255),
genetic_profile_stable_id varchar(255),
cancer_study_identifier varchar(255),
count int(11)
);

create table genomic_event
(
sample_unique_id varchar(255),
variant varchar(255),
hugo_gene_symbol varchar(255),
gene_panel_stable_id varchar(255),
cancer_study_identifier varchar(255),
genetic_profile_stable_id varchar(255),
PRIMARY KEY (sample_unique_id, variant, hugo_gene_symbol, cancer_study_identifier, genetic_profile_stable_id)
);

create table mutation
(
sample_unique_id varchar(255),
variant varchar(255),
hugo_gene_symbol varchar(255),
gene_panel_stable_id varchar(255),
cancer_study_identifier varchar(255),
genetic_profile_stable_id varchar(255),
PRIMARY KEY (sample_unique_id, variant, hugo_gene_symbol, cancer_study_identifier)
);

create table patient_clinical_attribute_categorical
(
patient_unique_id varchar(255),
attribute_name varchar(255),
attribute_value varchar(255),
cancer_study_identifier varchar(255),
PRIMARY KEY (patient_unique_id, attribute_name, attribute_value, cancer_study_identifier)
);

create table patient_clinical_attribute_numeric
(
patient_unique_id varchar(255),
attribute_name varchar(255),
attribute_value float,
cancer_study_identifier varchar(255),
PRIMARY KEY (patient_unique_id, attribute_name, attribute_value, cancer_study_identifier)
);

create table sample
(
sample_unique_id varchar(255),
sample_stable_id varchar(255),
patient_unique_id varchar(255),
patient_stable_id varchar(255),
cancer_study_identifier varchar(255),
sample_unique_id_base64 varchar(255),
patient_unique_id_base64 varchar(255),
PRIMARY KEY (sample_unique_id, patient_unique_id, cancer_study_identifier)
);

create table sample_clinical_attribute_categorical
(
patient_unique_id varchar(255),
sample_unique_id varchar(255),
attribute_name varchar(255),
attribute_value varchar(255),
cancer_study_identifier varchar(255),
PRIMARY KEY (patient_unique_id, sample_unique_id, attribute_name, attribute_value, cancer_study_identifier)
);

create table sample_clinical_attribute_numeric
(
patient_unique_id varchar(255),
sample_unique_id varchar(255),
attribute_name varchar(255),
attribute_value float,
cancer_study_identifier varchar(255),
PRIMARY KEY (patient_unique_id, sample_unique_id, attribute_name, attribute_value, cancer_study_identifier)
);

create table sample_list
(
sample_unique_id varchar(255),
sample_list_stable_id varchar(255),
name varchar(255),
cancer_study_identifier varchar(255),
PRIMARY KEY (sample_unique_id, sample_list_stable_id, name, cancer_study_identifier)
);

create table structural_variant
(
sample_unique_id varchar(255),
hugo_symbol_gene1 varchar(255),
hugo_symbol_gene2 varchar(255),
gene_panel_stable_id varchar(255),
cancer_study_identifier varchar(255),
genetic_profile_stable_id varchar(255),
PRIMARY KEY (sample_unique_id, hugo_symbol_gene1, hugo_symbol_gene2, cancer_study_identifier)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.cbioportal.persistence.mybatiscolumnstore;

import org.cbioportal.model.AlterationCountByGene;
import org.cbioportal.model.Sample;
import org.cbioportal.webparam.StudyViewFilter;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/testContextDatabaseCH.xml")
@Configurable
public class StudyViewMyBatisRepositoryTest {

@Autowired
private StudyViewMyBatisRepository studyViewMyBatisRepository;

@Test
public void getFilteredSamples() {
StudyViewFilter studyViewFilter = new StudyViewFilter();

List<String> studyIds = new ArrayList<>();
studyIds.add("msk_ch_2020");
studyViewFilter.setStudyIds(studyIds);

List<Sample> samples = studyViewMyBatisRepository.getFilteredSamplesFromColumnstore(studyViewFilter);
Assert.assertEquals(3, samples.size());
}

@Test
public void getMutatedGenes() {
StudyViewFilter studyViewFilter = new StudyViewFilter();

List<String> studyIds = new ArrayList<>();
studyIds.add("msk_ch_2020");
studyViewFilter.setStudyIds(studyIds);

List<AlterationCountByGene> mutations = studyViewMyBatisRepository.getMutatedGenes(studyViewFilter);
Assert.assertEquals(2, mutations.size());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
INSERT INTO patient_clinical_attribute_numeric (patient_unique_id, attribute_name, attribute_value, cancer_study_identifier) VALUES ('msk_ch_2020_P-0000004', 'AGE', 39.739902, 'msk_ch_2020');
INSERT INTO patient_clinical_attribute_numeric (patient_unique_id, attribute_name, attribute_value, cancer_study_identifier) VALUES ('msk_ch_2020_P-0000004', 'TIME_FROM_DX_TO_SEQ', 991, 'msk_ch_2020');
INSERT INTO patient_clinical_attribute_numeric (patient_unique_id, attribute_name, attribute_value, cancer_study_identifier) VALUES ('msk_ch_2020_P-0000004', 'TIME_TO_BLOOD_DRAW_FROM_TX', 609, 'msk_ch_2020');
INSERT INTO patient_clinical_attribute_numeric (patient_unique_id, attribute_name, attribute_value, cancer_study_identifier) VALUES ('msk_ch_2020_P-0000015', 'AGE', 44.440792, 'msk_ch_2020');
INSERT INTO patient_clinical_attribute_numeric (patient_unique_id, attribute_name, attribute_value, cancer_study_identifier) VALUES ('msk_ch_2020_P-0000015', 'TIME_FROM_DX_TO_SEQ', 2558, 'msk_ch_2020');
INSERT INTO patient_clinical_attribute_numeric (patient_unique_id, attribute_name, attribute_value, cancer_study_identifier) VALUES ('msk_ch_2020_P-0000015', 'TIME_TO_BLOOD_DRAW_FROM_TX', 5, 'msk_ch_2020');
INSERT INTO patient_clinical_attribute_numeric (patient_unique_id, attribute_name, attribute_value, cancer_study_identifier) VALUES ('msk_ch_2020_P-0000023', 'AGE', 61.319645, 'msk_ch_2020');
INSERT INTO patient_clinical_attribute_numeric (patient_unique_id, attribute_name, attribute_value, cancer_study_identifier) VALUES ('msk_ch_2020_P-0000023', 'TIME_FROM_DX_TO_SEQ', 245, 'msk_ch_2020');
INSERT INTO patient_clinical_attribute_numeric (patient_unique_id, attribute_name, attribute_value, cancer_study_identifier) VALUES ('msk_ch_2020_P-0000023', 'TIME_TO_BLOOD_DRAW_FROM_TX', 166, 'msk_ch_2020');

INSERT INTO sample (sample_unique_id, sample_unique_id_base64, sample_stable_id, patient_unique_id, patient_unique_id_base64, patient_stable_id, cancer_study_identifier) VALUES ('msk_ch_2020_P-0000004-N01', '', 'P-0000004-N01', 'msk_ch_2020_P-0000004', '', 'P-0000004', 'msk_ch_2020');
INSERT INTO sample (sample_unique_id, sample_unique_id_base64, sample_stable_id, patient_unique_id, patient_unique_id_base64, patient_stable_id, cancer_study_identifier) VALUES ('msk_ch_2020_P-0000015-N01', '', 'P-0000015-N01', 'msk_ch_2020_P-0000015', '', 'P-0000015', 'msk_ch_2020');
INSERT INTO sample (sample_unique_id, sample_unique_id_base64, sample_stable_id, patient_unique_id, patient_unique_id_base64, patient_stable_id, cancer_study_identifier) VALUES ('msk_ch_2020_P-0000023-N01', '', 'P-0000023-N01', 'msk_ch_2020_P-0000023', '', 'P-0000023', 'msk_ch_2020');
--
INSERT INTO genomic_event (sample_unique_id, variant, hugo_gene_symbol, gene_panel_stable_id, cancer_study_identifier, genetic_profile_stable_id) VALUES ('msk_ch_2020_P-0000004-N01', 'p.R1051Q', 'KDR', '', 'msk_ch_2020', 'msk_ch_2020_mutations');
INSERT INTO genomic_event (sample_unique_id, variant, hugo_gene_symbol, gene_panel_stable_id, cancer_study_identifier, genetic_profile_stable_id) VALUES ('msk_ch_2020_P-0000004-N01', 'p.T1884I', 'TET2', '', 'msk_ch_2020', 'msk_ch_2020_mutations');

INSERT INTO mutation (sample_unique_id, variant, hugo_gene_symbol, gene_panel_stable_id, cancer_study_identifier, genetic_profile_stable_id) VALUES ('msk_ch_2020_P-0000004-N01', 'p.R1051Q', 'KDR', '', 'msk_ch_2020', 'msk_ch_2020_mutations');
INSERT INTO mutation (sample_unique_id, variant, hugo_gene_symbol, gene_panel_stable_id, cancer_study_identifier, genetic_profile_stable_id) VALUES ('msk_ch_2020_P-0000004-N01', 'p.T1884I', 'TET2', '', 'msk_ch_2020', 'msk_ch_2020_mutations');

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Copyright (c) 2016 Memorial Sloan-Kettering Cancer Center.

This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
FOR A PARTICULAR PURPOSE. The software and documentation provided hereunder
is on an "as is" basis, and Memorial Sloan-Kettering Cancer Center has no
obligations to provide maintenance, support, updates, enhancements or
modifications. In no event shall Memorial Sloan-Kettering Cancer Center be
liable to any party for direct, indirect, special, incidental or
consequential damages, including lost profits, arising out of the use of this
software and its documentation, even if Memorial Sloan-Kettering Cancer
Center has been advised of the possibility of such damage.

This file is part of cBioPortal.

cBioPortal is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<bean id="dbcpDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="url" value="jdbc:h2:mem:;MODE=MySQL;DATABASE_TO_UPPER=false;INIT=RUNSCRIPT FROM 'classpath:clickhouse-test.sql'\;RUNSCRIPT FROM 'classpath:clickhouseTestSql.sql'"/>
</bean>


<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dbcpDataSource"/>
<property name="typeAliasesPackage" value="org.mskcc.cbio.portal.model"/>
<property name="typeHandlersPackage" value="org.cbioportal.persistence.mybatis.typehandler"/>
</bean>

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dbcpDataSource" />
</bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="org.cbioportal.persistence.mybatiscolumnstore"/>
</bean>

<context:component-scan base-package="org.cbioportal.persistence.mybatiscolumnstore"/>

</beans>