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

License:Apache License

@Override
public List<QueryResult> getAllByGenomicVariantList(List<Variant> variantList, QueryOptions options) {
    List<Document> queries = new ArrayList<>();
    List<String> ids = new ArrayList<>(variantList.size());
    List<QueryResult> queryResultList;
    for (Variant genomicVariant : variantList) {
        QueryBuilder builder = QueryBuilder.start("chromosome").is(genomicVariant.getChromosome()).and("start")
                .is(genomicVariant.getStart()).and("alternate").is(genomicVariant.getAlternate());
        if (genomicVariant.getReference() != null) {
            builder = builder.and("reference").is(genomicVariant.getReference());
        }//from   ww w.  j  av  a 2 s  .com
        queries.add(new Document(builder.get().toMap()));
        ids.add(genomicVariant.toString());
    }

    queryResultList = executeQueryList2(ids, queries, options);

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

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

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

            if (isCosmic(clinical)) {
                Cosmic cosmic = getCosmic(clinical);
                cosmicList.add(cosmic);
            } else if (isGwas(clinical)) {
                Gwas gwas = getGwas(clinical);
                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);
        //            }
        VariantTraitAssociation variantTraitAssociation = new VariantTraitAssociation(clinvarList, gwasList,
                cosmicList);
        if (!(variantTraitAssociation.getCosmic().isEmpty() && variantTraitAssociation.getGwas().isEmpty()
                && variantTraitAssociation.getClinvar().isEmpty())) {

            // FIXME quick solution to compile
            // queryResult.setResult(clinicalData);
            queryResult.setResult(Collections.singletonList(variantTraitAssociation));
            queryResult.setNumResults(variantTraitAssociation.getCosmic().size()
                    + variantTraitAssociation.getGwas().size() + variantTraitAssociation.getClinvar().size());
        } else {
            queryResult.setResult(null);
            queryResult.setNumResults(0);
        }
    }

    return queryResultList;
}

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

License:Apache License

public QueryResult getListClinvarAccessions(QueryOptions queryOptions) {
    QueryBuilder builder = QueryBuilder.start("clinvarSet.referenceClinVarAssertion.clinVarAccession.acc")
            .exists(true);/*from  www . j a va 2  s. c om*/
    queryOptions.put("include", Arrays.asList("clinvarSet.referenceClinVarAssertion.clinVarAccession.acc"));
    QueryResult queryResult = executeQuery("", new Document(builder.get().toMap()), queryOptions);
    List accInfoList = (List) queryResult.getResult();
    List<String> accList = new ArrayList<>(accInfoList.size());
    Document accInfo;
    QueryResult listAccessionsToReturn = new QueryResult();

    for (Object accInfoObject : accInfoList) {
        accInfo = (Document) accInfoObject;
        accInfo = (Document) accInfo.get("clinvarSet");
        accList.add((String) ((Document) ((Document) ((Document) accInfo.get("referenceClinVarAssertion")))
                .get("clinVarAccession")).get("acc"));
    }

    // setting listAccessionsToReturn fields
    listAccessionsToReturn.setId(queryResult.getId());
    listAccessionsToReturn.setDbTime(queryResult.getDbTime());
    listAccessionsToReturn.setNumResults(queryResult.getNumResults());
    listAccessionsToReturn.setNumTotalResults(queryResult.getNumTotalResults());
    listAccessionsToReturn.setResult(accList);

    return listAccessionsToReturn;
}

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

License:Apache License

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

    /**//from w  w  w  .  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);
    jsonObjectMapper.configure(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS, true);
    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.getReference()).and("alternate").is(variantAnnotation.getAlternate());
        Document update = null;
        try {
            update = new Document("$set",
                    new Document("annot", JSON.parse(writer.writeValueAsString(variantAnnotation))));
            update.put("$addToSet",
                    new Document("_geneIds", new Document("$each", getGeneIds(variantAnnotation))));
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        //            Document update = new Document("$set", new Document("annotation",
        //                    convertVariantAnnotation(variantAnnotation)));
        mongoDBCollection.update(new Document(builder.get().toMap()), update, queryOptions);
    }

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

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

License:Apache License

@Override
public List<QueryResult> getAllByIdList(List<String> idList, QueryOptions options) {
    List<Document> queries = new ArrayList<>(idList.size());
    for (String id : idList) {
        QueryBuilder builder = QueryBuilder.start("referenceClinVarAssertion.clinVarAccession.acc").is(id);
        queries.add(new Document(builder.get().toMap()));
    }//from  w w w  .j  ava2 s. c o m

    return executeQueryList2(idList, queries, options);
}

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

        // 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(new Document(builder.get().toMap()).toString());
        queries.add(new Document(builder.get().toMap()));
        ids.add(region.toString());/*from   ww  w . j  av a2 s  .com*/
    }
    return executeQueryList2(ids, queries, options);
}

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

License:Apache License

public QueryResult getListAccessions(QueryOptions queryOptions) {
    QueryBuilder builder = QueryBuilder.start();
    queryOptions.put("include", Arrays.asList("referenceClinVarAssertion.clinVarAccession.acc"));
    QueryResult queryResult = executeQuery("", new Document(builder.get().toMap()), queryOptions);
    BasicDBList accInfoList = (BasicDBList) queryResult.getResult();
    List<String> accList = new ArrayList<>(accInfoList.size());
    Document accInfo;//from   ww w.  j a va  2  s . c o  m
    QueryResult listAccessionsToReturn = new QueryResult();

    for (Object accInfoObject : accInfoList) {
        accInfo = (Document) accInfoObject;
        accInfo = (Document) accInfo.get("referenceClinVarAssertion");
        accInfo = (Document) accInfo.get("clinVarAccession");
        accList.add((String) accInfo.get("acc"));
    }

    // setting listAccessionsToReturn fields
    listAccessionsToReturn.setId(queryResult.getId());
    listAccessionsToReturn.setDbTime(queryResult.getDbTime());
    listAccessionsToReturn.setNumResults(queryResult.getNumResults());
    listAccessionsToReturn.setResult(accList);

    return listAccessionsToReturn;
}

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

License:Apache License

@Override
public QueryResult getAll(QueryOptions options) {
    QueryBuilder builder = new QueryBuilder();

    List<Object> biotypes = options.getList("disease", null);
    if (biotypes != null && biotypes.size() > 0) {
        BasicDBList biotypeIds = new BasicDBList();
        biotypeIds.addAll(biotypes);/*  www  . j  a  va2 s . c  o  m*/
        builder = builder.and("primaryHistology").in(biotypeIds);
    }

    return executeQuery("result", new Document(builder.get().toMap()), options);
}

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

License:Apache License

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

    return executeQueryList2(idList, queries, options);
}

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  va 2 s.  c  o  m*/

    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 ww w.ja v  a 2 s . co  m

    return executeQueryList2(geneNameList, queries, options);
}