List of usage examples for com.mongodb QueryBuilder and
@SuppressWarnings("unchecked") public QueryBuilder and(final DBObject... ands)
From source file:org.opencb.cellbase.mongodb.db.variation.ClinicalMongoDBAdaptor.java
License:Apache License
private QueryBuilder addClinvarTypeFilter(QueryBuilder builder, QueryOptions options) { List<String> typeList = (List<String>) options.getAsStringList("type"); // List<String> typeList = (List<String>) options.get("type"); if (typeList != null && typeList.size() > 0) { for (int i = 0; i < typeList.size(); i++) { typeList.set(i, typeList.get(i).replace("_", " ")); }/*www .j a v a 2s. co m*/ logger.info("Type filter activated, type list: " + typeList.toString()); builder = builder.and(new BasicDBObject("clinvarSet.referenceClinVarAssertion.measureSet.measure.type", new BasicDBObject("$in", typeList))); } return builder; }
From source file:org.opencb.cellbase.mongodb.db.variation.ClinicalMongoDBAdaptor.java
License:Apache License
private QueryBuilder addClinvarSoTermFilter(QueryBuilder builder, QueryOptions options) { List<String> soList = (List<String>) options.getAsStringList("so"); // List<String> soList = (List<String>) options.get("so"); if (soList != null && soList.size() > 0) { logger.info("So filter activated, SO list: " + soList.toString()); builder = builder.and( new BasicDBObject("annot.consequenceTypes.soTerms.soName", new BasicDBObject("$in", soList))); }//w w w . j av a2s.co m return builder; }
From source file:org.opencb.cellbase.mongodb.db.variation.ClinicalMongoDBAdaptor.java
License:Apache License
private QueryBuilder addClinvarRsFilter(QueryBuilder builder, QueryOptions options) { List<String> rsStringList = options.getAsStringList("rs"); // List<String> rsStringList = (List<String>) options.get("rs"); if (rsStringList != null && rsStringList.size() > 0) { logger.info("rs filter activated, res list: " + rsStringList.toString()); List<String> rsList = new ArrayList<>(rsStringList.size()); for (String rsString : rsStringList) { rsList.add(rsString.substring(2)); }//from w w w . j av a 2s. c o m builder = builder .and(new BasicDBObject("clinvarSet.referenceClinVarAssertion.measureSet.measure.xref.id", new BasicDBObject("$in", rsList))); builder = builder.and( new BasicDBObject("clinvarSet.referenceClinVarAssertion.measureSet.measure.xref.type", "rs")); } return builder; }
From source file:org.opencb.cellbase.mongodb.db.variation.ClinicalMongoDBAdaptor.java
License:Apache License
private QueryBuilder addClinvarRcvFilter(QueryBuilder builder, QueryOptions options) { // List<String> rcvList = (List<String>) options.get("rcv"); List<String> rcvList = (List<String>) options.getAsStringList("rcv"); if (rcvList != null && rcvList.size() > 0) { logger.info("rcv filter activated, rcv list: " + rcvList.toString()); builder = builder.and(new BasicDBObject("clinvarSet.referenceClinVarAssertion.clinVarAccession.acc", new BasicDBObject("$in", rcvList))); }/*from w ww . ja v a2 s . c o m*/ return builder; }
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()); }/* w ww .j ava 2s.c o m*/ 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.VariationMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getAllPhenotypeByRegion(List<Region> regions, QueryOptions options) { QueryBuilder builder = null; List<DBObject> queries = new ArrayList<>(); /**//from ww w . j a v a 2 s .co m * If source is present in options is it parsed and prepare first, * otherwise ti will be done for each iteration of regions. */ List<Object> source = options.getList("source", null); BasicDBList sourceIds = new BasicDBList(); if (source != null && source.size() > 0) { sourceIds.addAll(source); } // List<Region> regions = Region.parseRegions(options.getString("region")); List<String> ids = new ArrayList<>(regions.size()); for (Region region : regions) { if (region != null && !region.equals("")) { // If regions is 1 position then query can be optimize using chunks if (region.getStart() == region.getEnd()) { String chunkId = getChunkIdPrefix(region.getChromosome(), region.getStart(), variationChunkSize); System.out.println(chunkId); builder = QueryBuilder.start("_chunkIds").is(chunkId).and("end") .greaterThanEquals(region.getStart()).and("start").lessThanEquals(region.getEnd()); } else { builder = QueryBuilder.start("chromosome").is(region.getChromosome()).and("end") .greaterThanEquals(region.getStart()).and("start").lessThanEquals(region.getEnd()); } if (sourceIds != null && sourceIds.size() > 0) { builder = builder.and("source").in(sourceIds); } queries.add(builder.get()); ids.add(region.toString()); } } return executeQueryList2(ids, queries, options, mongoVariationPhenotypeDBCollection2); }
From source file:org.opencb.cellbase.mongodb.db.variation.VariationMongoDBAdaptor.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()); String phenotype = options.getString("phenotype"); if (phenotype != null && !phenotype.equals("")) { for (Region region : regions) { QueryBuilder builder = QueryBuilder.start("chromosome").is(region.getChromosome()).and("start") .greaterThanEquals(region.getStart()).lessThanEquals(region.getEnd()); builder = builder.and("phenotype").is(phenotype); queries.add(builder.get());/* w ww. j a va 2s.c om*/ ids.add(region.toString()); } return executeQueryList2(ids, queries, options, mongoVariationPhenotypeDBCollection2); } else { String consequenceTypes = options.getString("consequence_type", null); BasicDBList consequenceTypeDBList = new BasicDBList(); if (consequenceTypes != null && !consequenceTypes.equals("")) { for (String ct : consequenceTypes.split(",")) { consequenceTypeDBList.add(ct); } } for (Region region : regions) { // QueryBuilder builder = QueryBuilder.start("chromosome").is(region.getSequenceName()).and("end").greaterThan(region.getStart()).and("start").lessThan(region.getEnd()); QueryBuilder builder = QueryBuilder.start("chromosome").is(region.getChromosome()).and("start") .greaterThanEquals(region.getStart()).lessThanEquals(region.getEnd()); if (consequenceTypeDBList.size() > 0) { builder = builder.and("transcriptVariations.consequenceTypes").in(consequenceTypeDBList); } queries.add(builder.get()); ids.add(region.toString()); } return executeQueryList2(ids, queries, options); } }
From source file:org.opencb.cellbase.mongodb.db.variation.VariationMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getIdByVariantList(List<GenomicVariant> variations, QueryOptions options) { List<DBObject> queries = new ArrayList<>(variations.size()); List<QueryResult> results; for (GenomicVariant variation : variations) { String chunkId = getChunkIdPrefix(variation.getChromosome(), variation.getPosition(), variationChunkSize);/* w w w . ja v a 2s . c om*/ QueryBuilder builder = QueryBuilder.start("_chunkIds").is(chunkId).and("chromosome") .is(variation.getChromosome()).and("start").is(variation.getPosition()).and("alternate") .is(variation.getAlternative()); if (variation.getReference() != null) { builder = builder.and("reference").is(variation.getReference()); } queries.add(builder.get()); } results = executeQueryList2(variations, queries, options, mongoDBCollection); for (QueryResult result : results) { List<String> idList = new LinkedList(); BasicDBList idListObject = (BasicDBList) result.getResult(); for (Object idObject : idListObject) { DBObject variantObject = (DBObject) idObject; idList.add(variantObject.get("id").toString()); } // result.setResult(Joiner.on(",").skipNulls().join(idList)); result.setResult(idList); } return results; }
From source file:org.opencb.cellbase.mongodb.db.variation.VariationMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getAllByVariantList(List<GenomicVariant> variations, QueryOptions options) { List<DBObject> queries = new ArrayList<>(variations.size()); List<QueryResult> results; for (GenomicVariant variation : variations) { String chunkId = getChunkIdPrefix(variation.getChromosome(), variation.getPosition(), variationChunkSize);/* www.jav a2 s .c o m*/ QueryBuilder builder = QueryBuilder.start("_chunkIds").is(chunkId).and("chromosome") .is(variation.getChromosome()).and("start").is(variation.getPosition()).and("alternate") .is(variation.getAlternative()); if (variation.getReference() != null) { builder = builder.and("reference").is(variation.getReference()); } queries.add(builder.get()); } results = executeQueryList2(variations, queries, options, mongoDBCollection); // results = executeQueryList(variations, queries, options, mongoDBCollection); return results; }
From source file:org.opencb.cellbase.mongodb.db.VariationMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getAllPhenotypeByRegion(List<Region> regions, QueryOptions options) { QueryBuilder builder = null; List<DBObject> queries = new ArrayList<>(); /**//from www . ja va 2 s . c o m * If source is present in options is it parsed and prepare first, * otherwise ti will be done for each iteration of regions. */ List<Object> source = options.getList("source", null); BasicDBList sourceIds = new BasicDBList(); if (source != null && source.size() > 0) { sourceIds.addAll(source); } // List<Region> regions = Region.parseRegions(options.getString("region")); List<String> ids = new ArrayList<>(regions.size()); for (Region region : regions) { if (region != null && !region.equals("")) { // If regions is 1 position then query can be optimize using chunks if (region.getStart() == region.getEnd()) { String chunkId = getChunkIdPrefix(region.getChromosome(), region.getStart(), variationChunkSize); System.out.println(chunkId); builder = QueryBuilder.start("_chunkIds").is(chunkId).and("end") .greaterThanEquals(region.getStart()).and("start").lessThanEquals(region.getEnd()); } else { builder = QueryBuilder.start("chromosome").is(region.getChromosome()).and("end") .greaterThanEquals(region.getStart()).and("start").lessThanEquals(region.getEnd()); } if (sourceIds != null && sourceIds.size() > 0) { builder = builder.and("source").in(sourceIds); } queries.add(builder.get()); ids.add(region.toString()); } } return executeQueryList(ids, queries, options, db.getCollection("variation_phenotype_annotation")); }