Skip to content

Commit

Permalink
server: add the endpoints variant/snp/search and variant/snp/startsWi…
Browse files Browse the repository at this point in the history
…th, #TASK-5820, #TASK-5789
  • Loading branch information
jtarraga committed Mar 13, 2024
1 parent 90a4f68 commit 36c64fe
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,11 @@ public CellBaseDataResult groupBy(SnpQuery query) throws CellBaseException {

public CellBaseDataResult<Snp> startsWith(String id, QueryOptions options, int dataRelease) throws CellBaseException {
Bson regex = Filters.regex("id", Pattern.compile("^" + id));
Bson projection;
Bson projection = null;
if (options.containsKey(QueryOptions.INCLUDE)) {
projection = Projections.include(options.getAsStringList(QueryOptions.INCLUDE));
} else {
if (options.containsKey(QueryOptions.EXCLUDE)) {
projection = Projections.exclude(options.getAsStringList(QueryOptions.EXCLUDE));
} else {
projection = Projections.exclude("annotation");
}
} else if (options.containsKey(QueryOptions.EXCLUDE)) {
projection = Projections.exclude(options.getAsStringList(QueryOptions.EXCLUDE));
}

MongoDBCollection mongoDBCollection = getCollectionByRelease(mongoDBCollectionByRelease, dataRelease);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,11 @@ public CellBaseDataResult<GenomicScoreRegion> getFunctionalScoreRegion(List<Regi
return variantDBAdaptor.getFunctionalScoreRegion(new ArrayList<>(chunkIdSet), options, dataRelease);
}

public CellBaseDataResult<Snp> getSnps(SnpQuery query) throws CellBaseException {
public CellBaseDataResult<Snp> searchSnp(SnpQuery query) throws CellBaseException {
return snpDBAdaptor.query(query);
}

public CellBaseDataResult<Snp> startsWithSnp(String id, QueryOptions options, int dataRelease) throws CellBaseException {
return snpDBAdaptor.startsWith(id, options, dataRelease);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ public Response getAllConsequenceTypes() {
}

@GET
@Path("/snp")
@Path("/snp/search")
@ApiOperation(httpMethod = "GET", value = "Get SNPs", response = Snp.class, responseContainer = "QueryResponse")
@ApiImplicitParams({
@ApiImplicitParam(name = "exclude", value = EXCLUDE_DESCRIPTION,
Expand All @@ -476,17 +476,43 @@ public Response getAllConsequenceTypes() {
@ApiImplicitParam(name = "skip", value = SKIP_DESCRIPTION,
required = false, defaultValue = DEFAULT_SKIP, dataType = "java.util.List", paramType = "query")
})
public Response getSnps(@QueryParam("id") @ApiParam(name = "id", value = "ID") String id,
public Response searchSnp(@QueryParam("id") @ApiParam(name = "id", value = "SNP ID") String id,
@QueryParam("chromosome") @ApiParam(name = "chromosome", value = "Chromosome") String chromosome,
@QueryParam("position") @ApiParam(name = "position", value = "Position") Integer position,
@QueryParam("reference") @ApiParam(name = "reference", value = "Reference") String reference) {
try {
SnpQuery query = new SnpQuery(uriParams);
CellBaseDataResult<Snp> queryResult = variantManager.getSnps(query);
CellBaseDataResult<Snp> queryResult = variantManager.searchSnp(query);
return createOkResponse(queryResult);
} catch (Exception e) {
return createErrorResponse(e);
}
}

@GET
@Path("/snp/startsWith")
@ApiOperation(httpMethod = "GET", value = "Get SNPs starting with the input SNP ID", response = Snp.class,
responseContainer = "QueryResponse")
@ApiImplicitParams({
@ApiImplicitParam(name = "exclude", value = EXCLUDE_DESCRIPTION,
required = false, dataType = "java.util.List", paramType = "query"),
@ApiImplicitParam(name = "include", value = INCLUDE_DESCRIPTION,
required = false, dataType = "java.util.List", paramType = "query"),
@ApiImplicitParam(name = "limit", value = LIMIT_DESCRIPTION,
required = false, defaultValue = DEFAULT_LIMIT, dataType = "java.util.List",
paramType = "query")
})
public Response startsWithSnp(@QueryParam("id") @ApiParam(name = "id", value = "SNP ID, e.g.: rs15703916") String id) {
try {
try {
SnpQuery query = new SnpQuery(uriParams);
CellBaseDataResult<Snp> queryResult = variantManager.startsWithSnp(id, query.toQueryOptions(), getDataRelease());
return createOkResponse(queryResult);
} catch (Exception e) {
return createErrorResponse(e);
}
} catch (Exception e) {
return createErrorResponse(e);
}
}
}

0 comments on commit 36c64fe

Please sign in to comment.