Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Genomic data counts #10293

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cbioportal.service;

import org.cbioportal.model.*;
import org.cbioportal.service.exception.MolecularProfileNotFoundException;
import org.cbioportal.service.exception.StudyNotFoundException;

import java.util.List;
Expand All @@ -19,6 +20,9 @@ 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<GenericAssayDataCountItem> fetchGenericAssayDataCounts(List<String> sampleIds, List<String> studyIds, List<String> stableIds, List<String> profileTypes);

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class StudyViewServiceImpl implements StudyViewService {
@Autowired
private AlterationRepository alterationRepository;

@Autowired
private DiscreteCopyNumberService discreteCopyNumberService;

@Override
public List<GenomicDataCount> getGenomicDataCounts(List<String> studyIds, List<String> sampleIds) {
List<MolecularProfileCaseIdentifier> molecularProfileSampleIdentifiers =
Expand Down Expand Up @@ -186,6 +189,30 @@ public List<CopyNumberCountByGene> getCNAAlterationCountByGenes(List<String> stu
return copyNumberCountByGenes;
}

@Override
public List<GenomicDataCount> getCNAAlterationCountsByEvent(String molecularProfileId, List<Integer> entrezGeneIds,
List<Integer> alterations) throws MolecularProfileNotFoundException {

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

return copyNumberCounts
.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);

return genomicDataCount;
})
.collect(Collectors.toList());
}

@Override
public 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 @@ -14,6 +14,7 @@
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -41,6 +42,8 @@ public class StudyViewServiceImplTest extends BaseServiceImplTest {
private SignificantCopyNumberRegionService significantCopyNumberRegionService;
@Mock
private GenericAssayService genericAssayService;
@Mock
private DiscreteCopyNumberService discreteCopyNumberService;
private AlterationFilter alterationFilter = new AlterationFilter();

@Test
Expand Down Expand Up @@ -255,6 +258,64 @@ public void getCNAAlterationCountByGenes() throws Exception {
Assert.assertEquals(1, result.size());
}

@Test
public void getCNAAlterationCountByEvent() throws Exception {

List<Integer> entrezGeneIds = new ArrayList<>();
List<Integer> alterations = new ArrayList<>();

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

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

@Test
public void fetchGenericAssayDataCounts() throws Exception {

Expand Down
33 changes: 26 additions & 7 deletions web/src/main/java/org/cbioportal/web/StudyViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.apache.commons.math3.stat.correlation.SpearmansCorrelation;
import org.cbioportal.model.*;
import org.cbioportal.service.*;
import org.cbioportal.service.exception.MolecularProfileNotFoundException;
import org.cbioportal.service.exception.StudyNotFoundException;
import org.cbioportal.service.util.ClinicalAttributeUtil;
import org.cbioportal.web.config.annotation.InternalApi;
Expand All @@ -27,19 +28,14 @@
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.PostConstruct;
import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
Expand Down Expand Up @@ -845,6 +841,29 @@ 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,
7xuanlu marked this conversation as resolved.
Show resolved Hide resolved
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 Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.cbioportal.web.parameter;

public class CopyNumberCountFilter {

private String molecularProfileId;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should support multi profile, use profileType instead of molecularProfileId

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean List?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you are not using this class anymore. could you remove it?


private Integer entrezGeneId;
7xuanlu marked this conversation as resolved.
Show resolved Hide resolved

public String getMolecularProfileId() {return molecularProfileId; }

public void setMolecularProfileId(String molecularProfileId) {this.molecularProfileId = molecularProfileId; }

public Integer getEntrezGeneId() {
return entrezGeneId;
}

public void setEntrezGeneId(Integer entrezGeneId) {
this.entrezGeneId = entrezGeneId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class InvolvedCancerStudyExtractorInterceptor extends HandlerInterceptorA
public static final String STUDY_VIEW_CLINICAL_DATA_BIN_COUNTS_PATH = "/clinical-data-bin-counts/fetch";
public static final String STUDY_VIEW_CUSTOM_DATA_BIN_COUNTS_PATH = "/custom-data-bin-counts/fetch";
public static final String STUDY_VIEW_GENOMICL_DATA_BIN_COUNTS_PATH = "/genomic-data-bin-counts/fetch";
public static final String STUDY_VIEW_GENOMICL_DATA_COUNTS_PATH = "/genomic-data-counts/fetch";
public static final String STUDY_VIEW_GENERIC_ASSAY_DATA_BIN_COUNTS_PATH = "/generic-assay-data-bin-counts/fetch";
public static final String STUDY_VIEW_GENERIC_ASSAY_DATA_COUNTS_PATH = "/generic-assay-data-counts/fetch";
public static final String STUDY_VIEW_CLINICAL_DATA_COUNTS_PATH = "/clinical-data-counts/fetch";
Expand Down Expand Up @@ -137,7 +138,7 @@ public class InvolvedCancerStudyExtractorInterceptor extends HandlerInterceptorA
} else if (Arrays.asList(STUDY_VIEW_CLINICAL_DATA_COUNTS_PATH, STUDY_VIEW_CUSTOM_DATA_COUNTS_PATH)
.contains(requestPathInfo)) {
return extractAttributesFromClinicalDataCountFilter(request);
} else if (Arrays.asList(STUDY_VIEW_CLINICAL_DATA_DENSITY_PATH, STUDY_VIEW_CLINICAL_DATA_VIOLIN_PATH, STUDY_VIEW_CNA_GENES,
} else if (Arrays.asList(STUDY_VIEW_CLINICAL_DATA_DENSITY_PATH, STUDY_VIEW_CLINICAL_DATA_VIOLIN_PATH, STUDY_VIEW_CNA_GENES,
STUDY_VIEW_FILTERED_SAMPLES, STUDY_VIEW_MUTATED_GENES, STUDY_VIEW_STRUCTURAL_VARIANT_GENES,
STUDY_VIEW_STRUCTURAL_VARIANT_COUNTS, STUDY_VIEW_SAMPLE_COUNTS, STUDY_VIEW_SAMPLE_LIST_COUNTS_PATH, STUDY_VIEW_CLINICAL_TABLE_DATA_FETCH_PATH,
TREATMENTS_PATIENT_PATH, TREATMENTS_SAMPLE_PATH, STUDY_VIEW_PROFILE_SAMPLE_COUNTS_PATH, CLINICAL_EVENT_TYPE_COUNT_FETCH_PATH
Expand Down
38 changes: 38 additions & 0 deletions web/src/test/java/org/cbioportal/web/StudyViewControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public class StudyViewControllerTest {
private static final String TEST_GENERIC_ASSAY_DATA_VALUE_2 = "value2";
private static final String TEST_CLINICAL_EVENT_TYPE = "STATUS";
private static final Integer TEST_CLINICAL_EVENT_TYPE_COUNT = 513;
private static final String TEST_CNA_ALTERATION_NAME = "test_cna_event_type";
private static final String TEST_CNA_ALTERATION_VALUE = "2";
private static final String TEST_MOLECULAR_PROFILE_ID = "test_molecular_profile_id";

private List<SampleIdentifier> filteredSampleIdentifiers = new ArrayList<>();
private List<ClinicalData> clinicalData = new ArrayList<>();
Expand Down Expand Up @@ -506,6 +509,41 @@ public void fetchSampleCounts() throws Exception {
.andExpect(MockMvcResultMatchers.jsonPath("$[1].count").value(2));
}


@Test
public void fetchGenomicDataCounts() throws Exception {
List<GenomicDataCount> genomicDataCounts = new ArrayList<>();
GenomicDataCount genomicDataCount1 = new GenomicDataCount();
genomicDataCount1.setLabel(TEST_CNA_ALTERATION_NAME);
genomicDataCount1.setValue(TEST_CNA_ALTERATION_VALUE);
genomicDataCount1.setCount(1);
genomicDataCounts.add(genomicDataCount1);

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

when(studyViewService.getCNAAlterationCountsByEvent(
eq(TEST_MOLECULAR_PROFILE_ID),
eq(entrezGeneIds),
eq(alterations)))
.thenReturn(genomicDataCounts);

CopyNumberCountFilter copyNumberCountFilter = new CopyNumberCountFilter();
copyNumberCountFilter.setEntrezGeneId(TEST_ENTREZ_GENE_ID_1);
copyNumberCountFilter.setMolecularProfileId(TEST_MOLECULAR_PROFILE_ID);

mockMvc.perform(MockMvcRequestBuilders.post("/genomic-data-counts/fetch")
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(copyNumberCountFilter)))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].label").value(TEST_CNA_ALTERATION_NAME))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].value").value(TEST_CNA_ALTERATION_VALUE))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].count").value(1));
}

@Ignore("Skip StudyViewControllerTest.fetchClinicalDataDensityPlot due to assertion errors")
@Test
public void fetchClinicalDataDensityPlot() throws Exception {
Expand Down
Loading