List of usage examples for com.mongodb QueryBuilder get
public DBObject get()
From source file:org.opencb.cellbase.mongodb.db.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()); ids.add(region.toString());/*from w w w . ja v a 2s . co m*/ } return executeQueryList(ids, queries, options); }
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 a v a 2 s. 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.network.ProteinProteinInteractionMongoDBAdaptor.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("xrefs.id").is(id); queries.add(builder.get()); }/*from w w w . j a va2 s.co m*/ // options = addExcludeReturnFields("transcripts", options); return executeQueryList(idList, queries, options); }
From source file:org.opencb.cellbase.mongodb.db.ProteinFunctionPredictorMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getAllByEnsemblTranscriptIdList(List<String> transcriptIdList, QueryOptions options) { List<DBObject> queries = new ArrayList<>(transcriptIdList.size()); if (options.containsKey("aaPosition")) { if (options.containsKey("aaChange")) { addIncludeReturnFields(/*from w w w .ja va 2 s .c om*/ "aaPositions." + options.getString("aaPosition") + "." + options.getString("aaChange"), options); } else { addIncludeReturnFields("aaPositions." + options.getString("aaPosition"), options); } } for (String id : transcriptIdList) { QueryBuilder builder = QueryBuilder.start("transcriptId").is(id); queries.add(builder.get()); } // options = addExcludeReturnFields("transcripts", options); return executeQueryList(transcriptIdList, queries, options); }
From source file:org.opencb.cellbase.mongodb.db.ProteinFunctionPredictorMongoDBAdaptor.java
License:Apache License
public QueryResult getByAaChange(String transcriptId, Integer aaPosition, String newAa, QueryOptions queryOptions) {// w w w. jav a 2 s .c o m QueryBuilder builder = QueryBuilder.start("transcriptId").is(transcriptId); QueryResult allChangesQueryResult = executeQuery(transcriptId, builder.get(), queryOptions); QueryResult proteinSubstitionScoresQueryResult = new QueryResult(); proteinSubstitionScoresQueryResult.setDbTime(allChangesQueryResult.getDbTime()); proteinSubstitionScoresQueryResult.setId(transcriptId + "-" + aaPosition + "-" + newAa); String currentAaShortName; Map aaPositions; if (allChangesQueryResult.getNumResults() > 0 && (currentAaShortName = aaShortName.get(newAa)) != null && (aaPositions = ((HashMap) ((BasicDBObject) allChangesQueryResult.getResult().get(0)) .get("aaPositions"))) != null) { proteinSubstitionScoresQueryResult.setNumResults(1); proteinSubstitionScoresQueryResult.setResult(Arrays.asList( ((BasicDBObject) aaPositions.get(Integer.toString(aaPosition))).get(currentAaShortName))); } else { proteinSubstitionScoresQueryResult.setNumResults(0); } return proteinSubstitionScoresQueryResult; }
From source file:org.opencb.cellbase.mongodb.db.ProteinMongoDBAdaptor.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("name").is(id); queries.add(builder.get()); }//from w ww .j a v a 2 s. c o m // options = addExcludeReturnFields("transcripts", options); return executeQueryList(idList, queries, options); }
From source file:org.opencb.cellbase.mongodb.db.regulatory.RegulatoryRegionMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getAllByIdList(List<String> idList, QueryOptions options) { List<DBObject> queries = new ArrayList<>(); for (String id : idList) { QueryBuilder builder = QueryBuilder.start("name").is(id); // System.out.println("Query: " + builder.get()); queries.add(builder.get()); }/*from www. j av a 2 s. com*/ // options = addExcludeReturnFields("chunkIds", options); return executeQueryList2(idList, queries, 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);/* www . ja v a 2s . com*/ 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 w ww . j a va 2s . c o m } // 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);/* w ww . j a v a 2 s . c om*/ // 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); }