Example usage for com.mongodb QueryBuilder get

List of usage examples for com.mongodb QueryBuilder get

Introduction

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

Prototype

public DBObject get() 

Source Link

Document

Creates a DBObject query to be used for the driver's find operations

Usage

From source file:org.opencb.cellbase.mongodb.db.regulatory.TfbsMongoDBAdaptor.java

License:Apache License

/**
 * PARTICULAR METHODS FOR TFBS CLASS/* w ww  .j  a  v a  2  s.c om*/
 */
@Override
public List<QueryResult> getAllByIdList(List<String> idList, QueryOptions options) {
    List<DBObject> queries = new ArrayList<>();
    for (String id : idList) {
        QueryBuilder builder = QueryBuilder.start("name").is(id).and("featureType").is("TF_binding_site_motif");
        //            System.out.println("Query: " + builder.get());
        queries.add(builder.get());
    }
    options = addExcludeReturnFields("chunkIds", options);
    return executeQueryList2(idList, queries, options);
}

From source file:org.opencb.cellbase.mongodb.db.systems.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());
    }// w w  w. j  a v a  2s .c om
    //        options = addExcludeReturnFields("transcripts", options);
    return executeQueryList2(idList, queries, options);
}

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

License:Apache License

@Override
public List<QueryResult> getAllEffectsByVariantList(List<GenomicVariant> variants, QueryOptions options) {
    List<QueryResult> queryResults = new ArrayList<>(variants.size());
    List<DBObject> queries = new ArrayList<>(variants.size());
    for (GenomicVariant genomicVariant : variants) {
        QueryBuilder builder = QueryBuilder.start("chromosome").is(genomicVariant.getChromosome()).and("start")
                .lessThanEquals(genomicVariant.getPosition()).and("end")
                .greaterThanEquals(genomicVariant.getPosition());
        queries.add(builder.get());
    }//from w w  w.  j  ava2 s .  c o  m

    options = addExcludeReturnFields("transcripts.xrefs", options);

    BasicDBObject returnFields = getReturnFields(options);
    BasicDBList list = executeFind(queries.get(0), returnFields, options, db.getCollection("core"));
    long dbTimeStart, dbTimeEnd;

    GenomicVariantEffectPredictor genomicVariantEffectPredictor = new GenomicVariantEffectPredictor();
    //            List<Gene> genes = jsonObjectMapper.readValue(list.toString(), new TypeReference<List<Gene>>() { });
    List<Gene> genes = new ArrayList<>();
    dbTimeStart = System.currentTimeMillis();
    List<GenomicVariantEffect> a = genomicVariantEffectPredictor.getAllEffectsByVariant(variants.get(0), genes,
            null);
    dbTimeEnd = System.currentTimeMillis();

    QueryResult queryResult = new QueryResult();
    queryResult.setDbTime(Long.valueOf(dbTimeEnd - dbTimeStart).intValue());
    queryResult.setNumResults(list.size());
    queryResult.setResult(a);

    queryResults.add(queryResult);

    return queryResults;
}

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

License:Apache License

@Override
public QueryResult getAllClinvar(QueryOptions options) {
    //        options.addToListOption("include", "clinvarSet");
    //        options.addToListOption("include", "chromosome");
    //        options.addToListOption("include", "start");
    //        options.addToListOption("include", "end");
    //        options.addToListOption("include", "reference");
    //        options.addToListOption("include", "alternate");
    //        options.addToListOption("include", "annot");
    QueryBuilder builder = QueryBuilder.start();

    builder = addClinvarFilters(builder, options);

    //        List<DBObject> pipeline = new ArrayList<>();
    //        pipeline = addClinvarAggregationFilters(pipeline, options);
    //        DBObject fields = new BasicDBObject();
    //        fields.put("clinvarSet", 1);
    //        fields.put("chromosome", 1);
    //        fields.put("start", 1);
    //        fields.put("end", 1);
    //        fields.put("reference", 1);
    //        fields.put("alternate", 1);
    //        fields.put("annot", 1);
    //        pipeline.add(new BasicDBObject("$project", fields));

    //        return executeAggregation2("", pipeline, options);
    return executeQuery("result", builder.get(), options);
    //        return prepareClinvarQueryResultList(Collections.singletonList(executeQuery("result", builder.get(), options))).get(0);
}

From source file:org.opencb.cellbase.mongodb.db.variation.ClinicalMongoDBAdaptor.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("end")
                .greaterThanEquals(region.getStart()).and("start").lessThanEquals(region.getEnd());

        queries.add(builder.get());
        ids.add(region.toString());//w ww  .j  a v a  2  s.c om
    }
    return executeQueryList2(ids, queries, options);
}

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

License:Apache License

@Override
public List<QueryResult> getAllByGenomicVariantList(List<GenomicVariant> variantList, QueryOptions options) {
    List<DBObject> queries = new ArrayList<>();
    List<String> ids = new ArrayList<>(variantList.size());
    List<QueryResult> queryResultList;
    for (GenomicVariant genomicVariant : variantList) {
        QueryBuilder builder = QueryBuilder.start("chromosome").is(genomicVariant.getChromosome()).and("start")
                .is(genomicVariant.getPosition()).and("alternate").is(genomicVariant.getAlternative());
        if (genomicVariant.getReference() != null) {
            builder = builder.and("reference").is(genomicVariant.getReference());
        }/*from  w  ww  . j a  va2 s  .  co m*/
        queries.add(builder.get());
        ids.add(genomicVariant.toString());
    }

    queryResultList = executeQueryList2(ids, queries, options);

    for (QueryResult queryResult : queryResultList) {
        List<BasicDBObject> clinicalList = (List<BasicDBObject>) queryResult.getResult();

        List<Cosmic> cosmicList = new ArrayList<>();
        List<Gwas> gwasList = new ArrayList<>();
        List<Clinvar> clinvarList = new ArrayList<>();

        for (Object clinicalObject : clinicalList) {
            BasicDBObject clinical = (BasicDBObject) clinicalObject;

            if (isCosmic(clinical)) {
                Cosmic cosmic = getCosmic(clinical);
                //                    if (cosmicList == null) {
                //                        cosmicList = new ArrayList<>();
                //                    }
                cosmicList.add(cosmic);
            } else if (isGwas(clinical)) {
                Gwas gwas = getGwas(clinical);
                //                    if (gwasList == null) {
                //                        gwasList = new ArrayList<>();
                //                    }
                gwasList.add(gwas);

            } else if (isClinvar(clinical)) {
                Clinvar clinvar = getClinvar(clinical);
                //                    if (clinvarList == null) {
                //                        clinvarList = new ArrayList<>();
                //                    }
                clinvarList.add(clinvar);
            }
        }
        Map<String, Object> clinicalData = new HashMap<>();
        if (cosmicList != null && cosmicList.size() > 0) {
            clinicalData.put("cosmic", cosmicList);
        }
        if (gwasList != null && gwasList.size() > 0) {
            clinicalData.put("gwas", gwasList);
        }
        if (clinvarList != null && clinvarList.size() > 0) {
            clinicalData.put("clinvar", clinvarList);
        }
        if (!clinicalData.isEmpty()) {
            // FIXME quick solution to compile
            //            queryResult.setResult(clinicalData);
            queryResult.setResult(Arrays.asList(clinicalData));
            queryResult.setNumResults(cosmicList.size() + clinvarList.size() + gwasList.size());
        } else {
            queryResult.setResult(null);
            queryResult.setNumResults(0);
        }
    }

    return queryResultList;
}

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

License:Apache License

public QueryResult updateAnnotations(List<VariantAnnotation> variantAnnotations, QueryOptions queryOptions) {

    /**/* w ww  . j  av a 2 s .c  om*/
     * Multiple documents may contain the same annotation
     */
    queryOptions.put("multi", true);

    /**
     * Prepare jackson to generate json strings
     */
    ObjectMapper jsonObjectMapper = new ObjectMapper();
    jsonObjectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
    jsonObjectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    ObjectWriter writer = jsonObjectMapper.writer();

    long start = System.nanoTime();
    for (VariantAnnotation variantAnnotation : variantAnnotations) {
        QueryBuilder builder = QueryBuilder.start("chromosome").is(variantAnnotation.getChromosome())
                .and("start").is(variantAnnotation.getStart()).and("reference")
                .is(variantAnnotation.getReferenceAllele()).and("alternate")
                .is(variantAnnotation.getAlternateAllele());
        DBObject update = null;
        try {
            update = new BasicDBObject("$set",
                    new BasicDBObject("annot", JSON.parse(writer.writeValueAsString(variantAnnotation))));
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        //            DBObject update = new BasicDBObject("$set", new BasicDBObject("annotation",
        //                    convertVariantAnnotation(variantAnnotation)));
        mongoDBCollection.update(builder.get(), update, queryOptions);
    }

    return new QueryResult<>("", ((int) (System.nanoTime() - start)), 1, 1, "", "", new ArrayList());
}

From source file:org.opencb.cellbase.mongodb.db.variation.ClinVarMongoDBAdaptor.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("referenceClinVarAssertion.clinVarAccession.acc").is(id);
        queries.add(builder.get());
    }/* w w w  . ja  v  a2  s  . c  o m*/

    return executeQueryList2(idList, queries, options);
}

From source file:org.opencb.cellbase.mongodb.db.variation.ClinVarMongoDBAdaptor.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) {

        // If regions is 1 position then query can be optimize using chunks
        QueryBuilder builder = QueryBuilder
                .start("referenceClinVarAssertion.measureSet.measure.measureRelationship.sequenceLocation.chr")
                .is(region.getChromosome())
                .and("referenceClinVarAssertion.measureSet.measure.measureRelationship.sequenceLocation.stop")
                .greaterThanEquals(region.getStart())
                .and("referenceClinVarAssertion.measureSet.measure.measureRelationship.sequenceLocation.start")
                .lessThanEquals(region.getEnd());
        System.out.println(builder.get().toString());
        queries.add(builder.get());//from   w  ww  . j  a v  a  2 s .  c  o m
        ids.add(region.toString());
    }
    return executeQueryList2(ids, queries, options);
}

From source file:org.opencb.cellbase.mongodb.db.variation.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());
    }/*w w w  . j  a va2s.c o  m*/

    return executeQueryList2(idList, queries, options);
}