Search in sources :

Example 6 with KBestHaplotypeFinder

use of org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotypeFinder in project gatk-protected by broadinstitute.

the class ReadThreadingGraphUnitTest method testDanglingHeads.

@Test(dataProvider = "DanglingHeads")
public void testDanglingHeads(final String ref, final String alt, final String cigar, final boolean shouldBeMerged) {
    final int kmerSize = 5;
    // create the graph and populate it
    final ReadThreadingGraph rtgraph = new ReadThreadingGraph(kmerSize);
    rtgraph.addSequence("ref", ref.getBytes(), true);
    final GATKRead read = ArtificialReadUtils.createArtificialRead(alt.getBytes(), Utils.dupBytes((byte) 30, alt.length()), alt.length() + "M");
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader();
    rtgraph.addRead(read, header);
    rtgraph.setMaxMismatchesInDanglingHead(10);
    rtgraph.buildGraphIfNecessary();
    // confirm that we have just a single dangling head
    MultiDeBruijnVertex altSource = null;
    for (final MultiDeBruijnVertex v : rtgraph.vertexSet()) {
        if (rtgraph.isSource(v) && !rtgraph.isReferenceNode(v)) {
            Assert.assertTrue(altSource == null, "We found more than one non-reference source");
            altSource = v;
        }
    }
    Assert.assertTrue(altSource != null, "We did not find a non-reference source");
    // confirm that the SW alignment agrees with our expectations
    final ReadThreadingGraph.DanglingChainMergeHelper result = rtgraph.generateCigarAgainstUpwardsReferencePath(altSource, 0, 1);
    if (result == null) {
        Assert.assertFalse(shouldBeMerged);
        return;
    }
    Assert.assertTrue(cigar.equals(result.cigar.toString()), "SW generated cigar = " + result.cigar.toString());
    // confirm that the tail merging works as expected
    final int mergeResult = rtgraph.mergeDanglingHead(result);
    Assert.assertTrue(mergeResult > 0 || !shouldBeMerged);
    // confirm that we created the appropriate bubble in the graph only if expected
    rtgraph.cleanNonRefPaths();
    final SeqGraph seqGraph = rtgraph.toSequenceGraph();
    final List<KBestHaplotype> paths = new KBestHaplotypeFinder(seqGraph, seqGraph.getReferenceSourceVertex(), seqGraph.getReferenceSinkVertex());
    Assert.assertEquals(paths.size(), shouldBeMerged ? 2 : 1);
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) KBestHaplotype(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotype) SeqGraph(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.SeqGraph) KBestHaplotypeFinder(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotypeFinder) SAMFileHeader(htsjdk.samtools.SAMFileHeader) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 7 with KBestHaplotypeFinder

use of org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotypeFinder in project gatk-protected by broadinstitute.

the class ReadThreadingAssemblerUnitTest method testSingleIndelAsDoubleIndel3Reads.

@Test
public void testSingleIndelAsDoubleIndel3Reads() {
    final TestAssembler assembler = new TestAssembler(25);
    // The single indel spans two repetitive structures
    final String ref = "GTTTTTCCTAGGCAAATGGTTTCTATAAAATTATGTGTGTGTGTCTCTCTCTGTGTGTGTGTGTGTGTGTGTGTGTATACCTAATCTCACACTCTTTTTTCTGG";
    final String read1 = "GTTTTTCCTAGGCAAATGGTTTCTATAAAATTATGTGTGTGTGTCTCT----------GTGTGTGTGTGTGTGTGTATACCTAATCTCACACTCTTTTTTCTGG";
    final String read2 = "GTTTTTCCTAGGCAAATGGTTTCTATAAAATTATGTGTGTGTGTCTCT----------GTGTGTGTGTGTGTGTGTATACCTAATCTCACACTCTTTTTTCTGG";
    assembler.addSequence(ReadThreadingGraphUnitTest.getBytes(ref), true);
    assembler.addSequence(ReadThreadingGraphUnitTest.getBytes(read1), false);
    assembler.addSequence(ReadThreadingGraphUnitTest.getBytes(read2), false);
    final SeqGraph graph = assembler.assemble();
    final List<KBestHaplotype> paths = new KBestHaplotypeFinder(graph);
    Assert.assertEquals(paths.size(), 2);
    final byte[] refPath = paths.get(0).bases().length == ref.length() ? paths.get(0).bases() : paths.get(1).bases();
    final byte[] altPath = paths.get(0).bases().length == ref.length() ? paths.get(1).bases() : paths.get(0).bases();
    Assert.assertEquals(refPath, ReadThreadingGraphUnitTest.getBytes(ref));
    Assert.assertEquals(altPath, ReadThreadingGraphUnitTest.getBytes(read1));
}
Also used : KBestHaplotype(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotype) SeqGraph(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.SeqGraph) KBestHaplotypeFinder(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotypeFinder) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 8 with KBestHaplotypeFinder

use of org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotypeFinder in project gatk by broadinstitute.

the class ReadThreadingGraphUnitTest method testNsInReadsAreNotUsedForGraph.

@Test(enabled = !DEBUG)
public void testNsInReadsAreNotUsedForGraph() {
    final int length = 100;
    final byte[] ref = Utils.dupBytes((byte) 'A', length);
    final ReadThreadingGraph rtgraph = new ReadThreadingGraph(25);
    rtgraph.addSequence("ref", ref, true);
    // add reads with Ns at any position
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader();
    for (int i = 0; i < length; i++) {
        final byte[] bases = ref.clone();
        bases[i] = 'N';
        final GATKRead read = ArtificialReadUtils.createArtificialRead(bases, Utils.dupBytes((byte) 30, length), length + "M");
        rtgraph.addRead(read, header);
    }
    rtgraph.buildGraphIfNecessary();
    final SeqGraph graph = rtgraph.toSequenceGraph();
    Assert.assertEquals(new KBestHaplotypeFinder(graph, graph.getReferenceSourceVertex(), graph.getReferenceSinkVertex()).size(), 1);
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SeqGraph(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.SeqGraph) KBestHaplotypeFinder(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotypeFinder) SAMFileHeader(htsjdk.samtools.SAMFileHeader) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 9 with KBestHaplotypeFinder

use of org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotypeFinder in project gatk by broadinstitute.

the class ReadThreadingAssemblerUnitTest method assertSingleBubble.

private void assertSingleBubble(final TestAssembler assembler, final String one, final String two) {
    final SeqGraph graph = assembler.assemble();
    graph.simplifyGraph();
    final List<KBestHaplotype> paths = new KBestHaplotypeFinder(graph);
    Assert.assertEquals(paths.size(), 2);
    final Set<String> expected = new HashSet<>(Arrays.asList(one, two));
    for (final KBestHaplotype path : paths) {
        final String seq = new String(path.bases());
        Assert.assertTrue(expected.contains(seq));
        expected.remove(seq);
    }
}
Also used : KBestHaplotype(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotype) SeqGraph(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.SeqGraph) KBestHaplotypeFinder(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotypeFinder)

Example 10 with KBestHaplotypeFinder

use of org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotypeFinder in project gatk by broadinstitute.

the class ReadThreadingAssemblerUnitTest method testSingleIndelAsDoubleIndel3Reads.

@Test
public void testSingleIndelAsDoubleIndel3Reads() {
    final TestAssembler assembler = new TestAssembler(25);
    // The single indel spans two repetitive structures
    final String ref = "GTTTTTCCTAGGCAAATGGTTTCTATAAAATTATGTGTGTGTGTCTCTCTCTGTGTGTGTGTGTGTGTGTGTGTGTATACCTAATCTCACACTCTTTTTTCTGG";
    final String read1 = "GTTTTTCCTAGGCAAATGGTTTCTATAAAATTATGTGTGTGTGTCTCT----------GTGTGTGTGTGTGTGTGTATACCTAATCTCACACTCTTTTTTCTGG";
    final String read2 = "GTTTTTCCTAGGCAAATGGTTTCTATAAAATTATGTGTGTGTGTCTCT----------GTGTGTGTGTGTGTGTGTATACCTAATCTCACACTCTTTTTTCTGG";
    assembler.addSequence(ReadThreadingGraphUnitTest.getBytes(ref), true);
    assembler.addSequence(ReadThreadingGraphUnitTest.getBytes(read1), false);
    assembler.addSequence(ReadThreadingGraphUnitTest.getBytes(read2), false);
    final SeqGraph graph = assembler.assemble();
    final List<KBestHaplotype> paths = new KBestHaplotypeFinder(graph);
    Assert.assertEquals(paths.size(), 2);
    final byte[] refPath = paths.get(0).bases().length == ref.length() ? paths.get(0).bases() : paths.get(1).bases();
    final byte[] altPath = paths.get(0).bases().length == ref.length() ? paths.get(1).bases() : paths.get(0).bases();
    Assert.assertEquals(refPath, ReadThreadingGraphUnitTest.getBytes(ref));
    Assert.assertEquals(altPath, ReadThreadingGraphUnitTest.getBytes(read1));
}
Also used : KBestHaplotype(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotype) SeqGraph(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.SeqGraph) KBestHaplotypeFinder(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotypeFinder) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

KBestHaplotypeFinder (org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotypeFinder)10 SeqGraph (org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.SeqGraph)10 KBestHaplotype (org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotype)8 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)8 Test (org.testng.annotations.Test)8 SAMFileHeader (htsjdk.samtools.SAMFileHeader)4 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)4 SeqVertex (org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.SeqVertex)2