use of org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotype in project gatk 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);
}
use of org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotype in project gatk by broadinstitute.
the class ReadThreadingAssemblerUnitTest method testMismatchInFirstKmer.
@Test
public void testMismatchInFirstKmer() {
final TestAssembler assembler = new TestAssembler(3);
final String ref = "ACAACTGA";
final String alt = "AGCTGA";
assembler.addSequence(ref.getBytes(), true);
assembler.addSequence(alt.getBytes(), false);
final SeqGraph graph = assembler.assemble();
graph.simplifyGraph();
graph.removeSingletonOrphanVertices();
final Set<SeqVertex> sources = graph.getSources();
final Set<SeqVertex> sinks = graph.getSinks();
Assert.assertEquals(sources.size(), 1);
Assert.assertEquals(sinks.size(), 1);
Assert.assertNotNull(graph.getReferenceSourceVertex());
Assert.assertNotNull(graph.getReferenceSinkVertex());
final List<KBestHaplotype> paths = new KBestHaplotypeFinder(graph);
Assert.assertEquals(paths.size(), 1);
}
use of org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotype in project gatk-protected by broadinstitute.
the class ReadThreadingAssemblerUnitTest method testMismatchInFirstKmer.
@Test
public void testMismatchInFirstKmer() {
final TestAssembler assembler = new TestAssembler(3);
final String ref = "ACAACTGA";
final String alt = "AGCTGA";
assembler.addSequence(ref.getBytes(), true);
assembler.addSequence(alt.getBytes(), false);
final SeqGraph graph = assembler.assemble();
graph.simplifyGraph();
graph.removeSingletonOrphanVertices();
final Set<SeqVertex> sources = graph.getSources();
final Set<SeqVertex> sinks = graph.getSinks();
Assert.assertEquals(sources.size(), 1);
Assert.assertEquals(sinks.size(), 1);
Assert.assertNotNull(graph.getReferenceSourceVertex());
Assert.assertNotNull(graph.getReferenceSinkVertex());
final List<KBestHaplotype> paths = new KBestHaplotypeFinder(graph);
Assert.assertEquals(paths.size(), 1);
}
use of org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotype in project gatk-protected 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);
}
}
use of org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotype 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);
}
Aggregations