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.impl.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 w  w  w. j  av  a2 s.  c  o  m
        queries.add(new Document(builder.get().toMap()));
        logger.debug(new Document(builder.get().toMap()).toJson());
        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.impl.ConservationMongoDBAdaptor.java

License:Apache License

public List<QueryResult> getAllByRegionList(List regionList, QueryOptions options) {
    //TODO not finished yet
    List<Document> queries = new ArrayList<>();
    List<String> ids = new ArrayList<>(regionList.size());
    List<String> 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);//from  w ww  .  j  ava2 s. c  o  m
        }
        if (region.getEnd() < 1) {
            region.setEnd(1);
        }

        // Max region size is 10000bp
        if (region.getEnd() - region.getStart() > 10000) {
            region.setEnd(region.getStart() + 10000);
        }

        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);
            //                    integerChunkIds.add(region.getChromosomeInfo() + "_" + chunkId + "_" + this.chunkSize/1000 + "k");
            //                }
            //                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());
        }
        //            QueryBuilder builder = QueryBuilder.start("chromosome").is(region.getChromosomeInfo()).and("chunkId").in(hunkIds);
        /****/

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

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

    List<QueryResult> queryResults = executeQueryList2(ids, queries, options);
    for (int i = 0; i < regions.size(); i++) {
        Region region = regions.get(i);
        QueryResult queryResult = queryResults.get(i);
        //            BasicDBList list = (BasicDBList) queryResult.getResult();
        List list = queryResult.getResult();

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

        //            int start = region.getStart();

        for (int j = 0; j < list.size(); j++) {
            Document chunk = (Document) list.get(j);
            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);
            }

            //                BasicDBList valuesChunk = (BasicDBList) chunk.get("values");
            ArrayList 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++) {
                //                    System.out.println("valuesList SIZE = " + valuesList.size());
                //                    System.out.println("pos = " + pos);
                //                    System.out.println("DIV " + (chunk.getInt("start") - region.getStart()));
                //                    System.out.println("valuesChunk = " + valuesChunk.get(pos));
                //                    System.out.println("indexFinal = " + (pos + chunk.getInt("start") - region.getStart()));
                valuesList.set(pos + chunk.getInteger("start") - region.getStart(),
                        new Float((Double) valuesChunk.get(pos)));
            }
        }
        //
        BasicDBList resultList = new BasicDBList();
        //            ConservationScoreRegion conservedRegionChunk;
        GenomicScoreRegion<Float> conservedRegionChunk;
        for (Map.Entry<String, List<Float>> elem : typeMap.entrySet()) {
            //                conservedRegionChunk = new ConservationScoreRegion(region.getChromosome(), region.getStart(),
            //                        region.getEnd(), elem.getKey(), elem.getValue());
            conservedRegionChunk = new GenomicScoreRegion<>(region.getChromosome(), region.getStart(),
                    region.getEnd(), elem.getKey(), elem.getValue());
            resultList.add(conservedRegionChunk);
        }
        queryResult.setResult(resultList);
    }

    return queryResults;
}

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

License:Apache License

@Override
@Deprecated/* w w w .jav  a 2s.c  o m*/
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(), null));
                    }
                }
            }
            if (!resultList.isEmpty()) {
                queryResult.setResult(resultList);
            } else {
                queryResult.setResult(null);
            }
        }

    }
    return queryResults;
}

From source file:org.opencb.cellbase.lib.impl.GenomeMongoDBAdaptor.java

License:Apache License

@Override
//    public List<QueryResult<ConservationScoreRegion>> getConservation(List<Region> regionList, QueryOptions options) {
public List<QueryResult<GenomicScoreRegion<Float>>> getConservation(List<Region> regionList,
        QueryOptions options) {/* w w w . j  a va  2 s. com*/
    //TODO not finished yet
    List<Document> queries = new ArrayList<>();
    List<String> ids = new ArrayList<>(regionList.size());
    List<String> 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);
        }

        // Max region size is 10000bp
        if (region.getEnd() - region.getStart() > 10000) {
            region.setEnd(region.getStart() + 10000);
        }

        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);
            //                    integerChunkIds.add(region.getChromosomeInfo() + "_" + chunkId + "_" + this.chunkSize/1000 + "k");
            //                }
            //                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());
        }
        //            QueryBuilder builder = QueryBuilder.start("chromosome").is(region.getChromosomeInfo()).and("chunkId").in(hunkIds);
        /****/

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

    List<QueryResult> queryResults = executeQueryList2(ids, queries, options, conservationMongoDBCollection);
    //        List<QueryResult<ConservationScoreRegion>> conservationQueryResults = new ArrayList<>();
    List<QueryResult<GenomicScoreRegion<Float>>> conservationQueryResults = new ArrayList<>();

    for (int i = 0; i < regions.size(); i++) {
        Region region = regions.get(i);
        QueryResult queryResult = queryResults.get(i);
        //            QueryResult<ConservationScoreRegion> conservationQueryResult = new QueryResult<>();
        QueryResult<GenomicScoreRegion<Float>> conservationQueryResult = new QueryResult<>();

        //            BasicDBList list = (BasicDBList) queryResult.getResult();
        List list = queryResult.getResult();

        Map<String, List<Float>> typeMap = new HashMap<>();
        for (int j = 0; j < list.size(); j++) {
            Document chunk = (Document) list.get(j);
            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);
            }

            //                BasicDBList valuesChunk = (BasicDBList) chunk.get("values");
            ArrayList 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)));
            }
        }

        //            BasicDBList resultList = new BasicDBList();
        //            List<ConservationScoreRegion> resultList = new ArrayList<>();
        List<GenomicScoreRegion<Float>> resultList = new ArrayList<>();
        //            ConservationScoreRegion conservedRegionChunk;
        GenomicScoreRegion<Float> conservedRegionChunk;
        for (Map.Entry<String, List<Float>> elem : typeMap.entrySet()) {
            //                conservedRegionChunk = new ConservationScoreRegion(region.getChromosome(), region.getStart(), region.getEnd(),
            //                        elem.getKey(), elem.getValue());
            conservedRegionChunk = new GenomicScoreRegion<>(region.getChromosome(), region.getStart(),
                    region.getEnd(), elem.getKey(), elem.getValue());
            resultList.add(conservedRegionChunk);
        }
        //            queryResult.setResult(resultList);
        conservationQueryResult.setResult(resultList);
        conservationQueryResults.add(conservationQueryResult);
    }

    return conservationQueryResults;
}

From source file:org.opencb.cellbase.lib.impl.VariantMongoDBAdaptor.java

License:Apache License

@Override
public QueryResult<Score> getFunctionalScoreVariant(Variant variant, QueryOptions queryOptions) {
    String chromosome = variant.getChromosome();
    int position = variant.getStart();
    String reference = variant.getReference();
    String alternate = variant.getAlternate();

    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, caddDBCollection);

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

    List<Score> scores = new ArrayList<>();
    for (Object object : result.getResult()) {
        //            System.out.println("object = " + object);
        Document dbObject = (Document) object;
        int chunkStart = dbObject.getInteger("start");
        int chunkEnd = dbObject.getInteger("end");
        // CADD positions are not continuous through the whole chromosome. Several documents may be associated with
        // the same chunk id: we have to be sure that current document contains queried position. Only two documents
        // will contain queried position - one for raw and one for scaled values
        if (position >= chunkStart && position <= chunkEnd) {
            int offset = (position - chunkStart);
            ArrayList basicDBList = dbObject.get("values", ArrayList.class);

            //                long l1 = 0L; // TODO: delete
            //                try { // TODO: delete
            long l1 = Long.parseLong(basicDBList.get(offset).toString());
            //                                 l1 = (Long) basicDBList.get(offset);
            //                } catch (Exception e) {  // TODO: delete
            //                    logger.error("problematic variant: {}", variant.toString());
            //                    throw e;
            //                }

            if (dbObject.getString("source").equalsIgnoreCase("cadd_raw")) {
                float value = 0f;
                switch (alternate.toLowerCase()) {
                case "a":
                    //                            value = ((short) (l1 >> 48) - 10000) / DECIMAL_RESOLUTION;
                    value = (((short) (l1 >> 48)) / DECIMAL_RESOLUTION) - 10;
                    break;
                case "c":
                    value = (((short) (l1 >> 32)) / DECIMAL_RESOLUTION) - 10;
                    break;
                case "g":
                    value = (((short) (l1 >> 16)) / DECIMAL_RESOLUTION) - 10;
                    break;
                case "t":
                    value = (((short) (l1 >> 0)) / DECIMAL_RESOLUTION) - 10;
                    break;
                default:
                    break;
                }//w  w w. j av  a  2s.co  m
                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.mongodb.db.ChromosomeMongoDBAdaptor.java

License:Apache License

public QueryResult speciesInfoTmp(String id, QueryOptions options) {
    // reading application.properties file

    //        String[] speciesArray = applicationProperties.getProperty("SPECIES").split(",");

    //        List<DBObject> queries = new ArrayList<>(1);
    //        for (String id : idList) {
    QueryBuilder builder = QueryBuilder.start("species").is(id);

    //        queries.add(builder.get());
    //        }/*from   w  w w .  j  a va2s  . c om*/

    //        options = addExcludeReturnFields("transcripts", options);
    return executeQuery(id, builder.get(), options);

}

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

License:Apache License

@Override
public List<QueryResult> getAllClinvarByIdList(List<String> idList, QueryOptions options) {
    List<DBObject> queries = new ArrayList<>(idList.size());
    options.addToListOption("include", "clinvarList");
    options.addToListOption("include", "chromosome");
    options.addToListOption("include", "start");
    options.addToListOption("include", "end");
    options.addToListOption("include", "reference");
    options.addToListOption("include", "alternate");
    for (String id : idList) {
        if (id.toLowerCase().startsWith("rcv")) {
            QueryBuilder builder = addClinvarQueryFilters(QueryBuilder
                    .start("clinvarList.clinvarSet.referenceClinVarAssertion.clinVarAccession.acc").is(id),
                    options);/* w  w  w. j  a  v  a  2  s  .  co  m*/
            queries.add(builder.get());
        } else if (id.toLowerCase().startsWith("rs")) {
            QueryBuilder builder = addClinvarQueryFilters(QueryBuilder.start(
                    "clinvarList.clinvarSet.referenceClinVarAssertion.measureSet.measure.attributeSet.xref.type")
                    .is("rs")
                    .and("clinvarList.clinvarSet.referenceClinVarAssertion.measureSet.measure.attributeSet.xref.id")
                    .is(id), options);
            queries.add(builder.get());
        }
    }
    return prepareClinvarQueryResultList(executeQueryList2(idList, queries, options));
}

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

License:Apache License

@Override
public List<QueryResult> getAllClinvarByGeneList(List<String> geneList, QueryOptions options) {
    List<DBObject> queries = new ArrayList<>(geneList.size());
    options.addToListOption("include", "clinvarList");
    options.addToListOption("include", "chromosome");
    options.addToListOption("include", "start");
    options.addToListOption("include", "end");
    options.addToListOption("include", "reference");
    options.addToListOption("include", "alternate");
    for (String gene : geneList) {
        QueryBuilder builder = addClinvarQueryFilters(QueryBuilder.start(
                "clinvarList.clinvarSet.referenceClinVarAssertion.measureSet.measure.measureRelationship.symbol.elementValue.value")
                .is(gene), options);/*from w  w w.j  a  v  a 2 s  .co m*/
        queries.add(builder.get());
    }

    return prepareClinvarQueryResultList(executeQueryList2(geneList, queries, options));
}

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

License:Apache License

private QueryBuilder addClinvarRegionFilter(QueryBuilder builder, QueryOptions options) {
    List<Object> regions = options.getList("region", null);
    BasicDBList regionList = new BasicDBList();
    if (regions != null) {
        Region region = (Region) regions.get(0);
        QueryBuilder regionQueryBuilder = QueryBuilder.start("chromosome").is(region.getChromosome()).and("end")
                .greaterThanEquals(region.getStart()).and("start").lessThanEquals(region.getEnd());
        for (int i = 1; i < regions.size(); i++) {
            region = (Region) regions.get(i);
            regionQueryBuilder = regionQueryBuilder.or(QueryBuilder.start("chromosome")
                    .is(region.getChromosome()).and("end").greaterThanEquals(region.getStart()).and("start")
                    .lessThanEquals(region.getEnd()).get());
        }//from   w w w. j a v  a 2s  .c  o  m
        builder = builder.and(regionQueryBuilder.get());
    }
    return builder;
}

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

License:Apache License

@Override
public List<QueryResult> getAllClinvarByRegionList(List<Region> regions, QueryOptions options) {
    List<DBObject> queries = new ArrayList<>();

    options.addToListOption("include", "clinvarList");
    options.addToListOption("include", "chromosome");
    options.addToListOption("include", "start");
    options.addToListOption("include", "end");
    options.addToListOption("include", "reference");
    options.addToListOption("include", "alternate");
    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("chromosome").is(region.getChromosome()).and("end")
                .greaterThanEquals(region.getStart()).and("start").lessThanEquals(region.getEnd());
        builder = addClinvarQueryFilters(builder, options);
        System.out.println(builder.get().toString());
        queries.add(builder.get());//from   w w w  .j av  a2s .c om
        ids.add(region.toString());
    }
    return prepareClinvarQueryResultList(executeQueryList2(ids, queries, options));
}