Skip to content

Commit

Permalink
change CopyNumberDataCounterFilter to StudyViewFilter and GenomicData…
Browse files Browse the repository at this point in the history
…CountFilter
  • Loading branch information
qlu-cls committed Jul 26, 2023
1 parent fff09f4 commit 082f3f5
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ List<AlterationCountByGene> getStructuralVariantAlterationCountByGenes(List<Stri
List<CopyNumberCountByGene> getCNAAlterationCountByGenes(List<String> studyIds, List<String> sampleIds, AlterationFilter annotationFilter)
throws StudyNotFoundException;

List<GenomicDataCount> getCNAAlterationCountsByEvent(String molecularProfileId, List<Integer> entrezGeneIds,
List<Integer> alterations) throws MolecularProfileNotFoundException;
List<GenomicDataCount> getCNAAlterationCountsByGeneSpecific(List<String> studyIds,
List<String> sampleIds,
List<String> hugoGeneSymbols,
AlterationFilter alterationFilter)
throws StudyNotFoundException;

List<GenericAssayDataCountItem> fetchGenericAssayDataCounts(List<String> sampleIds, List<String> studyIds, List<String> stableIds, List<String> profileTypes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class StudyViewServiceImpl implements StudyViewService {
private AlterationRepository alterationRepository;

@Autowired
private DiscreteCopyNumberService discreteCopyNumberService;
private GeneService geneService;

@Override
public List<GenomicDataCount> getGenomicDataCounts(List<String> studyIds, List<String> sampleIds) {
Expand Down Expand Up @@ -157,7 +157,7 @@ public List<CopyNumberCountByGene> getCNAAlterationCountByGenes(List<String> stu
throws StudyNotFoundException {
List<MolecularProfileCaseIdentifier> caseIdentifiers =
molecularProfileService.getFirstDiscreteCNAProfileCaseIdentifiers(studyIds, sampleIds);
Select<CNA> cnaTypes = Select.byValues(CNA_TYPES_AMP_AND_HOMDEL);

List<CopyNumberCountByGene> copyNumberCountByGenes = alterationCountService.getSampleCnaGeneCounts(
caseIdentifiers,
Select.all(),
Expand Down Expand Up @@ -190,28 +190,47 @@ public List<CopyNumberCountByGene> getCNAAlterationCountByGenes(List<String> stu
}

@Override
public List<GenomicDataCount> getCNAAlterationCountsByEvent(String molecularProfileId, List<Integer> entrezGeneIds,
List<Integer> alterations) throws MolecularProfileNotFoundException {
public List<GenomicDataCount> getCNAAlterationCountsByGeneSpecific(List<String> studyIds,
List<String> sampleIds,
List<String> hugoGeneSymbols,
AlterationFilter alterationFilter) throws StudyNotFoundException {
List<MolecularProfileCaseIdentifier> caseIdentifiers =
molecularProfileService.getFirstDiscreteCNAProfileCaseIdentifiers(studyIds, sampleIds);

List<CopyNumberCount> copyNumberCounts = discreteCopyNumberService.fetchCopyNumberCounts(molecularProfileId, entrezGeneIds, alterations);

return copyNumberCounts
Select<Integer> entrezGeneIds = Select.byValues(
geneService
.fetchGenes(hugoGeneSymbols,
"HUGO_GENE_SYMBOL", "SUMMARY")
.stream()
.filter(c -> c.getNumberOfSamplesWithAlterationInGene() != null)
.map(entry -> {
int count = entry.getNumberOfSamplesWithAlterationInGene();
int alteration = entry.getAlteration();
String label = CNA.getByCode(entry.getAlteration().shortValue()).getDescription();

GenomicDataCount genomicDataCount = new GenomicDataCount();
genomicDataCount.setLabel(label);
genomicDataCount.setValue(String.valueOf(alteration));
genomicDataCount.setCount(count);
.map(Gene::getEntrezGeneId));

return genomicDataCount;
})
.collect(Collectors.toList());
}
List<CopyNumberCountByGene> copyNumberCountByGenes = alterationCountService.getSampleCnaGeneCounts(
caseIdentifiers,
entrezGeneIds,
true,
false,
alterationFilter).getFirst();
Set<String> distinctStudyIds = new HashSet<>(studyIds);
if (distinctStudyIds.size() == 1 && !copyNumberCountByGenes.isEmpty()) {
return copyNumberCountByGenes
.stream()
.filter(c -> c.getNumberOfAlteredCases() != null && c.getNumberOfAlteredCases() > 0)
.map(entry -> {
int count = entry.getNumberOfAlteredCases();
int alteration = entry.getAlteration();
String label = CNA.getByCode(entry.getAlteration().shortValue()).getDescription();

GenomicDataCount genomicDataCount = new GenomicDataCount();
genomicDataCount.setLabel(label);
genomicDataCount.setValue(String.valueOf(alteration));
genomicDataCount.setCount(count);

return genomicDataCount;
})
.collect(Collectors.toList());
}
return new ArrayList<GenomicDataCount>();
};

@Override
public List<GenericAssayDataCountItem> fetchGenericAssayDataCounts(List<String> sampleIds, List<String> studyIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class StudyViewServiceImplTest extends BaseServiceImplTest {
@Mock
private GenericAssayService genericAssayService;
@Mock
private DiscreteCopyNumberService discreteCopyNumberService;
private GeneService geneService;
private AlterationFilter alterationFilter = new AlterationFilter();

@Test
Expand Down Expand Up @@ -259,61 +259,61 @@ public void getCNAAlterationCountByGenes() throws Exception {
}

@Test
public void getCNAAlterationCountByEvent() throws Exception {
public void getCNAAlterationCountByGeneSpecific() throws Exception {

List<Integer> entrezGeneIds = new ArrayList<>();
List<Integer> alterations = new ArrayList<>();
List<String> sampleIds = Arrays.asList(BaseServiceImplTest.SAMPLE_ID1, BaseServiceImplTest.SAMPLE_ID2, BaseServiceImplTest.SAMPLE_ID3);
List<String> studyIds = Collections.nCopies(3, BaseServiceImplTest.STUDY_ID);
List<String> hugoGeneSymbols = Arrays.asList(BaseServiceImplTest.HUGO_GENE_SYMBOL_1);

List<MolecularProfileCaseIdentifier> molecularProfileCaseIdentifiers = new ArrayList<>();
MolecularProfileCaseIdentifier profileCaseIdentifier1 = new MolecularProfileCaseIdentifier(BaseServiceImplTest.SAMPLE_ID1, BaseServiceImplTest.MOLECULAR_PROFILE_ID);
molecularProfileCaseIdentifiers.add(profileCaseIdentifier1);
MolecularProfileCaseIdentifier profileCaseIdentifier2 = new MolecularProfileCaseIdentifier(BaseServiceImplTest.SAMPLE_ID2, BaseServiceImplTest.MOLECULAR_PROFILE_ID);
molecularProfileCaseIdentifiers.add(profileCaseIdentifier2);
Mockito.when(molecularProfileService.getFirstDiscreteCNAProfileCaseIdentifiers(studyIds, sampleIds))
.thenReturn(molecularProfileCaseIdentifiers);

for (int i = -2; i < 3; i++) {
entrezGeneIds.add(BaseServiceImplTest.ENTREZ_GENE_ID_1);
alterations.add(i);
}

List<CopyNumberCount> alterationCountByEvents = new ArrayList<>();
CopyNumberCount alterationCountByEvent1 = new CopyNumberCount();
CopyNumberCount alterationCountByEvent2 = new CopyNumberCount();
CopyNumberCount alterationCountByEvent3 = new CopyNumberCount();
CopyNumberCount alterationCountByEvent4 = new CopyNumberCount();
CopyNumberCount alterationCountByEvent5 = new CopyNumberCount();
List<CopyNumberCountByGene> alterationCountByGenes = new ArrayList<>();
CopyNumberCountByGene alterationCountByGene1 = new CopyNumberCountByGene();

alterationCountByEvent1.setMolecularProfileId(BaseServiceImplTest.MOLECULAR_PROFILE_ID);
alterationCountByEvent1.setEntrezGeneId(BaseServiceImplTest.ENTREZ_GENE_ID_1);
alterationCountByEvent1.setAlteration(-2);
alterationCountByEvent1.setNumberOfSamples(5);
alterationCountByEvent1.setNumberOfSamplesWithAlterationInGene(1);
alterationCountByEvent2.setMolecularProfileId(BaseServiceImplTest.MOLECULAR_PROFILE_ID);
alterationCountByEvent2.setEntrezGeneId(BaseServiceImplTest.ENTREZ_GENE_ID_1);
alterationCountByEvent2.setAlteration(-1);
alterationCountByEvent2.setNumberOfSamples(5);
alterationCountByEvent2.setNumberOfSamplesWithAlterationInGene(1);
alterationCountByEvent3.setMolecularProfileId(BaseServiceImplTest.MOLECULAR_PROFILE_ID);
alterationCountByEvent3.setEntrezGeneId(BaseServiceImplTest.ENTREZ_GENE_ID_1);
alterationCountByEvent3.setAlteration(0);
alterationCountByEvent3.setNumberOfSamples(5);
alterationCountByEvent3.setNumberOfSamplesWithAlterationInGene(1);
alterationCountByEvent4.setMolecularProfileId(BaseServiceImplTest.MOLECULAR_PROFILE_ID);
alterationCountByEvent4.setEntrezGeneId(BaseServiceImplTest.ENTREZ_GENE_ID_1);
alterationCountByEvent4.setAlteration(1);
alterationCountByEvent4.setNumberOfSamples(5);
alterationCountByEvent4.setNumberOfSamplesWithAlterationInGene(1);
alterationCountByEvent5.setMolecularProfileId(BaseServiceImplTest.MOLECULAR_PROFILE_ID);
alterationCountByEvent5.setEntrezGeneId(BaseServiceImplTest.ENTREZ_GENE_ID_1);
alterationCountByEvent5.setAlteration(2);
alterationCountByEvent5.setNumberOfSamples(5);
alterationCountByEvent5.setNumberOfSamplesWithAlterationInGene(1);
alterationCountByEvents.add(alterationCountByEvent1);
alterationCountByEvents.add(alterationCountByEvent2);
alterationCountByEvents.add(alterationCountByEvent3);
alterationCountByEvents.add(alterationCountByEvent4);
alterationCountByEvents.add(alterationCountByEvent5);

Mockito.when(discreteCopyNumberService.fetchCopyNumberCounts(
eq(BaseServiceImplTest.MOLECULAR_PROFILE_ID),
eq(entrezGeneIds),
eq(alterations)
)).thenReturn(alterationCountByEvents);
List<GenomicDataCount> result = studyViewService.getCNAAlterationCountsByEvent(BaseServiceImplTest.MOLECULAR_PROFILE_ID, entrezGeneIds, alterations);
Assert.assertEquals(5, result.size());
alterationCountByGene1.setEntrezGeneId(BaseServiceImplTest.ENTREZ_GENE_ID_1);
alterationCountByGene1.setAlteration(-2);
alterationCountByGene1.setNumberOfAlteredCases(1);
alterationCountByGenes.add(alterationCountByGene1);

CopyNumberCountByGene alterationCountByGene2 = new CopyNumberCountByGene();
alterationCountByGene2.setEntrezGeneId(BaseServiceImplTest.ENTREZ_GENE_ID_1);
alterationCountByGene2.setAlteration(-1);
alterationCountByGene2.setNumberOfAlteredCases(1);
alterationCountByGenes.add(alterationCountByGene2);

CopyNumberCountByGene alterationCountByGene3 = new CopyNumberCountByGene();
alterationCountByGene3.setEntrezGeneId(BaseServiceImplTest.ENTREZ_GENE_ID_1);
alterationCountByGene3.setAlteration(0);
alterationCountByGene3.setNumberOfAlteredCases(1);
alterationCountByGenes.add(alterationCountByGene3);

CopyNumberCountByGene alterationCountByGene4 = new CopyNumberCountByGene();
alterationCountByGene4.setEntrezGeneId(BaseServiceImplTest.ENTREZ_GENE_ID_1);
alterationCountByGene4.setAlteration(1);
alterationCountByGene4.setNumberOfAlteredCases(1);
alterationCountByGenes.add(alterationCountByGene4);

CopyNumberCountByGene alterationCountByGene5 = new CopyNumberCountByGene();
alterationCountByGene5.setEntrezGeneId(BaseServiceImplTest.ENTREZ_GENE_ID_1);
alterationCountByGene5.setAlteration(2);
alterationCountByGene5.setNumberOfAlteredCases(1);
alterationCountByGenes.add(alterationCountByGene5);

Mockito.when(alterationCountService.getSampleCnaGeneCounts(
any(),
any(),
eq(true),
eq(false),
any(AlterationFilter.class)))
.thenReturn(new Pair<>(alterationCountByGenes, 5L));
List<GenomicDataCount> result = studyViewService.getCNAAlterationCountsByGeneSpecific(studyIds, sampleIds, hugoGeneSymbols, new AlterationFilter());
Assert.assertEquals(5L, result.size());
}

@Test
Expand Down
65 changes: 42 additions & 23 deletions web/src/main/java/org/cbioportal/web/StudyViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -841,29 +841,6 @@ public List<CaseListDataCount> fetchCaseListCounts(
.collect(Collectors.toList());

}

@PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection<CancerStudyId>', T(org.cbioportal.utils.security.AccessLevel).READ)")
@RequestMapping(value = "/genomic-data-counts/fetch", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation("Fetch genomic data counts by CopyNumberCountFilter")
public ResponseEntity<List<GenomicDataCount>> fetchGenomicDataCounts(
@ApiIgnore // prevent reference to this attribute in the swagger-ui interface
@RequestAttribute(required = false, value = "involvedCancerStudies") Collection<String> involvedCancerStudies,
@ApiParam(required = true, value = "List of copy number count identifiers")
@RequestBody CopyNumberCountFilter copyNumberCountFilter
) throws MolecularProfileNotFoundException {
String molecularProfileId = copyNumberCountFilter.getMolecularProfileId();
int entrezGeneId = copyNumberCountFilter.getEntrezGeneId();

List<Integer> entrezGeneIds = new ArrayList<>();
List<Integer> alterations = DiscreteCopyNumberEventType.ALL.getAlterationTypes();
for (int i = 0; i < alterations.size(); i++) entrezGeneIds.add(entrezGeneId);

return new ResponseEntity<>(
studyViewService.getCNAAlterationCountsByEvent(molecularProfileId, entrezGeneIds, alterations),
HttpStatus.OK
);
}

@PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection<CancerStudyId>', T(org.cbioportal.utils.security.AccessLevel).READ)")
@RequestMapping(value = "/genomic-data-bin-counts/fetch", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -880,6 +857,48 @@ public ResponseEntity<List<GenomicDataBin>> fetchGenomicDataBinCounts(
return new ResponseEntity<>(studyViewFilterApplier.getDataBins(dataBinMethod, interceptedGenomicDataBinCountFilter), HttpStatus.OK);
}

@PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection<CancerStudyId>', T(org.cbioportal.utils.security.AccessLevel).READ)")
@RequestMapping(value = "/genomic-data-counts/fetch", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation("Fetch genomic data counts by GenomicDataCountFilter")
public ResponseEntity<List<GenomicDataCount>> fetchGenomicDataCounts(
@ApiParam(required = true, value = "Genomic data bin count filter") @Valid @RequestBody(required = false) GenomicDataCountFilter genomicDataCountFilter,
@ApiIgnore // prevent reference to this attribute in the swagger-ui interface
@RequestAttribute(required = false, value = "involvedCancerStudies") Collection<String> involvedCancerStudies,
@ApiParam(required = true, value = "List of copy number count identifiers")
@ApiIgnore
@Valid @RequestAttribute(required = false, value = "interceptedGenomicDataCountFilter") GenomicDataCountFilter interceptedGenomicDataCountFilter
) throws StudyNotFoundException {
List<GenomicDataFilter> gdFilters = interceptedGenomicDataCountFilter.getGenomicDataFilters();
StudyViewFilter studyViewFilter = interceptedGenomicDataCountFilter.getStudyViewFilter();
// when there is only one filter, it means study view is doing a single chart filter operation
// remove filter from studyViewFilter to return all data counts
// the reason we do this is to make sure after chart get filtered, user can still see unselected portion of the chart
if (gdFilters.size() == 1) {
studyViewFilterUtil.removeSelfFromGenomicDataFilter(
gdFilters.get(0).getHugoGeneSymbol(),
gdFilters.get(0).getProfileType(),
studyViewFilter);
}
List<SampleIdentifier> filteredSampleIdentifiers = studyViewFilterApplier.apply(studyViewFilter);

if (filteredSampleIdentifiers.isEmpty()) {
return new ResponseEntity<>(new ArrayList<>(), HttpStatus.OK);
}

List<String> studyIds = new ArrayList<>();
List<String> sampleIds = new ArrayList<>();
studyViewFilterUtil.extractStudyAndSampleIds(filteredSampleIdentifiers, studyIds, sampleIds);

List<GenomicDataCount> result = studyViewService.getCNAAlterationCountsByGeneSpecific(
studyIds,
sampleIds,
gdFilters.stream().map(GenomicDataFilter::getHugoGeneSymbol).collect(Collectors.toList()),
studyViewFilter.getAlterationFilter());

return new ResponseEntity<>(result, HttpStatus.OK);
}

@PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection<CancerStudyId>', T(org.cbioportal.utils.security.AccessLevel).READ)")
@RequestMapping(value = "/generic-assay-data-counts/fetch", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation("Fetch generic assay data counts by study view filter")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.cbioportal.web.parameter;

import java.io.Serializable;
import java.util.List;

public class GenomicDataCountFilter implements Serializable {

private List<GenomicDataFilter> genomicDataFilters;
private StudyViewFilter studyViewFilter;

public List<GenomicDataFilter> getGenomicDataFilters() {
return genomicDataFilters;
}

public void setGenomicDataFilters(List<GenomicDataFilter> genomicDataFilters) {
this.genomicDataFilters = genomicDataFilters;
}

public StudyViewFilter getStudyViewFilter() {
return studyViewFilter;
}

public void setStudyViewFilter(StudyViewFilter studyViewFilter) {
this.studyViewFilter = studyViewFilter;
}
}
Loading

0 comments on commit 082f3f5

Please sign in to comment.