List of usage examples for com.mongodb QueryBuilder start
public static QueryBuilder start(final String key)
From source file:org.opencb.cellbase.mongodb.db.variation.ClinicalMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getAllByRegionList(List<Region> regions, QueryOptions options) { List<DBObject> queries = new ArrayList<>(); List<String> ids = new ArrayList<>(regions.size()); for (Region region : regions) { QueryBuilder builder = QueryBuilder.start("chromosome").is(region.getChromosome()).and("end") .greaterThanEquals(region.getStart()).and("start").lessThanEquals(region.getEnd()); queries.add(builder.get());/*from ww w . j ava 2s . c o m*/ ids.add(region.toString()); } return executeQueryList2(ids, queries, options); }
From source file:org.opencb.cellbase.mongodb.db.variation.ClinicalMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getAllByGenomicVariantList(List<GenomicVariant> variantList, QueryOptions options) { List<DBObject> queries = new ArrayList<>(); List<String> ids = new ArrayList<>(variantList.size()); List<QueryResult> queryResultList; for (GenomicVariant genomicVariant : variantList) { QueryBuilder builder = QueryBuilder.start("chromosome").is(genomicVariant.getChromosome()).and("start") .is(genomicVariant.getPosition()).and("alternate").is(genomicVariant.getAlternative()); if (genomicVariant.getReference() != null) { builder = builder.and("reference").is(genomicVariant.getReference()); }// ww w .j av a 2 s.c om queries.add(builder.get()); ids.add(genomicVariant.toString()); } queryResultList = executeQueryList2(ids, queries, options); for (QueryResult queryResult : queryResultList) { List<BasicDBObject> clinicalList = (List<BasicDBObject>) queryResult.getResult(); List<Cosmic> cosmicList = new ArrayList<>(); List<Gwas> gwasList = new ArrayList<>(); List<Clinvar> clinvarList = new ArrayList<>(); for (Object clinicalObject : clinicalList) { BasicDBObject clinical = (BasicDBObject) clinicalObject; if (isCosmic(clinical)) { Cosmic cosmic = getCosmic(clinical); // if (cosmicList == null) { // cosmicList = new ArrayList<>(); // } cosmicList.add(cosmic); } else if (isGwas(clinical)) { Gwas gwas = getGwas(clinical); // if (gwasList == null) { // gwasList = new ArrayList<>(); // } gwasList.add(gwas); } else if (isClinvar(clinical)) { Clinvar clinvar = getClinvar(clinical); // if (clinvarList == null) { // clinvarList = new ArrayList<>(); // } clinvarList.add(clinvar); } } Map<String, Object> clinicalData = new HashMap<>(); if (cosmicList != null && cosmicList.size() > 0) { clinicalData.put("cosmic", cosmicList); } if (gwasList != null && gwasList.size() > 0) { clinicalData.put("gwas", gwasList); } if (clinvarList != null && clinvarList.size() > 0) { clinicalData.put("clinvar", clinvarList); } if (!clinicalData.isEmpty()) { // FIXME quick solution to compile // queryResult.setResult(clinicalData); queryResult.setResult(Arrays.asList(clinicalData)); queryResult.setNumResults(cosmicList.size() + clinvarList.size() + gwasList.size()); } else { queryResult.setResult(null); queryResult.setNumResults(0); } } return queryResultList; }
From source file:org.opencb.cellbase.mongodb.db.variation.ClinicalMongoDBAdaptor.java
License:Apache License
public QueryResult updateAnnotations(List<VariantAnnotation> variantAnnotations, QueryOptions queryOptions) { /**//w ww .j a v a 2 s. co m * Multiple documents may contain the same annotation */ queryOptions.put("multi", true); /** * Prepare jackson to generate json strings */ ObjectMapper jsonObjectMapper = new ObjectMapper(); jsonObjectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); jsonObjectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); ObjectWriter writer = jsonObjectMapper.writer(); long start = System.nanoTime(); for (VariantAnnotation variantAnnotation : variantAnnotations) { QueryBuilder builder = QueryBuilder.start("chromosome").is(variantAnnotation.getChromosome()) .and("start").is(variantAnnotation.getStart()).and("reference") .is(variantAnnotation.getReferenceAllele()).and("alternate") .is(variantAnnotation.getAlternateAllele()); DBObject update = null; try { update = new BasicDBObject("$set", new BasicDBObject("annot", JSON.parse(writer.writeValueAsString(variantAnnotation)))); } catch (JsonProcessingException e) { e.printStackTrace(); } // DBObject update = new BasicDBObject("$set", new BasicDBObject("annotation", // convertVariantAnnotation(variantAnnotation))); mongoDBCollection.update(builder.get(), update, queryOptions); } return new QueryResult<>("", ((int) (System.nanoTime() - start)), 1, 1, "", "", new ArrayList()); }
From source file:org.opencb.cellbase.mongodb.db.variation.ClinVarMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getAllByIdList(List<String> idList, QueryOptions options) { List<DBObject> queries = new ArrayList<>(idList.size()); for (String id : idList) { QueryBuilder builder = QueryBuilder.start("referenceClinVarAssertion.clinVarAccession.acc").is(id); queries.add(builder.get());/* w w w. j a v a 2 s.c o m*/ } return executeQueryList2(idList, queries, options); }
From source file:org.opencb.cellbase.mongodb.db.variation.ClinVarMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getAllByRegionList(List<Region> regions, QueryOptions options) { List<DBObject> queries = new ArrayList<>(); List<String> ids = new ArrayList<>(regions.size()); for (Region region : regions) { // If regions is 1 position then query can be optimize using chunks QueryBuilder builder = QueryBuilder .start("referenceClinVarAssertion.measureSet.measure.measureRelationship.sequenceLocation.chr") .is(region.getChromosome()) .and("referenceClinVarAssertion.measureSet.measure.measureRelationship.sequenceLocation.stop") .greaterThanEquals(region.getStart()) .and("referenceClinVarAssertion.measureSet.measure.measureRelationship.sequenceLocation.start") .lessThanEquals(region.getEnd()); System.out.println(builder.get().toString()); queries.add(builder.get());//w ww . ja va2 s . c o m ids.add(region.toString()); } return executeQueryList2(ids, queries, options); }
From source file:org.opencb.cellbase.mongodb.db.variation.MutationMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getAllByIdList(List<String> idList, QueryOptions options) { List<DBObject> queries = new ArrayList<>(idList.size()); for (String id : idList) { QueryBuilder builder = QueryBuilder.start("id").is(id); queries.add(builder.get());//from www .ja va 2 s .co m } return executeQueryList2(idList, queries, options); }
From source file:org.opencb.cellbase.mongodb.db.variation.MutationMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getAllByDiseaseList(List<String> idList, QueryOptions options) { List<DBObject> queries = new ArrayList<>(idList.size()); for (String id : idList) { QueryBuilder builder = QueryBuilder.start("primaryHistology").is(id); queries.add(builder.get());/*from ww w . jav a 2s . c om*/ } return executeQueryList2(idList, queries, options); }
From source file:org.opencb.cellbase.mongodb.db.variation.MutationMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getAllByGeneNameList(List<String> geneNameList, QueryOptions options) { List<DBObject> queries = new ArrayList<>(); for (String id : geneNameList) { QueryBuilder builder = QueryBuilder.start("gene").is(id); queries.add(builder.get());// ww w .j a va2s . co m } return executeQueryList2(geneNameList, queries, options); }
From source file:org.opencb.cellbase.mongodb.db.variation.MutationMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getAllByProteinIdList(List<String> proteinIdList, QueryOptions options) { List<DBObject> queries = new ArrayList<>(); for (String id : proteinIdList) { QueryBuilder builder = QueryBuilder.start("protein").is(id); queries.add(builder.get());/*from ww w . j a va 2s .c o m*/ } return executeQueryList2(proteinIdList, queries, options); }
From source file:org.opencb.cellbase.mongodb.db.variation.MutationMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getAllByRegionList(List<Region> regions, QueryOptions options) { List<DBObject> queries = new ArrayList<>(); List<String> ids = new ArrayList<>(regions.size()); for (Region region : regions) { QueryBuilder builder = QueryBuilder.start("chromosome").is(region.getChromosome()).and("start") .greaterThanEquals(region.getStart()).lessThanEquals(region.getEnd()); queries.add(builder.get());//ww w.j av a 2 s . c o m ids.add(region.toString()); } return executeQueryList2(ids, queries, options); }