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.lib.db.variation.MutationMongoDBAdaptor.java

License:Apache License

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

    return executeQueryList2(idList, queries, options);
}

From source file:org.opencb.cellbase.lib.db.variation.MutationMongoDBAdaptor.java

License:Apache License

@Override
public List<QueryResult> getAllByGeneNameList(List<String> geneNameList, QueryOptions options) {
    List<Document> queries = new ArrayList<>();
    for (String id : geneNameList) {
        QueryBuilder builder = QueryBuilder.start("gene").is(id);
        queries.add(new Document(builder.get().toMap()));
    }/*from  w w w  .jav a2 s. com*/

    return executeQueryList2(geneNameList, queries, options);
}

From source file:org.opencb.cellbase.lib.db.variation.MutationMongoDBAdaptor.java

License:Apache License

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

    return executeQueryList2(proteinIdList, queries, options);
}

From source file:org.opencb.cellbase.lib.db.variation.MutationMongoDBAdaptor.java

License:Apache License

@Override
public List<QueryResult> getAllByRegionList(List<Region> regions, QueryOptions options) {
    List<Document> 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(new Document(builder.get().toMap()));
        ids.add(region.toString());//from   w w  w.  j  a  va  2  s  .c  o m
    }

    return executeQueryList2(ids, queries, options);
}

From source file:org.opencb.cellbase.lib.db.variation.VariantFunctionalScoreMongoDBAdaptor.java

License:Apache License

@Override
public QueryResult getByVariant(String chromosome, int position, String reference, String alternate,
        QueryOptions queryOptions) {/*from   ww w .ja v  a 2 s  . c o  m*/
    String chunkId = getChunkIdPrefix(chromosome, position,
            MongoDBCollectionConfiguration.VARIATION_FUNCTIONAL_SCORE_CHUNK_SIZE);
    QueryBuilder builder = QueryBuilder.start("_chunkIds").is(chunkId);
    //                .and("chromosome").is(chromosome)
    //                .and("start").is(position);
    //        System.out.println(chunkId);
    QueryResult result = executeQuery(chromosome + "_" + position + "_" + reference + "_" + alternate,
            new Document(builder.get().toMap()), queryOptions, mongoDBCollection);

    //        System.out.println("result = " + result);

    int offset = (position % MongoDBCollectionConfiguration.VARIATION_FUNCTIONAL_SCORE_CHUNK_SIZE) - 1;
    List<Score> scores = new ArrayList<>();
    for (Object object : result.getResult()) {
        //            System.out.println("object = " + object);
        Document dbObject = (Document) object;
        BasicDBList basicDBList = (BasicDBList) dbObject.get("values");
        Long l1 = (Long) basicDBList.get(offset);
        //            System.out.println("l1 = " + l1);
        if (dbObject.getString("source").equalsIgnoreCase("cadd_raw")) {
            float value = 0f;
            switch (alternate.toLowerCase()) {
            case "a":
                value = ((short) (l1 >> 48) - 10000) / DECIMAL_RESOLUTION;
                break;
            case "c":
                value = ((short) (l1 >> 32) - 10000) / DECIMAL_RESOLUTION;
                break;
            case "g":
                value = ((short) (l1 >> 16) - 10000) / DECIMAL_RESOLUTION;
                break;
            case "t":
                value = ((short) (l1 >> 0) - 10000) / DECIMAL_RESOLUTION;
                break;
            default:
                break;
            }
            scores.add(Score.newBuilder().setScore(value).setSource(dbObject.getString("source"))
                    .setDescription(null)
                    //                        .setDescription("")
                    .build());
        }

        if (dbObject.getString("source").equalsIgnoreCase("cadd_scaled")) {
            float value = 0f;
            switch (alternate.toLowerCase()) {
            case "a":
                value = ((short) (l1 >> 48)) / DECIMAL_RESOLUTION;
                break;
            case "c":
                value = ((short) (l1 >> 32)) / DECIMAL_RESOLUTION;
                break;
            case "g":
                value = ((short) (l1 >> 16)) / DECIMAL_RESOLUTION;
                break;
            case "t":
                value = ((short) (l1 >> 0)) / DECIMAL_RESOLUTION;
                break;
            default:
                break;
            }
            scores.add(Score.newBuilder().setScore(value).setSource(dbObject.getString("source"))
                    .setDescription(null)
                    //                        .setDescription("")
                    .build());
        }
    }

    result.setResult(scores);
    return result;
}

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

License:Apache License

@Override
public List<QueryResult> getAllByIdList(List<String> idList, QueryOptions options) {
    List<Document> queries = new ArrayList<>();
    for (String id : idList) {
        QueryBuilder builder = QueryBuilder.start("ids").is(id);
        queries.add(new Document(builder.get().toMap()));
    }//from  w  w w.  ja v  a2 s .c o  m
    return executeQueryList2(idList, queries, options);
}

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

License:Apache License

@Override
public List<QueryResult> getAllByTranscriptIdList(List<String> idList, QueryOptions options) {
    List<Document> queries = new ArrayList<>();
    for (String id : idList) {
        QueryBuilder builder = QueryBuilder.start("annotation.consequenceTypes.ensemblTranscriptId").is(id);
        queries.add(new Document(builder.get().toMap()));
    }//  w w w.j  a  va  2  s  .c  o m
    return executeQueryList2(idList, queries, options);
}

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

License:Apache License

@Override
public List<QueryResult> getAllByRegionList(List<Region> regions, QueryOptions options) {
    List<Document> queries = new ArrayList<>();
    List<String> ids = new ArrayList<>(regions.size());

    // TODO: do not allow phenotype queries on the variation collection.
    // TODO: phenotype queries shall be answered by the clinicalMongoDBAdaptor
    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(new Document(builder.get().toMap()));
            ids.add(region.toString());// ww  w  .  java 2s. c o m
        }
        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("annotation.consequenceTypes.sequenceOntologyTerms.name")
                        .in(consequenceTypeDBList);
            }
            queries.add(new Document(builder.get().toMap()));
            ids.add(region.toString());
        }

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

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

License:Apache License

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

    for (Variant variation : variations) {
        String chunkId = getChunkIdPrefix(variation.getChromosome(), variation.getStart(), variationChunkSize);
        QueryBuilder builder = QueryBuilder.start("_chunkIds").is(chunkId).and("chromosome")
                .is(variation.getChromosome()).and("start").is(variation.getStart()).and("alternate")
                .is(variation.getAlternate());
        if (variation.getReference() != null) {
            builder = builder.and("reference").is(variation.getReference());
        }//  w ww  .j a v  a  2  s. c  om

        queries.add(new Document(builder.get().toMap()));
    }

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

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

        BasicDBList idListObject = (BasicDBList) result.getResult();
        for (Object idObject : idListObject) {
            Document variantObject = (Document) idObject;
            // Arbitrarily selects the first one. Assuming variants in variation collection will just have one id
            idList.add(((BasicDBList) variantObject.get("ids")).get(0).toString());
        }

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

    return results;
}

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

License:Apache License

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

    for (Variant variation : variations) {
        String chunkId = getChunkIdPrefix(variation.getChromosome(), variation.getStart(), variationChunkSize);

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

        if (variation.getReference() != null) {
            builder = builder.and("reference").is(variation.getReference());
        }//from   ww w.ja v a2 s. c om

        queries.add(new Document(builder.get().toMap()));
    }

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

    return results;
}