diff --git a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/GenericRestWSServer.java b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/GenericRestWSServer.java index 7b9c8051ff..d33a7f47fd 100755 --- a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/GenericRestWSServer.java +++ b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/GenericRestWSServer.java @@ -78,15 +78,15 @@ public class GenericRestWSServer implements IWSServer { + " Please note that this parameter may not be enabled for all web services.") protected String include; - @DefaultValue("-1") + @DefaultValue("10") @QueryParam("limit") - @ApiParam(name = "limit", value = "Max number of results to be returned. No limit applied when -1." + @ApiParam(name = "limit", value = "Max number of results to be returned. Cannot exceed 5,000." + " Please note that this option may not be available for all web services.") protected int limit; - @DefaultValue("-1") + @DefaultValue("0") @QueryParam("skip") - @ApiParam(name = "skip", value = "Number of results to be skipped. No skip applied when -1. " + @ApiParam(name = "skip", value = "Number of results to be skipped. No skip applied when 0. " + " Please note that this option may not be available for all web services.") protected int skip; @@ -252,7 +252,7 @@ private void checkPathParams(boolean checkSpecies) throws VersionException, Spec } @Override - public void parseQueryParams() { + public void parseQueryParams() throws CellbaseException { MultivaluedMap multivaluedMap = uriInfo.getQueryParameters(); queryOptions.put("metadata", multivaluedMap.get("metadata") == null || multivaluedMap.get("metadata").get(0).equals("true")); @@ -276,9 +276,18 @@ public void parseQueryParams() { queryOptions.put(QueryOptions.SORT, sort); } - queryOptions.put(QueryOptions.LIMIT, (limit > 0) ? Math.min(limit, LIMIT_MAX) : LIMIT_DEFAULT); - queryOptions.put(QueryOptions.SKIP, (skip >= 0) ? skip : -1); -// queryOptions.put(QueryOptions.SKIP_COUNT, StringUtils.isNotBlank(skipCount) && Boolean.parseBoolean(skipCount)); + if (limit < 0) { + throw new CellbaseException("Limit is not valid. Expected a number greater than zero but was " + limit); + } else if (limit > LIMIT_MAX) { + throw new CellbaseException("Limit is not valid. Expected a number less than " + LIMIT_MAX + " but was " + limit); + } + + if (skip < 0) { + throw new CellbaseException("Skip is not valid. Expected a number greater than zero but was " + skip); + } + + queryOptions.put(QueryOptions.LIMIT, limit); + queryOptions.put(QueryOptions.SKIP, skip); queryOptions.put(QueryOptions.COUNT, StringUtils.isNotBlank(count) && Boolean.parseBoolean(count)); // Add all the others QueryParams from the URL diff --git a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/IWSServer.java b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/IWSServer.java index a3930b7367..086d296843 100755 --- a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/IWSServer.java +++ b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/IWSServer.java @@ -16,14 +16,16 @@ package org.opencb.cellbase.server.rest; +import org.opencb.cellbase.core.exception.CellbaseException; + import javax.ws.rs.core.Response; public interface IWSServer { - void parseQueryParams(); + void parseQueryParams() throws CellbaseException; - default Response first() { + default Response first() throws Exception { return Response.ok("No implemented yet").build(); } diff --git a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/clinical/ClinicalWSServer.java b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/clinical/ClinicalWSServer.java index f904faf110..685f11dc13 100644 --- a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/clinical/ClinicalWSServer.java +++ b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/clinical/ClinicalWSServer.java @@ -128,7 +128,7 @@ public Response getAll() { } @GET - @Path("/variant/allele_origin_labels") + @Path("/variant/alleleOriginLabels") @ApiOperation(httpMethod = "GET", notes = "", value = "Retrieves all available allele origin labels", response = Variant.class, responseContainer = "QueryResponse") @@ -143,7 +143,7 @@ public Response getAlleleOriginLabels() { } @GET - @Path("/variant/mode_inheritance_labels") + @Path("/variant/modeInheritanceLabels") @ApiOperation(httpMethod = "GET", notes = "", value = "Retrieves all available mode of inheritance labels", response = Variant.class, responseContainer = "QueryResponse") @@ -158,7 +158,7 @@ public Response getModeInheritanceLabels() { } @GET - @Path("/variant/clinsig_labels") + @Path("/variant/clinsigLabels") @ApiOperation(httpMethod = "GET", notes = "", value = "Retrieves all available clinical significance labels", response = Variant.class, responseContainer = "QueryResponse") @@ -173,7 +173,7 @@ public Response getClinicalSignificanceLabels() { } @GET - @Path("/variant/consistency_labels") + @Path("/variant/consistencyLabels") @ApiOperation(httpMethod = "GET", notes = "", value = "Retrieves all available consistency labels", response = Variant.class, responseContainer = "QueryResponse") diff --git a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/GeneWSServer.java b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/GeneWSServer.java index 218b92fe6c..9aa0a7b3d1 100755 --- a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/GeneWSServer.java +++ b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/GeneWSServer.java @@ -76,7 +76,7 @@ public Response getModel() { @Override @Deprecated @ApiOperation(httpMethod = "GET", value = "Get the first object in the database", response = Gene.class, - responseContainer = "QueryResponse") + responseContainer = "QueryResponse", hidden = true) public Response first() { GeneDBAdaptor geneDBAdaptor = dbAdaptorFactory.getGeneDBAdaptor(this.species, this.assembly); return createOkResponse(geneDBAdaptor.first(queryOptions)); @@ -86,7 +86,7 @@ public Response first() { @Path("/count") @Deprecated @ApiOperation(httpMethod = "GET", value = "Get the number of genes in the database", response = Integer.class, - responseContainer = "QueryResponse") + responseContainer = "QueryResponse", hidden = true) @ApiImplicitParams({ @ApiImplicitParam(name = "region", value = "Comma separated list of genomic regions to be queried, e.g.: 1:6635137-6635325", diff --git a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/IdWSServer.java b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/IdWSServer.java index ba023f26a2..70c2f4cf75 100755 --- a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/IdWSServer.java +++ b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/IdWSServer.java @@ -137,7 +137,7 @@ public Response getAllXrefsByFeatureId(@PathParam("id") } @GET - @Path("/{id}/starts_with") + @Path("/{id}/startsWith") @ApiOperation(httpMethod = "GET", value = "Get the gene HGNC symbols of genes for which there is an Xref id that " + "matches the beginning of the given string", response = Map.class, responseContainer = "QueryResponse") public Response getByLikeQuery(@PathParam("id") diff --git a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/ProteinWSServer.java b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/ProteinWSServer.java index 871f90980d..f9031ac057 100755 --- a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/ProteinWSServer.java +++ b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/ProteinWSServer.java @@ -135,7 +135,7 @@ public Response getAll() { } @GET - @Path("/{proteinId}/substitution_scores") + @Path("/{proteinId}/substitutionScores") @ApiOperation(httpMethod = "GET", value = "Get the gene corresponding substitution scores for the input protein", notes = "Schema of returned objects will vary depending on provided query parameters. If the amino acid " + " position is provided, all scores will be returned for every possible amino acid" @@ -161,7 +161,6 @@ public Response getSubstitutionScores(@PathParam("proteinId") required = true) String id) { try { parseQueryParams(); -// query.put(ProteinDBAdaptor.QueryParams.XREFS.key(), id); // Fetch Ensembl transcriptId to query substiturion scores TranscriptDBAdaptor transcriptDBAdaptor = dbAdaptorFactory.getTranscriptDBAdaptor(this.species, this.assembly); diff --git a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/TranscriptWSServer.java b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/TranscriptWSServer.java index 389e8f1609..29f977a4e9 100755 --- a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/TranscriptWSServer.java +++ b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/TranscriptWSServer.java @@ -77,8 +77,8 @@ public Response getModel() { @Override @Deprecated @ApiOperation(httpMethod = "GET", value = "Get the first transcript in the database", response = Transcript.class, - responseContainer = "QueryResponse") - public Response first() { + responseContainer = "QueryResponse", hidden = true) + public Response first() throws Exception { parseQueryParams(); TranscriptDBAdaptor transcriptDBAdaptor = dbAdaptorFactory.getTranscriptDBAdaptor(this.species, this.assembly); return createOkResponse(transcriptDBAdaptor.first(queryOptions)); @@ -88,7 +88,7 @@ public Response first() { @Path("/count") @Deprecated @ApiOperation(httpMethod = "GET", value = "Get the number of transcripts in the database", response = Integer.class, - responseContainer = "QueryResponse") + responseContainer = "QueryResponse", hidden = true) public Response count(@DefaultValue("") @QueryParam("region") @ApiParam(name = "region", @@ -315,7 +315,7 @@ public Response getProtein(@PathParam("transcriptId") } @GET - @Path("/{transcriptId}/function_prediction") + @Path("/{transcriptId}/functionPrediction") @ApiOperation(httpMethod = "GET", value = "Get the gene corresponding substitution scores for the protein of a" + " certain transcript", notes = "Schema of returned objects will vary depending on provided query parameters. If the amino acid " diff --git a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/VariationWSServer.java b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/VariationWSServer.java deleted file mode 100644 index a8b8f35d8f..0000000000 --- a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/feature/VariationWSServer.java +++ /dev/null @@ -1,317 +0,0 @@ -/* - * Copyright 2015-2020 OpenCB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.opencb.cellbase.server.rest.feature; - -import io.swagger.annotations.*; -import org.opencb.biodata.models.core.Transcript; -import org.opencb.biodata.models.variant.Variant; -import org.opencb.cellbase.core.api.VariantDBAdaptor; -import org.opencb.cellbase.core.exception.CellbaseException; -import org.opencb.cellbase.core.result.CellBaseDataResult; -import org.opencb.cellbase.core.variant.annotation.VariantAnnotationUtils; -import org.opencb.cellbase.server.exception.SpeciesException; -import org.opencb.cellbase.server.exception.VersionException; -import org.opencb.cellbase.server.rest.GenericRestWSServer; -import org.opencb.commons.datastore.core.Query; -import org.opencb.commons.datastore.core.QueryOptions; - - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.*; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import java.io.IOException; -import java.util.*; -import java.util.stream.Collectors; - -/** - * Created by fjlopez on 29/04/16. - */ -@Path("/{version}/{species}/feature/variation") -@Produces(MediaType.APPLICATION_JSON) -@Api(value = "Variation", description = "Known genomic variation RESTful Web Services API") -public class VariationWSServer extends GenericRestWSServer { - - protected static final HashMap> CACHE_TRANSCRIPT = new HashMap<>(); - - public VariationWSServer(@PathParam("version") - @ApiParam(name = "version", value = "Possible values: v4, v5", - defaultValue = "v5") String version, - @PathParam("species") - @ApiParam(name = "species", value = "Name of the species, e.g.: hsapiens. For a full list " - + "of potentially available species ids, please refer to: " - + "https://bioinfo.hpc.cam.ac.uk/cellbase/webservices/rest/v4/meta/species") String species, - @Context UriInfo uriInfo, - @Context HttpServletRequest hsr) throws VersionException, SpeciesException, IOException, CellbaseException { - super(version, species, uriInfo, hsr); - } - - @GET - @Path("/model") - @ApiOperation(httpMethod = "GET", value = "Get JSON specification of Variant data model", response = Map.class, - responseContainer = "QueryResponse") - public Response getModel() { - return createModelResponse(Variant.class); - } - - @GET - @Path("/first") - @Override - @ApiOperation(httpMethod = "GET", value = "Get the first object in the database", response = Variant.class, - responseContainer = "QueryResponse") - public Response first() { - VariantDBAdaptor variationDBAdaptor = dbAdaptorFactory.getVariationDBAdaptor(this.species, this.assembly); - return createOkResponse(variationDBAdaptor.first(queryOptions)); - } - - @GET - @Path("/count") - @Deprecated - @ApiOperation(httpMethod = "GET", value = "Retrieves all the gene objects for the regions.", - response = Integer.class, responseContainer = "QueryResponse") - @ApiImplicitParams({ - @ApiImplicitParam(name = "region", - value = "Comma separated list of genomic regions to be queried, e.g.: 1:6635137-6635325", - required = false, dataType = "java.util.List", paramType = "query"), - @ApiImplicitParam(name = "consequenceType", - value = "Comma separated list of sequence ontology term names, e.g.: missense_variant. Exact text " - + "matches will be returned.", - required = false, dataType = "java.util.List", paramType = "query"), - @ApiImplicitParam(name = "gene", - value = "Comma separated list ENSEMBL gene ids, e.g.: ENSG00000161905. Exact text matches will be " - + "returned.", - required = false, dataType = "java.util.List", paramType = "query"), - @ApiImplicitParam(name = "id", - value = "Comma separated list of rs ids, e.g.: rs6025", - required = false, dataType = "java.util.List", paramType = "query"), - @ApiImplicitParam(name = "chromosome", - value = "Comma separated list of chromosomes to be queried, e.g.: 1,X,MT", - required = false, dataType = "java.util.List", paramType = "query"), - @ApiImplicitParam(name = "reference", - value = "Comma separated list of possible reference to be queried, e.g.: A,T", - required = false, dataType = "java.util.List", paramType = "query"), - @ApiImplicitParam(name = "alternate", - value = "Comma separated list of possible alternate to be queried, e.g.: A,T", - required = false, dataType = "java.util.List", paramType = "query") - }) - public Response count() { - VariantDBAdaptor variationDBAdaptor = dbAdaptorFactory.getVariationDBAdaptor(this.species, this.assembly); - return createOkResponse(variationDBAdaptor.count(query)); - } - - @GET - @Path("/stats") - @Override - @ApiOperation(httpMethod = "GET", value = "Not implemented yet.", - response = Integer.class, responseContainer = "QueryResponse", hidden = true) - public Response stats() { - return super.stats(); - } - - @GET - @Path("/{id}/info") - @ApiOperation(httpMethod = "GET", value = "Resource to get information about a (list of) SNPs", notes = "An independent" - + " database query will be issued for each region in id, meaning that results for each region will be" - + " returned in independent CellBaseDataResult objects within the QueryResponse object.", - response = Variant.class, responseContainer = "QueryResponse") - @ApiImplicitParams({ - @ApiImplicitParam(name = "region", - value = "Comma separated list of genomic regions to be queried, e.g.: 1:6635137-6635325", - required = false, dataType = "java.util.List", paramType = "query"), - @ApiImplicitParam(name = "consequenceType", - value = "Comma separated list of sequence ontology term names, e.g.: missense_variant. Exact text " - + "matches will be returned.", - required = false, dataType = "java.util.List", paramType = "query"), - @ApiImplicitParam(name = "gene", - value = "Comma separated list ENSEMBL gene ids, e.g.: ENSG00000161905. Exact text matches will be " - + "returned.", - required = false, dataType = "java.util.List", paramType = "query"), - @ApiImplicitParam(name = "chromosome", - value = "Comma separated list of chromosomes to be queried, e.g.: 1,X,MT", - required = false, dataType = "java.util.List", paramType = "query"), - @ApiImplicitParam(name = "reference", - value = "Comma separated list of possible reference to be queried, e.g.: A,T", - required = false, dataType = "java.util.List", paramType = "query"), - @ApiImplicitParam(name = "alternate", - value = "Comma separated list of possible alternate to be queried, e.g.: A,T", - required = false, dataType = "java.util.List", paramType = "query") - }) - public Response getByEnsemblId(@PathParam("id") - @ApiParam(name = "id", - value = "Comma separated list of rs ids, e.g.: rs6025", - required = true) String id) { - try { - parseQueryParams(); - VariantDBAdaptor variationDBAdaptor = dbAdaptorFactory.getVariationDBAdaptor(this.species, this.assembly); - List queries = createQueries(id, VariantDBAdaptor.QueryParams.ID.key()); - List queryResults = variationDBAdaptor.nativeGet(queries, queryOptions); - for (int i = 0; i < queries.size(); i++) { - queryResults.get(i).setId((String) queries.get(i).get(VariantDBAdaptor.QueryParams.ID.key())); - } - return createOkResponse(queryResults); - } catch (Exception e) { - return createErrorResponse(e); - } - } - - @GET - @Path("/search") - @ApiOperation(httpMethod = "GET", notes = "No more than 1000 objects are allowed to be returned at a time.", - value = "Retrieves all variation objects", response = Variant.class, responseContainer = "QueryResponse") - @ApiImplicitParams({ - @ApiImplicitParam(name = "region", - value = "Comma separated list of genomic regions to be queried, e.g.: 1:6635137-6635325", - dataType = "java.util.List", paramType = "query"), - @ApiImplicitParam(name = "id", - value = "Comma separated list of rs ids, e.g.: rs6025, rs666" - + " Exact text matches will be returned", dataType = "java.util.List", paramType = "query"), - @ApiImplicitParam(name = "consequenceType", - value = "Comma separated list of sequence ontology term names, e.g.: missense_variant." - + " Exact text matches will be returned", dataType = "java.util.List", paramType = "query"), - @ApiImplicitParam(name = "gene", - value = "Comma separated list ENSEMBL gene ids, e.g.: ENSG00000161905. Exact text matches will be " - + "returned.", dataType = "java.util.List", paramType = "query"), - @ApiImplicitParam(name = "chromosome", - value = "Comma separated list of chromosomes to be queried, e.g.: 1,X,MT", - dataType = "java.util.List", paramType = "query"), - @ApiImplicitParam(name = "reference", - value = "Comma separated list of possible reference to be queried, e.g.: A,T", - dataType = "java.util.List", paramType = "query"), - @ApiImplicitParam(name = "alternate", - value = "Comma separated list of possible alternate to be queried, e.g.: A,T", - dataType = "java.util.List", paramType = "query") - }) - public Response search() { - try { - parseQueryParams(); - VariantDBAdaptor variationDBAdaptor = dbAdaptorFactory.getVariationDBAdaptor(this.species, this.assembly); - return createOkResponse(variationDBAdaptor.nativeGet(query, queryOptions)); - } catch (Exception e) { - return createErrorResponse(e); - } - } - - @GET - @Path("/{id}/next") - @ApiOperation(httpMethod = "GET", value = "Get information about the next SNP", hidden = true) - public Response getNextById(@PathParam("id") - @ApiParam(name = "id", - value = "Rs id, e.g.: rs6025", - required = true) String id) { - try { - parseQueryParams(); - VariantDBAdaptor variationDBAdaptor = dbAdaptorFactory.getVariationDBAdaptor(this.species, this.assembly); - query.put(VariantDBAdaptor.QueryParams.ID.key(), id.split(",")[0]); - CellBaseDataResult queryResult = variationDBAdaptor.next(query, queryOptions); - queryResult.setId(id); - return createOkResponse(queryResult); - } catch (Exception e) { - return createErrorResponse(e); - } - } - - @GET - @Path("/consequence_types") - @ApiOperation(httpMethod = "GET", value = "Get all sequence ontology terms describing consequence types", - response = String.class, responseContainer = "QueryResponse") - public Response getAllConsequenceTypes() { - try { - parseQueryParams(); - List consequenceTypes = VariantAnnotationUtils.SO_SEVERITY.keySet().stream() - .sorted() - .collect(Collectors.toList()); - CellBaseDataResult queryResult = new CellBaseDataResult<>("consequence_types"); - queryResult.setNumResults(consequenceTypes.size()); - queryResult.setResults(consequenceTypes); - return createOkResponse(queryResult); - } catch (Exception e) { - return createErrorResponse(e); - } - } - - // FIXME: 29/04/16 GET and POST web services to be fixed - @GET - @Path("/{snpId}/consequence_type") - @ApiOperation(httpMethod = "GET", value = "Get the biological impact of the SNP(s)", response = String.class, - responseContainer = "QueryResponse") - public Response getConsequenceTypeByGetMethod(@PathParam("snpId") String snpId) { - return getConsequenceType(snpId); - } - - @POST - @Path("/consequence_type") - @ApiOperation(httpMethod = "POST", value = "Get the biological impact of the SNP(s)", response = String.class, - responseContainer = "QueryResponse") - public Response getConsequenceTypeByPostMethod(@QueryParam("id") String snpId) { - return getConsequenceType(snpId); - } - - private Response getConsequenceType(String snpId) { - try { - parseQueryParams(); - VariantDBAdaptor variationDBAdaptor = dbAdaptorFactory.getVariationDBAdaptor(this.species, this.assembly); - query.put(VariantDBAdaptor.QueryParams.ID.key(), snpId); - queryOptions.put(QueryOptions.INCLUDE, "annotation.displayConsequenceType"); - CellBaseDataResult queryResult = variationDBAdaptor.get(query, queryOptions); - CellBaseDataResult queryResult1 = new CellBaseDataResult<>( - queryResult.getId(), queryResult.getTime(), queryResult.getEvents(), queryResult.getNumResults(), - Collections.singletonList(queryResult.getResults().get(0).getAnnotation().getDisplayConsequenceType()), 1); - return createOkResponse(queryResult1); - } catch (Exception e) { - return createErrorResponse("getConsequenceTypeByPostMethod", e.toString()); - } - } - - // FIXME: 29/04/16 GET and POST methods to be fixed - @GET - @Path("/{snpId}/regulatory") - @ApiOperation(httpMethod = "GET", value = "Get the regulatory impact of the SNP(s)", hidden = true) - public Response getRegulatoryByGetMethod(@PathParam("snpId") String snpId) { - return getRegulatoryType(snpId); - } - - @POST - @Path("/regulatory") - @ApiOperation(httpMethod = "POST", value = "Get the regulatory impact of the SNP(s)", hidden = true) - public Response getRegulatoryTypeByPostMethod(@QueryParam("id") String snpId) { - return getRegulatoryType(snpId); - } - - private Response getRegulatoryType(String snpId) { - try { - parseQueryParams(); - VariantDBAdaptor variationDBAdaptor = dbAdaptorFactory.getVariationDBAdaptor(this.species, this.assembly); - return null; - } catch (Exception e) { - return createErrorResponse(e); - } - } - - @GET - @Path("/{snpId}/sequence") - @ApiOperation(httpMethod = "GET", value = "Get the adjacent sequence to the SNP(s) - Not yet implemented", - hidden = true) - public Response getSequence(@PathParam("snpId") String query) { - try { - return null; - } catch (Exception e) { - return createErrorResponse(e); - } - } -} diff --git a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/genomic/ChromosomeWSServer.java b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/genomic/ChromosomeWSServer.java index 42a60b8954..35d814c7b5 100644 --- a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/genomic/ChromosomeWSServer.java +++ b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/genomic/ChromosomeWSServer.java @@ -88,7 +88,8 @@ public Response getChromosomesAll() { @GET @Path("/list") @Deprecated - @ApiOperation(httpMethod = "GET", value = "Retrieves the chromosomes names", response = CellBaseDataResult.class) + @ApiOperation(httpMethod = "GET", value = "Retrieves the chromosomes names", response = CellBaseDataResult.class, + hidden = true) public Response getChromosomes() { try { parseQueryParams(); diff --git a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/genomic/RegionWSServer.java b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/genomic/RegionWSServer.java index a4ef6043ab..ce7a6e9a9c 100755 --- a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/genomic/RegionWSServer.java +++ b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/genomic/RegionWSServer.java @@ -96,7 +96,7 @@ private boolean hasHistogramQueryParam() { + "histogram=false Gene objects will be returned " + "(see https://github.com/opencb/biodata/tree/develop/biodata-models/src/main/java/org/opencb/biodata/models/core). " + "If histogram=true Document objects with keys start,end,chromosome & feature_count will be returned.", - responseContainer = "QueryResponse") + responseContainer = "QueryResponse", hidden = true) @ApiImplicitParams({ @ApiImplicitParam(name = "histogram", value = "Boolean to indicate whether gene counts per interval shall be returned", defaultValue = "false", diff --git a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/genomic/VariantWSServer.java b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/genomic/VariantWSServer.java index d168652ab3..c1bec1cfc7 100755 --- a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/genomic/VariantWSServer.java +++ b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/genomic/VariantWSServer.java @@ -16,9 +16,7 @@ package org.opencb.cellbase.server.rest.genomic; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; +import io.swagger.annotations.*; import org.opencb.biodata.models.variant.Variant; import org.opencb.biodata.models.variant.VariantBuilder; import org.opencb.biodata.models.variant.avro.Score; @@ -29,10 +27,12 @@ import org.opencb.cellbase.core.result.CellBaseDataResult; import org.opencb.cellbase.core.variant.AnnotationBasedPhasedQueryManager; import org.opencb.cellbase.core.variant.annotation.VariantAnnotationCalculator; +import org.opencb.cellbase.core.variant.annotation.VariantAnnotationUtils; import org.opencb.cellbase.server.exception.SpeciesException; import org.opencb.cellbase.server.exception.VersionException; import org.opencb.cellbase.server.rest.GenericRestWSServer; - +import org.opencb.commons.datastore.core.Query; +import org.opencb.commons.datastore.core.QueryOptions; import javax.servlet.http.HttpServletRequest; @@ -46,6 +46,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; @Path("/{version}/{species}/genomic/variant") @Produces(MediaType.APPLICATION_JSON) @@ -99,7 +100,7 @@ public Response getVariantsByPhenotype(@PathParam("phenotype") String phenotype) value = "Retrieves variant annotation for a list of variants.", notes = "Include and exclude lists take" + " values from the following set: {variation, clinical, conservation, functionalScore, consequenceType," + " expression, geneDisease, drugInteraction, populationFrequencies, repeats}.", - response = VariantAnnotation.class, responseContainer = "QueryResponse") + response = VariantAnnotation.class, responseContainer = "QueryResponse", hidden = true) public Response getAnnotationByVariantsPOST(@ApiParam(name = "variants", value = "Comma separated list of variants to" + "annotate, e.g. " + "19:45411941:T:C,14:38679764:-:GATCTG,1:6635210:G:-," @@ -328,9 +329,10 @@ private Variant parseVariant(String variantString) { } @GET + @Deprecated @Path("/{variants}/cadd") @ApiOperation(httpMethod = "GET", value = "Get CADD scores for a (list of) variant(s)", response = Score.class, - responseContainer = "QueryResponse") + responseContainer = "QueryResponse", hidden = true) public Response getCaddScoreByVariant(@PathParam("variants") @ApiParam(name = "variants", value = "Comma separated list of variants for" + "which CADD socores will be returned, e.g. " @@ -348,4 +350,189 @@ public Response getCaddScoreByVariant(@PathParam("variants") return createErrorResponse(e); } } + + @GET + @Path("/stats") + @Override + @ApiOperation(httpMethod = "GET", value = "Not implemented yet.", + response = Integer.class, responseContainer = "QueryResponse", hidden = true) + public Response stats() { + return super.stats(); + } + + @GET + @Path("/{id}/info") + @ApiOperation(httpMethod = "GET", value = "Resource to get information about a (list of) SNPs", notes = "An independent" + + " database query will be issued for each region in id, meaning that results for each region will be" + + " returned in independent CellBaseDataResult objects within the QueryResponse object.", + response = Variant.class, responseContainer = "QueryResponse") + @ApiImplicitParams({ + @ApiImplicitParam(name = "region", + value = "Comma separated list of genomic regions to be queried, e.g.: 1:6635137-6635325", + required = false, dataType = "java.util.List", paramType = "query"), + @ApiImplicitParam(name = "consequenceType", + value = "Comma separated list of sequence ontology term names, e.g.: missense_variant. Exact text " + + "matches will be returned.", + required = false, dataType = "java.util.List", paramType = "query"), + @ApiImplicitParam(name = "gene", + value = "Comma separated list ENSEMBL gene ids, e.g.: ENSG00000161905. Exact text matches will be " + + "returned.", + required = false, dataType = "java.util.List", paramType = "query"), + @ApiImplicitParam(name = "chromosome", + value = "Comma separated list of chromosomes to be queried, e.g.: 1,X,MT", + required = false, dataType = "java.util.List", paramType = "query"), + @ApiImplicitParam(name = "reference", + value = "Comma separated list of possible reference to be queried, e.g.: A,T", + required = false, dataType = "java.util.List", paramType = "query"), + @ApiImplicitParam(name = "alternate", + value = "Comma separated list of possible alternate to be queried, e.g.: A,T", + required = false, dataType = "java.util.List", paramType = "query") + }) + public Response getByEnsemblId(@PathParam("id") + @ApiParam(name = "id", + value = "Comma separated list of rs ids, e.g.: rs6025", + required = true) String id) { + try { + parseQueryParams(); + VariantDBAdaptor variationDBAdaptor = dbAdaptorFactory.getVariationDBAdaptor(this.species, this.assembly); + List queries = createQueries(id, VariantDBAdaptor.QueryParams.ID.key()); + List queryResults = variationDBAdaptor.nativeGet(queries, queryOptions); + for (int i = 0; i < queries.size(); i++) { + queryResults.get(i).setId((String) queries.get(i).get(VariantDBAdaptor.QueryParams.ID.key())); + } + return createOkResponse(queryResults); + } catch (Exception e) { + return createErrorResponse(e); + } + } + + @GET + @Path("/search") + @ApiOperation(httpMethod = "GET", notes = "No more than 1000 objects are allowed to be returned at a time.", + value = "Retrieves all variation objects", response = Variant.class, responseContainer = "QueryResponse") + @ApiImplicitParams({ + @ApiImplicitParam(name = "region", + value = "Comma separated list of genomic regions to be queried, e.g.: 1:6635137-6635325", + dataType = "java.util.List", paramType = "query"), + @ApiImplicitParam(name = "id", + value = "Comma separated list of rs ids, e.g.: rs6025, rs666" + + " Exact text matches will be returned", dataType = "java.util.List", paramType = "query"), + @ApiImplicitParam(name = "consequenceType", + value = "Comma separated list of sequence ontology term names, e.g.: missense_variant." + + " Exact text matches will be returned", dataType = "java.util.List", paramType = "query"), + @ApiImplicitParam(name = "gene", + value = "Comma separated list ENSEMBL gene ids, e.g.: ENSG00000161905. Exact text matches will be " + + "returned.", dataType = "java.util.List", paramType = "query"), + @ApiImplicitParam(name = "chromosome", + value = "Comma separated list of chromosomes to be queried, e.g.: 1,X,MT", + dataType = "java.util.List", paramType = "query"), + @ApiImplicitParam(name = "reference", + value = "Comma separated list of possible reference to be queried, e.g.: A,T", + dataType = "java.util.List", paramType = "query"), + @ApiImplicitParam(name = "alternate", + value = "Comma separated list of possible alternate to be queried, e.g.: A,T", + dataType = "java.util.List", paramType = "query") + }) + public Response search() { + try { + parseQueryParams(); + VariantDBAdaptor variationDBAdaptor = dbAdaptorFactory.getVariationDBAdaptor(this.species, this.assembly); + return createOkResponse(variationDBAdaptor.nativeGet(query, queryOptions)); + } catch (Exception e) { + return createErrorResponse(e); + } + } + + @GET + @Path("/{id}/next") + @ApiOperation(httpMethod = "GET", value = "Get information about the next SNP", hidden = true) + public Response getNextById(@PathParam("id") + @ApiParam(name = "id", + value = "Rs id, e.g.: rs6025", + required = true) String id) { + try { + parseQueryParams(); + VariantDBAdaptor variationDBAdaptor = dbAdaptorFactory.getVariationDBAdaptor(this.species, this.assembly); + query.put(VariantDBAdaptor.QueryParams.ID.key(), id.split(",")[0]); + CellBaseDataResult queryResult = variationDBAdaptor.next(query, queryOptions); + queryResult.setId(id); + return createOkResponse(queryResult); + } catch (Exception e) { + return createErrorResponse(e); + } + } + + @GET + @Path("/consequenceTypes") + @ApiOperation(httpMethod = "GET", value = "Get all sequence ontology terms describing consequence types", + response = String.class, responseContainer = "QueryResponse") + public Response getAllConsequenceTypes() { + try { + parseQueryParams(); + List consequenceTypes = VariantAnnotationUtils.SO_SEVERITY.keySet().stream() + .sorted() + .collect(Collectors.toList()); + CellBaseDataResult queryResult = new CellBaseDataResult<>("consequence_types"); + queryResult.setNumResults(consequenceTypes.size()); + queryResult.setResults(consequenceTypes); + return createOkResponse(queryResult); + } catch (Exception e) { + return createErrorResponse(e); + } + } + + // FIXME: 29/04/16 GET and POST web services to be fixed + @GET + @Path("/{snpId}/consequenceType") + @ApiOperation(httpMethod = "GET", value = "Get the biological impact of the SNP(s)", response = String.class, + responseContainer = "QueryResponse") + public Response getConsequenceTypeByGetMethod(@PathParam("snpId") String snpId) { + return getConsequenceType(snpId); + } + + private Response getConsequenceType(String snpId) { + try { + parseQueryParams(); + VariantDBAdaptor variationDBAdaptor = dbAdaptorFactory.getVariationDBAdaptor(this.species, this.assembly); + query.put(VariantDBAdaptor.QueryParams.ID.key(), snpId); + queryOptions.put(QueryOptions.INCLUDE, "annotation.displayConsequenceType"); + CellBaseDataResult queryResult = variationDBAdaptor.get(query, queryOptions); + CellBaseDataResult queryResult1 = new CellBaseDataResult<>( + queryResult.getId(), queryResult.getTime(), queryResult.getEvents(), queryResult.getNumResults(), + Collections.singletonList(queryResult.getResults().get(0).getAnnotation().getDisplayConsequenceType()), 1); + return createOkResponse(queryResult1); + } catch (Exception e) { + return createErrorResponse("getConsequenceTypeByPostMethod", e.toString()); + } + } + + // FIXME: 29/04/16 GET and POST methods to be fixed + @GET + @Path("/{snpId}/regulatory") + @ApiOperation(httpMethod = "GET", value = "Get the regulatory impact of the SNP(s)", hidden = true) + public Response getRegulatoryByGetMethod(@PathParam("snpId") String snpId) { + return getRegulatoryType(snpId); + } + + private Response getRegulatoryType(String snpId) { + try { + parseQueryParams(); + VariantDBAdaptor variationDBAdaptor = dbAdaptorFactory.getVariationDBAdaptor(this.species, this.assembly); + return null; + } catch (Exception e) { + return createErrorResponse(e); + } + } + + @GET + @Path("/{snpId}/sequence") + @ApiOperation(httpMethod = "GET", value = "Get the adjacent sequence to the SNP(s) - Not yet implemented", + hidden = true) + public Response getSequence(@PathParam("snpId") String query) { + try { + return null; + } catch (Exception e) { + return createErrorResponse(e); + } + } }