Skip to content

Commit

Permalink
Code review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
alisman committed Aug 19, 2024
1 parent 95fcc74 commit a74cade
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface StudyViewRepository {

Map<String, ClinicalDataType> getClinicalAttributeDatatypeMap();

List<CaseListDataCount> getCaseListDataCounts(StudyViewFilter studyViewFilter);
List<CaseListDataCount> getCaseListDataCountsPerStudy(StudyViewFilter studyViewFilter);

Map<String, Integer> getTotalProfiledCounts(StudyViewFilter studyViewFilter, String alterationType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ List<AlterationCountByGene> getStructuralVariantGenes(StudyViewFilter studyViewF
List<ClinicalDataCount> getClinicalDataCounts(StudyViewFilter studyViewFilter, CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter,
boolean applyPatientIdFilters, List<String> attributeIds, List<String> filteredAttributeValues);

List<CaseListDataCount> getCaseListDataCounts(StudyViewFilter studyViewFilter, CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter, boolean applyPatientIdFilters);
List<CaseListDataCount> getCaseListDataCountsPerStudy(StudyViewFilter studyViewFilter, CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter, boolean applyPatientIdFilters);

List<ClinicalAttribute> getClinicalAttributes();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,34 +135,10 @@ public Map<String, ClinicalDataType> getClinicalAttributeDatatypeMap() {
return attributeDatatypeMap;
}

public static List<CaseListDataCount> mergeCaseListCounts(List<CaseListDataCount> counts) {
Map<String, List<CaseListDataCount>> countsPerListType = counts.stream()
.collect((Collectors.groupingBy(CaseListDataCount::getValue)));

// different cancer studies combined into one cohort will have separate case lists
// of a given type (e.g. rppa). We need to merge the counts for these
// different lists based on the type and choose a label
// this code just picks the first label, which assumes that the labels will match for a give type
List<CaseListDataCount> mergedCounts = new ArrayList<>();
for (Map.Entry<String,List<CaseListDataCount>> entry : countsPerListType.entrySet()) {
var dc = new CaseListDataCount();
dc.setValue(entry.getKey());
// here just snatch the label of the first profile
dc.setLabel(entry.getValue().get(0).getLabel());
Integer sum = entry.getValue().stream()
.map(x -> x.getCount())
.collect(Collectors.summingInt(Integer::intValue));
dc.setCount(sum);
mergedCounts.add(dc);
}
return mergedCounts;
}

@Override
public List<CaseListDataCount> getCaseListDataCounts(StudyViewFilter studyViewFilter) {
public List<CaseListDataCount> getCaseListDataCountsPerStudy(StudyViewFilter studyViewFilter) {
CategorizedClinicalDataCountFilter categorizedClinicalDataCountFilter = extractClinicalDataCountFilters(studyViewFilter);
var caseListDataCounts = mapper.getCaseListDataCounts(studyViewFilter, categorizedClinicalDataCountFilter, shouldApplyPatientIdFilters(studyViewFilter,categorizedClinicalDataCountFilter));
return mergeCaseListCounts(caseListDataCounts);
return mapper.getCaseListDataCountsPerStudy(studyViewFilter, categorizedClinicalDataCountFilter, shouldApplyPatientIdFilters(studyViewFilter,categorizedClinicalDataCountFilter));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ public List<ClinicalDataCountItem> getClinicalDataCounts(StudyViewFilter studyVi

@Override
public List<CaseListDataCount> getCaseListDataCounts(StudyViewFilter studyViewFilter) {
return studyViewRepository.getCaseListDataCounts(studyViewFilter);
// the study view merges case lists by type across studies
// type is determined by the suffix of case list name (after study name)
var caseListDataCountsPerStudy = studyViewRepository.getCaseListDataCountsPerStudy(studyViewFilter);
return mergeCaseListCounts(caseListDataCountsPerStudy);
}


Expand Down Expand Up @@ -146,4 +149,31 @@ public List<GenomicDataCountItem> getMutationTypeCountsByGeneSpecific(StudyViewF
return studyViewRepository.getMutationCountsByType(studyViewFilter, genomicDataFilters);
}



public static List<CaseListDataCount> mergeCaseListCounts(List<CaseListDataCount> counts) {
Map<String, List<CaseListDataCount>> countsPerListType = counts.stream()
.collect((Collectors.groupingBy(CaseListDataCount::getValue)));

// different cancer studies combined into one cohort will have separate case lists
// of a given type (e.g. rppa). We need to merge the counts for these
// different lists based on the type and choose a label
// this code just picks the first label, which assumes that the labels will match for a give type
List<CaseListDataCount> mergedCounts = new ArrayList<>();
for (Map.Entry<String,List<CaseListDataCount>> entry : countsPerListType.entrySet()) {
var dc = new CaseListDataCount();
dc.setValue(entry.getKey());
// here just snatch the label of the first profile
dc.setLabel(entry.getValue().get(0).getLabel());
Integer sum = entry.getValue().stream()
.map(x -> x.getCount())
.collect(Collectors.summingInt(Integer::intValue));
dc.setCount(sum);
mergedCounts.add(dc);
}
return mergedCounts;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
</select>

<!-- for /sample-lists-counts/fetch (returns CaseListDataCount) -->
<select id="getCaseListDataCounts" resultType="org.cbioportal.model.CaseListDataCount">
<select id="getCaseListDataCountsPerStudy" resultType="org.cbioportal.model.CaseListDataCount">
SELECT
name AS label,
REPLACE(stable_id, CONCAT(cancer_study_identifier, '_'), '') AS value,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.cbioportal.persistence.mybatisclickhouse;

import org.cbioportal.persistence.StudyViewRepository;
import org.cbioportal.persistence.mybatisclickhouse.config.MyBatisConfig;

import org.cbioportal.service.impl.StudyViewColumnarServiceImpl;
import org.cbioportal.web.parameter.CategorizedClinicalDataCountFilter;
import org.cbioportal.web.parameter.StudyViewFilter;
import org.junit.Test;
Expand All @@ -27,7 +27,7 @@
@DirtiesContext
@AutoConfigureTestDatabase(replace= AutoConfigureTestDatabase.Replace.NONE)
@ContextConfiguration(initializers = AbstractTestcontainers.Initializer.class)
public class CaseListSamplesCountsTest extends AbstractTestcontainers {
public class StudyViewCaseListSamplesCountsTest extends AbstractTestcontainers {

private static final String STUDY_TCGA_PUB = "study_tcga_pub";
private static final String STUDY_ACC_TCGA = "acc_tcga";
Expand All @@ -45,7 +45,7 @@ public void getMolecularProfileCounts() {

studyViewFilter.setCaseLists(caseListGroups);

var sampleListCounts = studyViewMapper.getCaseListDataCounts(studyViewFilter,
var sampleListCounts = studyViewMapper.getCaseListDataCountsPerStudy(studyViewFilter,
CategorizedClinicalDataCountFilter.getBuilder().build(), false );

var size = sampleListCounts.stream().filter(gc->gc.getValue().equals("mrna"))
Expand All @@ -64,7 +64,7 @@ public void getMolecularProfileCountsMultipleListsOr() {

studyViewFilter.setCaseLists(caseListGroups);

var sampleListCounts = studyViewMapper.getCaseListDataCounts(studyViewFilter,
var sampleListCounts = studyViewMapper.getCaseListDataCountsPerStudy(studyViewFilter,
CategorizedClinicalDataCountFilter.getBuilder().build(), false );

var size = sampleListCounts.stream().filter(gc->gc.getValue().equals("mrna"))
Expand All @@ -84,7 +84,7 @@ public void getMolecularProfileCountsMultipleListsAnd() {

studyViewFilter.setCaseLists(caseListGroups);

var sampleListCounts = studyViewMapper.getCaseListDataCounts(studyViewFilter,
var sampleListCounts = studyViewMapper.getCaseListDataCountsPerStudy(studyViewFilter,
CategorizedClinicalDataCountFilter.getBuilder().build(), false );

var size = sampleListCounts.stream().filter(gc->gc.getValue().equals("mrna"))
Expand All @@ -103,10 +103,10 @@ public void getMolecularProfileCountsAcrossStudies() {

studyViewFilter.setCaseLists(caseListGroups);

var unMergedCounts = studyViewMapper.getCaseListDataCounts(studyViewFilter,
var unMergedCounts = studyViewMapper.getCaseListDataCountsPerStudy(studyViewFilter,
CategorizedClinicalDataCountFilter.getBuilder().build(), false );

var caseListCountsMerged = StudyViewMyBatisRepository.mergeCaseListCounts(
var caseListCountsMerged = StudyViewColumnarServiceImpl.mergeCaseListCounts(
unMergedCounts
);

Expand Down

0 comments on commit a74cade

Please sign in to comment.