Skip to content

Commit

Permalink
add unit tests for clinical data counts sql
Browse files Browse the repository at this point in the history
  • Loading branch information
onursumer committed Aug 13, 2024
1 parent 280dd58 commit 32152ed
Show file tree
Hide file tree
Showing 2 changed files with 207 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.cbioportal.persistence.mybatisclickhouse;

import org.cbioportal.model.AlterationFilter;
import org.cbioportal.model.ClinicalDataCount;
import org.cbioportal.model.MutationEventType;
import org.cbioportal.model.TemporalRelation;
import org.cbioportal.persistence.helper.AlterationFilterHelper;
import org.cbioportal.persistence.mybatisclickhouse.config.MyBatisConfig;
import org.cbioportal.web.parameter.CategorizedClinicalDataCountFilter;
import org.cbioportal.web.parameter.ClinicalDataFilter;
import org.cbioportal.web.parameter.DataFilter;
import org.cbioportal.web.parameter.DataFilterValue;
import org.cbioportal.web.parameter.StudyViewFilter;
Expand All @@ -25,8 +27,9 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.Arrays;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -46,6 +49,7 @@ public class StudyViewMapperTest extends AbstractTestcontainers {

private static final String STUDY_TCGA_PUB = "study_tcga_pub";
private static final String STUDY_ACC_TCGA = "acc_tcga";
private static final String STUDY_GENIE_PUB = "study_genie_pub";

@Autowired
private StudyViewMapper studyViewMapper;
Expand Down Expand Up @@ -237,4 +241,109 @@ public void getSampleTreatmentCounts() {

}

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

var numericalClinicalDataCounts = studyViewMapper.getClinicalDataCounts(
studyViewFilter,
CategorizedClinicalDataCountFilter.getBuilder().build(),
false,
List.of("mutation_count"),
Collections.emptyList()
);
assertEquals(6, numericalClinicalDataCounts.size());
assertEquals(1, findClinicaDataCount(numericalClinicalDataCounts, "11"));
assertEquals(1, findClinicaDataCount(numericalClinicalDataCounts, "6"));
assertEquals(2, findClinicaDataCount(numericalClinicalDataCounts, "4"));
assertEquals(4, findClinicaDataCount(numericalClinicalDataCounts, "2"));
assertEquals(2, findClinicaDataCount(numericalClinicalDataCounts, "1"));
// 1 empty string + 1 'NAN' + 11 samples with no data
assertEquals(13, findClinicaDataCount(numericalClinicalDataCounts, "NA"));

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"));

var combinedClinicalDataCounts = studyViewMapper.getClinicalDataCounts(
studyViewFilter,
CategorizedClinicalDataCountFilter.getBuilder().build(),
false,
List.of("mutation_count", "center"),
Collections.emptyList()
);

assertEquals(13, combinedClinicalDataCounts.size());

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"));

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();
}
}
Loading

0 comments on commit 32152ed

Please sign in to comment.