forked from cBioPortal/cbioportal
-
Notifications
You must be signed in to change notification settings - Fork 0
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
264 additions
and
3 deletions.
There are no files selected for viewing
167 changes: 167 additions & 0 deletions
167
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,167 @@ | ||
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() | ||
); | ||
|
||
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")); | ||
// 1 empty string + 1 'NAN' + 1 'N/A' + 1 patient without data | ||
assertEquals(4, findClinicaDataCount(ageCounts, "NA")); | ||
} | ||
|
||
@Test | ||
public void getMutationCountsFilteredByAge() { | ||
StudyViewFilter studyViewFilter = new StudyViewFilter(); | ||
studyViewFilter.setStudyIds(List.of(STUDY_GENIE_PUB)); | ||
DataFilterValue value = new DataFilterValue(); | ||
value.setStart(BigDecimal.valueOf(20)); | ||
value.setEnd(BigDecimal.valueOf(70)); | ||
ClinicalDataFilter filter = new ClinicalDataFilter(); | ||
filter.setAttributeId("age"); | ||
filter.setValues(List.of(value)); | ||
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")); | ||
} | ||
|
||
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.