Example usage for com.mongodb QueryBuilder start

List of usage examples for com.mongodb QueryBuilder start

Introduction

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

Prototype

public static QueryBuilder start(final String key) 

Source Link

Document

Creates a new query with a document key

Usage

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());// www.  jav a2 s . c  o m
    }

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

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

License:Apache License

@Override
public QueryResult getAllBiotypes(QueryOptions options) {
    DBObject query = null;//  w  w w  .j av a  2 s. c o  m

    if (options != null && options.get("chromosome") != null) {
        query = QueryBuilder.start("chromosome").is(options.get("chromosome")).get();
    }
    return executeDistinct("", "biotype", query);
}

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 ww .j  av a  2  s  .c o 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 = 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;/*from  www. ja v  a  2s .  co  m*/
    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 {
        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 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  2 s .  c om*/
    }

    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());// ww w.  j ava  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> 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());//from  ww w  .  jav  a  2  s  .  com
    }

    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());/*w w  w.  ja  va  2  s  . com*/
    }

    return executeQueryList(proteinIdList, queries, options);
}

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());//from w  ww .  j  a  va  2s  .  c o  m
        ids.add(region.toString());
    }

    return executeQueryList(ids, queries, 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  v  a  2  s .  c  o  m
    }
    //        options = addExcludeReturnFields("transcripts", options);
    return executeQueryList(idList, queries, options);
}