Skip to content

Commit

Permalink
Add tests for categorical
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzhaoyuan authored and alisman committed Dec 3, 2024
1 parent 36eb05e commit a79aa2d
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 53 deletions.
7 changes: 7 additions & 0 deletions src/main/java/org/cbioportal/model/GenericAssayDataCount.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ public class GenericAssayDataCount implements Serializable {
private String value;
private Integer count;

public GenericAssayDataCount() {}

public GenericAssayDataCount(String value, Integer count) {
this.value = value;
this.count = count;
}

public String getValue() {
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ public class GenericAssayDataCountItem implements Serializable {
private String stableId;
private List<GenericAssayDataCount> counts;

public GenericAssayDataCountItem() {}

public GenericAssayDataCountItem(String stableId, List<GenericAssayDataCount> counts) {
this.stableId = stableId;
this.counts = counts;
}

public String getStableId() {
return stableId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ private CategorizedGenericAssayDataCountFilter extractGenericAssayDataCountFilte

CategorizedGenericAssayDataCountFilter.Builder builder = CategorizedGenericAssayDataCountFilter.getBuilder();

// No BINARY in the database yet
List<String> sampleNumericalProfileTypes = genericAssayProfilesMap.get(DataSource.SAMPLE)
.stream().filter(profile -> profile.getDatatype().equals("LIMIT-VALUE"))
.map(profile -> profile.getStableId().replace(profile.getCancerStudyIdentifier() + "_", ""))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ public class GenericAssayDataFilter extends DataFilter implements Serializable {
private String stableId;
private String profileType;

public GenericAssayDataFilter() {}

public GenericAssayDataFilter(String stableId, String profileType) {
this.stableId = stableId;
this.profileType = profileType;
}

public String getStableId() {
return stableId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ public void getSamplesFilteredByClinicalData() {
)
);
var filteredSamples5 = studyViewMapper.getFilteredSamples(StudyViewFilterHelper.build(studyViewFilter, null, new ArrayList<>()));
// 4 acc_tcga + 4 study_genie_pub samples with "NA" AGE data or no AGE data
assertEquals(8, filteredSamples5.size());
// 4 acc_tcga + 7 study_genie_pub samples with "NA" AGE data or no AGE data
assertEquals(11, filteredSamples5.size());

// NA + UNKNOWN
studyViewFilter.setClinicalDataFilters(
Expand All @@ -147,8 +147,8 @@ public void getSamplesFilteredByClinicalData() {
)
);
var filteredSamples6 = studyViewMapper.getFilteredSamples(StudyViewFilterHelper.build(studyViewFilter, null, new ArrayList<>()));
// 8 NA + 1 UNKNOWN
assertEquals(9, filteredSamples6.size());
// 11 NA + 1 UNKNOWN
assertEquals(12, filteredSamples6.size());
}

private DataFilterValue newDataFilterValue(Double start, Double end, String value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package org.cbioportal.persistence.mybatisclickhouse;

import org.cbioportal.model.GenericAssayDataCount;
import org.cbioportal.model.GenericAssayDataCountItem;
import org.cbioportal.persistence.helper.StudyViewFilterHelper;
import org.cbioportal.persistence.mybatisclickhouse.config.MyBatisConfig;
import org.cbioportal.web.parameter.GenericAssayDataFilter;
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.util.List;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(SpringRunner.class)
@Import(MyBatisConfig.class)
@DataJpaTest
@DirtiesContext
@AutoConfigureTestDatabase(replace= AutoConfigureTestDatabase.Replace.NONE)
@ContextConfiguration(initializers = AbstractTestcontainers.Initializer.class)
public class GenericAssayDataCountsTest extends AbstractTestcontainers {

private static final String ACC_TCGA = "acc_tcga";
private static final String STUDY_GENIE_PUB = "study_genie_pub";

@Autowired
private StudyViewMapper studyViewMapper;

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

GenericAssayDataFilter genericAssayDataFilter = new GenericAssayDataFilter("1p_status", "armlevel_cna");
List<GenericAssayDataCountItem> actualCounts = studyViewMapper.getGenericAssayDataCounts(
StudyViewFilterHelper.build(studyViewFilter, null, null),
List.of(genericAssayDataFilter)
);

List<GenericAssayDataCountItem> expectedCounts = List.of(
new GenericAssayDataCountItem("1p_status", List.of(
new GenericAssayDataCount("Loss", 1),
new GenericAssayDataCount("Gain", 1),
new GenericAssayDataCount("Unchanged", 1),
new GenericAssayDataCount("NA", 1)
))
);

assertThat(actualCounts)
.usingRecursiveComparison()
.ignoringCollectionOrder()
.isEqualTo(expectedCounts);
}

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

GenericAssayDataFilter genericAssayDataFilter = new GenericAssayDataFilter("DMETS_DX_ADRENAL", "distant_mets");
List<GenericAssayDataCountItem> actualCounts = studyViewMapper.getGenericAssayDataCounts(
StudyViewFilterHelper.build(studyViewFilter, null, null),
List.of(genericAssayDataFilter)
);

List<GenericAssayDataCountItem> expectedCounts = List.of(
new GenericAssayDataCountItem("DMETS_DX_ADRENAL", List.of(
new GenericAssayDataCount("No", 9),
new GenericAssayDataCount("Yes", 1),
new GenericAssayDataCount("NA", 14)
))
);

assertThat(actualCounts)
.usingRecursiveComparison()
.ignoringCollectionOrder()
.isEqualTo(expectedCounts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@DirtiesContext
@AutoConfigureTestDatabase(replace= AutoConfigureTestDatabase.Replace.NONE)
@ContextConfiguration(initializers = AbstractTestcontainers.Initializer.class)
public class MutationCountsTest extends AbstractTestcontainers {
public class MutationDataCountsTest extends AbstractTestcontainers {

private static final String STUDY_TCGA_PUB = "study_tcga_pub";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public void getMutationCounts() {
assertEquals(2, findClinicaDataCount(mutationsCounts, "4"));
assertEquals(4, findClinicaDataCount(mutationsCounts, "2"));
assertEquals(2, findClinicaDataCount(mutationsCounts, "1"));
// 1 empty string + 1 'NAN' + 12 samples with no data
assertEquals(14, findClinicaDataCount(mutationsCounts, "NA"));
// 1 empty string + 1 'NAN' + 15 samples with no data
assertEquals(17, findClinicaDataCount(mutationsCounts, "NA"));
}

@Test
Expand Down
Loading

0 comments on commit a79aa2d

Please sign in to comment.