Search in sources :

Example 86 with Haplotype

use of org.broadinstitute.hellbender.utils.haplotype.Haplotype in project gatk by broadinstitute.

the class ReferenceConfidenceModelUnitTest method testRefConfidencePartialReads.

@Test
public void testRefConfidencePartialReads() {
    final PloidyModel ploidyModel = new HomogeneousPloidyModel(samples, 2);
    final IndependentSampleGenotypesModel genotypingModel = new IndependentSampleGenotypesModel();
    final String ref = "ACGTAACCGGTT";
    for (int readLen = 3; readLen < ref.length(); readLen++) {
        for (int start = 0; start < ref.length() - readLen; start++) {
            final RefConfData data = new RefConfData(ref, 0);
            final List<Haplotype> haplotypes = Arrays.asList(data.getRefHap());
            final List<VariantContext> calls = Collections.emptyList();
            data.getActiveRegion().add(data.makeRead(start, readLen));
            final ReadLikelihoods<Haplotype> likelihoods = createDummyStratifiedReadMap(data.getRefHap(), samples, data.getActiveRegion());
            final List<Integer> expectedDPs = new ArrayList<>(Collections.nCopies(data.getActiveRegion().getSpan().size(), 0));
            for (int i = start; i < readLen + start; i++) expectedDPs.set(i, 1);
            final List<VariantContext> contexts = model.calculateRefConfidence(data.getRefHap(), haplotypes, data.getPaddedRefLoc(), data.getActiveRegion(), likelihoods, ploidyModel, calls);
            checkReferenceModelResult(data, contexts, expectedDPs, calls);
        }
    }
}
Also used : IndependentSampleGenotypesModel(org.broadinstitute.hellbender.tools.walkers.genotyper.IndependentSampleGenotypesModel) VariantContext(htsjdk.variant.variantcontext.VariantContext) HomogeneousPloidyModel(org.broadinstitute.hellbender.tools.walkers.genotyper.HomogeneousPloidyModel) PloidyModel(org.broadinstitute.hellbender.tools.walkers.genotyper.PloidyModel) HomogeneousPloidyModel(org.broadinstitute.hellbender.tools.walkers.genotyper.HomogeneousPloidyModel) Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 87 with Haplotype

use of org.broadinstitute.hellbender.utils.haplotype.Haplotype in project gatk by broadinstitute.

the class KBestHaplotypeFinderUnitTest method testScore.

@Test
public void testScore() {
    final SeqGraph g = new SeqGraph(3);
    final SeqVertex v1 = new SeqVertex("A");
    final SeqVertex v2 = new SeqVertex("C");
    final SeqVertex v3 = new SeqVertex("G");
    final SeqVertex v4 = new SeqVertex("T");
    final SeqVertex v5 = new SeqVertex("A");
    //source
    g.addVertex(v1);
    g.addVertex(v2);
    g.addVertex(v3);
    g.addVertex(v4);
    g.addVertex(v5);
    g.addEdge(v1, v2);
    g.addEdge(v2, v3);
    g.addEdge(v2, v4);
    g.addEdge(v2, v5);
    final KBestHaplotypeFinder finder = new KBestHaplotypeFinder(g);
    Assert.assertEquals(finder.sources.size(), 1);
    Assert.assertEquals(finder.sinks.size(), 3);
    final double score = finder.score("ACG".getBytes());
    Assert.assertEquals(score, -0.47712125471966244);
    final double scoreH = finder.score(new Haplotype("ACG".getBytes()));
    Assert.assertEquals(scoreH, -0.47712125471966244);
}
Also used : Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 88 with Haplotype

use of org.broadinstitute.hellbender.utils.haplotype.Haplotype in project gatk-protected by broadinstitute.

the class AssemblyBasedCallerGenotypingEngine method createAlleleMapper.

protected static Map<Allele, List<Haplotype>> createAlleleMapper(final List<VariantContext> eventsAtThisLoc, final VariantContext mergedVC, final int loc, final List<Haplotype> haplotypes) {
    Utils.validateArg(haplotypes.size() > eventsAtThisLoc.size(), "expected haplotypes.size() >= eventsAtThisLoc.size() + 1");
    final Map<Allele, List<Haplotype>> result = new LinkedHashMap<>();
    final Allele ref = mergedVC.getReference();
    result.put(ref, new ArrayList<>());
    //Note: we can't use the alleles implied by eventsAtThisLoc because they are not yet merged to a common reference
    //For example, a homopolymer AAAAA reference with a single and double deletion would yield (i) AA* A and (ii) AAA* A
    //in eventsAtThisLoc, when in mergedVC it would yield AAA* AA A
    mergedVC.getAlternateAlleles().stream().filter(a -> !a.isSymbolic()).forEach(a -> result.put(a, new ArrayList<>()));
    for (final Haplotype h : haplotypes) {
        final VariantContext haplotypeVC = h.getEventMap().get(loc);
        if (haplotypeVC == null) {
            //no events --> this haplotype supports the reference at this locus
            result.get(ref).add(h);
        } else {
            //TODO: that's not good enough
            for (int n = 0; n < eventsAtThisLoc.size(); n++) {
                if (haplotypeVC.hasSameAllelesAs(eventsAtThisLoc.get(n))) {
                    result.get(mergedVC.getAlternateAllele(n)).add(h);
                    break;
                }
            }
        }
    }
    return result;
}
Also used : java.util(java.util) GATKVCFConstants(org.broadinstitute.hellbender.utils.variant.GATKVCFConstants) Predicate(java.util.function.Predicate) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) htsjdk.variant.variantcontext(htsjdk.variant.variantcontext) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Collectors(java.util.stream.Collectors) EventMap(org.broadinstitute.hellbender.utils.haplotype.EventMap) ReadLikelihoods(org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods) Pair(org.apache.commons.lang3.tuple.Pair) org.broadinstitute.hellbender.tools.walkers.genotyper(org.broadinstitute.hellbender.tools.walkers.genotyper) AFCalculatorProvider(org.broadinstitute.hellbender.tools.walkers.genotyper.afcalc.AFCalculatorProvider) Utils(org.broadinstitute.hellbender.utils.Utils) Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype)

Aggregations

Haplotype (org.broadinstitute.hellbender.utils.haplotype.Haplotype)88 Test (org.testng.annotations.Test)31 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)28 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)28 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)12 DataProvider (org.testng.annotations.DataProvider)10 VariantContext (htsjdk.variant.variantcontext.VariantContext)9 KBestHaplotype (org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotype)8 ArrayList (java.util.ArrayList)7 Cigar (htsjdk.samtools.Cigar)6 AssemblyRegion (org.broadinstitute.hellbender.engine.AssemblyRegion)6 HomogeneousPloidyModel (org.broadinstitute.hellbender.tools.walkers.genotyper.HomogeneousPloidyModel)6 IndependentSampleGenotypesModel (org.broadinstitute.hellbender.tools.walkers.genotyper.IndependentSampleGenotypesModel)6 PloidyModel (org.broadinstitute.hellbender.tools.walkers.genotyper.PloidyModel)6 ReadThreadingGraph (org.broadinstitute.hellbender.tools.walkers.haplotypecaller.readthreading.ReadThreadingGraph)6 SampleList (org.broadinstitute.hellbender.utils.genotyper.SampleList)6 EventMap (org.broadinstitute.hellbender.utils.haplotype.EventMap)6 CigarElement (htsjdk.samtools.CigarElement)4 Allele (htsjdk.variant.variantcontext.Allele)4 File (java.io.File)4