Skip to content

Commit

Permalink
add tests for clinical data filters (#10249)
Browse files Browse the repository at this point in the history
  • Loading branch information
onursumer authored Jun 29, 2023
1 parent 047cb26 commit 18819b1
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@
</if>
</trim>
</foreach>
</foreach>
)
</foreach>
</if>
<!-- ... extend for other elements of the StudyViewFilter object -->
</trim>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.cbioportal.model.AlterationCountByGene;
import org.cbioportal.model.Sample;
import org.cbioportal.webparam.ClinicalDataFilter;
import org.cbioportal.webparam.DataFilterValue;
import org.cbioportal.webparam.StudyViewFilter;
import org.junit.Assert;
import org.junit.Test;
Expand All @@ -11,8 +13,10 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.ArrayList;
import java.util.List;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/testContextDatabaseClickhouse.xml")
Expand All @@ -24,26 +28,77 @@ public class StudyViewMyBatisRepositoryTest {

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

List<String> studyIds = new ArrayList<>();
studyIds.add("msk_ch_2020");
studyViewFilter.setStudyIds(studyIds);
StudyViewFilter studyViewFilter = generateStudyViewFilter(new String[]{"msk_ch_2020", "msk_impact_2017"}, null);

// test total number of samples
List<Sample> samples = studyViewMyBatisRepository.getFilteredSamplesFromColumnstore(studyViewFilter);
Assert.assertEquals(3, samples.size());
Assert.assertEquals(11, samples.size());

// test sample numerical clinical attributes
studyViewFilter = generateStudyViewFilter(
new String[]{"msk_impact_2017"},
Collections.singletonList(
generateNumericalClinicalDataFilter("TUMOR_PURITY", new String[]{"20-35"})
)
);

samples = studyViewMyBatisRepository.getFilteredSamplesFromColumnstore(studyViewFilter);
Assert.assertEquals(2, samples.size());
}

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

List<String> studyIds = new ArrayList<>();
studyIds.add("msk_ch_2020");
studyViewFilter.setStudyIds(studyIds);
StudyViewFilter studyViewFilter = generateStudyViewFilter(new String[]{"msk_ch_2020"}, null);

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


private StudyViewFilter generateStudyViewFilter(
String[] studyIds,
List<ClinicalDataFilter> clinicalDataFilters
) {
StudyViewFilter studyViewFilter = new StudyViewFilter();
studyViewFilter.setStudyIds(Arrays.asList(studyIds));
studyViewFilter.setClinicalDataFilters(clinicalDataFilters);

return studyViewFilter;
}

private ClinicalDataFilter generateCategoricalClinicalDataFilter(String attributeId, String[] values) {
return generateClinicalDataFilter(attributeId, values, mapCategoricalValues);
}

private ClinicalDataFilter generateNumericalClinicalDataFilter(String attributeId, String[] values) {
return generateClinicalDataFilter(attributeId, values, mapNumericalValues);
}

private ClinicalDataFilter generateClinicalDataFilter(String attributeId, String[] values, Function<String, DataFilterValue> mapper) {
ClinicalDataFilter clinicalDataFilter = new ClinicalDataFilter();
List<DataFilterValue> dataFilterValues = Arrays.stream(values).map(mapper).collect(Collectors.toList());

clinicalDataFilter.setValues(dataFilterValues);
clinicalDataFilter.setAttributeId(attributeId);

return clinicalDataFilter;
}

private final Function<String, DataFilterValue> mapCategoricalValues = v -> {
DataFilterValue dataFilterValue = new DataFilterValue();
dataFilterValue.setValue(v);
return dataFilterValue;
};

private final Function<String, DataFilterValue> mapNumericalValues = v -> {
DataFilterValue dataFilterValue = new DataFilterValue();

String[] parts = v.split("-");
long start = Long.parseLong(parts[0]);
long end = parts.length > 1 ? Long.parseLong(parts[1]) : start;
dataFilterValue.setStart(BigDecimal.valueOf(start));
dataFilterValue.setEnd(BigDecimal.valueOf(end));

return dataFilterValue;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,28 @@ INSERT INTO patient_clinical_attribute_numeric (patient_unique_id, attribute_nam
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_clinical_attribute_numeric (patient_unique_id, sample_unique_id, attribute_name, attribute_value, cancer_study_identifier) VALUES ('msk_impact_2017_P-0012622', 'msk_impact_2017_P-0000004-T01-IM3', 'TUMOR_PURITY', 50, 'msk_impact_2017');
INSERT INTO sample_clinical_attribute_numeric (patient_unique_id, sample_unique_id, attribute_name, attribute_value, cancer_study_identifier) VALUES ('msk_impact_2017_P-0012622', 'msk_impact_2017_P-0000015-T01-IM3', 'TUMOR_PURITY', 40, 'msk_impact_2017');
INSERT INTO sample_clinical_attribute_numeric (patient_unique_id, sample_unique_id, attribute_name, attribute_value, cancer_study_identifier) VALUES ('msk_impact_2017_P-0012622', 'msk_impact_2017_P-0000023-T01-IM3', 'TUMOR_PURITY', 30, 'msk_impact_2017');
INSERT INTO sample_clinical_attribute_numeric (patient_unique_id, sample_unique_id, attribute_name, attribute_value, cancer_study_identifier) VALUES ('msk_impact_2017_P-0012622', 'msk_impact_2017_P-0000024-T01-IM3', 'TUMOR_PURITY', 40, 'msk_impact_2017');
INSERT INTO sample_clinical_attribute_numeric (patient_unique_id, sample_unique_id, attribute_name, attribute_value, cancer_study_identifier) VALUES ('msk_impact_2017_P-0012622', 'msk_impact_2017_P-0000025-T02-IM5', 'TUMOR_PURITY', 30, 'msk_impact_2017');
INSERT INTO sample_clinical_attribute_numeric (patient_unique_id, sample_unique_id, attribute_name, attribute_value, cancer_study_identifier) VALUES ('msk_impact_2017_P-0012622', 'msk_impact_2017_P-0000026-T01-IM3', 'TUMOR_PURITY', 10, 'msk_impact_2017');
INSERT INTO sample_clinical_attribute_numeric (patient_unique_id, sample_unique_id, attribute_name, attribute_value, cancer_study_identifier) VALUES ('msk_impact_2017_P-0012622', 'msk_impact_2017_P-0000030-T01-IM3', 'TUMOR_PURITY', 40, 'msk_impact_2017');
INSERT INTO sample_clinical_attribute_numeric (patient_unique_id, sample_unique_id, attribute_name, attribute_value, cancer_study_identifier) VALUES ('msk_impact_2017_P-0012622', 'msk_impact_2017_P-0000034-T01-IM3', 'TUMOR_PURITY', 40, 'msk_impact_2017');

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 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_impact_2017_P-0000004-T01-IM3', '', 'P-0000004-T01-IM3', 'msk_impact_2017_P-0012622', '', 'P-0012622', 'msk_impact_2017');
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_impact_2017_P-0000015-T01-IM3', '', 'P-0000015-T01-IM3', 'msk_impact_2017_P-0012622', '', 'P-0012622', 'msk_impact_2017');
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_impact_2017_P-0000023-T01-IM3', '', 'P-0000023-T01-IM3', 'msk_impact_2017_P-0012622', '', 'P-0012622', 'msk_impact_2017');
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_impact_2017_P-0000024-T01-IM3', '', 'P-0000024-T01-IM3', 'msk_impact_2017_P-0012622', '', 'P-0012622', 'msk_impact_2017');
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_impact_2017_P-0000025-T02-IM5', '', 'P-0000025-T02-IM5', 'msk_impact_2017_P-0012622', '', 'P-0012622', 'msk_impact_2017');
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_impact_2017_P-0000026-T01-IM3', '', 'P-0000026-T01-IM3', 'msk_impact_2017_P-0012622', '', 'P-0012622', 'msk_impact_2017');
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_impact_2017_P-0000030-T01-IM3', '', 'P-0000030-T01-IM3', 'msk_impact_2017_P-0012622', '', 'P-0012622', 'msk_impact_2017');
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_impact_2017_P-0000034-T01-IM3', '', 'P-0000034-T01-IM3', 'msk_impact_2017_P-0012622', '', 'P-0012622', 'msk_impact_2017');

--
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');
Expand Down

0 comments on commit 18819b1

Please sign in to comment.