Example usage for com.mongodb QueryBuilder get

List of usage examples for com.mongodb QueryBuilder get

Introduction

In this page you can find the example usage for com.mongodb QueryBuilder get.

Prototype

public DBObject get() 

Source Link

Document

Creates a DBObject query to be used for the driver's find operations

Usage

From source file:org.opencb.cellbase.mongodb.db.core.GeneMongoDBAdaptor.java

License:Apache License

@Override
public QueryResult getAll(QueryOptions options) {
    QueryBuilder builder = new QueryBuilder();

    List<String> biotypes = options.getAsStringList("biotype");
    if (biotypes != null && biotypes.size() > 0) {
        BasicDBList biotypeIds = new BasicDBList();
        biotypeIds.addAll(biotypes);//from  ww w.  ja v  a  2 s. com
        builder = builder.and("biotype").in(biotypeIds);
    }

    return executeQuery("result", builder.get(), options);
}

From source file:org.opencb.cellbase.mongodb.db.core.GeneMongoDBAdaptor.java

License:Apache License

@Override
public List<QueryResult> getAllByIdList(List<String> idList, QueryOptions options) {
    //      QueryBuilder builder = QueryBuilder.start("transcripts.xrefs.id").in(idList);

    List<DBObject> queries = new ArrayList<>(idList.size());
    for (String id : idList) {
        QueryBuilder builder = QueryBuilder.start("transcripts.xrefs.id").is(id);
        queries.add(builder.get());
    }/*from www. j  av a 2s.c om*/

    //        options = addExcludeReturnFields("transcripts", options);
    //        return executeQueryList(idList, queries, options);
    return executeQueryList2(idList, queries, options);
}

From source file:org.opencb.cellbase.mongodb.db.core.GeneMongoDBAdaptor.java

License:Apache License

@Override
public List<QueryResult> getAllByRegionList(List<Region> regions, QueryOptions options) {
    List<DBObject> queries = new ArrayList<>();

    List<Object> biotypes = options.getList("biotype", null);
    BasicDBList biotypeIds = new BasicDBList();
    if (biotypes != null && biotypes.size() > 0) {
        biotypeIds.addAll(biotypes);//from w ww.j  ava2s  .  c  o  m
    }

    List<String> ids = new ArrayList<>(regions.size());
    for (Region region : regions) {

        QueryBuilder builder = null;
        // If regions is 1 position then query can be optimize using chunks
        if (region.getStart() == region.getEnd()) {
            builder = QueryBuilder.start("_chunkIds")
                    .is(getChunkIdPrefix(region.getChromosome(), region.getStart(), geneChunkSize)).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 (biotypeIds.size() > 0) {
            builder = builder.and("biotype").in(biotypeIds);
        }
        queries.add(builder.get());
        ids.add(region.toString());
    }
    return executeQueryList2(ids, queries, options);
    //        return executeQueryList(ids, queries, options);
}

From source file:org.opencb.cellbase.mongodb.db.core.GenomeMongoDBAdaptor.java

License:Apache License

@Deprecated
public QueryResult speciesInfoTmp(String id, QueryOptions options) {
    // reading application.properties file

    //        String[] speciesArray = applicationProperties.getProperty("SPECIES").split(",");

    //        List<DBObject> queries = new ArrayList<>(1);
    //        for (String id : idList) {
    QueryBuilder builder = QueryBuilder.start("species").is(id);

    //        queries.add(builder.get());
    //        }//from   www  .  j a  v  a2  s  .  c o  m

    //        options = addExcludeReturnFields("transcripts", options);
    return executeQuery(id, builder.get(), options);

}

From source file:org.opencb.cellbase.mongodb.db.core.GenomeMongoDBAdaptor.java

License:Apache License

@Override
public List<QueryResult> getAllSequencesByRegionList(List<Region> regions, QueryOptions options) {
    /****//*from ww w .  j av  a  2  s  .  co  m*/
    String chunkIdSuffix = this.chunkSize / 1000 + "k";
    /****/

    List<DBObject> queries = new ArrayList<>();
    List<String> ids = new ArrayList<>(regions.size());
    List<String> chunkIds;
    List<Integer> integerChunkIds;
    for (Region region : regions) {
        chunkIds = new ArrayList<>();
        integerChunkIds = new ArrayList<>();
        // positions below 1 are not allowed
        if (region.getStart() < 1) {
            region.setStart(1);
        }
        if (region.getEnd() < 1) {
            region.setEnd(1);
        }

        /****/
        int regionChunkStart = getChunkId(region.getStart(), this.chunkSize);
        int regionChunkEnd = getChunkId(region.getEnd(), this.chunkSize);
        for (int chunkId = regionChunkStart; chunkId <= regionChunkEnd; chunkId++) {
            String chunkIdStr = region.getChromosome() + "_" + chunkId + "_" + chunkIdSuffix;
            chunkIds.add(chunkIdStr);
            integerChunkIds.add(chunkId);
        }
        //            QueryBuilder builder = QueryBuilder.start("sequenceName").is(region.getChromosome()).and("_chunkIds").in(chunkIds);
        QueryBuilder builder = QueryBuilder.start("_chunkIds").in(chunkIds);
        /****/
        queries.add(builder.get());
        ids.add(region.toString());

        logger.info(builder.get().toString());
    }

    List<QueryResult> queryResults = executeQueryList2(ids, queries, options, genomeSequenceCollection);
    for (int i = 0; i < regions.size(); i++) {
        Region region = regions.get(i);
        QueryResult queryResult = queryResults.get(i);

        List list = queryResult.getResult();
        StringBuilder sb = new StringBuilder();
        for (int j = 0; j < list.size(); j++) {
            BasicDBObject chunk = (BasicDBObject) list.get(j);
            sb.append(chunk.get("sequence"));
        }

        int startStr = getOffset(region.getStart());
        int endStr = getOffset(region.getStart()) + (region.getEnd() - region.getStart()) + 1;

        String subStr = "";

        if (getChunkId(region.getStart(), this.chunkSize) > 0) {
            if (sb.toString().length() > 0 && sb.toString().length() >= endStr) {
                subStr = sb.toString().substring(startStr, endStr);
            }
        } else {
            if (sb.toString().length() > 0 && sb.toString().length() + 1 >= endStr) {
                subStr = sb.toString().substring(startStr - 1, endStr - 1);
            }
        }
        logger.info("((BasicDBObject)list.get(0)).getString(\"sequenceType\") = {}",
                ((BasicDBObject) list.get(0)).getString("sequenceType"));
        logger.info("((BasicDBObject)list.get(0)).getString(\"assembly\") = {}",
                ((BasicDBObject) list.get(0)).getString("assembly"));
        GenomeSequenceFeature genomeSequenceFeature = new GenomeSequenceFeature(region.getChromosome(),
                region.getStart(), region.getEnd(), 1, ((BasicDBObject) list.get(0)).getString("sequenceType"),
                ((BasicDBObject) list.get(0)).getString("assembly"), subStr);
        //            GenomeSequenceChunk genomeSequenceChunk = new GenomeSequenceChunk(region.getSequenceName(), region.getStart(), region.getEnd(), subStr);

        queryResult.setResult(Arrays.asList(genomeSequenceFeature));
    }

    return queryResults;
}

From source file:org.opencb.cellbase.mongodb.db.core.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   ww  w.  j  ava2 s .  c om*/

    //        options = addExcludeReturnFields("transcripts", options);
    return executeQueryList2(idList, queries, options);
}

From source file:org.opencb.cellbase.mongodb.db.core.ProteinMongoDBAdaptor.java

License:Apache License

@Override
public List<QueryResult> getAllByXrefList(List<String> idList, QueryOptions options) {
    List<DBObject> queries = new ArrayList<>(idList.size());
    for (String id : idList) {
        QueryBuilder builder = QueryBuilder.start("dbReference.id").is(id);
        queries.add(builder.get());
    }//  ww w. j a v a  2s  .  c o m

    //        options = addExcludeReturnFields("transcripts", options);
    //        return executeQueryList(idList, queries, options);
    return executeQueryList2(idList, queries, options);
}

From source file:org.opencb.cellbase.mongodb.db.core.ProteinMongoDBAdaptor.java

License:Apache License

@Override
public List<QueryResult> getAllFunctionPredictionByEnsemblTranscriptIdList(List<String> transcriptIdList,
        QueryOptions options) {/*  www.j  a v  a  2s.c  o m*/
    List<DBObject> queries = new ArrayList<>(transcriptIdList.size());

    if (options.containsKey("aaPosition")) {
        if (options.containsKey("aaChange")) {
            addIncludeReturnFields(
                    "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 executeQueryList2(transcriptIdList, queries, options, proteinFunctionalPredictionCollection);
}

From source file:org.opencb.cellbase.mongodb.db.core.ProteinMongoDBAdaptor.java

License:Apache License

public QueryResult getFunctionPredictionByAaChange(String transcriptId, Integer aaPosition, String newAa,
        QueryOptions queryOptions) {/*  w w  w. ja va 2s .  co  m*/

    QueryBuilder builder = QueryBuilder.start("transcriptId").is(transcriptId);
    QueryResult allChangesQueryResult = executeQuery(transcriptId, builder.get(), queryOptions,
            proteinFunctionalPredictionCollection);

    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.core.XRefsMongoDBAdaptor.java

License:Apache License

@Override
public List<QueryResult> getByStartsWithQueryList(List<String> ids, QueryOptions options) {
    List<DBObject> queries = new ArrayList<>();

    for (String id : ids) {
        QueryBuilder qb = QueryBuilder.start("transcripts.xrefs.id").regex(Pattern.compile("^" + id));
        queries.add(qb.get());
    }/*from   www.  j a  v a2  s  .com*/
    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);
}