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

License:Apache License

@Override
public QueryResult getAllBiotypes(QueryOptions options) {
    DBObject query = null;//w  ww  .j  a v  a  2 s.  com

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

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);//w ww .  ja  v a 2s  .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());
    //        }//  ww w.  ja v a 2  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  w  ww .  j  a  va2s.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 = 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());/*w  w w . ja v a2s.  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());//from   w ww . ja va  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.ProteinMongoDBAdaptor.java

License:Apache License

@Override
public List<QueryResult> getAllFunctionPredictionByEnsemblTranscriptIdList(List<String> transcriptIdList,
        QueryOptions options) {/* w  ww.ja  va  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) {/*from  w  ww  . j  av a  2  s .  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   w ww  . j  av  a 2  s.c  o  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.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 w  w w. j  a va 2  s  .c  om*/
        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);
    }
}