Skip to content

Commit

Permalink
trying to fix merge issues
Browse files Browse the repository at this point in the history
  • Loading branch information
julie-sullivan committed Feb 25, 2020
1 parent 3aa1050 commit 46b07bb
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.commons.lang3.StringUtils;
import org.opencb.cellbase.core.exception.CellbaseException;
import org.opencb.commons.datastore.core.ObjectMap;
import org.opencb.commons.datastore.core.Query;
import org.opencb.commons.datastore.core.QueryOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -149,4 +150,9 @@ public QueryOptions toQueryOptions() {
queryOptions.put(QueryOptions.FACET, facet);
return queryOptions;
}

// temporary method because java commons still uses query
public Query toQuery() {
return new Query();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.opencb.cellbase.core.api.queries;

import org.opencb.biodata.models.core.Region;
import org.opencb.cellbase.core.exception.CellbaseException;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -203,6 +204,12 @@ public GeneQuery setAnnotationDrugsGene(List<String> annotationDrugsGene) {
return this;
}

public void validate() throws CellbaseException {
super.validate();

// excludes and includes contain valid values
}

@Override
public String toString() {
return "GeneQuery{"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ public void testCount() {
assertFalse(geneQuery.getCount());
}


@Test
public void testBuild() {
geneQuery = new GeneQuery.Builder().withIds(Arrays.asList("1")).withBiotypes(Arrays.asList("a", "b", "c"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.opencb.biodata.models.core.Gene;
import org.opencb.biodata.models.core.Region;
import org.opencb.cellbase.core.api.core.GeneDBAdaptor;
import org.opencb.cellbase.core.api.queries.GeneQuery;
import org.opencb.cellbase.core.result.CellBaseDataResult;
import org.opencb.cellbase.lib.MongoDBCollectionConfiguration;
import org.opencb.commons.datastore.core.Query;
Expand Down Expand Up @@ -144,6 +145,13 @@ public CellBaseDataResult nativeGet(Query geneQuery, QueryOptions queryOption) {
return postDBFiltering(geneQuery, new CellBaseDataResult<>(mongoDBCollection.find(bson, null)));
}

public CellBaseDataResult nativeGet(GeneQuery geneQuery) {
Bson bson = parseQuery(geneQuery);
logger.info("geneQuery: {}", bson.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry()) .toJson());
// logger.info("options: {}", options.toJson());
return postDBFiltering(geneQuery, new CellBaseDataResult<>(mongoDBCollection.find(bson, geneQuery.toQueryOptions())));
}

@Override
public Iterator<Gene> iterator(Query geneQuery, QueryOptions options) {
return null;
Expand Down Expand Up @@ -252,8 +260,37 @@ public CellBaseDataResult getTfbs(Query geneQuery, QueryOptions queryOptions) {

private Bson parseQuery(Query geneQuery) {
List<Bson> andBsonList = new ArrayList<>();
createRegionQuery(geneQuery, QueryParams.REGION.key(), MongoDBCollectionConfiguration.GENE_CHUNK_SIZE, andBsonList);

createOrQuery(geneQuery, QueryParams.ID.key(), "id", andBsonList);
createOrQuery(geneQuery, QueryParams.NAME.key(), "name", andBsonList);
createOrQuery(geneQuery, QueryParams.BIOTYPE.key(), "biotype", andBsonList);
createOrQuery(geneQuery, QueryParams.XREFS.key(), "transcripts.xrefs.id", andBsonList);

createOrQuery(geneQuery, QueryParams.TRANSCRIPT_ID.key(), "transcripts.id", andBsonList);
createOrQuery(geneQuery, QueryParams.TRANSCRIPT_NAME.key(), "transcripts.name", andBsonList);
createOrQuery(geneQuery, QueryParams.TRANSCRIPT_BIOTYPE.key(), "transcripts.biotype", andBsonList);
createOrQuery(geneQuery, QueryParams.TRANSCRIPT_ANNOTATION_FLAGS.key(), "transcripts.annotationFlags", andBsonList);

createOrQuery(geneQuery, QueryParams.TFBS_NAME.key(), "transcripts.tfbs.name", andBsonList);
createOrQuery(geneQuery, QueryParams.ANNOTATION_DISEASE_ID.key(), "annotation.diseases.id", andBsonList);
createOrQuery(geneQuery, QueryParams.ANNOTATION_DISEASE_NAME.key(), "annotation.diseases.name", andBsonList);
createOrQuery(geneQuery, QueryParams.ANNOTATION_EXPRESSION_GENE.key(), "annotation.expression.geneName", andBsonList);

createOrQuery(geneQuery, QueryParams.ANNOTATION_DRUGS_NAME.key(), "annotation.drugs.drugName", andBsonList);
createOrQuery(geneQuery, QueryParams.ANNOTATION_DRUGS_GENE.key(), "annotation.drugs.geneName", andBsonList);

createExpressionQuery(geneQuery, andBsonList);

if (andBsonList.size() > 0) {
return Filters.and(andBsonList);
} else {
return new Document();
}
}

private Bson parseQuery(GeneQuery geneQuery) {
List<Bson> andBsonList = new ArrayList<>();
createRegionQuery(geneQuery, QueryParams.REGION.key(), MongoDBCollectionConfiguration.GENE_CHUNK_SIZE, andBsonList);

createOrQuery(geneQuery, QueryParams.ID.key(), "id", andBsonList);
Expand Down Expand Up @@ -300,6 +337,7 @@ private Boolean postDBFilteringParametersEnabled(Query geneQuery) {
return StringUtils.isNotEmpty(geneQuery.getString(QueryParams.TRANSCRIPT_ANNOTATION_FLAGS.key()));
}

@Deprecated
private CellBaseDataResult<Document> postDBFiltering(Query geneQuery, CellBaseDataResult<Document> documentCellBaseDataResult) {
String annotationFlagsString = geneQuery.getString(QueryParams.TRANSCRIPT_ANNOTATION_FLAGS.key());
if (StringUtils.isNotEmpty(annotationFlagsString)) {
Expand All @@ -323,4 +361,25 @@ private CellBaseDataResult<Document> postDBFiltering(Query geneQuery, CellBaseDa
return documentCellBaseDataResult;
}

private CellBaseDataResult<Document> postDBFiltering(GeneQuery geneQuery, CellBaseDataResult<Document> documentCellBaseDataResult) {
List<String> flags = geneQuery.getTranscriptsAnnotationFlags();
if (flags != null && !flags.isEmpty()) {
List<Document> documents = documentCellBaseDataResult.getResults();
for (Document document : documents) {
ArrayList<Document> transcripts = document.get(TRANSCRIPTS, ArrayList.class);
ArrayList<Document> matchedTranscripts = new ArrayList<>();
for (Document transcript : transcripts) {
ArrayList annotationFlags = transcript.get(ANNOTATION_FLAGS, ArrayList.class);
if (annotationFlags != null && annotationFlags.size() > 0) {
if (CollectionUtils.containsAny(annotationFlags, flags)) {
matchedTranscripts.add(transcript);
}
}
}
document.put(TRANSCRIPTS, matchedTranscripts);
}
documentCellBaseDataResult.setResults(documents);
}
return documentCellBaseDataResult;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ private void init() {
public CellBaseDataResult<Gene> search(GeneQuery geneQuery) throws CellbaseException {
geneQuery.setDefaults();
geneQuery.validate();
// return geneDBAdaptor.nativeGet(geneQuery);
return null;
// TODO throw execption if facets populated
return geneDBAdaptor.nativeGet(geneQuery);
}

public CellBaseDataResult<Gene> groupBy(Query geneQuery, String fields) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,30 +359,30 @@ public Response getAll() throws CellbaseException {
@ApiOperation(httpMethod = "GET", value = "Get information about the specified gene(s)", response = Gene.class,
responseContainer = "QueryResponse")
@ApiImplicitParams({
@ApiImplicitParam(name = "biotype", value = ParamConstants.GENE_BIOTYPES,
required = false, dataType = "java.util.List", paramType = "query"),
@ApiImplicitParam(name = "transcripts.biotype", value = ParamConstants.TRANSCRIPT_BIOTYPES,
required = false, dataType = "java.util.List", paramType = "query"),
@ApiImplicitParam(name = "transcripts.id", value = ParamConstants.TRANSCRIPT_ENSEMBL_IDS,
required = false, dataType = "java.util.List", paramType = "query"),
@ApiImplicitParam(name = "transcripts.name", value = ParamConstants.TRANSCRIPT_NAMES,
required = false, dataType = "java.util.List", paramType = "query"),
@ApiImplicitParam(name = "transcripts.annotationFlags", value = ParamConstants.TRANSCRIPT_ANNOTATION_FLAGS,
required = false, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "transcripts.tfbs.name", value = ParamConstants.TRANSCRIPT_TFBS_NAMES,
required = false, dataType = "java.util.List", paramType = "query"),
@ApiImplicitParam(name = "annotation.diseases.id", value = ParamConstants.ANNOTATION_DISEASES_IDS,
required = false, dataType = "java.util.List", paramType = "query"),
@ApiImplicitParam(name = "annotation.diseases.name", value = ParamConstants.ANNOTATION_DISEASES_NAMES,
required = false, dataType = "java.util.List", paramType = "query"),
@ApiImplicitParam(name = "annotation.expression.gene", value = ParamConstants.ANNOTATION_EXPRESSION_GENE,
required = false, dataType = "java.util.List", paramType = "query"),
@ApiImplicitParam(name = "annotation.expression.tissue", value = ParamConstants.ANNOTATION_EXPRESSION_TISSUE,
required = false, dataType = "java.util.List", paramType = "query"),
@ApiImplicitParam(name = "annotation.drugs.name", value = ParamConstants.ANNOTATION_DRUGS_NAME,
required = false, dataType = "java.util.List", paramType = "query"),
@ApiImplicitParam(name = "annotation.drugs.gene", value = ParamConstants.ANNOTATION_DRUGS_GENE,
required = false, dataType = "java.util.List", paramType = "query"),
// @ApiImplicitParam(name = "biotype", value = ParamConstants.GENE_BIOTYPES,
// required = false, dataType = "java.util.List", paramType = "query"),
// @ApiImplicitParam(name = "transcripts.biotype", value = ParamConstants.TRANSCRIPT_BIOTYPES,
// required = false, dataType = "java.util.List", paramType = "query"),
// @ApiImplicitParam(name = "transcripts.id", value = ParamConstants.TRANSCRIPT_ENSEMBL_IDS,
// required = false, dataType = "java.util.List", paramType = "query"),
// @ApiImplicitParam(name = "transcripts.name", value = ParamConstants.TRANSCRIPT_NAMES,
// required = false, dataType = "java.util.List", paramType = "query"),
// @ApiImplicitParam(name = "transcripts.annotationFlags", value = ParamConstants.TRANSCRIPT_ANNOTATION_FLAGS,
// required = false, dataType = "string", paramType = "query"),
// @ApiImplicitParam(name = "transcripts.tfbs.name", value = ParamConstants.TRANSCRIPT_TFBS_NAMES,
// required = false, dataType = "java.util.List", paramType = "query"),
// @ApiImplicitParam(name = "annotation.diseases.id", value = ParamConstants.ANNOTATION_DISEASES_IDS,
// required = false, dataType = "java.util.List", paramType = "query"),
// @ApiImplicitParam(name = "annotation.diseases.name", value = ParamConstants.ANNOTATION_DISEASES_NAMES,
// required = false, dataType = "java.util.List", paramType = "query"),
// @ApiImplicitParam(name = "annotation.expression.gene", value = ParamConstants.ANNOTATION_EXPRESSION_GENE,
// required = false, dataType = "java.util.List", paramType = "query"),
// @ApiImplicitParam(name = "annotation.expression.tissue", value = ParamConstants.ANNOTATION_EXPRESSION_TISSUE,
// required = false, dataType = "java.util.List", paramType = "query"),
// @ApiImplicitParam(name = "annotation.drugs.name", value = ParamConstants.ANNOTATION_DRUGS_NAME,
// required = false, dataType = "java.util.List", paramType = "query"),
// @ApiImplicitParam(name = "annotation.drugs.gene", value = ParamConstants.ANNOTATION_DRUGS_GENE,
// required = false, dataType = "java.util.List", paramType = "query"),
@ApiImplicitParam(name = "exclude", value = ParamConstants.EXCLUDE_DESCRIPTION,
required = false, dataType = "java.util.List", paramType = "query"),
@ApiImplicitParam(name = "include", value = ParamConstants.INCLUDE_DESCRIPTION,
Expand Down

0 comments on commit 46b07bb

Please sign in to comment.