Search in sources :

Example 76 with Haplotype

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

the class AssemblyResultSetUnitTest method testAddReferenceHaplotype.

@Test
public void testAddReferenceHaplotype() {
    final Haplotype ref = new Haplotype("ACGT".getBytes(), true);
    ref.setGenomeLocation(genomeLocParser.createGenomeLoc("1", 1, ref.length() + 1));
    final AssemblyResultSet subject = new AssemblyResultSet();
    Assert.assertTrue(subject.add(ref));
    Assert.assertFalse(subject.add(ref));
    Assert.assertEquals(subject.getReferenceHaplotype(), ref);
    Assert.assertEquals(subject.getHaplotypeCount(), 1);
    Assert.assertEquals(subject.getHaplotypeList().size(), 1);
}
Also used : Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 77 with Haplotype

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

the class AssemblyRegionTestDataSet method haplotypeList.

public List<Haplotype> haplotypeList() {
    if (haplotypeList == null) {
        final List<Haplotype> result = new ArrayList<>(haplotypeCigars.length);
        final String reference = this.reference;
        for (final String cigar : haplotypeCigars) {
            if (cigar.matches("^Civar:.*$")) {
                stringRepresentation = cigar.substring(6);
                result.addAll(expandAllHaplotypeCombinations(cigar.substring(6), reference));
            } else if (cigar.matches("^.*\\d+.*$")) {
                result.add(cigarToHaplotype(reference, cigar, 0, true));
            } else {
                final Haplotype h = new Haplotype(cigar.getBytes());
                h.setGenomeLocation(genomeLocParser.createGenomeLoc("chr1", 1, reference.length()));
                result.add(h);
            }
        }
        haplotypeList = result;
    }
    return haplotypeList;
}
Also used : ArrayList(java.util.ArrayList) Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype)

Example 78 with Haplotype

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

the class ReferenceConfidenceModelUnitTest method testRefConfidenceWithCalls.

@Test
public void testRefConfidenceWithCalls() {
    final RefConfData xxxdata = new RefConfData("ACGTAACCGGTT", 0);
    final int start = xxxdata.getStart();
    final int stop = xxxdata.getEnd();
    final PloidyModel ploidyModel = new HomogeneousPloidyModel(samples, 2);
    final IndependentSampleGenotypesModel genotypingModel = new IndependentSampleGenotypesModel();
    for (int nReads = 0; nReads < 2; nReads++) {
        final VariantContext vcStart = GATKVariantContextUtils.makeFromAlleles("test", "chr1", start, Arrays.asList("A", "C"));
        final VariantContext vcEnd = GATKVariantContextUtils.makeFromAlleles("test", "chr1", stop, Arrays.asList("A", "C"));
        final VariantContext vcMiddle = GATKVariantContextUtils.makeFromAlleles("test", "chr1", start + 2, Arrays.asList("A", "C"));
        final VariantContext vcDel = GATKVariantContextUtils.makeFromAlleles("test", "chr1", start + 4, Arrays.asList("AAC", "A"));
        final VariantContext vcIns = GATKVariantContextUtils.makeFromAlleles("test", "chr1", start + 8, Arrays.asList("G", "GCG"));
        final List<VariantContext> allCalls = Arrays.asList(vcStart, vcEnd, vcMiddle, vcDel, vcIns);
        for (int n = 1; n <= allCalls.size(); n++) {
            for (final List<VariantContext> calls : Utils.makePermutations(allCalls, n, false)) {
                final RefConfData data = new RefConfData("ACGTAACCGGTT", 0);
                final List<Haplotype> haplotypes = Arrays.asList(data.getRefHap());
                for (int i = 0; i < nReads; i++) {
                    data.getActiveRegion().add(data.makeRead(0, data.getRefLength()));
                }
                final ReadLikelihoods<Haplotype> likelihoods = createDummyStratifiedReadMap(data.getRefHap(), samples, data.getActiveRegion());
                final List<Integer> expectedDPs = Collections.nCopies(data.getActiveRegion().getSpan().size(), nReads);
                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) HomogeneousPloidyModel(org.broadinstitute.hellbender.tools.walkers.genotyper.HomogeneousPloidyModel) VariantContext(htsjdk.variant.variantcontext.VariantContext) HomogeneousPloidyModel(org.broadinstitute.hellbender.tools.walkers.genotyper.HomogeneousPloidyModel) PloidyModel(org.broadinstitute.hellbender.tools.walkers.genotyper.PloidyModel) Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 79 with Haplotype

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

the class ReadThreadingAssemblerUnitTest method testSimpleAssembly.

@Test(dataProvider = "SimpleAssemblyTestData")
public void testSimpleAssembly(final String name, final ReadThreadingAssembler assembler, final SimpleInterval loc, final String ref, final String alt) {
    final byte[] refBases = ref.getBytes();
    final byte[] altBases = alt.getBytes();
    final List<GATKRead> reads = new LinkedList<>();
    for (int i = 0; i < 20; i++) {
        final byte[] bases = altBases.clone();
        final byte[] quals = Utils.dupBytes((byte) 30, altBases.length);
        final String cigar = altBases.length + "M";
        final GATKRead read = ArtificialReadUtils.createArtificialRead(header, loc.getContig(), loc.getContig(), loc.getStart(), bases, quals, cigar);
        reads.add(read);
    }
    final Haplotype refHaplotype = new Haplotype(refBases, true);
    final Haplotype altHaplotype = new Haplotype(altBases, false);
    final List<Haplotype> haplotypes = assemble(assembler, refBases, loc, reads);
    Assert.assertTrue(haplotypes.size() > 0, "Failed to find ref haplotype");
    Assert.assertEquals(haplotypes.get(0), refHaplotype);
    Assert.assertEquals(haplotypes.size(), 2, "Failed to find single alt haplotype");
    Assert.assertEquals(haplotypes.get(1), altHaplotype);
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) KBestHaplotype(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotype) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 80 with Haplotype

use of org.broadinstitute.hellbender.utils.haplotype.Haplotype in project gatk-protected 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)

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