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

License:Apache License

@Override
public QueryResult getAllGenesByPhenotype(String phenotype, QueryOptions options) {
    QueryBuilder builder = QueryBuilder.start("phenotype").is(phenotype);
    return executeQuery(phenotype, builder.get(), options, mongoVariationPhenotypeDBCollection);
}

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

License:Apache License

@Override
public List<QueryResult> getAllGenesByPhenotypeList(List<String> phenotypeList, QueryOptions options) {
    List<DBObject> queries = new ArrayList<>(phenotypeList.size());
    for (String id : phenotypeList) {
        QueryBuilder builder = QueryBuilder.start("phenotype").is(id);
        queries.add(builder.get());//from  ww  w. j  ava 2  s  . c  o  m
    }
    return executeQueryList(phenotypeList, queries, options, mongoVariationPhenotypeDBCollection);
}

From source file:org.opencb.cellbase.mongodb.db.VariationMongoDBAdaptor.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());

    String phenotype = options.getString("phenotype");
    if (phenotype != null && !phenotype.equals("")) {
        for (Region region : regions) {
            QueryBuilder builder = QueryBuilder.start("chromosome").is(region.getChromosome()).and("start")
                    .greaterThanEquals(region.getStart()).lessThanEquals(region.getEnd());
            builder = builder.and("phenotype").is(phenotype);
            queries.add(builder.get());//from   www  .  ja  v  a 2s . c om
            ids.add(region.toString());
        }
        return executeQueryList(ids, queries, options, db.getCollection("variation_phenotype_annotation"));
    } else {
        String consequenceTypes = options.getString("consequence_type", null);
        BasicDBList consequenceTypeDBList = new BasicDBList();
        if (consequenceTypes != null && !consequenceTypes.equals("")) {
            for (String ct : consequenceTypes.split(",")) {
                consequenceTypeDBList.add(ct);
            }
        }

        for (Region region : regions) {
            //         QueryBuilder builder = QueryBuilder.start("chromosome").is(region.getSequenceName()).and("end").greaterThan(region.getStart()).and("start").lessThan(region.getEnd());
            QueryBuilder builder = QueryBuilder.start("chromosome").is(region.getChromosome()).and("start")
                    .greaterThanEquals(region.getStart()).lessThanEquals(region.getEnd());
            if (consequenceTypeDBList.size() > 0) {
                builder = builder.and("transcriptVariations.consequenceTypes").in(consequenceTypeDBList);
            }
            queries.add(builder.get());
            ids.add(region.toString());
        }

        return executeQueryList(ids, queries, options);
    }
}

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

License:Apache License

@Override
public List<QueryResult> getIdByVariantList(List<GenomicVariant> variations, QueryOptions options) {
    List<DBObject> queries = new ArrayList<>(variations.size());
    List<QueryResult> results;

    for (GenomicVariant variation : variations) {
        String chunkId = getChunkIdPrefix(variation.getChromosome(), variation.getPosition(),
                variationChunkSize);//w ww.  jav  a 2 s  .  co m
        QueryBuilder builder = QueryBuilder.start("_chunkIds").is(chunkId).and("chromosome")
                .is(variation.getChromosome()).and("start").is(variation.getPosition()).and("alternate")
                .is(variation.getAlternative());
        if (variation.getReference() != null) {
            builder = builder.and("reference").is(variation.getReference());
        }

        queries.add(builder.get());
    }

    results = executeQueryList2(variations, queries, options, mongoDBCollection2);

    for (QueryResult result : results) {
        List<String> idList = new LinkedList();

        BasicDBList idListObject = (BasicDBList) result.getResult();
        for (Object idObject : idListObject) {
            DBObject variantObject = (DBObject) idObject;
            idList.add(variantObject.get("id").toString());
        }

        //            result.setResult(Joiner.on(",").skipNulls().join(idList));
        result.setResult(idList);
    }

    return results;
}

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

License:Apache License

@Override
public List<QueryResult> getAllByVariantList(List<GenomicVariant> variations, QueryOptions options) {
    List<DBObject> queries = new ArrayList<>(variations.size());
    List<QueryResult> results;

    for (GenomicVariant variation : variations) {
        String chunkId = getChunkIdPrefix(variation.getChromosome(), variation.getPosition(),
                variationChunkSize);/*from  w w w . jav a2s  . c om*/

        QueryBuilder builder = QueryBuilder.start("_chunkIds").is(chunkId).and("chromosome")
                .is(variation.getChromosome()).and("start").is(variation.getPosition()).and("alternate")
                .is(variation.getAlternative());

        if (variation.getReference() != null) {
            builder = builder.and("reference").is(variation.getReference());
        }

        queries.add(builder.get());
    }

    results = executeQueryList2(variations, queries, options, mongoDBCollection2);
    //        results = executeQueryList(variations, queries, options, mongoDBCollection);

    return results;
}

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

    return executeQueryList(idList, queries, options);
}

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

License:Apache License

@Override
public List<QueryResult> getAllByGeneList(List<String> geneList, QueryOptions options) {
    List<DBObject> queries = new ArrayList<>(geneList.size());
    for (String id : geneList) {
        QueryBuilder builder = QueryBuilder.start("associatedGenes").is(id);
        queries.add(builder.get());//w w w .ja v a2s  . com
    }
    return executeQueryList(geneList, queries, options);
}

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

License:Apache License

@Override
public List<QueryResult> getAllGenesByPhenotypeList(List<String> phenotypeList, QueryOptions options) {
    List<DBObject> queries = new ArrayList<>(phenotypeList.size());
    for (String id : phenotypeList) {
        QueryBuilder builder = QueryBuilder.start("phenotype").is(id);
        queries.add(builder.get());/*  w  ww  .j av a  2s .  c o  m*/
    }
    return executeQueryList(phenotypeList, queries, options);
}

From source file:org.opencb.cellbase.mongodb.db.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());//  ww  w. ja  v a 2 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 executeQueryList(ids, queries, options);
}

From source file:org.opencb.cellbase.mongodb.impl.ConservationMongoDBAdaptor.java

License:Apache License

@Override
@Deprecated/*  w  ww  .j  a v a  2 s.  c om*/
public List<QueryResult> getAllScoresByRegionList(List regionList, QueryOptions options) {
    //TODO not finished yet
    List<Document> queries = new ArrayList<>();
    List<String> ids = new ArrayList<>(regionList.size());
    List<Integer> integerChunkIds;

    List<Region> regions = regionList;
    for (Region region : regions) {
        integerChunkIds = new ArrayList<>();
        // positions below 1 are not allowed
        if (region.getStart() < 1) {
            region.setStart(1);
        }
        if (region.getEnd() < 1) {
            region.setEnd(1);
        }

        /****/
        QueryBuilder builder;
        int regionChunkStart = getChunkId(region.getStart(),
                MongoDBCollectionConfiguration.CONSERVATION_CHUNK_SIZE);
        int regionChunkEnd = getChunkId(region.getEnd(),
                MongoDBCollectionConfiguration.CONSERVATION_CHUNK_SIZE);
        if (regionChunkStart == regionChunkEnd) {
            builder = QueryBuilder.start("_chunkIds").is(getChunkIdPrefix(region.getChromosome(),
                    region.getStart(), MongoDBCollectionConfiguration.CONSERVATION_CHUNK_SIZE));
        } else {
            //                for (int chunkId = regionChunkStart; chunkId <= regionChunkEnd; chunkId++) {
            //                    integerChunkIds.add(chunkId);
            //                }
            //    //            QueryBuilder builder = QueryBuilder.start("chromosome").is(region.getChromosomeInfo()).and("chunkId").in(hunkIds);
            //                builder = QueryBuilder.start("chromosome").is(region.getChromosomeInfo()).and("chunkId").in(integerChunkIds);
            builder = QueryBuilder.start("chromosome").is(region.getChromosome()).and("end")
                    .greaterThanEquals(region.getStart()).and("start").lessThanEquals(region.getEnd());
        }
        /****/

        queries.add(new Document(builder.get().toMap()));
        ids.add(region.toString());

        //            logger.debug(builder.get().toString());

    }
    List<QueryResult> queryResults = executeQueryList2(ids, queries, options);
    //        List<QueryResult> queryResults = executeQueryList(ids, queries, options);

    for (int i = 0; i < regions.size(); i++) {
        Region region = regions.get(i);
        QueryResult queryResult = queryResults.get(i);
        List<Document> list = (List<Document>) queryResult.getResult();

        Map<String, List<Float>> typeMap = new HashMap();

        //            int start = region.getStart();

        for (int j = 0; j < list.size(); j++) {
            Document chunk = list.get(j);

            if (!chunk.isEmpty()) {
                //                    BasicDBList valuesChunk = (BasicDBList) chunk.get("values");
                ArrayList valuesChunk = chunk.get("values", ArrayList.class);

                if (valuesChunk != null) { // TODO: temporary patch to skip empty chunks - remove as soon as conservation is reloaded
                    String source = chunk.getString("source");
                    List<Float> valuesList;
                    if (!typeMap.containsKey(source)) {
                        valuesList = new ArrayList<>(region.getEnd() - region.getStart() + 1);
                        for (int val = 0; val < region.getEnd() - region.getStart() + 1; val++) {
                            valuesList.add(null);
                        }
                        typeMap.put(source, valuesList);
                    } else {
                        valuesList = typeMap.get(source);
                    }

                    //                        valuesChunk = (BasicDBList) chunk.get("values");
                    valuesChunk = chunk.get("values", ArrayList.class);
                    int pos = 0;
                    if (region.getStart() > chunk.getInteger("start")) {
                        pos = region.getStart() - chunk.getInteger("start");
                    }

                    for (; pos < valuesChunk.size()
                            && (pos + chunk.getInteger("start") <= region.getEnd()); pos++) {
                        valuesList.set(pos + chunk.getInteger("start") - region.getStart(),
                                new Float((Double) valuesChunk.get(pos)));
                    }
                } else {
                    continue;
                }

            }

            BasicDBList resultList = new BasicDBList();
            for (Map.Entry<String, List<Float>> elem : typeMap.entrySet()) {
                for (Float value : elem.getValue()) {
                    if (value != null) {
                        resultList.add(new Score(new Double(value), elem.getKey()));
                    }
                }
            }
            if (!resultList.isEmpty()) {
                queryResult.setResult(resultList);
            } else {
                queryResult.setResult(null);
            }
        }

    }
    return queryResults;
}