List of usage examples for com.mongodb QueryBuilder get
public DBObject get()
From source file:org.opencb.cellbase.lib.db.core.ProteinMongoDBAdaptor.java
License:Apache License
public QueryResult getFunctionPredictionByAaChange(String transcriptId, Integer aaPosition, String newAa, QueryOptions queryOptions) {/* w w w .j a v a 2 s . co m*/ QueryBuilder builder = QueryBuilder.start("transcriptId").is(transcriptId); QueryResult allChangesQueryResult = executeQuery(transcriptId, new Document(builder.get().toMap()), queryOptions, proteinFunctionalPredictionCollection); QueryResult proteinSubstitionScoresQueryResult = new QueryResult(); proteinSubstitionScoresQueryResult.setDbTime(allChangesQueryResult.getDbTime()); proteinSubstitionScoresQueryResult.setId(transcriptId + "-" + aaPosition + "-" + newAa); //<<<<<<< HEAD // String currentAaShortName = aaShortName.get(newAa); // Map aaPositions = ((HashMap) ((Document) allChangesQueryResult.getResult().get(0)).get("aaPositions")); // if (allChangesQueryResult.getNumResults() > 0 && currentAaShortName != null && aaPositions != null) { // Document positionDBObject = (Document) aaPositions.get(Integer.toString(aaPosition)); // if (positionDBObject != null) { // Object aaObject = positionDBObject.get(currentAaShortName); // if (aaObject != null) { // proteinSubstitionScoresQueryResult.setNumResults(1); // proteinSubstitionScoresQueryResult.setResult(Arrays.asList(aaObject)); //======= if (allChangesQueryResult.getNumResults() > 0) { String currentAaShortName = aaShortName.get(newAa); Map aaPositions = ((HashMap) ((Document) allChangesQueryResult.getResult().get(0)).get("aaPositions")); if (currentAaShortName != null && aaPositions != null) { Document positionDBObject = (Document) aaPositions.get(Integer.toString(aaPosition)); if (positionDBObject != null) { Object aaObject = positionDBObject.get(currentAaShortName); if (aaObject != null) { proteinSubstitionScoresQueryResult.setNumResults(1); proteinSubstitionScoresQueryResult.setResult(Arrays.asList(aaObject)); } else { proteinSubstitionScoresQueryResult.setErrorMsg("Unaccepted AA " + currentAaShortName + ". Available AA changes for transcript " + transcriptId + ", position " + aaPosition + ": " + positionDBObject.keySet().toString()); return proteinSubstitionScoresQueryResult; } //>>>>>>> develop } else { proteinSubstitionScoresQueryResult.setErrorMsg("Unaccepted position " + Integer.toString(aaPosition) + ". Available positions for transcript " + transcriptId + ": " + aaPositions.keySet().toString()); return proteinSubstitionScoresQueryResult; } } else { proteinSubstitionScoresQueryResult.setNumResults(0); } } return proteinSubstitionScoresQueryResult; }
From source file:org.opencb.cellbase.lib.db.core.XRefsMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getByStartsWithQueryList(List<String> ids, QueryOptions options) { List<Document> queries = new ArrayList<>(); for (String id : ids) { QueryBuilder builder = QueryBuilder.start("transcripts.xrefs.id").regex(Pattern.compile("^" + id)); queries.add(new Document(builder.get().toMap())); }/* ww w. ja v a2 s . co m*/ int limit = options.getInt("limit", 50); if (limit > 50) { options.put("limit", 50); } System.out.println(options.getInt("limit")); options.put("include", Arrays.asList("chromosome", "start", "end", "id", "name")); return executeQueryList2(ids, queries, options); }
From source file:org.opencb.cellbase.lib.db.MongoDBAdaptor.java
License:Apache License
public QueryResult next(String chromosome, int position, QueryOptions options, MongoDBCollection mongoDBCollection) { QueryBuilder builder; if (options.getString("strand") == null || options.getString("strand").equals("") || (options.getString("strand").equals("1") || options.getString("strand").equals("+"))) { builder = QueryBuilder.start("chromosome").is(chromosome).and("start").greaterThanEquals(position); options.put("sort", new HashMap<String, String>().put("start", "asc")); options.put("limit", 1); } else {// w w w . ja v a 2s . co m builder = QueryBuilder.start("chromosome").is(chromosome).and("end").lessThanEquals(position); options.put("sort", new HashMap<String, String>().put("end", "desc")); options.put("limit", 1); } return executeQuery("result", new Document(builder.get().toMap()), options, mongoDBCollection); }
From source file:org.opencb.cellbase.lib.db.regulatory.RegulatoryRegionMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getAllByIdList(List<String> idList, QueryOptions options) { List<Document> queries = new ArrayList<>(); for (String id : idList) { QueryBuilder builder = QueryBuilder.start("name").is(id); // System.out.println("Query: " + new Document(builder.get().toMap())); queries.add(new Document(builder.get().toMap())); }//from w w w . j a v a 2s .co m // options = addExcludeReturnFields("chunkIds", options); return executeQueryList2(idList, queries, options); }
From source file:org.opencb.cellbase.lib.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<Document> 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 ww . ja va 2 s . c o 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: " + new Document(builder.get().toMap())); queries.add(new Document(builder.get().toMap())); } System.out.println("Query: " + queries); // options = addExcludeReturnFields("chunkIds", options); return executeQueryList2(positionList, queries, options); }
From source file:org.opencb.cellbase.lib.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<Document> 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);//ww w .j a v a 2 s .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(new Document(builder.get().toMap())); } // System.out.println(">>"+regionList); // System.out.println(">>"+new Document(builder.get().toMap()).toString()); return executeQueryList2(regionList, queries, options); }
From source file:org.opencb.cellbase.lib.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 w w .j a v a 2s . 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 Document("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 Document("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(new Document(builder.get().toMap())); return executeQuery("result", new Document(builder.get().toMap()), options); }
From source file:org.opencb.cellbase.lib.db.regulatory.TfbsMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getAllByIdList(List<String> idList, QueryOptions options) { List<Document> queries = new ArrayList<>(); for (String id : idList) { QueryBuilder builder = QueryBuilder.start("name").is(id).and("featureType").is("TF_binding_site_motif"); // System.out.println("Query: " + builder.get()); queries.add(new Document(builder.get().toMap())); }/* w w w . j ava 2s . c o m*/ options = addExcludeReturnFields("chunkIds", options); return executeQueryList2(idList, queries, options); }
From source file:org.opencb.cellbase.lib.db.systems.ProteinProteinInteractionMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getAllByIdList(List<String> idList, QueryOptions options) { List<Document> queries = new ArrayList<>(idList.size()); for (String id : idList) { QueryBuilder builder = QueryBuilder.start("xrefs.id").is(id); queries.add(new Document(builder.get().toMap())); }//from w w w . j a v a 2s. c om // options = addExcludeReturnFields("transcripts", options); return executeQueryList2(idList, queries, options); }
From source file:org.opencb.cellbase.lib.db.variation.ClinicalMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getAllByRegionList(List<Region> regions, QueryOptions options) { List<Document> 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(new Document(builder.get().toMap())); ids.add(region.toString());/*from w w w.jav a2 s .c o m*/ } return executeQueryList2(ids, queries, options); }