List of usage examples for com.mongodb QueryBuilder start
public static QueryBuilder start(final String key)
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 ww.j a v a2s .c o m*/ "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) {// www. ja v a2s. com 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());/* w w w. ja v a 2 s . com*/ } // 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 ww w.j a va2 s .c o m } // 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);//from www .j ava 2 s . c om 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 a 2s . co 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);//ww w .j a va 2 s . c o 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.regulatory.TfbsMongoDBAdaptor.java
License:Apache License
/** * PARTICULAR METHODS FOR TFBS CLASS//w w w .j a va 2 s. com */ @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).and("featureType").is("TF_binding_site_motif"); // System.out.println("Query: " + builder.get()); queries.add(builder.get()); } options = addExcludeReturnFields("chunkIds", options); return executeQueryList2(idList, queries, options); }
From source file:org.opencb.cellbase.mongodb.db.systems.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());/*ww w . ja va2s.c o m*/ } // options = addExcludeReturnFields("transcripts", options); return executeQueryList2(idList, queries, options); }
From source file:org.opencb.cellbase.mongodb.db.VariantEffectMongoDBAdaptor.java
License:Apache License
@Override public List<QueryResult> getAllEffectsByVariantList(List<GenomicVariant> variants, QueryOptions options) { List<QueryResult> queryResults = new ArrayList<>(variants.size()); List<DBObject> queries = new ArrayList<>(variants.size()); for (GenomicVariant genomicVariant : variants) { QueryBuilder builder = QueryBuilder.start("chromosome").is(genomicVariant.getChromosome()).and("start") .lessThanEquals(genomicVariant.getPosition()).and("end") .greaterThanEquals(genomicVariant.getPosition()); queries.add(builder.get());/* w ww .j a va2s.c o m*/ } options = addExcludeReturnFields("transcripts.xrefs", options); BasicDBObject returnFields = getReturnFields(options); BasicDBList list = executeFind(queries.get(0), returnFields, options, db.getCollection("core")); long dbTimeStart, dbTimeEnd; GenomicVariantEffectPredictor genomicVariantEffectPredictor = new GenomicVariantEffectPredictor(); // List<Gene> genes = jsonObjectMapper.readValue(list.toString(), new TypeReference<List<Gene>>() { }); List<Gene> genes = new ArrayList<>(); dbTimeStart = System.currentTimeMillis(); List<GenomicVariantEffect> a = genomicVariantEffectPredictor.getAllEffectsByVariant(variants.get(0), genes, null); dbTimeEnd = System.currentTimeMillis(); QueryResult queryResult = new QueryResult(); queryResult.setDbTime(Long.valueOf(dbTimeEnd - dbTimeStart).intValue()); queryResult.setNumResults(list.size()); queryResult.setResult(a); queryResults.add(queryResult); return queryResults; }