Package htsjdk.variant.variantcontext

Examples of htsjdk.variant.variantcontext.VariantContext


    private LDMergeData getPairOfEventsToMerge(final List<Haplotype> haplotypes, final int thisStart, final int nextStart) {
        final LDMergeData mergeData = new LDMergeData();

        for( final Haplotype h : haplotypes ) {
            // only make complex substitutions out of consecutive biallelic sites
            final VariantContext thisHapVC = h.getEventMap().get(thisStart);
            if( thisHapVC != null && !thisHapVC.isSymbolic() ) { // something was found at this location on this haplotype
                if( mergeData.firstVC == null ) {
                    mergeData.firstVC = thisHapVC;
                } else if( !thisHapVC.hasSameAllelesAs( mergeData.firstVC) ) {
                    return mergeData.cantBeMerged();
                }
            }
            final VariantContext nextHapVC = h.getEventMap().get(nextStart);
            if( nextHapVC != null && !nextHapVC.isSymbolic() ) { // something was found at the next location on this haplotype
                if( mergeData.secondVC == null ) {
                    mergeData.secondVC = nextHapVC;
                } else if( !nextHapVC.hasSameAllelesAs( mergeData.secondVC) ) {
                    return mergeData.cantBeMerged();
                }
            }
        }
View Full Code Here


        for ( final Map<Haplotype, Double> entry : haplotypeLikelihoodsPerSample ) {
            for ( final Map.Entry<Haplotype, Double> haplotypeLikelihood : entry.entrySet() ) {
                final Haplotype h = haplotypeLikelihood.getKey();
                // count up the co-occurrences of the events for the R^2 calculation
                final VariantContext thisHapVC = h.getEventMap().get(first.getStart());
                final VariantContext nextHapVC = h.getEventMap().get(second.getStart()); // TODO -- add function to take a VC
                final int i = thisHapVC == null ? 0 : 1;
                final int j = nextHapVC == null ? 0 : 1;
                final int index = 2 * i + j;
                table[index] = MathUtils.approximateLog10SumLog10(table[index], haplotypeLikelihood.getValue());
            }
View Full Code Here

        if ( log10AlleleFrequencyPriors == null ) throw new IllegalArgumentException("priors vector cannot be null");

        // reset the result, so we can store our new result there
        final StateTracker stateTracker = getStateTracker(true,maximumAlternativeAlleles);

        final VariantContext vcWorking = reduceScope(vc,defaultPloidy, maximumAlternativeAlleles);

        callTimer.start();
        final AFCalculationResult result = computeLog10PNonRef(vcWorking, defaultPloidy, log10AlleleFrequencyPriors, stateTracker);
        final long nanoTime = callTimer.getElapsedTimeNano();
View Full Code Here

        final byte[] ref = "AATTCCGGAATTCCGGAATT".getBytes();
        final GenomeLoc refLoc = genomeLocParser.createGenomeLoc("2", 1700, 1700 + ref.length);

        // SNP + SNP = simple MNP
        VariantContext thisVC = new VariantContextBuilder().loc("2", 1703, 1703).alleles("T","G").make();
        VariantContext nextVC = new VariantContextBuilder().loc("2", 1704, 1704).alleles("C","G").make();
        VariantContext truthVC = new VariantContextBuilder().loc("2", 1703, 1704).alleles("TC","GG").source("merged").make();
        VariantContext mergedVC = merger.createMergedVariantContext(thisVC, nextVC, ref, refLoc);
        logger.warn(truthVC + " == " + mergedVC);
        Assert.assertTrue(truthVC.hasSameAllelesAs(mergedVC));
        Assert.assertEquals(truthVC.getStart(), mergedVC.getStart());
        Assert.assertEquals(truthVC.getEnd(), mergedVC.getEnd());

        // SNP + ref + SNP = MNP with ref base gap
        thisVC = new VariantContextBuilder().loc("2", 1703, 1703).alleles("T","G").make();
        nextVC = new VariantContextBuilder().loc("2", 1705, 1705).alleles("C","G").make();
        truthVC = new VariantContextBuilder().loc("2", 1703, 1705).alleles("TCC","GCG").source("merged").make();
        mergedVC = merger.createMergedVariantContext(thisVC, nextVC, ref, refLoc);
        logger.warn(truthVC + " == " + mergedVC);
        Assert.assertTrue(truthVC.hasSameAllelesAs(mergedVC));
        Assert.assertEquals(truthVC.getStart(), mergedVC.getStart());
        Assert.assertEquals(truthVC.getEnd(), mergedVC.getEnd());

        // insertion + SNP
        thisVC = new VariantContextBuilder().loc("2", 1703, 1703).alleles("T","TAAAAA").make();
        nextVC = new VariantContextBuilder().loc("2", 1705, 1705).alleles("C","G").make();
        truthVC = new VariantContextBuilder().loc("2", 1703, 1705).alleles("TCC","TAAAAACG").source("merged").make();
        mergedVC = merger.createMergedVariantContext(thisVC, nextVC, ref, refLoc);
        logger.warn(truthVC + " == " + mergedVC);
        Assert.assertTrue(truthVC.hasSameAllelesAs(mergedVC));
        Assert.assertEquals(truthVC.getStart(), mergedVC.getStart());
        Assert.assertEquals(truthVC.getEnd(), mergedVC.getEnd());

        // SNP + insertion
        thisVC = new VariantContextBuilder().loc("2", 1703, 1703).alleles("T","G").make();
        nextVC = new VariantContextBuilder().loc("2", 1705, 1705).alleles("C","CAAAAA").make();
        truthVC = new VariantContextBuilder().loc("2", 1703, 1705).alleles("TCC","GCCAAAAA").source("merged").make();
        mergedVC = merger.createMergedVariantContext(thisVC, nextVC, ref, refLoc);
        logger.warn(truthVC + " == " + mergedVC);
        Assert.assertTrue(truthVC.hasSameAllelesAs(mergedVC));
        Assert.assertEquals(truthVC.getStart(), mergedVC.getStart());
        Assert.assertEquals(truthVC.getEnd(), mergedVC.getEnd());

        // deletion + SNP
        thisVC = new VariantContextBuilder().loc("2", 1703, 1704).alleles("TC","T").make();
        nextVC = new VariantContextBuilder().loc("2", 1705, 1705).alleles("C","G").make();
        truthVC = new VariantContextBuilder().loc("2", 1703, 1705).alleles("TCC","TG").source("merged").make();
        mergedVC = merger.createMergedVariantContext(thisVC, nextVC, ref, refLoc);
        logger.warn(truthVC + " == " + mergedVC);
        Assert.assertTrue(truthVC.hasSameAllelesAs(mergedVC));
        Assert.assertEquals(truthVC.getStart(), mergedVC.getStart());
        Assert.assertEquals(truthVC.getEnd(), mergedVC.getEnd());

        // SNP + deletion
        thisVC = new VariantContextBuilder().loc("2", 1703, 1703).alleles("T","G").make();
        nextVC = new VariantContextBuilder().loc("2", 1705, 1706).alleles("CG","C").make();
        truthVC = new VariantContextBuilder().loc("2", 1703, 1706).alleles("TCCG","GCC").source("merged").make();
        mergedVC = merger.createMergedVariantContext(thisVC, nextVC, ref, refLoc);
        logger.warn(truthVC + " == " + mergedVC);
        Assert.assertTrue(truthVC.hasSameAllelesAs(mergedVC));
        Assert.assertEquals(truthVC.getStart(), mergedVC.getStart());
        Assert.assertEquals(truthVC.getEnd(), mergedVC.getEnd());

        // insertion + deletion = MNP
        thisVC = new VariantContextBuilder().loc("2", 1703, 1703).alleles("T","TA").make();
        nextVC = new VariantContextBuilder().loc("2", 1705, 1706).alleles("CG","C").make();
        truthVC = new VariantContextBuilder().loc("2", 1704, 1706).alleles("CCG","ACC").source("merged").make();
        mergedVC = merger.createMergedVariantContext(thisVC, nextVC, ref, refLoc);
        logger.warn(truthVC + " == " + mergedVC);
        Assert.assertTrue(truthVC.hasSameAllelesAs(mergedVC));
        Assert.assertEquals(truthVC.getStart(), mergedVC.getStart());
        Assert.assertEquals(truthVC.getEnd(), mergedVC.getEnd());

        // insertion + deletion
        thisVC = new VariantContextBuilder().loc("2", 1703, 1703).alleles("T","TAAAAA").make();
        nextVC = new VariantContextBuilder().loc("2", 1705, 1706).alleles("CG","C").make();
        truthVC = new VariantContextBuilder().loc("2", 1703, 1706).alleles("TCCG","TAAAAACC").source("merged").make();
        mergedVC = merger.createMergedVariantContext(thisVC, nextVC, ref, refLoc);
        logger.warn(truthVC + " == " + mergedVC);
        Assert.assertTrue(truthVC.hasSameAllelesAs(mergedVC));
        Assert.assertEquals(truthVC.getStart(), mergedVC.getStart());
        Assert.assertEquals(truthVC.getEnd(), mergedVC.getEnd());

        // insertion + insertion
        thisVC = new VariantContextBuilder().loc("2", 1703, 1703).alleles("T","TA").make();
        nextVC = new VariantContextBuilder().loc("2", 1705, 1705).alleles("C","CA").make();
        truthVC = new VariantContextBuilder().loc("2", 1703, 1705).alleles("TCC","TACCA").source("merged").make();
        mergedVC = merger.createMergedVariantContext(thisVC, nextVC, ref, refLoc);
        logger.warn(truthVC + " == " + mergedVC);
        Assert.assertTrue(truthVC.hasSameAllelesAs(mergedVC));
        Assert.assertEquals(truthVC.getStart(), mergedVC.getStart());
        Assert.assertEquals(truthVC.getEnd(), mergedVC.getEnd());

        // deletion + deletion
        thisVC = new VariantContextBuilder().loc("2", 1701, 1702).alleles("AT","A").make();
        nextVC = new VariantContextBuilder().loc("2", 1705, 1706).alleles("CG","C").make();
        truthVC = new VariantContextBuilder().loc("2", 1701, 1706).alleles("ATTCCG","ATCC").source("merged").make();
        mergedVC = merger.createMergedVariantContext(thisVC, nextVC, ref, refLoc);
        logger.warn(truthVC + " == " + mergedVC);
        Assert.assertTrue(truthVC.hasSameAllelesAs(mergedVC));
        Assert.assertEquals(truthVC.getStart(), mergedVC.getStart());
        Assert.assertEquals(truthVC.getEnd(), mergedVC.getEnd());

        // deletion + insertion (abutting)
        thisVC = new VariantContextBuilder().loc("2", 1701, 1702).alleles("AT","A").make();
        nextVC = new VariantContextBuilder().loc("2", 1702, 1702).alleles("T","GCGCGC").make();
        truthVC = new VariantContextBuilder().loc("2", 1701, 1702).alleles("AT","AGCGCGC").source("merged").make();
        mergedVC = merger.createMergedVariantContext(thisVC, nextVC, ref, refLoc);
        logger.warn(truthVC + " == " + mergedVC);
        Assert.assertTrue(truthVC.hasSameAllelesAs(mergedVC));
        Assert.assertEquals(truthVC.getStart(), mergedVC.getStart());
        Assert.assertEquals(truthVC.getEnd(), mergedVC.getEnd());

        // complex + complex
        thisVC = new VariantContextBuilder().loc("2", 1703, 1704).alleles("TC","AAA").make();
        nextVC = new VariantContextBuilder().loc("2", 1706, 1707).alleles("GG","AC").make();
        truthVC = new VariantContextBuilder().loc("2", 1703, 1707).alleles("TCCGG","AAACAC").source("merged").make();
        mergedVC = merger.createMergedVariantContext(thisVC, nextVC, ref, refLoc);
        logger.warn(truthVC + " == " + mergedVC);
        Assert.assertTrue(truthVC.hasSameAllelesAs(mergedVC));
        Assert.assertEquals(truthVC.getStart(), mergedVC.getStart());
        Assert.assertEquals(truthVC.getEnd(), mergedVC.getEnd());
    }
View Full Code Here

    }

    @Test(dataProvider = "ContiguousData")
    public void testIsContiguous(final String contig, final int pos, final boolean expected) {
        final HomRefBlock band = new HomRefBlock(vc, 10, 20, HomoSapiensConstants.DEFAULT_PLOIDY);
        final VariantContext testVC = new VariantContextBuilder(vc).chr(contig).start(pos).stop(pos).make();
        Assert.assertEquals(band.isContiguous(testVC), expected);
    }
View Full Code Here

    public void testInsertionDeletionBecomingNullAllele() {
        final byte[] ref = "CAAA".getBytes();
        final GenomeLoc refLoc = genomeLocParser.createGenomeLoc("2", 1700, 1700 + ref.length);

        // insertion + deletion results in a null allele, should return false
        final VariantContext thisVC = new VariantContextBuilder().loc("2", 1700, 1701).alleles("CA","C").make();
        final VariantContext nextVC = new VariantContextBuilder().loc("2", 1703, 1703).alleles("A","AA").make();
        final VariantContext mergedVC = merger.createMergedVariantContext(thisVC, nextVC, ref, refLoc);
        Assert.assertNull(mergedVC,  "Insertion deletion becoming a null allele should return a null variant context");
    }
View Full Code Here

        Assert.assertEquals(vcStarts.size(), nEvents);
        final boolean merged = merger.mergeConsecutiveEventsBasedOnLDOnce(haplotypes, r2Calc, 1, vcStarts, ref.getBases(), loc);
        Assert.assertEquals(merged, expectMerge);
        Assert.assertEquals(vcStarts.size(), expectMerge ? 1 : nEvents);
        if ( expectMerge ) {
            final VariantContext vc = hap.getEventMap().getVariantContexts().iterator().next();
            Assert.assertTrue(vc.isBiallelic());
            Assert.assertEquals(vc.getReference().getDisplayString(), expectedMergedRef);
            Assert.assertEquals(vc.getAlternateAllele(0).getDisplayString(), expectedMergedAlt);
        }
    }
View Full Code Here

        Assert.assertEquals(vcStarts.size(), 2);
        final boolean merged = merger.mergeConsecutiveEventsBasedOnLDOnce(haplotypes, r2Calc, 1, vcStarts, ref.getBases(), loc);
        Assert.assertEquals(merged, true);
        Assert.assertEquals(vcStarts.size(), 1);

        final VariantContext vc = hap1.getEventMap().getVariantContexts().iterator().next();
        Assert.assertTrue(vc.isBiallelic());
        Assert.assertEquals(vc.getReference().getDisplayString(), "ACGT");
        Assert.assertEquals(vc.getAlternateAllele(0).getDisplayString(), "CCGA");

        Assert.assertEquals(hap2.getEventMap().size(), 0);
    }
View Full Code Here

        final File gVCF = executeTest("testOneStartsBeforeTwoAndEndsAfterwards", spec).first.get(0);
        final List<VariantContext> allVCs = GATKVCFUtils.readVCF(gVCF).getSecond();

        Assert.assertEquals(allVCs.size(), 2, "Observed: " + allVCs);

        final VariantContext first = allVCs.get(0);
        Assert.assertEquals(first.getStart(), 69491);
        Assert.assertEquals(first.getEnd(), 69497);
        Assert.assertEquals(first.getGenotypes().size(), 2);
        Assert.assertTrue(first.getGenotype("NA1").isNoCall());
        Assert.assertTrue(first.getGenotype("NA2").isNoCall());

        final VariantContext second = allVCs.get(1);
        Assert.assertEquals(second.getStart(), 69498);
        Assert.assertEquals(second.getEnd(), 69506);
        Assert.assertEquals(second.getGenotypes().size(), 2);
        Assert.assertTrue(second.getGenotype("NA1").isNoCall());
        Assert.assertTrue(second.getGenotype("NA2").isNoCall());
    }
View Full Code Here

        final File gVCF = executeTest("testOneHasAltAndTwoHasNothing", spec).first.get(0);
        final List<VariantContext> allVCs = GATKVCFUtils.readVCF(gVCF).getSecond();

        Assert.assertEquals(allVCs.size(), 1);

        final VariantContext first = allVCs.get(0);
        Assert.assertEquals(first.getStart(), 69511);
        Assert.assertEquals(first.getEnd(), 69511);
        Assert.assertEquals(first.getGenotypes().size(), 2);
    }
View Full Code Here

TOP

Related Classes of htsjdk.variant.variantcontext.VariantContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.