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.network.ProteinProteinInteractionMongoDBAdaptor.java
License:Apache License
@Override public QueryResult getAll(QueryOptions options) { QueryBuilder builder = new QueryBuilder(); // Fiilter all by interactor ID List<Object> interactors = options.getList("interactor", null); if (interactors != null && interactors.size() > 0) { BasicDBList interactorDBList = new BasicDBList(); interactorDBList.addAll(interactors); BasicDBList or = new BasicDBList(); DBObject orA = new BasicDBObject("interactorA.xrefs.id", new BasicDBObject("$in", interactorDBList)); DBObject orB = new BasicDBObject("interactorB.xrefs.id", new BasicDBObject("$in", interactorDBList)); or.add(orA);/* www. j ava 2s. c o m*/ or.add(orB); // builder = builder.or(orA, orB); builder = builder.and(new BasicDBObject("$or", or)); } // Filter all by Interaction Type (name and PSIMI) List<Object> type = options.getList("type", null); if (type != null && type.size() > 0) { BasicDBList typeDBList = new BasicDBList(); typeDBList.addAll(type); BasicDBList or = new BasicDBList(); DBObject orName = new BasicDBObject("type.name", new BasicDBObject("$in", typeDBList)); DBObject orPsimi = new BasicDBObject("type.psimi", new BasicDBObject("$in", typeDBList)); or.add(orName); or.add(orPsimi); // builder = builder.or(orName, orPsimi); builder = builder.and(new BasicDBObject("$or", or)); } // Filter all by source database List<Object> database = options.getList("database", null); if (database != null && database.size() > 0) { BasicDBList databaseDBList = new BasicDBList(); databaseDBList.addAll(database); builder = builder.and("source.name").in(databaseDBList); } // Filter all by detection method (name and PSIMI) List<Object> detectionMethod = options.getList("detectionMethod", null); if (detectionMethod != null && detectionMethod.size() > 0) { BasicDBList detectionMethodDBList = new BasicDBList(); detectionMethodDBList.addAll(detectionMethod); BasicDBList or = new BasicDBList(); DBObject orName = new BasicDBObject("detectionMethod.name", new BasicDBObject("$in", detectionMethodDBList)); DBObject orPsimi = new BasicDBObject("detectionMethod.psimi", new BasicDBObject("$in", detectionMethodDBList)); or.add(orName); or.add(orPsimi); // builder = builder.or(orName, orPsimi); builder = builder.and(new BasicDBObject("$or", or)); } // Filter all by status List<Object> status = options.getList("status", null); if (status != null && status.size() > 0) { BasicDBList statusDBList = new BasicDBList(); statusDBList.addAll(status); builder = builder.and("status").in(statusDBList); } // List<Object> type = options.getList("type", null); // if (type != null && type.size() > 0) { // BasicDBList typeDBList = new BasicDBList(); // typeDBList.addAll(type); // builder = builder.and("type.name").in(typeDBList); // } // String type = options.getString("type", null); // if (type != null && !type.equals("")) { // builder = builder.and("type.name").is(type); // } System.out.println(builder.get().toString()); // options = addExcludeReturnFields("transcripts", options); return executeQuery("result", builder.get(), options); }
From source file:org.opencb.cellbase.mongodb.db.regulatory.RegulatoryRegionMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getAllByPositionList(List<Position> positionList, QueryOptions options) { // db.regulatory_region.find({"chunkIds": {$in:["1_200", "1_300"]}, "start": 601156}) String featureType = options.getString("featureType", null); String featureClass = options.getString("featureClass", null); List<DBObject> queries = new ArrayList<>(); for (Position position : positionList) { String chunkId = position.getChromosome() + "_" + getChunkId(position.getPosition(), regulatoryRegionChunkSize) + "_" + regulatoryRegionChunkSize / 1000 + "k"; BasicDBList chunksId = new BasicDBList(); chunksId.add(chunkId);/* w w w . j a va 2 s. co m*/ QueryBuilder builder = QueryBuilder.start("_chunkIds").in(chunksId).and("start") .is(position.getPosition()); if (featureType != null) { builder.and("featureType").is(featureType); } if (featureClass != null) { builder.and("featureClass").is(featureClass); } // System.out.println("Query: " + builder.get()); queries.add(builder.get()); } System.out.println("Query: " + queries); // options = addExcludeReturnFields("chunkIds", options); return executeQueryList2(positionList, queries, options); }
From source file:org.opencb.cellbase.mongodb.db.regulatory.RegulatoryRegionMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getAllByRegionList(List<Region> regionList, QueryOptions options) { // db.regulatory_region.find({"chunkIds": {$in:["1_200", "1_300"]}, "start": 601156}) QueryBuilder builder = new QueryBuilder(); List<Object> featureType = options.getAsList("featureType"); List<Object> featureClass = options.getAsList("featureClass"); // options = addExcludeReturnFields("chunkIds", options); List<DBObject> queries = new ArrayList<>(); for (Region region : regionList) { int firstChunkId = getChunkId(region.getStart(), regulatoryRegionChunkSize); int lastChunkId = getChunkId(region.getEnd(), regulatoryRegionChunkSize); BasicDBList chunksId = new BasicDBList(); for (int j = firstChunkId; j <= lastChunkId; j++) { String chunkId = region.getChromosome() + "_" + j + "_" + regulatoryRegionChunkSize / 1000 + "k"; chunksId.add(chunkId);/*from ww w . j a v a2s . c om*/ } // logger.info(chunksId.toString()); builder = builder.start("_chunkIds").in(chunksId).and("start").lessThanEquals(region.getEnd()) .and("end").greaterThanEquals(region.getStart()); if (featureType != null && featureType.size() > 0) { BasicDBList featureTypeDBList = new BasicDBList(); featureTypeDBList.addAll(featureType); builder = builder.and("featureType").in(featureTypeDBList); } if (featureClass != null && featureClass.size() > 0) { BasicDBList featureClassDBList = new BasicDBList(); featureClassDBList.addAll(featureClass); builder = builder.and("featureClass").in(featureClassDBList); } queries.add(builder.get()); } // System.out.println(">>"+regionList); // System.out.println(">>"+builder.get().toString()); return executeQueryList2(regionList, queries, options); }
From source file:org.opencb.cellbase.mongodb.db.regulatory.RegulatoryRegionMongoDBAdaptor.java
License:Apache License
@Override public QueryResult next(String chromosome, int position, QueryOptions options) { String featureType = options.getString("featureType", null); String featureClass = options.getString("featureClass", null); BasicDBList chunksId = new BasicDBList(); String chunkId = chromosome + "_" + getChunkId(position, regulatoryRegionChunkSize) + "_" + regulatoryRegionChunkSize / 1000 + "k"; chunksId.add(chunkId);/*from w ww . j a v a 2 s .co m*/ // TODO: Add query to find next item considering next chunk // db.regulatory_region.find({ "chromosome" : "19" , "start" : { "$gt" : 62005} , "featureType" : "TF_binding_site_motif"}).sort({start:1}).limit(1) QueryBuilder builder; if (options.getString("strand") == null || (options.getString("strand").equals("1") || options.getString("strand").equals("+"))) { // db.core.find({chromosome: "1", start: {$gt: 1000000}}).sort({start: 1}).limit(1) builder = QueryBuilder.start("_chunkIds").in(chunksId).and("chromosome").is(chromosome).and("start") .greaterThan(position); options.put("sort", new BasicDBObject("start", 1)); options.put("limit", 1); } else { builder = QueryBuilder.start("_chunkIds").in(chunksId).and("chromosome").is(chromosome).and("end") .lessThan(position); options.put("sort", new BasicDBObject("end", -1)); options.put("limit", 1); } if (featureType != null) { builder.and("featureType").is(featureType); } if (featureClass != null) { builder.and("featureClass").is(featureClass); } System.out.println(builder.get()); return executeQuery("result", builder.get(), options); }
From source file:org.opencb.cellbase.mongodb.db.variation.ClinicalMongoDBAdaptor.java
License:Apache License
private QueryBuilder addClinvarFilters(QueryBuilder builder, QueryOptions options) { List<DBObject> filterSteps = new ArrayList<>(); builder.and(new BasicDBObject("clinvarSet", new BasicDBObject("$exists", 1))); builder = addClinvarRcvFilter(builder, options); builder = addClinvarRsFilter(builder, options); builder = addClinvarSoTermFilter(builder, options); builder = addClinvarTypeFilter(builder, options); builder = addClinvarReviewFilter(builder, options); builder = addClinvarClinicalSignificanceFilter(builder, options); builder = addClinvarRegionFilter(builder, options); builder = addClinvarGeneFilter(builder, options); builder = addClinvarPhenotypeFilter(builder, options); ///*w ww .j a v a 2 s . c o m*/ // // Filtering steps repeated twice to avoid undwind over all clinical records // pipeline.addAll(filterSteps); //// pipeline.add(new BasicDBObject("$unwind", "$clinvarList")); //// pipeline.addAll(filterSteps); // pipeline.add(new BasicDBObject("$limit", 100)); return builder; }
From source file:org.opencb.cellbase.mongodb.db.variation.ClinicalMongoDBAdaptor.java
License:Apache License
private QueryBuilder addClinvarPhenotypeFilter(QueryBuilder builder, QueryOptions options) { List<String> phenotypeList = options.getAsStringList("phenotype", "\\|"); if (phenotypeList != null && phenotypeList.size() > 0) { logger.info("phenotype filter activated, phenotype list: " + phenotypeList.toString()); builder = builder.and( new BasicDBObject("clinvarSet.referenceClinVarAssertion.traitSet.trait.name.elementValue.value", new BasicDBObject("$in", getClinvarPhenotypeRegex(phenotypeList)))); }/* w w w .j ava 2 s . c om*/ return builder; }
From source file:org.opencb.cellbase.mongodb.db.variation.ClinicalMongoDBAdaptor.java
License:Apache License
private QueryBuilder addClinvarGeneFilter(QueryBuilder builder, QueryOptions options) { // List<String> geneList = (List<String>) options.get("gene"); List<String> geneList = options.getAsStringList("gene"); System.out.println("geneList = " + geneList); if (geneList != null && geneList.size() > 0) { logger.info("gene filter activated, gene list: " + geneList.toString()); builder = builder.and(new BasicDBObject( "clinvarSet.referenceClinVarAssertion.measureSet.measure.measureRelationship.symbol.elementValue.value", new BasicDBObject("$in", geneList))); }// 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
private QueryBuilder addClinvarRegionFilter(QueryBuilder builder, QueryOptions options) { List<Region> regionList = Region.parseRegions((String) options.get("region")); // List<Region> regionList = (List<Region>) options.get("region"); if (regionList != null && regionList.size() > 0) { logger.info("region filter activated, region list: " + regionList.toString()); builder = builder.and(getClinvarRegionFilterDBObject(regionList)); }/*from w w w .j a v a 2 s .c o m*/ return builder; }
From source file:org.opencb.cellbase.mongodb.db.variation.ClinicalMongoDBAdaptor.java
License:Apache License
private QueryBuilder addClinvarClinicalSignificanceFilter(QueryBuilder builder, QueryOptions options) { List<String> clinicalSignificanceList = (List<String>) options.getAsStringList("significance"); // List<String> clinicalSignificanceList = (List<String>) options.get("significance"); if (clinicalSignificanceList != null && clinicalSignificanceList.size() > 0) { for (int i = 0; i < clinicalSignificanceList.size(); i++) { clinicalSignificanceList.set(i, clinicalSignificanceList.get(i).replace("_", " ")); }/* w w w . j a va2s .c om*/ logger.info("Clinical significance filter activated, clinical significance list: " + clinicalSignificanceList.toString()); builder = builder .and(new BasicDBObject("clinvarSet.referenceClinVarAssertion.clinicalSignificance.description", new BasicDBObject("$in", clinicalSignificanceList))); } return builder; }
From source file:org.opencb.cellbase.mongodb.db.variation.ClinicalMongoDBAdaptor.java
License:Apache License
private QueryBuilder addClinvarReviewFilter(QueryBuilder builder, QueryOptions options) { List<String> reviewStatusList = (List<String>) options.getAsStringList("review"); // List<String> reviewStatusList = (List<String>) options.get("review"); if (reviewStatusList != null && reviewStatusList.size() > 0) { for (int i = 0; i < reviewStatusList.size(); i++) { reviewStatusList.set(i, reviewStatusList.get(i).toUpperCase()); }//from w ww . j a v a2 s. com logger.info("Review staus filter activated, review status list: " + reviewStatusList.toString()); builder = builder .and(new BasicDBObject("clinvarSet.referenceClinVarAssertion.clinicalSignificance.reviewStatus", new BasicDBObject("$in", reviewStatusList))); } return builder; }