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

Updates to API endpoints (SV, Generic Assay, Gene Panel) #9457

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
54 changes: 0 additions & 54 deletions web/src/main/java/org/cbioportal/web/GenePanelController.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,58 +98,4 @@ public ResponseEntity<List<GenePanel>> fetchGenePanels(

return new ResponseEntity<>(genePanelService.fetchGenePanels(genePanelIds, projection.name()), HttpStatus.OK);
}

@PreAuthorize("hasPermission(#molecularProfileId, 'MolecularProfileId', T(org.cbioportal.utils.security.AccessLevel).READ)")
@RequestMapping(value = "/molecular-profiles/{molecularProfileId}/gene-panel-data/fetch", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation("Get gene panel data")
public ResponseEntity<List<GenePanelData>> getGenePanelData(
@ApiParam(required = true, value = "Molecular Profile ID e.g. nsclc_unito_2016_mutations")
@PathVariable String molecularProfileId,
@ApiParam(required = true, value = "List of Sample IDs/Sample List ID and Entrez Gene IDs")
@Valid @RequestBody GenePanelDataFilter genePanelDataFilter) throws MolecularProfileNotFoundException {

List<GenePanelData> genePanelDataList;
if (genePanelDataFilter.getSampleListId() != null) {
genePanelDataList = genePanelService.getGenePanelData(molecularProfileId,
genePanelDataFilter.getSampleListId());
} else {
genePanelDataList = genePanelService.fetchGenePanelData(molecularProfileId,
genePanelDataFilter.getSampleIds());
}

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

@PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection<CancerStudyId>', T(org.cbioportal.utils.security.AccessLevel).READ)")
@RequestMapping(value = "/gene-panel-data/fetch", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation("Fetch gene panel data")
public ResponseEntity<List<GenePanelData>> fetchGenePanelDataInMultipleMolecularProfiles(
@ApiIgnore // prevent reference to this attribute in the swagger-ui interface
@RequestAttribute(required = false, value = "involvedCancerStudies") Collection<String> involvedCancerStudies,
@ApiIgnore // prevent reference to this attribute in the swagger-ui interface. this attribute is needed for the @PreAuthorize tag above.
@Valid @RequestAttribute(required = false, value = "interceptedGenePanelDataMultipleStudyFilter") GenePanelDataMultipleStudyFilter interceptedGenePanelDataMultipleStudyFilter,
@ApiParam(required = true, value = "Gene panel data filter object")
@RequestBody(required = false) GenePanelDataMultipleStudyFilter genePanelDataMultipleStudyFilter) {

List<GenePanelData> genePanelDataList;
if(CollectionUtils.isEmpty(interceptedGenePanelDataMultipleStudyFilter.getMolecularProfileIds())) {
List<MolecularProfileCaseIdentifier> molecularProfileSampleIdentifiers = interceptedGenePanelDataMultipleStudyFilter.getSampleMolecularIdentifiers()
.stream()
.map(sampleMolecularIdentifier -> {
MolecularProfileCaseIdentifier profileCaseIdentifier = new MolecularProfileCaseIdentifier();
profileCaseIdentifier.setMolecularProfileId(sampleMolecularIdentifier.getMolecularProfileId());
profileCaseIdentifier.setCaseId(sampleMolecularIdentifier.getSampleId());
return profileCaseIdentifier;
})
.collect(Collectors.toList());

genePanelDataList = genePanelService.fetchGenePanelDataInMultipleMolecularProfiles(molecularProfileSampleIdentifiers);
} else {
genePanelDataList = genePanelService.fetchGenePanelDataByMolecularProfileIds(new HashSet<>(interceptedGenePanelDataMultipleStudyFilter.getMolecularProfileIds()));
}

return new ResponseEntity<>(genePanelDataList, HttpStatus.OK);
}
}
98 changes: 98 additions & 0 deletions web/src/main/java/org/cbioportal/web/GenePanelDataController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package org.cbioportal.web;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.cbioportal.model.GenePanel;
import org.cbioportal.model.GenePanelData;
import org.cbioportal.model.MolecularProfileCaseIdentifier;
import org.cbioportal.service.GenePanelService;
import org.cbioportal.service.exception.GenePanelNotFoundException;
import org.cbioportal.service.exception.MolecularProfileNotFoundException;
import org.cbioportal.web.config.PublicApiTags;
import org.cbioportal.web.config.annotation.PublicApi;
import org.cbioportal.web.parameter.*;
import org.cbioportal.web.parameter.sort.GenePanelSortBy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Size;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

@PublicApi
@RestController
@Validated
@Api(tags = PublicApiTags.GENE_PANEL_DATA, description = " ")
public class GenePanelDataController {

@Autowired
private GenePanelService genePanelService;

@PreAuthorize("hasPermission(#molecularProfileId, 'MolecularProfileId', T(org.cbioportal.utils.security.AccessLevel).READ)")
@RequestMapping(value = "/molecular-profiles/{molecularProfileId}/gene-panel-data/fetch", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation("Get gene panel data")
public ResponseEntity<List<GenePanelData>> getGenePanelData(
@ApiParam(required = true, value = "Molecular Profile ID e.g. nsclc_unito_2016_mutations")
@PathVariable String molecularProfileId,
@ApiParam(required = true, value = "List of Sample IDs/Sample List ID and Entrez Gene IDs")
@Valid @RequestBody GenePanelDataFilter genePanelDataFilter) throws MolecularProfileNotFoundException {

List<GenePanelData> genePanelDataList;
if (genePanelDataFilter.getSampleListId() != null) {
genePanelDataList = genePanelService.getGenePanelData(molecularProfileId,
genePanelDataFilter.getSampleListId());
} else {
genePanelDataList = genePanelService.fetchGenePanelData(molecularProfileId,
genePanelDataFilter.getSampleIds());
}

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

@PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection<CancerStudyId>', T(org.cbioportal.utils.security.AccessLevel).READ)")
@RequestMapping(value = "/gene-panel-data/fetch", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation("Fetch gene panel data")
public ResponseEntity<List<GenePanelData>> fetchGenePanelDataInMultipleMolecularProfiles(
@ApiIgnore // prevent reference to this attribute in the swagger-ui interface
@RequestAttribute(required = false, value = "involvedCancerStudies") Collection<String> involvedCancerStudies,
@ApiIgnore // prevent reference to this attribute in the swagger-ui interface. this attribute is needed for the @PreAuthorize tag above.
@Valid @RequestAttribute(required = false, value = "interceptedGenePanelDataMultipleStudyFilter") GenePanelDataMultipleStudyFilter interceptedGenePanelDataMultipleStudyFilter,
@ApiParam(required = true, value = "Gene panel data filter object")
@RequestBody(required = false) GenePanelDataMultipleStudyFilter genePanelDataMultipleStudyFilter) {

List<GenePanelData> genePanelDataList;
if(CollectionUtils.isEmpty(interceptedGenePanelDataMultipleStudyFilter.getMolecularProfileIds())) {
List<MolecularProfileCaseIdentifier> molecularProfileSampleIdentifiers = interceptedGenePanelDataMultipleStudyFilter.getSampleMolecularIdentifiers()
.stream()
.map(sampleMolecularIdentifier -> {
MolecularProfileCaseIdentifier profileCaseIdentifier = new MolecularProfileCaseIdentifier();
profileCaseIdentifier.setMolecularProfileId(sampleMolecularIdentifier.getMolecularProfileId());
profileCaseIdentifier.setCaseId(sampleMolecularIdentifier.getSampleId());
return profileCaseIdentifier;
})
.collect(Collectors.toList());

genePanelDataList = genePanelService.fetchGenePanelDataInMultipleMolecularProfiles(molecularProfileSampleIdentifiers);
} else {
genePanelDataList = genePanelService.fetchGenePanelDataByMolecularProfileIds(new HashSet<>(interceptedGenePanelDataMultipleStudyFilter.getMolecularProfileIds()));
}

return new ResponseEntity<>(genePanelDataList, HttpStatus.OK);
}
}
93 changes: 22 additions & 71 deletions web/src/main/java/org/cbioportal/web/GenericAssayController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -54,7 +55,7 @@ public class GenericAssayController {
@RequestMapping(value = "/generic_assay_meta/fetch", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation("Fetch meta data for generic-assay by ID")
public ResponseEntity<List<GenericAssayMeta>> fetchGenericAssayMetaData(
public ResponseEntity<List<GenericAssayMeta>> fetchGenericAssayMeta(
@ApiParam(required = true, value = "List of Molecular Profile ID or List of Stable ID")
@Valid @RequestBody GenericAssayMetaFilter genericAssayMetaFilter,
@ApiParam("Level of detail of the response")
Expand All @@ -71,85 +72,35 @@ public ResponseEntity<List<GenericAssayMeta>> fetchGenericAssayMetaData(
return new ResponseEntity<>(result, HttpStatus.OK);
}

@PreAuthorize("hasPermission(#molecularProfileId, 'MolecularProfileId', T(org.cbioportal.utils.security.AccessLevel).READ)")
@RequestMapping(value = "/generic_assay_data/{molecularProfileId}/fetch",
method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE,
// PreAuthorize is removed for performance reason
@RequestMapping(value = "/generic-assay-meta/{molecularProfileId}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation("fetch generic_assay_data in a molecular profile")
public ResponseEntity<List<GenericAssayData>> fetchGenericAssayDataInMolecularProfile(
@ApiOperation("Fetch meta data for generic-assay by ID")
public ResponseEntity<List<GenericAssayMeta>> getGenericAssayMeta(
@ApiParam(required = true, value = "Molecular Profile ID")
@PathVariable String molecularProfileId,
@ApiParam(required = true, value = "List of Sample IDs/Sample List ID and Generic Assay IDs")
@Valid @RequestBody GenericAssayFilter genericAssayDataFilter,
@ApiParam("Level of detail of the response")
@RequestParam(defaultValue = "SUMMARY") Projection projection) throws MolecularProfileNotFoundException {

List<GenericAssayData> result;
if (genericAssayDataFilter.getSampleListId() != null) {
result = filterEmptyGenericAssayData(genericAssayService.getGenericAssayData(molecularProfileId,
genericAssayDataFilter.getSampleListId(), genericAssayDataFilter.getGenericAssayStableIds(), projection.name()));
} else {
result = filterEmptyGenericAssayData(genericAssayService.fetchGenericAssayData(molecularProfileId,
genericAssayDataFilter.getSampleIds(), genericAssayDataFilter.getGenericAssayStableIds(), projection.name()));
}
@RequestParam(defaultValue = "SUMMARY") Projection projection) throws GenericAssayNotFoundException {
List<GenericAssayMeta> result;

result = genericAssayService.getGenericAssayMetaByStableIdsAndMolecularIds(null, Arrays.asList(molecularProfileId), projection.name());

if (projection == Projection.META) {
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.add(HeaderKeyConstants.TOTAL_COUNT, String.valueOf(result.size()));
return new ResponseEntity<>(responseHeaders, HttpStatus.OK);
} else {
return new ResponseEntity<>(result, HttpStatus.OK);
}
return new ResponseEntity<>(result, HttpStatus.OK);
}

@PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection<CancerStudyId>', T(org.cbioportal.utils.security.AccessLevel).READ)")
@RequestMapping(value = "/generic_assay_data/fetch", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation("Fetch generic_assay_data")
public ResponseEntity<List<GenericAssayData>> fetchGenericAssayDataInMultipleMolecularProfiles(
@ApiIgnore // prevent reference to this attribute in the swagger-ui interface
@RequestAttribute(required = false, value = "involvedCancerStudies") Collection<String> involvedCancerStudies,
@ApiIgnore // prevent reference to this attribute in the swagger-ui interface. this attribute is needed for the @PreAuthorize tag above.
@RequestAttribute(required = false, value = "interceptedGenericAssayDataMultipleStudyFilter") GenericAssayDataMultipleStudyFilter interceptedGenericAssayDataMultipleStudyFilter,
@ApiParam(required = true, value = "List of Molecular Profile ID and Sample ID pairs or List of Molecular" +
"Profile IDs and Generic Assay IDs")
@Valid @RequestBody(required = false) GenericAssayDataMultipleStudyFilter genericAssayDataMultipleStudyFilter,
@RequestMapping(value = "/generic-assay-meta/generic-assay/{genericAssayStableId}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation("Fetch meta data for generic-assay by ID")
public ResponseEntity<List<GenericAssayMeta>> getGenericAssayMeta_ga(
@ApiParam(required = false, value = "Generic Assay stable ID")
@PathVariable String genericAssayStableId,
@ApiParam("Level of detail of the response")
@RequestParam(defaultValue = "SUMMARY") Projection projection) throws MolecularProfileNotFoundException {

List<GenericAssayData> result;
if (interceptedGenericAssayDataMultipleStudyFilter.getMolecularProfileIds() != null) {
result = filterEmptyGenericAssayData(genericAssayService.fetchGenericAssayData(
interceptedGenericAssayDataMultipleStudyFilter.getMolecularProfileIds(), null,
interceptedGenericAssayDataMultipleStudyFilter.getGenericAssayStableIds(), projection.name()));
} else {

List<String> molecularProfileIds = new ArrayList<>();
List<String> sampleIds = new ArrayList<>();
extractMolecularProfileAndSampleIds(interceptedGenericAssayDataMultipleStudyFilter, molecularProfileIds, sampleIds);
result = filterEmptyGenericAssayData(genericAssayService.fetchGenericAssayData(molecularProfileIds,
sampleIds, interceptedGenericAssayDataMultipleStudyFilter.getGenericAssayStableIds(), projection.name()));
}

if (projection == Projection.META) {
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.add(HeaderKeyConstants.TOTAL_COUNT, String.valueOf(result.size()));
return new ResponseEntity<>(responseHeaders, HttpStatus.OK);
} else {
return new ResponseEntity<>(result, HttpStatus.OK);
}
@RequestParam(defaultValue = "SUMMARY") Projection projection) throws GenericAssayNotFoundException {
List<GenericAssayMeta> result;
result = genericAssayService.getGenericAssayMetaByStableIdsAndMolecularIds(Arrays.asList(genericAssayStableId), null, projection.name());

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

private void extractMolecularProfileAndSampleIds(GenericAssayDataMultipleStudyFilter molecularDataMultipleStudyFilter, List<String> molecularProfileIds, List<String> sampleIds) {
for (SampleMolecularIdentifier sampleMolecularIdentifier : molecularDataMultipleStudyFilter.getSampleMolecularIdentifiers()) {
molecularProfileIds.add(sampleMolecularIdentifier.getMolecularProfileId());
sampleIds.add(sampleMolecularIdentifier.getSampleId());
}
}

private List<GenericAssayData> filterEmptyGenericAssayData(List<GenericAssayData> genericAssayDataList) {
return genericAssayDataList.stream()
.filter(g -> StringUtils.isNotEmpty(g.getValue()) && !g.getValue().equals("NA"))
.collect(Collectors.toList());
}
}
Loading