Example usage for com.mongodb BasicDBList get

List of usage examples for com.mongodb BasicDBList get

Introduction

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

Prototype

public Object get(final String key) 

Source Link

Document

Gets a value at an index.

Usage

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

License:Apache License

private void solveCodingPositiveTranscript(Boolean isInsertion, GenomicVariant variant, HashSet<String> SoNames,
        BasicDBObject transcriptInfo, Integer transcriptStart, Integer transcriptEnd, Integer variantStart,
        Integer variantEnd, Integer cdsLength, BasicDBList transcriptFlags,
        ConsequenceType consequenceTypeTemplate) {
    Integer genomicCodingStart;/*from  ww  w . j  a  v  a  2 s.c  o  m*/
    Integer genomicCodingEnd;
    Integer cdnaCodingStart;
    Integer cdnaCodingEnd;
    BasicDBList exonInfoList;
    BasicDBObject exonInfo;
    Integer exonStart;
    Integer exonEnd;
    String transcriptSequence;
    Boolean variantAhead;
    Integer cdnaExonEnd;
    Integer cdnaVariantStart;
    Integer cdnaVariantEnd;
    Boolean splicing;
    int exonCounter;
    int firstCdsPhase = -1;
    Integer prevSpliceSite;
    Boolean[] junctionSolution = { false, false };

    genomicCodingStart = (Integer) transcriptInfo.get("genomicCodingStart");
    genomicCodingEnd = (Integer) transcriptInfo.get("genomicCodingEnd");
    cdnaCodingStart = (Integer) transcriptInfo.get("cdnaCodingStart");
    cdnaCodingEnd = (Integer) transcriptInfo.get("cdnaCodingEnd");
    exonInfoList = (BasicDBList) transcriptInfo.get("exons");
    exonInfo = (BasicDBObject) exonInfoList.get(0);
    exonStart = (Integer) exonInfo.get("start");
    exonEnd = (Integer) exonInfo.get("end");
    transcriptSequence = (String) exonInfo.get("sequence");
    variantAhead = true; // we need a first iteration within the while to ensure junction is solved in case needed
    cdnaExonEnd = (exonEnd - exonStart + 1);
    cdnaVariantStart = null;
    cdnaVariantEnd = null;
    junctionSolution[0] = false;
    junctionSolution[1] = false;
    splicing = false;

    if (firstCdsPhase == -1 && genomicCodingStart <= exonEnd) {
        firstCdsPhase = (int) exonInfo.get("phase");
    }
    if (variantStart >= exonStart) {
        if (variantStart <= exonEnd) { // Variant start within the exon
            cdnaVariantStart = cdnaExonEnd - (exonEnd - variantStart);
            consequenceTypeTemplate.setcDnaPosition(cdnaVariantStart);
            if (variantEnd <= exonEnd) { // Both variant start and variant end within the exon  ----||||S|||||E||||----
                cdnaVariantEnd = cdnaExonEnd - (exonEnd - variantEnd);
            }
        }
    } else {
        if (variantEnd <= exonEnd) {
            //                                if(variantEnd >= exonStart) {  // Only variant end within the exon  ----||||||||||E||||----
            // We do not contemplate that variant end can be located before this exon since this is the first exon
            cdnaVariantEnd = cdnaExonEnd - (exonEnd - variantEnd);
            //                                }
        } // Variant includes the whole exon. Variant start is located before the exon, variant end is located after the exon
    }

    exonCounter = 1;
    while (exonCounter < exonInfoList.size() && variantAhead) { // This is not a do-while since we cannot call solveJunction  until
        //        while(exonCounter<exonInfoList.size() && !splicing && variantAhead) {  // This is not a do-while since we cannot call solveJunction  until
        exonInfo = (BasicDBObject) exonInfoList.get(exonCounter); // next exon has been loaded
        exonStart = (Integer) exonInfo.get("start");
        prevSpliceSite = exonEnd + 1;
        exonEnd = (Integer) exonInfo.get("end");
        transcriptSequence = transcriptSequence + ((String) exonInfo.get("sequence"));
        if (firstCdsPhase == -1 && genomicCodingStart <= exonEnd) { // Set firsCdsPhase only when the first coding exon is reached
            firstCdsPhase = (int) exonInfo.get("phase");
        }
        solveJunction(isInsertion, prevSpliceSite, exonStart - 1, variantStart, variantEnd, SoNames,
                "splice_donor_variant", "splice_acceptor_variant", junctionSolution);
        splicing = (splicing || junctionSolution[0]);

        if (variantStart >= exonStart) {
            cdnaExonEnd += (exonEnd - exonStart + 1);
            if (variantStart <= exonEnd) { // Variant start within the exon
                cdnaVariantStart = cdnaExonEnd - (exonEnd - variantStart);
                consequenceTypeTemplate.setcDnaPosition(cdnaVariantStart);
                if (variantEnd <= exonEnd) { // Both variant start and variant end within the exon  ----||||S|||||E||||----
                    cdnaVariantEnd = cdnaExonEnd - (exonEnd - variantEnd);
                }
            }
        } else {
            if (variantEnd <= exonEnd) {
                if (variantEnd >= exonStart) { // Only variant end within the exon  ----||||||||||E||||----
                    cdnaExonEnd += (exonEnd - exonStart + 1);
                    cdnaVariantEnd = cdnaExonEnd - (exonEnd - variantEnd);
                } else { // Variant does not include this exon, variant is located before this exon
                    variantAhead = false;
                }
            } else { // Variant includes the whole exon. Variant start is located before the exon, variant end is located after the exon
                cdnaExonEnd += (exonEnd - exonStart + 1);
            }
        }
        exonCounter++;
    }
    // Is not intron variant (both ends fall within the same intron)
    if (!junctionSolution[1]) {
        if (isInsertion) {
            if (cdnaVariantStart == null && cdnaVariantEnd != null) { // To account for those insertions in the 3' end of an intron
                cdnaVariantStart = cdnaVariantEnd - 1;
            } else if (cdnaVariantEnd == null && cdnaVariantStart != null) { // To account for those insertions in the 5' end of an intron
                cdnaVariantEnd = cdnaVariantStart + 1;
            }
        }
        solveCodingPositiveTranscriptEffect(splicing, transcriptSequence, transcriptStart, transcriptEnd,
                genomicCodingStart, genomicCodingEnd, variantStart, variantEnd, cdnaCodingStart, cdnaCodingEnd,
                cdnaVariantStart, cdnaVariantEnd, // Be careful, originalVariantStart is used here!
                cdsLength, transcriptFlags, firstCdsPhase, variant.getReference(), variant.getAlternative(),
                SoNames, consequenceTypeTemplate);
    }
}

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

License:Apache License

private void solveCodingNegativeTranscript(Boolean isInsertion, GenomicVariant variant, HashSet<String> SoNames,
        BasicDBObject transcriptInfo, Integer transcriptStart, Integer transcriptEnd, Integer variantStart,
        Integer variantEnd, Integer cdsLength, BasicDBList transcriptFlags,
        ConsequenceType consequenceTypeTemplate) {
    Integer genomicCodingStart;/*from   www . j a va 2s.c  om*/
    Integer genomicCodingEnd;
    Integer cdnaCodingStart;
    Integer cdnaCodingEnd;
    BasicDBList exonInfoList;
    BasicDBObject exonInfo;
    Integer exonStart;
    Integer exonEnd;
    String transcriptSequence;
    Boolean variantAhead;
    Integer cdnaExonEnd;
    Integer cdnaVariantStart;
    Integer cdnaVariantEnd;
    Boolean splicing;
    int exonCounter;
    int firstCdsPhase = -1;
    Integer prevSpliceSite;
    Boolean[] junctionSolution = { false, false };

    genomicCodingStart = (Integer) transcriptInfo.get("genomicCodingStart");
    genomicCodingEnd = (Integer) transcriptInfo.get("genomicCodingEnd");
    cdnaCodingStart = (Integer) transcriptInfo.get("cdnaCodingStart");
    cdnaCodingEnd = (Integer) transcriptInfo.get("cdnaCodingEnd");
    exonInfoList = (BasicDBList) transcriptInfo.get("exons");
    exonInfo = (BasicDBObject) exonInfoList.get(0);
    exonStart = (Integer) exonInfo.get("start");
    exonEnd = (Integer) exonInfo.get("end");
    transcriptSequence = (String) exonInfo.get("sequence");
    variantAhead = true; // we need a first iteration within the while to ensure junction is solved in case needed
    cdnaExonEnd = (exonEnd - exonStart + 1); // cdnaExonEnd poinst to the same base than exonStart
    cdnaVariantStart = null; // cdnaVariantStart points to the same base than variantEnd
    cdnaVariantEnd = null; // cdnaVariantEnd points to the same base than variantStart
    junctionSolution[0] = false;
    junctionSolution[1] = false;
    splicing = false;

    if (firstCdsPhase == -1 && genomicCodingEnd >= exonStart) {
        firstCdsPhase = (int) exonInfo.get("phase");
    }
    if (variantEnd <= exonEnd) {
        if (variantEnd >= exonStart) { // Variant end within the exon
            cdnaVariantStart = cdnaExonEnd - (variantEnd - exonStart);
            consequenceTypeTemplate.setcDnaPosition(cdnaVariantStart);
            if (variantStart >= exonStart) { // Both variant start and variant end within the exon  ----||||S|||||E||||----
                cdnaVariantEnd = cdnaExonEnd - (variantStart - exonStart);
            }
        }
    } else {
        if (variantStart >= exonStart) {
            //                                if(variantEnd >= exonStart) {  // Only variant end within the exon  ----||||||||||E||||----
            // We do not contemplate that variant end can be located before this exon since this is the first exon
            cdnaVariantEnd = cdnaExonEnd - (variantEnd - exonStart);
            //                                }
        } // Variant includes the whole exon. Variant end is located before the exon, variant start is located after the exon
    }

    exonCounter = 1;
    while (exonCounter < exonInfoList.size() && variantAhead) { // This is not a do-while since we cannot call solveJunction  until
        //        while(exonCounter<exonInfoList.size() && !splicing && variantAhead) {  // This is not a do-while since we cannot call solveJunction  until
        exonInfo = (BasicDBObject) exonInfoList.get(exonCounter); // next exon has been loaded
        prevSpliceSite = exonStart - 1;
        exonStart = (Integer) exonInfo.get("start");
        exonEnd = (Integer) exonInfo.get("end");
        transcriptSequence = ((String) exonInfo.get("sequence")) + transcriptSequence;
        if (firstCdsPhase == -1 && genomicCodingEnd >= exonStart) { // Set firsCdsPhase only when the first coding exon is reached
            firstCdsPhase = (int) exonInfo.get("phase");
        }
        solveJunction(isInsertion, exonEnd + 1, prevSpliceSite, variantStart, variantEnd, SoNames,
                "splice_acceptor_variant", "splice_donor_variant", junctionSolution);
        splicing = (splicing || junctionSolution[0]);

        if (variantEnd <= exonEnd) {
            cdnaExonEnd += (exonEnd - exonStart + 1);
            if (variantEnd >= exonStart) { // Variant end within the exon
                cdnaVariantStart = cdnaExonEnd - (variantEnd - exonStart);
                consequenceTypeTemplate.setcDnaPosition(cdnaVariantStart);
                if (variantStart >= exonStart) { // Both variant start and variant end within the exon  ----||||S|||||E||||----
                    cdnaVariantEnd = cdnaExonEnd - (variantStart - exonStart);
                }
            }
        } else {
            if (variantStart >= exonStart) {
                if (variantStart <= exonEnd) { // Only variant start within the exon  ----||||||||||E||||----
                    cdnaExonEnd += (exonEnd - exonStart + 1);
                    cdnaVariantEnd = cdnaExonEnd - (variantStart - exonStart);
                } else { // Variant does not include this exon, variant is located before this exon
                    variantAhead = false;
                }
            } else { // Variant includes the whole exon. Variant start is located before the exon, variant end is located after the exon
                cdnaExonEnd += (exonEnd - exonStart + 1);
            }
        }
        exonCounter++;
    }
    // Is not intron variant (both ends fall within the same intron)
    if (!junctionSolution[1]) {
        if (isInsertion) {
            if (cdnaVariantStart == null && cdnaVariantEnd != null) { // To account for those insertions in the 3' end of an intron
                cdnaVariantStart = cdnaVariantEnd - 1;
            } else if (cdnaVariantEnd == null && cdnaVariantStart != null) { // To account for those insertions in the 5' end of an intron
                cdnaVariantEnd = cdnaVariantStart + 1;
            }
        }
        solveCodingNegativeTranscriptEffect(splicing, transcriptSequence, transcriptStart, transcriptEnd,
                genomicCodingStart, genomicCodingEnd, variantStart, variantEnd, cdnaCodingStart, cdnaCodingEnd,
                cdnaVariantStart, cdnaVariantEnd, cdsLength, transcriptFlags, firstCdsPhase,
                variant.getReference(), variant.getAlternative(), SoNames, consequenceTypeTemplate);
    }
}

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

License:Apache License

private void solveNonCodingPositiveTranscript(Boolean isInsertion, GenomicVariant variant,
        HashSet<String> SoNames, BasicDBObject transcriptInfo, Integer transcriptStart, Integer transcriptEnd,
        BasicDBObject miRnaInfo, Integer variantStart, Integer variantEnd,
        ConsequenceType consequenceTypeTemplate) {
    BasicDBList exonInfoList;
    BasicDBObject exonInfo;//w ww  .ja  va  2  s  .c  o  m
    Integer exonStart;
    Integer exonEnd;
    String transcriptSequence;
    Boolean variantAhead;
    Integer cdnaExonEnd;
    Integer cdnaVariantStart;
    Integer cdnaVariantEnd;
    Boolean splicing;
    int exonCounter;
    Integer prevSpliceSite;
    Boolean[] junctionSolution = { false, false };

    exonInfoList = (BasicDBList) transcriptInfo.get("exons");
    exonInfo = (BasicDBObject) exonInfoList.get(0);
    exonStart = (Integer) exonInfo.get("start");
    exonEnd = (Integer) exonInfo.get("end");
    transcriptSequence = (String) exonInfo.get("sequence");
    variantAhead = true; // we need a first iteration within the while to ensure junction is solved in case needed
    cdnaExonEnd = (exonEnd - exonStart + 1);
    cdnaVariantStart = null;
    cdnaVariantEnd = null;
    junctionSolution[0] = false;
    junctionSolution[1] = false;
    splicing = false;

    if (variantStart >= exonStart) {
        if (variantStart <= exonEnd) { // Variant start within the exon. Set cdnaPosition in consequenceTypeTemplate
            cdnaVariantStart = cdnaExonEnd - (exonEnd - variantStart);
            consequenceTypeTemplate.setcDnaPosition(cdnaVariantStart);
            if (variantEnd <= exonEnd) { // Both variant start and variant end within the exon  ----||||S|||||E||||----
                cdnaVariantEnd = cdnaExonEnd - (exonEnd - variantEnd);
            }
        }
    } else {
        if (variantEnd <= exonEnd) {
            //                                if(variantEnd >= exonStart) {  // Only variant end within the exon  ----||||||||||E||||----
            // We do not contemplate that variant end can be located before this exon since this is the first exon
            cdnaVariantEnd = cdnaExonEnd - (exonEnd - variantEnd);
            //                                }
        } // Variant includes the whole exon. Variant start is located before the exon, variant end is located after the exon
    }

    exonCounter = 1;
    while (exonCounter < exonInfoList.size() && variantAhead) { // This is not a do-while since we cannot call solveJunction  until
        //        while(exonCounter<exonInfoList.size() && !splicing && variantAhead) {  // This is not a do-while since we cannot call solveJunction  until
        exonInfo = (BasicDBObject) exonInfoList.get(exonCounter); // next exon has been loaded
        exonStart = (Integer) exonInfo.get("start");
        prevSpliceSite = exonEnd + 1;
        exonEnd = (Integer) exonInfo.get("end");
        transcriptSequence = transcriptSequence + ((String) exonInfo.get("sequence"));
        solveJunction(isInsertion, prevSpliceSite, exonStart - 1, variantStart, variantEnd, SoNames,
                "splice_donor_variant", "splice_acceptor_variant", junctionSolution);
        splicing = (splicing || junctionSolution[0]);

        if (variantStart >= exonStart) {
            cdnaExonEnd += (exonEnd - exonStart + 1);
            if (variantStart <= exonEnd) { // Variant start within the exon. Set cdnaPosition in consequenceTypeTemplate
                cdnaVariantStart = cdnaExonEnd - (exonEnd - variantStart);
                consequenceTypeTemplate.setcDnaPosition(cdnaVariantStart);
                if (variantEnd <= exonEnd) { // Both variant start and variant end within the exon  ----||||S|||||E||||----
                    cdnaVariantEnd = cdnaExonEnd - (exonEnd - variantEnd);
                }
            }
        } else {
            if (variantEnd <= exonEnd) {
                if (variantEnd >= exonStart) { // Only variant end within the exon  ----||||||||||E||||----
                    cdnaVariantEnd = cdnaExonEnd - (exonEnd - variantEnd);
                } else { // Variant does not include this exon, variant is located before this exon
                    variantAhead = false;
                }
            } else { // Variant includes the whole exon. Variant start is located before the exon, variant end is located after the exon
                cdnaExonEnd += (exonEnd - exonStart + 1);
            }
        }
        exonCounter++;
    }

    if (miRnaInfo != null) { // miRNA with miRBase data
        BasicDBList matureMiRnaInfo = (BasicDBList) miRnaInfo.get("matures");
        if (cdnaVariantStart == null) { // Probably deletion starting before the miRNA location
            cdnaVariantStart = 1; // Truncate to the first transcript position to avoid null exception
        }
        if (cdnaVariantEnd == null) { // Probably deletion ending after the miRNA location
            cdnaVariantEnd = ((String) miRnaInfo.get("sequence")).length(); // Truncate to the last transcript position to avoid null exception
        }
        int i = 0;
        while (i < matureMiRnaInfo.size()
                && !regionsOverlap((Integer) ((BasicDBObject) matureMiRnaInfo.get(i)).get("cdnaStart"),
                        (Integer) ((BasicDBObject) matureMiRnaInfo.get(i)).get("cdnaEnd"), cdnaVariantStart,
                        cdnaVariantEnd)) {
            i++;
        }
        if (i < matureMiRnaInfo.size()) { // Variant overlaps at least one mature miRNA
            SoNames.add("mature_miRNA_variant");
        } else {
            if (!junctionSolution[1]) { // Exon variant
                SoNames.add("non_coding_transcript_exon_variant");
            }
            SoNames.add("non_coding_transcript_variant");
        }
    } else {
        if (!junctionSolution[1]) { // Exon variant
            SoNames.add("non_coding_transcript_exon_variant");
        }
        SoNames.add("non_coding_transcript_variant");
    }
}

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

License:Apache License

private void solveNonCodingNegativeTranscript(Boolean isInsertion, GenomicVariant variant,
        HashSet<String> SoNames, BasicDBObject transcriptInfo, Integer transcriptStart, Integer transcriptEnd,
        BasicDBObject miRnaInfo, Integer variantStart, Integer variantEnd,
        ConsequenceType consequenceTypeTemplate) {
    BasicDBList exonInfoList;
    BasicDBObject exonInfo;/*from  w w w  .  ja  v  a  2  s .  c  o  m*/
    Integer exonStart;
    Integer exonEnd;
    String transcriptSequence;
    Boolean variantAhead;
    Integer cdnaExonEnd;
    Integer cdnaVariantStart;
    Integer cdnaVariantEnd;
    Boolean splicing;
    int exonCounter;
    Integer prevSpliceSite;
    Boolean[] junctionSolution = { false, false };

    exonInfoList = (BasicDBList) transcriptInfo.get("exons");
    exonInfo = (BasicDBObject) exonInfoList.get(0);
    exonStart = (Integer) exonInfo.get("start");
    exonEnd = (Integer) exonInfo.get("end");
    transcriptSequence = (String) exonInfo.get("sequence");
    variantAhead = true; // we need a first iteration within the while to ensure junction is solved in case needed
    cdnaExonEnd = (exonEnd - exonStart + 1); // cdnaExonEnd poinst to the same base than exonStart
    cdnaVariantStart = null; // cdnaVariantStart points to the same base than variantEnd
    cdnaVariantEnd = null; // cdnaVariantEnd points to the same base than variantStart

    junctionSolution[0] = false;
    junctionSolution[1] = false;
    splicing = false;

    if (variantEnd <= exonEnd) {
        if (variantEnd >= exonStart) { // Variant end within the exon
            cdnaVariantStart = cdnaExonEnd - (variantEnd - exonStart);
            consequenceTypeTemplate.setcDnaPosition(cdnaVariantStart);
            if (variantStart >= exonStart) { // Both variant start and variant end within the exon  ----||||S|||||E||||----
                cdnaVariantEnd = cdnaExonEnd - (variantStart - exonStart);
            }
        }
    } else {
        if (variantStart >= exonStart) {
            //                                if(variantEnd >= exonStart) {  // Only variant end within the exon  ----||||||||||E||||----
            // We do not contemplate that variant end can be located before this exon since this is the first exon
            cdnaVariantEnd = cdnaExonEnd - (variantEnd - exonStart);
            //                                }
        } // Variant includes the whole exon. Variant end is located before the exon, variant start is located after the exon
    }

    exonCounter = 1;
    while (exonCounter < exonInfoList.size() && variantAhead) { // This is not a do-while since we cannot call solveJunction  until
        //        while(exonCounter<exonInfoList.size() && !splicing && variantAhead) {  // This is not a do-while since we cannot call solveJunction  until
        exonInfo = (BasicDBObject) exonInfoList.get(exonCounter); // next exon has been loaded
        prevSpliceSite = exonStart - 1;
        exonStart = (Integer) exonInfo.get("start");
        exonEnd = (Integer) exonInfo.get("end");
        transcriptSequence = ((String) exonInfo.get("sequence")) + transcriptSequence;
        solveJunction(isInsertion, exonEnd + 1, prevSpliceSite, variantStart, variantEnd, SoNames,
                "splice_acceptor_variant", "splice_donor_variant", junctionSolution);
        splicing = (splicing || junctionSolution[0]);

        if (variantEnd <= exonEnd) {
            cdnaExonEnd += (exonEnd - exonStart + 1);
            if (variantEnd >= exonStart) { // Variant end within the exon
                cdnaVariantStart = cdnaExonEnd - (variantEnd - exonStart);
                consequenceTypeTemplate.setcDnaPosition(cdnaVariantStart);
                if (variantStart >= exonStart) { // Both variant start and variant end within the exon  ----||||S|||||E||||----
                    cdnaVariantEnd = cdnaExonEnd - (variantStart - exonStart);
                }
            }
        } else {
            if (variantStart >= exonStart) {
                if (variantStart <= exonEnd) { // Only variant start within the exon  ----||||||||||E||||----
                    cdnaVariantEnd = cdnaExonEnd - (variantStart - exonStart);
                } else { // Variant does not include this exon, variant is located before this exon
                    variantAhead = false;
                }
            } else { // Variant includes the whole exon. Variant start is located before the exon, variant end is located after the exon
                cdnaExonEnd += (exonEnd - exonStart + 1);
            }
        }
        exonCounter++;
    }

    if (miRnaInfo != null) { // miRNA with miRBase data
        BasicDBList matureMiRnaInfo = (BasicDBList) miRnaInfo.get("matures");
        int i = 0;
        while (i < matureMiRnaInfo.size()
                && !regionsOverlap((Integer) ((BasicDBObject) matureMiRnaInfo.get(i)).get("cdnaStart"),
                        (Integer) ((BasicDBObject) matureMiRnaInfo.get(i)).get("cdnaEnd"), cdnaVariantStart,
                        cdnaVariantEnd)) {
            i++;
        }
        if (i < matureMiRnaInfo.size()) { // Variant overlaps at least one mature miRNA
            SoNames.add("mature_miRNA_variant");
        } else {
            if (!junctionSolution[1]) { // Exon variant
                SoNames.add("non_coding_transcript_exon_variant");
            }
            SoNames.add("non_coding_transcript_variant");
        }
    } else {
        if (!junctionSolution[1]) { // Exon variant
            SoNames.add("non_coding_transcript_exon_variant");
        }
        SoNames.add("non_coding_transcript_variant");
    }
}

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

License:Apache License

public List<QueryResult> getAnnotationByVariantList(List<GenomicVariant> variantList,
        QueryOptions queryOptions) {//  w w  w.j a va 2s .com

    List<QueryResult> variationQueryResultList = variationDBAdaptor.getAllByVariantList(variantList,
            queryOptions);
    List<QueryResult> clinicalQueryResultList = clinicalDBAdaptor.getAllByGenomicVariantList(variantList,
            queryOptions);
    List<QueryResult> variationConsequenceTypeList = getAllConsequenceTypesByVariantList(variantList,
            queryOptions);
    List<QueryResult> conservedRegionQueryResultList = conservedRegionDBAdaptor
            .getAllScoresByRegionList(variantListToRegionList(variantList), queryOptions);

    VariantAnnotation variantAnnotation;

    Integer i = 0;
    for (QueryResult clinicalQueryResult : clinicalQueryResultList) {
        Map<String, Object> phenotype = new HashMap<>();
        if (clinicalQueryResult.getResult() != null && clinicalQueryResult.getResult().size() > 0) {
            phenotype = (Map<String, Object>) clinicalQueryResult.getResult().get(0);
        }

        List<ConsequenceType> consequenceTypeList = (List<ConsequenceType>) variationConsequenceTypeList.get(i)
                .getResult();

        // TODO: start & end are both being set to variantList.get(i).getPosition(), modify this for indels
        variantAnnotation = new VariantAnnotation(variantList.get(i).getChromosome(),
                variantList.get(i).getPosition(), variantList.get(i).getPosition(),
                variantList.get(i).getReference(), variantList.get(i).getAlternative());

        variantAnnotation.setClinicalData(phenotype);
        variantAnnotation.setConsequenceTypes(consequenceTypeList);
        variantAnnotation
                .setConservedRegionScores((List<Score>) conservedRegionQueryResultList.get(i).getResult());

        List<BasicDBObject> variationDBList = (List<BasicDBObject>) variationQueryResultList.get(i).getResult();
        if (variationDBList != null && variationDBList.size() > 0) {
            String id = null;
            id = ((BasicDBObject) variationDBList.get(0)).get("id").toString();
            variantAnnotation.setId(id);

            BasicDBList freqsDBList = null;
            if ((freqsDBList = (BasicDBList) ((BasicDBObject) variationDBList.get(0))
                    .get("populationFrequencies")) != null) {
                BasicDBObject freqDBObject;
                for (int j = 0; j < freqsDBList.size(); j++) {
                    freqDBObject = ((BasicDBObject) freqsDBList.get(j));
                    variantAnnotation.addPopulationFrequency(new PopulationFrequency(
                            freqDBObject.get("study").toString(), freqDBObject.get("pop").toString(),
                            freqDBObject.get("superPop").toString(), freqDBObject.get("refAllele").toString(),
                            freqDBObject.get("altAllele").toString(),
                            Float.valueOf(freqDBObject.get("refAlleleFreq").toString()),
                            Float.valueOf(freqDBObject.get("altAlleleFreq").toString())));
                }
            }
        }

        List<VariantAnnotation> value = Collections.singletonList(variantAnnotation);
        clinicalQueryResult.setResult(value);
        i++;
    }

    return clinicalQueryResultList;
}

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

License:Apache License

private void solveCodingPositiveTranscript(Boolean isInsertion, GenomicVariant variant, HashSet<String> SoNames,
        BasicDBObject transcriptInfo, Integer transcriptStart, Integer transcriptEnd, Integer variantStart,
        Integer variantEnd, Integer cdsLength, BasicDBList transcriptFlags,
        ConsequenceType consequenceTypeTemplate) {
    Integer genomicCodingStart;//from  w  w w. j a  v  a2  s .c  om
    Integer genomicCodingEnd;
    Integer cdnaCodingStart;
    Integer cdnaCodingEnd;
    BasicDBList exonInfoList;
    BasicDBObject exonInfo;
    Integer exonStart;
    Integer exonEnd;
    String transcriptSequence;
    Boolean variantAhead;
    Integer cdnaExonEnd;
    Integer cdnaVariantStart;
    Integer cdnaVariantEnd;
    Boolean splicing;
    int exonCounter;
    int firstCdsPhase = -1;
    Integer prevSpliceSite;
    Boolean[] junctionSolution = { false, false };

    genomicCodingStart = (Integer) transcriptInfo.get("genomicCodingStart");
    genomicCodingEnd = (Integer) transcriptInfo.get("genomicCodingEnd");
    cdnaCodingStart = (Integer) transcriptInfo.get("cdnaCodingStart");
    cdnaCodingEnd = (Integer) transcriptInfo.get("cdnaCodingEnd");
    exonInfoList = (BasicDBList) transcriptInfo.get("exons");
    exonInfo = (BasicDBObject) exonInfoList.get(0);
    exonStart = (Integer) exonInfo.get("start");
    exonEnd = (Integer) exonInfo.get("end");
    transcriptSequence = (String) exonInfo.get("sequence");
    variantAhead = true; // we need a first iteration within the while to ensure junction is solved in case needed
    cdnaExonEnd = (exonEnd - exonStart + 1);
    cdnaVariantStart = null;
    cdnaVariantEnd = null;
    junctionSolution[0] = false;
    junctionSolution[1] = false;
    splicing = false;

    if (firstCdsPhase == -1 && genomicCodingStart <= exonEnd) {
        firstCdsPhase = (int) exonInfo.get("phase");
    }
    if (variantStart >= exonStart) {
        if (variantStart <= exonEnd) { // Variant start within the exon
            cdnaVariantStart = cdnaExonEnd - (exonEnd - variantStart);
            consequenceTypeTemplate.setcDnaPosition(cdnaVariantStart);
            if (variantEnd <= exonEnd) { // Both variant start and variant end within the exon  ----||||S|||||E||||----
                cdnaVariantEnd = cdnaExonEnd - (exonEnd - variantEnd);
            }
        }
    } else {
        if (variantEnd <= exonEnd) {
            //                                if(variantEnd >= exonStart) {  // Only variant end within the exon  ----||||||||||E||||----
            // We do not contemplate that variant end can be located before this exon since this is the first exon
            cdnaVariantEnd = cdnaExonEnd - (exonEnd - variantEnd);
            //                                }
        } // Variant includes the whole exon. Variant start is located before the exon, variant end is located after the exon
    }

    exonCounter = 1;
    while (exonCounter < exonInfoList.size() && variantAhead) { // This is not a do-while since we cannot call solveJunction  until
        //        while(exonCounter<exonInfoList.size() && !splicing && variantAhead) {  // This is not a do-while since we cannot call solveJunction  until
        exonInfo = (BasicDBObject) exonInfoList.get(exonCounter); // next exon has been loaded
        exonStart = (Integer) exonInfo.get("start");
        prevSpliceSite = exonEnd + 1;
        exonEnd = (Integer) exonInfo.get("end");
        transcriptSequence = transcriptSequence + ((String) exonInfo.get("sequence"));
        if (firstCdsPhase == -1 && genomicCodingStart <= exonEnd) { // Set firsCdsPhase only when the first coding exon is reached
            firstCdsPhase = (int) exonInfo.get("phase");
        }
        solveJunction(isInsertion, prevSpliceSite, exonStart - 1, variantStart, variantEnd, SoNames,
                "splice_donor_variant", "splice_acceptor_variant", junctionSolution);
        splicing = (splicing || junctionSolution[0]);

        if (variantStart >= exonStart) {
            cdnaExonEnd += (exonEnd - exonStart + 1);
            if (variantStart <= exonEnd) { // Variant start within the exon
                cdnaVariantStart = cdnaExonEnd - (exonEnd - variantStart);
                consequenceTypeTemplate.setcDnaPosition(cdnaVariantStart);
                if (variantEnd <= exonEnd) { // Both variant start and variant end within the exon  ----||||S|||||E||||----
                    cdnaVariantEnd = cdnaExonEnd - (exonEnd - variantEnd);
                }
            }
        } else {
            if (variantEnd <= exonEnd) {
                if (variantEnd >= exonStart) { // Only variant end within the exon  ----||||||||||E||||----
                    cdnaExonEnd += (exonEnd - exonStart + 1);
                    cdnaVariantEnd = cdnaExonEnd - (exonEnd - variantEnd);
                } else { // Variant does not include this exon, variant is located before this exon
                    variantAhead = false;
                }
            } else { // Variant includes the whole exon. Variant start is located before the exon, variant end is located after the exon
                cdnaExonEnd += (exonEnd - exonStart + 1);
            }
        }
        exonCounter++;
    }
    // Is not intron variant (both ends fall within the same intron)
    if (!junctionSolution[1]) {
        if (isInsertion) {
            if (cdnaVariantStart == null && cdnaVariantEnd != null) { // To account for those insertions in the 3' end of an intron
                cdnaVariantStart = cdnaVariantEnd - 1;
            } else if (cdnaVariantEnd == null && cdnaVariantStart != null) { // To account for those insertions in the 5' end of an intron
                cdnaVariantEnd = cdnaVariantStart + 1;
            }
        }
        solveCodingPositiveTranscriptEffect(splicing, transcriptSequence, variant.getChromosome(),
                transcriptStart, transcriptEnd, genomicCodingStart, genomicCodingEnd, variantStart, variantEnd,
                cdnaCodingStart, cdnaCodingEnd, cdnaVariantStart, cdnaVariantEnd, cdsLength, transcriptFlags, // Be careful, originalVariantStart is used here!
                firstCdsPhase, variant.getReference(), variant.getAlternative(), SoNames,
                consequenceTypeTemplate);
    }
}

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

License:Apache License

private void solveCodingNegativeTranscript(Boolean isInsertion, GenomicVariant variant, HashSet<String> SoNames,
        BasicDBObject transcriptInfo, Integer transcriptStart, Integer transcriptEnd, Integer variantStart,
        Integer variantEnd, Integer cdsLength, BasicDBList transcriptFlags,
        ConsequenceType consequenceTypeTemplate) {
    Integer genomicCodingStart;//from  w w  w.  j  av  a2  s  .  co m
    Integer genomicCodingEnd;
    Integer cdnaCodingStart;
    Integer cdnaCodingEnd;
    BasicDBList exonInfoList;
    BasicDBObject exonInfo;
    Integer exonStart;
    Integer exonEnd;
    String transcriptSequence;
    Boolean variantAhead;
    Integer cdnaExonEnd;
    Integer cdnaVariantStart;
    Integer cdnaVariantEnd;
    Boolean splicing;
    int exonCounter;
    int firstCdsPhase = -1;
    Integer prevSpliceSite;
    Boolean[] junctionSolution = { false, false };

    genomicCodingStart = (Integer) transcriptInfo.get("genomicCodingStart");
    genomicCodingEnd = (Integer) transcriptInfo.get("genomicCodingEnd");
    cdnaCodingStart = (Integer) transcriptInfo.get("cdnaCodingStart");
    cdnaCodingEnd = (Integer) transcriptInfo.get("cdnaCodingEnd");
    exonInfoList = (BasicDBList) transcriptInfo.get("exons");
    exonInfo = (BasicDBObject) exonInfoList.get(0);
    exonStart = (Integer) exonInfo.get("start");
    exonEnd = (Integer) exonInfo.get("end");
    transcriptSequence = (String) exonInfo.get("sequence");
    variantAhead = true; // we need a first iteration within the while to ensure junction is solved in case needed
    cdnaExonEnd = (exonEnd - exonStart + 1); // cdnaExonEnd poinst to the same base than exonStart
    cdnaVariantStart = null; // cdnaVariantStart points to the same base than variantEnd
    cdnaVariantEnd = null; // cdnaVariantEnd points to the same base than variantStart
    junctionSolution[0] = false;
    junctionSolution[1] = false;
    splicing = false;

    if (firstCdsPhase == -1 && genomicCodingEnd >= exonStart) {
        firstCdsPhase = (int) exonInfo.get("phase");
    }
    if (variantEnd <= exonEnd) {
        if (variantEnd >= exonStart) { // Variant end within the exon
            cdnaVariantStart = cdnaExonEnd - (variantEnd - exonStart);
            consequenceTypeTemplate.setcDnaPosition(cdnaVariantStart);
            if (variantStart >= exonStart) { // Both variant start and variant end within the exon  ----||||S|||||E||||----
                cdnaVariantEnd = cdnaExonEnd - (variantStart - exonStart);
            }
        }
    } else {
        if (variantStart >= exonStart) {
            //                                if(variantEnd >= exonStart) {  // Only variant end within the exon  ----||||||||||E||||----
            // We do not contemplate that variant end can be located before this exon since this is the first exon
            cdnaVariantEnd = cdnaExonEnd - (variantEnd - exonStart);
            //                                }
        } // Variant includes the whole exon. Variant end is located before the exon, variant start is located after the exon
    }

    exonCounter = 1;
    while (exonCounter < exonInfoList.size() && variantAhead) { // This is not a do-while since we cannot call solveJunction  until
        //        while(exonCounter<exonInfoList.size() && !splicing && variantAhead) {  // This is not a do-while since we cannot call solveJunction  until
        exonInfo = (BasicDBObject) exonInfoList.get(exonCounter); // next exon has been loaded
        prevSpliceSite = exonStart - 1;
        exonStart = (Integer) exonInfo.get("start");
        exonEnd = (Integer) exonInfo.get("end");
        transcriptSequence = ((String) exonInfo.get("sequence")) + transcriptSequence;
        if (firstCdsPhase == -1 && genomicCodingEnd >= exonStart) { // Set firsCdsPhase only when the first coding exon is reached
            firstCdsPhase = (int) exonInfo.get("phase");
        }
        solveJunction(isInsertion, exonEnd + 1, prevSpliceSite, variantStart, variantEnd, SoNames,
                "splice_acceptor_variant", "splice_donor_variant", junctionSolution);
        splicing = (splicing || junctionSolution[0]);

        if (variantEnd <= exonEnd) {
            cdnaExonEnd += (exonEnd - exonStart + 1);
            if (variantEnd >= exonStart) { // Variant end within the exon
                cdnaVariantStart = cdnaExonEnd - (variantEnd - exonStart);
                consequenceTypeTemplate.setcDnaPosition(cdnaVariantStart);
                if (variantStart >= exonStart) { // Both variant start and variant end within the exon  ----||||S|||||E||||----
                    cdnaVariantEnd = cdnaExonEnd - (variantStart - exonStart);
                }
            }
        } else {
            if (variantStart >= exonStart) {
                if (variantStart <= exonEnd) { // Only variant start within the exon  ----||||||||||E||||----
                    cdnaExonEnd += (exonEnd - exonStart + 1);
                    cdnaVariantEnd = cdnaExonEnd - (variantStart - exonStart);
                } else { // Variant does not include this exon, variant is located before this exon
                    variantAhead = false;
                }
            } else { // Variant includes the whole exon. Variant start is located before the exon, variant end is located after the exon
                cdnaExonEnd += (exonEnd - exonStart + 1);
            }
        }
        exonCounter++;
    }
    // Is not intron variant (both ends fall within the same intron)
    if (!junctionSolution[1]) {
        if (isInsertion) {
            if (cdnaVariantStart == null && cdnaVariantEnd != null) { // To account for those insertions in the 3' end of an intron
                cdnaVariantStart = cdnaVariantEnd - 1;
            } else if (cdnaVariantEnd == null && cdnaVariantStart != null) { // To account for those insertions in the 5' end of an intron
                cdnaVariantEnd = cdnaVariantStart + 1;
            }
        }
        solveCodingNegativeTranscriptEffect(splicing, transcriptSequence, variant.getChromosome(),
                transcriptStart, transcriptEnd, genomicCodingStart, genomicCodingEnd, variantStart, variantEnd,
                cdnaCodingStart, cdnaCodingEnd, cdnaVariantStart, cdnaVariantEnd, cdsLength, transcriptFlags,
                firstCdsPhase, variant.getReference(), variant.getAlternative(), SoNames,
                consequenceTypeTemplate);
    }
}

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

License:Apache License

private void solveNonCodingPositiveTranscript(Boolean isInsertion, GenomicVariant variant,
        HashSet<String> SoNames, BasicDBObject transcriptInfo, Integer transcriptStart, Integer transcriptEnd,
        BasicDBObject miRnaInfo, Integer variantStart, Integer variantEnd,
        ConsequenceType consequenceTypeTemplate) {
    BasicDBList exonInfoList;
    BasicDBObject exonInfo;//from   w  w  w.  ja v a 2s .co  m
    Integer exonStart;
    Integer exonEnd;
    String transcriptSequence;
    Boolean variantAhead;
    Integer cdnaExonEnd;
    Integer cdnaVariantStart;
    Integer cdnaVariantEnd;
    Boolean splicing;
    int exonCounter;
    Integer prevSpliceSite;
    Boolean[] junctionSolution = { false, false };

    exonInfoList = (BasicDBList) transcriptInfo.get("exons");
    exonInfo = (BasicDBObject) exonInfoList.get(0);
    exonStart = (Integer) exonInfo.get("start");
    exonEnd = (Integer) exonInfo.get("end");
    transcriptSequence = (String) exonInfo.get("sequence");
    variantAhead = true; // we need a first iteration within the while to ensure junction is solved in case needed
    cdnaExonEnd = (exonEnd - exonStart + 1);
    cdnaVariantStart = null;
    cdnaVariantEnd = null;
    junctionSolution[0] = false;
    junctionSolution[1] = false;
    splicing = false;

    if (variantStart >= exonStart) {
        if (variantStart <= exonEnd) { // Variant start within the exon. Set cdnaPosition in consequenceTypeTemplate
            cdnaVariantStart = cdnaExonEnd - (exonEnd - variantStart);
            consequenceTypeTemplate.setcDnaPosition(cdnaVariantStart);
            if (variantEnd <= exonEnd) { // Both variant start and variant end within the exon  ----||||S|||||E||||----
                cdnaVariantEnd = cdnaExonEnd - (exonEnd - variantEnd);
            }
        }
    } else {
        if (variantEnd <= exonEnd) {
            //                                if(variantEnd >= exonStart) {  // Only variant end within the exon  ----||||||||||E||||----
            // We do not contemplate that variant end can be located before this exon since this is the first exon
            cdnaVariantEnd = cdnaExonEnd - (exonEnd - variantEnd);
            //                                }
        } // Variant includes the whole exon. Variant start is located before the exon, variant end is located after the exon
    }

    exonCounter = 1;
    while (exonCounter < exonInfoList.size() && variantAhead) { // This is not a do-while since we cannot call solveJunction  until
        //        while(exonCounter<exonInfoList.size() && !splicing && variantAhead) {  // This is not a do-while since we cannot call solveJunction  until
        exonInfo = (BasicDBObject) exonInfoList.get(exonCounter); // next exon has been loaded
        exonStart = (Integer) exonInfo.get("start");
        prevSpliceSite = exonEnd + 1;
        exonEnd = (Integer) exonInfo.get("end");
        transcriptSequence = transcriptSequence + ((String) exonInfo.get("sequence"));
        solveJunction(isInsertion, prevSpliceSite, exonStart - 1, variantStart, variantEnd, SoNames,
                "splice_donor_variant", "splice_acceptor_variant", junctionSolution);
        splicing = (splicing || junctionSolution[0]);

        if (variantStart >= exonStart) {
            cdnaExonEnd += (exonEnd - exonStart + 1);
            if (variantStart <= exonEnd) { // Variant start within the exon. Set cdnaPosition in consequenceTypeTemplate
                cdnaVariantStart = cdnaExonEnd - (exonEnd - variantStart);
                consequenceTypeTemplate.setcDnaPosition(cdnaVariantStart);
                if (variantEnd <= exonEnd) { // Both variant start and variant end within the exon  ----||||S|||||E||||----
                    cdnaVariantEnd = cdnaExonEnd - (exonEnd - variantEnd);
                }
            }
        } else {
            if (variantEnd <= exonEnd) {
                if (variantEnd >= exonStart) { // Only variant end within the exon  ----||||||||||E||||----
                    cdnaVariantEnd = cdnaExonEnd - (exonEnd - variantEnd);
                } else { // Variant does not include this exon, variant is located before this exon
                    variantAhead = false;
                }
            } else { // Variant includes the whole exon. Variant start is located before the exon, variant end is located after the exon
                cdnaExonEnd += (exonEnd - exonStart + 1);
            }
        }
        exonCounter++;
    }

    if (miRnaInfo != null) { // miRNA with miRBase data
        BasicDBList matureMiRnaInfo = (BasicDBList) miRnaInfo.get("matures");
        if (cdnaVariantStart == null) { // Probably deletion starting before the miRNA location
            cdnaVariantStart = 1; // Truncate to the first transcript position to avoid null exception
        }
        if (cdnaVariantEnd == null) { // Probably deletion ending after the miRNA location
            cdnaVariantEnd = ((String) miRnaInfo.get("sequence")).length(); // Truncate to the last transcript position to avoid null exception
        }
        int i = 0;
        while (i < matureMiRnaInfo.size()
                && !regionsOverlap((Integer) ((BasicDBObject) matureMiRnaInfo.get(i)).get("cdnaStart"),
                        (Integer) ((BasicDBObject) matureMiRnaInfo.get(i)).get("cdnaEnd"),
                        cdnaVariantStart == null ? 1 : cdnaVariantStart,
                        cdnaVariantEnd == null ? cdnaExonEnd : cdnaVariantEnd)) {
            i++;
        }
        if (i < matureMiRnaInfo.size()) { // Variant overlaps at least one mature miRNA
            SoNames.add("mature_miRNA_variant");
        } else {
            if (!junctionSolution[1]) { // Exon variant
                SoNames.add("non_coding_transcript_exon_variant");
            }
            SoNames.add("non_coding_transcript_variant");
        }
    } else {
        if (!junctionSolution[1]) { // Exon variant
            SoNames.add("non_coding_transcript_exon_variant");
        }
        SoNames.add("non_coding_transcript_variant");
    }
}

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

License:Apache License

private void solveNonCodingNegativeTranscript(Boolean isInsertion, GenomicVariant variant,
        HashSet<String> SoNames, BasicDBObject transcriptInfo, Integer transcriptStart, Integer transcriptEnd,
        BasicDBObject miRnaInfo, Integer variantStart, Integer variantEnd,
        ConsequenceType consequenceTypeTemplate) {
    BasicDBList exonInfoList;
    BasicDBObject exonInfo;/*from   w w w  .j a v a2  s .  co m*/
    Integer exonStart;
    Integer exonEnd;
    String transcriptSequence;
    Boolean variantAhead;
    Integer cdnaExonEnd;
    Integer cdnaVariantStart;
    Integer cdnaVariantEnd;
    Boolean splicing;
    int exonCounter;
    Integer prevSpliceSite;
    Boolean[] junctionSolution = { false, false };

    exonInfoList = (BasicDBList) transcriptInfo.get("exons");
    exonInfo = (BasicDBObject) exonInfoList.get(0);
    exonStart = (Integer) exonInfo.get("start");
    exonEnd = (Integer) exonInfo.get("end");
    transcriptSequence = (String) exonInfo.get("sequence");
    variantAhead = true; // we need a first iteration within the while to ensure junction is solved in case needed
    cdnaExonEnd = (exonEnd - exonStart + 1); // cdnaExonEnd poinst to the same base than exonStart
    cdnaVariantStart = null; // cdnaVariantStart points to the same base than variantEnd
    cdnaVariantEnd = null; // cdnaVariantEnd points to the same base than variantStart

    junctionSolution[0] = false;
    junctionSolution[1] = false;
    splicing = false;

    if (variantEnd <= exonEnd) {
        if (variantEnd >= exonStart) { // Variant end within the exon
            cdnaVariantStart = cdnaExonEnd - (variantEnd - exonStart);
            consequenceTypeTemplate.setcDnaPosition(cdnaVariantStart);
            if (variantStart >= exonStart) { // Both variant start and variant end within the exon  ----||||S|||||E||||----
                cdnaVariantEnd = cdnaExonEnd - (variantStart - exonStart);
            }
        }
    } else {
        if (variantStart >= exonStart) {
            //                                if(variantEnd >= exonStart) {  // Only variant end within the exon  ----||||||||||E||||----
            // We do not contemplate that variant end can be located before this exon since this is the first exon
            cdnaVariantEnd = cdnaExonEnd - (variantEnd - exonStart);
            //                                }
        } // Variant includes the whole exon. Variant end is located before the exon, variant start is located after the exon
    }

    exonCounter = 1;
    while (exonCounter < exonInfoList.size() && variantAhead) { // This is not a do-while since we cannot call solveJunction  until
        //        while(exonCounter<exonInfoList.size() && !splicing && variantAhead) {  // This is not a do-while since we cannot call solveJunction  until
        exonInfo = (BasicDBObject) exonInfoList.get(exonCounter); // next exon has been loaded
        prevSpliceSite = exonStart - 1;
        exonStart = (Integer) exonInfo.get("start");
        exonEnd = (Integer) exonInfo.get("end");
        transcriptSequence = ((String) exonInfo.get("sequence")) + transcriptSequence;
        solveJunction(isInsertion, exonEnd + 1, prevSpliceSite, variantStart, variantEnd, SoNames,
                "splice_acceptor_variant", "splice_donor_variant", junctionSolution);
        splicing = (splicing || junctionSolution[0]);

        if (variantEnd <= exonEnd) {
            cdnaExonEnd += (exonEnd - exonStart + 1);
            if (variantEnd >= exonStart) { // Variant end within the exon
                cdnaVariantStart = cdnaExonEnd - (variantEnd - exonStart);
                consequenceTypeTemplate.setcDnaPosition(cdnaVariantStart);
                if (variantStart >= exonStart) { // Both variant start and variant end within the exon  ----||||S|||||E||||----
                    cdnaVariantEnd = cdnaExonEnd - (variantStart - exonStart);
                }
            }
        } else {
            if (variantStart >= exonStart) {
                if (variantStart <= exonEnd) { // Only variant start within the exon  ----||||||||||E||||----
                    cdnaVariantEnd = cdnaExonEnd - (variantStart - exonStart);
                } else { // Variant does not include this exon, variant is located before this exon
                    variantAhead = false;
                }
            } else { // Variant includes the whole exon. Variant start is located before the exon, variant end is located after the exon
                cdnaExonEnd += (exonEnd - exonStart + 1);
            }
        }
        exonCounter++;
    }

    if (miRnaInfo != null) { // miRNA with miRBase data
        BasicDBList matureMiRnaInfo = (BasicDBList) miRnaInfo.get("matures");
        int i = 0;
        while (i < matureMiRnaInfo.size()
                && !regionsOverlap((Integer) ((BasicDBObject) matureMiRnaInfo.get(i)).get("cdnaStart"),
                        (Integer) ((BasicDBObject) matureMiRnaInfo.get(i)).get("cdnaEnd"),
                        cdnaVariantStart == null ? 1 : cdnaVariantStart,
                        cdnaVariantEnd == null ? cdnaExonEnd : cdnaVariantEnd)) {
            i++;
        }
        if (i < matureMiRnaInfo.size()) { // Variant overlaps at least one mature miRNA
            SoNames.add("mature_miRNA_variant");
        } else {
            if (!junctionSolution[1]) { // Exon variant
                SoNames.add("non_coding_transcript_exon_variant");
            }
            SoNames.add("non_coding_transcript_variant");
        }
    } else {
        if (!junctionSolution[1]) { // Exon variant
            SoNames.add("non_coding_transcript_exon_variant");
        }
        SoNames.add("non_coding_transcript_variant");
    }
}

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

License:Apache License

public List<QueryResult> getAnnotationByVariantList(List<GenomicVariant> variantList,
        QueryOptions queryOptions) {/*from   w  w  w  .j a  v a  2 s  .  c  o m*/

    // TODO: validation of queryoption 'include' values
    List<String> includeList = queryOptions.getAsStringList("include");
    if (includeList.isEmpty()) {
        includeList = Arrays.asList("variation", "clinical", "consequenceType", "conservation",
                "drugInteraction");
    }

    List<QueryResult> annotations = null;
    List<QueryResult> variationQueryResultList = null;
    if (includeList.contains("variation")) {
        variationQueryResultList = variationDBAdaptor.getAllByVariantList(variantList, queryOptions);
        annotations = variationQueryResultList;
    }
    List<QueryResult> clinicalQueryResultList = null;
    if (includeList.contains("clinical")) {
        clinicalQueryResultList = clinicalDBAdaptor.getAllByGenomicVariantList(variantList, queryOptions);
        if (annotations == null) {
            annotations = clinicalQueryResultList;
        }
    }
    //        List<QueryResult> variationConsequenceTypeList = null;
    //        if (includeList.contains("consequenceType")) {
    //            variationConsequenceTypeList = getAllConsequenceTypesByVariantList(variantList, queryOptions);
    //            if (annotations == null) {
    //                annotations = variationConsequenceTypeList;
    //            }
    //        }
    List<QueryResult> conservedRegionQueryResultList = null;
    if (includeList.contains("conservation")) {
        conservedRegionQueryResultList = conservedRegionDBAdaptor
                .getAllScoresByRegionList(variantListToRegionList(variantList), queryOptions);
        if (annotations == null) {
            annotations = conservedRegionQueryResultList;
        }
    }

    for (int i = 0; i < variantList.size(); i++) {
        // TODO: start & end are both being set to variantList.get(i).getPosition(), modify this for indels
        VariantAnnotation variantAnnotation = new VariantAnnotation(variantList.get(i).getChromosome(),
                variantList.get(i).getPosition(), variantList.get(i).getPosition(),
                variantList.get(i).getReference(), variantList.get(i).getAlternative());

        if (clinicalQueryResultList != null) {
            QueryResult clinicalQueryResult = clinicalQueryResultList.get(i);
            if (clinicalQueryResult.getResult() != null && clinicalQueryResult.getResult().size() > 0) {
                variantAnnotation.setClinical((Map<String, Object>) clinicalQueryResult.getResult().get(0));
            }
        }

        //            if (variationConsequenceTypeList != null) {
        if (includeList.contains("consequenceType")) {
            variantAnnotation.setConsequenceTypes(
                    (List<ConsequenceType>) getAllConsequenceTypesByVariant(variantList.get(i),
                            new QueryOptions()).getResult());
        }

        if (includeList.contains("drugInteraction")) {
            Map<String, List<Object>> geneDrugInteractionMap = new HashMap<>(1);
            geneDrugInteractionMap.put("dgidb", getGeneDrugInteractions(variantList.get(i)));
            variantAnnotation.setGeneDrugInteraction(geneDrugInteractionMap);
        }

        if (conservedRegionQueryResultList != null) {
            variantAnnotation
                    .setConservationScores((List<Score>) conservedRegionQueryResultList.get(i).getResult());
        }

        List<BasicDBObject> variationDBList = null;
        if (variationQueryResultList != null) {
            variationDBList = (List<BasicDBObject>) variationQueryResultList.get(i).getResult();
        }

        if (variationDBList != null && variationDBList.size() > 0) {
            String id = variationDBList.get(0).get("id").toString();
            variantAnnotation.setId(id);

            BasicDBList freqsDBList = (BasicDBList) variationDBList.get(0).get("populationFrequencies");
            if (freqsDBList != null) {
                BasicDBObject freqDBObject;
                for (int j = 0; j < freqsDBList.size(); j++) {
                    freqDBObject = ((BasicDBObject) freqsDBList.get(j));
                    if (freqDBObject != null) {
                        if (freqDBObject.containsKey("study")) {
                            variantAnnotation.addPopulationFrequency(new PopulationFrequency(
                                    freqDBObject.get("study").toString(), freqDBObject.get("pop").toString(),
                                    freqDBObject.get("superPop").toString(),
                                    freqDBObject.get("refAllele").toString(),
                                    freqDBObject.get("altAllele").toString(),
                                    Float.valueOf(freqDBObject.get("refAlleleFreq").toString()),
                                    Float.valueOf(freqDBObject.get("altAlleleFreq").toString())));
                        } else {
                            variantAnnotation.addPopulationFrequency(new PopulationFrequency("1000G_PHASE_3",
                                    freqDBObject.get("pop").toString(), freqDBObject.get("superPop").toString(),
                                    freqDBObject.get("refAllele").toString(),
                                    freqDBObject.get("altAllele").toString(),
                                    Float.valueOf(freqDBObject.get("refAlleleFreq").toString()),
                                    Float.valueOf(freqDBObject.get("altAlleleFreq").toString())));
                        }
                    }
                }
            }
        }
        List<VariantAnnotation> value = Collections.singletonList(variantAnnotation);
        annotations.get(i).setResult(value);
    }

    return annotations;
    //        return clinicalQueryResultList;
}