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.GeneMongoDBAdaptor.java

License:Apache License

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

    List<Object> biotypes = options.getList("biotypes", null);
    if (biotypes != null && biotypes.size() > 0) {
        BasicDBList biotypeIds = new BasicDBList();
        biotypeIds.addAll(biotypes);/*from  w  w  w.  jav  a  2s.  co  m*/
        builder = builder.and("biotype").in(biotypeIds);
    }

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

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

License:Apache License

@Override
public QueryResult next(String chromosome, int position, QueryOptions options) {
    if (options.getString("strand") == null || options.getString("strand").equals("")
            || (options.getString("strand").equals("1") || options.getString("strand").equals("+"))) {
        // db.core.find({chromosome: "1", start: {$gt: 1000000}}).sort({start: 1}).limit(1)
        QueryBuilder builder = QueryBuilder.start("chromosome").is(chromosome).and("start")
                .greaterThanEquals(position);
        // options.put("sortAsc", "start");
        options.put("sort", new HashMap<String, String>().put("start", "asc"));
        options.put("limit", 1);
        // mongoDBCollection.find().sort(new BasicDBObject("", "")).limit(1);
        return executeQuery("result", builder.get(), options);
    } else {//from  ww  w . j a va 2s .c o m
        QueryBuilder builder = QueryBuilder.start("chromosome").is(chromosome).and("end")
                .lessThanEquals(position);
        // options.put("sortDesc", "end");
        options.put("sort", new HashMap<String, String>().put("end", "desc"));
        options.put("limit", 1);
        //              mongoDBCollection.find().sort(new BasicDBObject("", "")).limit(1);
        return executeQuery("result", builder.get(), options);
    }
}

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

License:Apache License

@Override
public List<org.opencb.datastore.core.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   w w  w  .j  ava  2 s . com

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

From source file:org.opencb.cellbase.mongodb.db.GenomeSequenceMongoDBAdaptor.java

License:Apache License

@Override
public List<QueryResult> getAllByRegionList(List<Region> regions, QueryOptions options) {
    /****///from  w  w w.ja v a 2s.  c om
    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 = getChunk(region.getStart());
        int regionChunkEnd = getChunk(region.getEnd());
        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);
    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 (getChunk(region.getStart()) > 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);
            }
        }
        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.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 {//from  ww w.  j  a  v a 2  s . com
        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", builder.get(), options, mongoDBCollection);
}

From source file:org.opencb.cellbase.mongodb.db.MutationMongoDBAdaptor.java

License:Apache License

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

    List<Object> biotypes = options.getList("disease", null);
    if (biotypes != null && biotypes.size() > 0) {
        BasicDBList biotypeIds = new BasicDBList();
        biotypeIds.addAll(biotypes);/*from   w  w  w  .ja va2  s  .co m*/
        builder = builder.and("primaryHistology").in(biotypeIds);
    }

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

From source file:org.opencb.cellbase.mongodb.db.MutationMongoDBAdaptor.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("id").is(id);
        queries.add(builder.get());
    }/*from   w w w  . j  a  v  a 2s .c  o  m*/

    return executeQueryList(idList, queries, options);
}

From source file:org.opencb.cellbase.mongodb.db.MutationMongoDBAdaptor.java

License:Apache License

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

    return executeQueryList(idList, queries, options);
}

From source file:org.opencb.cellbase.mongodb.db.MutationMongoDBAdaptor.java

License:Apache License

@Override
public List<QueryResult> getAllByGeneNameList(List<String> geneNameList, QueryOptions options) {
    List<DBObject> queries = new ArrayList<>();
    for (String id : geneNameList) {
        QueryBuilder builder = QueryBuilder.start("gene").is(id);
        queries.add(builder.get());
    }/*  w  w w. j  a v a2  s.c  o m*/

    return executeQueryList(geneNameList, queries, options);
}

From source file:org.opencb.cellbase.mongodb.db.MutationMongoDBAdaptor.java

License:Apache License

@Override
public List<QueryResult> getAllByProteinIdList(List<String> proteinIdList, QueryOptions options) {
    List<DBObject> queries = new ArrayList<>();
    for (String id : proteinIdList) {
        QueryBuilder builder = QueryBuilder.start("protein").is(id);
        queries.add(builder.get());
    }//from   w w w  . ja  va2  s  . c  o m

    return executeQueryList(proteinIdList, queries, options);
}