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.variation.VariationMongoDBAdaptor.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());/* ww  w.  ja  v  a  2 s  .co  m*/
    }
    return executeQueryList2(idList, queries, options);
}

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

License:Apache License

@Override
public List<QueryResult> getAllByTranscriptIdList(List<String> idList, QueryOptions options) {
    List<DBObject> queries = new ArrayList<>();
    for (String id : idList) {
        QueryBuilder builder = QueryBuilder.start("transcriptVariations.transcriptId").is(id);
        queries.add(builder.get());//from  w  w w.  j av a2  s  .  com
    }
    return executeQueryList2(idList, queries, options);
}

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

License:Apache License

@Override
public QueryResult getAllPhenotypes(QueryOptions options) {
    //        return executeDistinct("distinct", "phenotype", mongoVariationPhenotypeDBCollection);
    QueryBuilder builder = new QueryBuilder();
    if (options.containsKey("phenotype")) {
        String pheno = options.getString("phenotype");
        if (pheno != null && !pheno.equals("")) {
            builder = builder.start("phenotype").is(pheno);
        }//from   ww  w .  j av  a2  s.  c  om
    }
    return executeQuery("result", builder.get(), options);
    //        return executeQuery("result", builder.get(), options, mongoVariationPhenotypeDBCollection);
}

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

License:Apache License

@Override
public List<QueryResult> getAllPhenotypeByRegion(List<Region> regions, QueryOptions options) {
    QueryBuilder builder = null;//ww  w . j av  a 2 s . c om
    List<DBObject> queries = new ArrayList<>();

    /**
     * If source is present in options is it parsed and prepare first,
     * otherwise ti will be done for each iteration of regions.
     */
    List<Object> source = options.getList("source", null);
    BasicDBList sourceIds = new BasicDBList();
    if (source != null && source.size() > 0) {
        sourceIds.addAll(source);
    }

    //        List<Region> regions = Region.parseRegions(options.getString("region"));
    List<String> ids = new ArrayList<>(regions.size());
    for (Region region : regions) {
        if (region != null && !region.equals("")) {
            // If regions is 1 position then query can be optimize using chunks
            if (region.getStart() == region.getEnd()) {
                String chunkId = getChunkIdPrefix(region.getChromosome(), region.getStart(),
                        variationChunkSize);
                System.out.println(chunkId);
                builder = QueryBuilder.start("_chunkIds").is(chunkId).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 (sourceIds != null && sourceIds.size() > 0) {
                builder = builder.and("source").in(sourceIds);
            }

            queries.add(builder.get());
            ids.add(region.toString());
        }
    }
    return executeQueryList2(ids, queries, options, mongoVariationPhenotypeDBCollection2);
}

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

License:Apache License

@Override
public QueryResult getAllByPhenotype(String phenotype, QueryOptions options) {
    QueryBuilder builder = QueryBuilder.start("phenotype").is(phenotype);

    List<QueryResult> queryResults = new ArrayList<>();
    if (options.containsKey("variants")) {
        List<Object> variantList = options.getList("variants");
        List<GenomicVariant> variants = new ArrayList<>(variantList.size());
        for (int i = 0; i < variantList.size(); i++) {
            GenomicVariant genomicVariant = (GenomicVariant) variantList.get(i);
            variants.add(genomicVariant);
        }/*from ww  w.j a v a2  s .c om*/
    }

    return null;
}

From source file:org.opencb.cellbase.mongodb.db.variation.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, mongoVariationPhenotypeDBCollection2);
}

From source file:org.opencb.cellbase.mongodb.db.variation.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());/*  ww w  .  j a  va 2 s  .co m*/
    }
    return executeQueryList2(phenotypeList, queries, options, mongoVariationPhenotypeDBCollection2);
}

From source file:org.opencb.cellbase.mongodb.db.variation.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());//  www .ja  v a  2s  .co  m
            ids.add(region.toString());
        }
        return executeQueryList2(ids, queries, options, mongoVariationPhenotypeDBCollection2);
    } 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 executeQueryList2(ids, queries, options);
    }
}

From source file:org.opencb.cellbase.mongodb.db.variation.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);//from  w  ww .  j av a2 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, mongoDBCollection);

    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.variation.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  ww  .j  av  a  2s  . 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, mongoDBCollection);
    //        results = executeQueryList(variations, queries, options, mongoDBCollection);

    return results;
}