-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit tests for clinical data counts sql
- Loading branch information
Showing
3 changed files
with
340 additions
and
3 deletions.
There are no files selected for viewing
243 changes: 243 additions & 0 deletions
243
src/test/java/org/cbioportal/persistence/mybatisclickhouse/ClinicalDataCountTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
package org.cbioportal.persistence.mybatisclickhouse; | ||
|
||
import org.cbioportal.model.ClinicalDataCount; | ||
import org.cbioportal.persistence.mybatisclickhouse.config.MyBatisConfig; | ||
import org.cbioportal.web.parameter.CategorizedClinicalDataCountFilter; | ||
import org.cbioportal.web.parameter.ClinicalDataFilter; | ||
import org.cbioportal.web.parameter.DataFilterValue; | ||
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.math.BigDecimal; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
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 ClinicalDataCountTest extends AbstractTestcontainers { | ||
private static final String STUDY_ACC_TCGA = "acc_tcga"; | ||
private static final String STUDY_GENIE_PUB = "study_genie_pub"; | ||
|
||
@Autowired | ||
private StudyViewMapper studyViewMapper; | ||
|
||
@Test | ||
public void getMutationCounts() { | ||
StudyViewFilter studyViewFilter = new StudyViewFilter(); | ||
studyViewFilter.setStudyIds(List.of(STUDY_GENIE_PUB)); | ||
|
||
var mutationsCounts = studyViewMapper.getClinicalDataCounts( | ||
studyViewFilter, | ||
CategorizedClinicalDataCountFilter.getBuilder().build(), | ||
false, | ||
List.of("mutation_count"), | ||
Collections.emptyList() | ||
); | ||
|
||
assertEquals(6, mutationsCounts.size()); | ||
assertEquals(1, findClinicaDataCount(mutationsCounts, "11")); | ||
assertEquals(1, findClinicaDataCount(mutationsCounts, "6")); | ||
assertEquals(2, findClinicaDataCount(mutationsCounts, "4")); | ||
assertEquals(4, findClinicaDataCount(mutationsCounts, "2")); | ||
assertEquals(2, findClinicaDataCount(mutationsCounts, "1")); | ||
// 1 empty string + 1 'NAN' + 11 samples with no data | ||
assertEquals(13, findClinicaDataCount(mutationsCounts, "NA")); | ||
} | ||
|
||
@Test | ||
public void getCenterCounts() { | ||
StudyViewFilter studyViewFilter = new StudyViewFilter(); | ||
studyViewFilter.setStudyIds(List.of(STUDY_GENIE_PUB)); | ||
|
||
var categoricalClinicalDataCounts = studyViewMapper.getClinicalDataCounts( | ||
studyViewFilter, | ||
CategorizedClinicalDataCountFilter.getBuilder().build(), | ||
false, | ||
List.of("center"), | ||
Collections.emptyList() | ||
); | ||
|
||
assertEquals(7, categoricalClinicalDataCounts.size()); | ||
assertEquals(3, findClinicaDataCount(categoricalClinicalDataCounts, "msk")); | ||
assertEquals(2, findClinicaDataCount(categoricalClinicalDataCounts, "dfci")); | ||
assertEquals(2, findClinicaDataCount(categoricalClinicalDataCounts, "chop")); | ||
assertEquals(1, findClinicaDataCount(categoricalClinicalDataCounts, "mda")); | ||
assertEquals(1, findClinicaDataCount(categoricalClinicalDataCounts, "ohsu")); | ||
assertEquals(1, findClinicaDataCount(categoricalClinicalDataCounts, "ucsf")); | ||
// 1 empty string + 1 'NA' + 11 samples with no data | ||
assertEquals(13, findClinicaDataCount(categoricalClinicalDataCounts, "NA")); | ||
} | ||
|
||
@Test | ||
public void getMutationAndCenterCounts() { | ||
StudyViewFilter studyViewFilter = new StudyViewFilter(); | ||
studyViewFilter.setStudyIds(List.of(STUDY_GENIE_PUB)); | ||
|
||
var combinedClinicalDataCounts = studyViewMapper.getClinicalDataCounts( | ||
studyViewFilter, | ||
CategorizedClinicalDataCountFilter.getBuilder().build(), | ||
false, | ||
List.of("mutation_count", "center"), | ||
Collections.emptyList() | ||
); | ||
|
||
assertEquals(13, combinedClinicalDataCounts.size()); | ||
} | ||
|
||
@Test | ||
public void getAgeCounts() { | ||
StudyViewFilter studyViewFilter = new StudyViewFilter(); | ||
studyViewFilter.setStudyIds(List.of(STUDY_GENIE_PUB)); | ||
|
||
var ageCounts = studyViewMapper.getClinicalDataCounts( | ||
studyViewFilter, | ||
CategorizedClinicalDataCountFilter.getBuilder().build(), | ||
false, | ||
List.of("age"), | ||
Collections.emptyList() | ||
); | ||
|
||
assertAgeCounts(ageCounts); | ||
|
||
// 1 empty string + 1 'NAN' + 1 'N/A' + 1 patient without data | ||
assertEquals(4, findClinicaDataCount(ageCounts, "NA")); | ||
} | ||
|
||
@Test | ||
public void getAgeCountsForMultipleStudies() { | ||
StudyViewFilter studyViewFilter = new StudyViewFilter(); | ||
studyViewFilter.setStudyIds(List.of(STUDY_GENIE_PUB, STUDY_ACC_TCGA)); | ||
|
||
var ageCounts = studyViewMapper.getClinicalDataCounts( | ||
studyViewFilter, | ||
CategorizedClinicalDataCountFilter.getBuilder().build(), | ||
false, | ||
List.of("age"), | ||
Collections.emptyList() | ||
); | ||
|
||
// everything should be exactly the same as single study (STUDY_GENIE_PUB) filter | ||
// except NA counts | ||
assertAgeCounts(ageCounts); | ||
|
||
// TODO this fails because of a known issue | ||
// (https://github.com/cBioPortal/rfc80-team/issues/39) | ||
// 1 empty string + 1 'NAN' + 1 'N/A' + 1 GENIE_PUB patient without data + 4 ACC_TCGA data without data | ||
// assertEquals(8, findClinicaDataCount(ageCounts, "NA")); | ||
} | ||
|
||
private void assertAgeCounts(List<ClinicalDataCount> ageCounts) { | ||
assertEquals(14, ageCounts.size()); | ||
|
||
assertEquals(3, findClinicaDataCount(ageCounts, "<18")); | ||
assertEquals(1, findClinicaDataCount(ageCounts, "18")); | ||
assertEquals(1, findClinicaDataCount(ageCounts, "22")); | ||
assertEquals(2, findClinicaDataCount(ageCounts, "42")); | ||
assertEquals(1, findClinicaDataCount(ageCounts, "66")); | ||
assertEquals(1, findClinicaDataCount(ageCounts, "66")); | ||
assertEquals(1, findClinicaDataCount(ageCounts, "68")); | ||
assertEquals(1, findClinicaDataCount(ageCounts, "77")); | ||
assertEquals(1, findClinicaDataCount(ageCounts, "78")); | ||
assertEquals(1, findClinicaDataCount(ageCounts, "79")); | ||
assertEquals(2, findClinicaDataCount(ageCounts, "80")); | ||
assertEquals(2, findClinicaDataCount(ageCounts, "82")); | ||
assertEquals(1, findClinicaDataCount(ageCounts, "89")); | ||
assertEquals(2, findClinicaDataCount(ageCounts, ">89")); | ||
} | ||
|
||
@Test | ||
public void getMutationCountsFilteredByAge() { | ||
StudyViewFilter studyViewFilter = new StudyViewFilter(); | ||
studyViewFilter.setStudyIds(List.of(STUDY_GENIE_PUB)); | ||
|
||
// filter patients with age between 20 and 70 | ||
// (there are 5 patients within this range, which are 307..311) | ||
ClinicalDataFilter filter = buildClinicalDataFilter("age", 20, 70); | ||
studyViewFilter.setClinicalDataFilters(List.of(filter)); | ||
|
||
var mutationCountsFiltered = studyViewMapper.getClinicalDataCounts( | ||
studyViewFilter, | ||
CategorizedClinicalDataCountFilter | ||
.getBuilder() | ||
.setPatientNumericalClinicalDataFilters(List.of(filter)) | ||
.build(), | ||
true, | ||
List.of("mutation_count"), | ||
Collections.emptyList() | ||
); | ||
|
||
assertEquals(3, mutationCountsFiltered.size()); | ||
assertEquals(2, findClinicaDataCount(mutationCountsFiltered, "2")); | ||
assertEquals(2, findClinicaDataCount(mutationCountsFiltered, "1")); | ||
assertEquals(1, findClinicaDataCount(mutationCountsFiltered, "NA")); | ||
} | ||
|
||
@Test | ||
public void getMutationCountsFilteredByAgeWithSpecialValues() { | ||
StudyViewFilter studyViewFilter = new StudyViewFilter(); | ||
studyViewFilter.setStudyIds(List.of(STUDY_GENIE_PUB)); | ||
|
||
// filter patients with age less than 20 | ||
// (there are 4 patients within this range, which are 301,302,303, and 306) | ||
ClinicalDataFilter filter = buildClinicalDataFilter("age", null, 20); | ||
studyViewFilter.setClinicalDataFilters(List.of(filter)); | ||
|
||
var mutationCountsFiltered = studyViewMapper.getClinicalDataCounts( | ||
studyViewFilter, | ||
CategorizedClinicalDataCountFilter | ||
.getBuilder() | ||
.setPatientNumericalClinicalDataFilters(List.of(filter)) | ||
.build(), | ||
true, | ||
List.of("mutation_count"), | ||
Collections.emptyList() | ||
); | ||
|
||
// TODO commented out tests below are failing due to a known issue | ||
// (https://github.com/cBioPortal/rfc80-team/issues/32) | ||
// assertEquals(4, mutationCountsFiltered.size()); | ||
// assertEquals(1, findClinicaDataCount(mutationCountsFiltered, "11")); // patient 301 | ||
// assertEquals(1, findClinicaDataCount(mutationCountsFiltered, "6")); // patient 302 | ||
// assertEquals(1, findClinicaDataCount(mutationCountsFiltered, "4")); // patient 303 | ||
assertEquals(1, findClinicaDataCount(mutationCountsFiltered, "2")); // patient 306 | ||
|
||
// no patients/samples with NA | ||
assertEquals(0, findClinicaDataCount(mutationCountsFiltered, "NA")); | ||
} | ||
|
||
private ClinicalDataFilter buildClinicalDataFilter(String attributeId, Integer start, Integer end) { | ||
DataFilterValue value = new DataFilterValue(); | ||
if (start != null) { | ||
value.setStart(BigDecimal.valueOf(start)); | ||
} | ||
if (end != null) { | ||
value.setEnd(BigDecimal.valueOf(end)); | ||
} | ||
|
||
ClinicalDataFilter filter = new ClinicalDataFilter(); | ||
filter.setAttributeId(attributeId); | ||
filter.setValues(List.of(value)); | ||
|
||
return filter; | ||
} | ||
|
||
private int findClinicaDataCount(List<ClinicalDataCount> counts, String attrValue) { | ||
var count = counts.stream().filter(c -> c.getValue().equals(attrValue)).findAny().orElse(null); | ||
|
||
return count == null ? 0 : count.getCount(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.