Debian Codegraph @

tests/src/poa/test_PoaConsensus.cpp

raw
1 #include <pbcopper/poa/PoaConsensus.h>
2
3 #include <cstdlib>
4
5 #include <algorithm>
6 #include <memory>
7 #include <string>
8 #include <utility>
9 #include <vector>
10
11 #include <boost/algorithm/string.hpp>
12 #include <boost/assign.hpp>
13 #include <boost/assign/std/vector.hpp>
14
15 #include <pbcopper/align/AlignConfig.h>
16
17 #include <gtest/gtest.h>
18
19 using boost::erase_all_copy;
20
21 using namespace boost::assign; // NOLINT
22 using namespace PacBio::Poa; // NOLINT
23 using namespace PacBio::Align; // NOLINT
24
25 #define MAKE_ALL_PLOTS false
26
27 namespace PoaConsensusTests {
28 namespace {
29
30 void plotConsensus(const PacBio::Poa::PoaConsensus* pc, std::string description,
31 bool REALLY_MAKE_THIS_ONE = false)
32 {
33 if (MAKE_ALL_PLOTS || REALLY_MAKE_THIS_ONE) {
34 std::string dotFname = description + ".dot";
35 std::string pngFname = description + ".png";
36 std::string cmd = std::string("dot -Tpng ") + dotFname + " > " + pngFname;
37 pc->Graph.WriteGraphVizFile(description + ".dot",
38 (PoaGraph::COLOR_NODES | PoaGraph::VERBOSE_NODES), pc);
39 // std::cout << cmd << std::endl;
40 const int result = std::system(cmd.c_str());
41 if (result) {
42 std::cerr << "Running '" << cmd << "' failed\n";
43 }
44 }
45 }
46
47 } // namespace
48 } // namespace PoaConsensusTests
49
50 // TEST(PoaGraph, NoReadsTest)
51 // {
52 // // Test that it works with no reads
53 // std::vector<const SequenceFeatures*> reads;
54 // std::unique_ptr<const PacBio::Poa::PoaConsensus> pc{PoaConsensus::findConsensus(reads,
55 // PoaConfig::GLOBAL_ALIGNMENT)};
56 // std::string dot = pc->getGraph()->toGraphViz();
57 // std::cout << dot << std::endl;
58 // }
59
60 TEST(PoaGraph, SmallBasicTest1)
61 {
62 // Test that it works with a single sequence
63 std::vector<std::string> reads;
64 reads += "GGG";
65 std::unique_ptr<const PacBio::Poa::PoaConsensus> pc{
66 PoaConsensus::FindConsensus(reads, AlignMode::GLOBAL)};
67 std::string dot = pc->Graph.ToGraphViz();
68 std::string expectedDot =
69 "digraph G {"
70 "rankdir=\"LR\";"
71 "0[shape=Mrecord, label=\"{ ^ | 0 }\"];"
72 "1[shape=Mrecord, label=\"{ $ | 0 }\"];"
73 "2[shape=Mrecord, label=\"{ G | 1 }\"];"
74 "3[shape=Mrecord, label=\"{ G | 1 }\"];"
75 "4[shape=Mrecord, label=\"{ G | 1 }\"];"
76 "0->2 ;"
77 "2->3 ;"
78 "3->4 ;"
79 "4->1 ;"
80 "}";
81 PoaConsensusTests::plotConsensus(pc.get(), "small-basic-1");
82 EXPECT_EQ(expectedDot, erase_all_copy(dot, "\n"));
83 EXPECT_EQ("GGG", pc->Sequence);
84 }
85
86 TEST(PoaGraph, SmallBasicTest2)
87 {
88 // Test that it works with two identical sequences
89 std::vector<std::string> reads;
90 reads += "GGG", "GGG";
91 std::unique_ptr<const PacBio::Poa::PoaConsensus> pc{
92 PoaConsensus::FindConsensus(reads, AlignMode::GLOBAL)};
93 std::string dot = pc->Graph.ToGraphViz();
94 std::string expectedDot =
95 "digraph G {"
96 "rankdir=\"LR\";"
97 "0[shape=Mrecord, label=\"{ ^ | 0 }\"];"
98 "1[shape=Mrecord, label=\"{ $ | 0 }\"];"
99 "2[shape=Mrecord, label=\"{ G | 2 }\"];"
100 "3[shape=Mrecord, label=\"{ G | 2 }\"];"
101 "4[shape=Mrecord, label=\"{ G | 2 }\"];"
102 "0->2 ;"
103 "2->3 ;"
104 "3->4 ;"
105 "4->1 ;"
106 "}";
107 PoaConsensusTests::plotConsensus(pc.get(), "small-basic-2");
108 EXPECT_EQ(expectedDot, erase_all_copy(dot, "\n"));
109 EXPECT_EQ("GGG", pc->Sequence);
110 }
111
112 TEST(PoaGraph, SmallExtraTests)
113 {
114 // Extra at beginning
115 {
116 std::vector<std::string> reads;
117 reads += "GGG", "TGGG";
118 std::unique_ptr<const PacBio::Poa::PoaConsensus> pc{
119 PoaConsensus::FindConsensus(reads, AlignMode::GLOBAL)};
120 std::string dot = pc->Graph.ToGraphViz();
121 std::string expectedDot =
122 "digraph G {"
123 "rankdir=\"LR\";"
124 "0[shape=Mrecord, label=\"{ ^ | 0 }\"];"
125 "1[shape=Mrecord, label=\"{ $ | 0 }\"];"
126 "2[shape=Mrecord, label=\"{ G | 2 }\"];"
127 "3[shape=Mrecord, label=\"{ G | 2 }\"];"
128 "4[shape=Mrecord, label=\"{ G | 2 }\"];"
129 "5[shape=Mrecord, label=\"{ T | 1 }\"];"
130 "0->2 ;"
131 "2->3 ;"
132 "3->4 ;"
133 "4->1 ;"
134 "5->2 ;"
135 "0->5 ;"
136 "}";
137 PoaConsensusTests::plotConsensus(pc.get(), "extra-at-beginning");
138 EXPECT_EQ(expectedDot, erase_all_copy(dot, "\n"));
139 EXPECT_EQ("GGG", pc->Sequence);
140 }
141
142 // Extra in middle
143 {
144 std::vector<std::string> reads;
145 reads += "GGG", "GTGG";
146 std::unique_ptr<const PacBio::Poa::PoaConsensus> pc{
147 PoaConsensus::FindConsensus(reads, AlignMode::GLOBAL)};
148 std::string dot = pc->Graph.ToGraphViz();
149 // this would be easier if we could use the C++0x raw
150 // strings feature (in g++ 4.5+)
151 std::string expectedDot =
152 "digraph G {"
153 "rankdir=\"LR\";"
154 "0[shape=Mrecord, label=\"{ ^ | 0 }\"];"
155 "1[shape=Mrecord, label=\"{ $ | 0 }\"];"
156 "2[shape=Mrecord, label=\"{ G | 2 }\"];"
157 "3[shape=Mrecord, label=\"{ G | 2 }\"];"
158 "4[shape=Mrecord, label=\"{ G | 2 }\"];"
159 "5[shape=Mrecord, label=\"{ T | 1 }\"];"
160 "0->2 ;"
161 "2->3 ;"
162 "3->4 ;"
163 "4->1 ;"
164 "5->3 ;"
165 "2->5 ;"
166 "}";
167 PoaConsensusTests::plotConsensus(pc.get(), "extra-in-middle");
168 EXPECT_EQ(expectedDot, erase_all_copy(dot, "\n"));
169 EXPECT_EQ("GGG", pc->Sequence);
170 }
171
172 // Extra at end
173 {
174 std::vector<std::string> reads;
175 reads += "GGG", "GGGT";
176 std::unique_ptr<const PacBio::Poa::PoaConsensus> pc{
177 PoaConsensus::FindConsensus(reads, AlignMode::GLOBAL)};
178 std::string dot = pc->Graph.ToGraphViz();
179 std::string expectedDot =
180 "digraph G {"
181 "rankdir=\"LR\";"
182 "0[shape=Mrecord, label=\"{ ^ | 0 }\"];"
183 "1[shape=Mrecord, label=\"{ $ | 0 }\"];"
184 "2[shape=Mrecord, label=\"{ G | 2 }\"];"
185 "3[shape=Mrecord, label=\"{ G | 2 }\"];"
186 "4[shape=Mrecord, label=\"{ G | 2 }\"];"
187 "5[shape=Mrecord, label=\"{ T | 1 }\"];"
188 "0->2 ;"
189 "2->3 ;"
190 "3->4 ;"
191 "4->1 ;"
192 "5->1 ;"
193 "4->5 ;"
194 "}";
195 PoaConsensusTests::plotConsensus(pc.get(), "extra-at-end");
196 EXPECT_EQ(expectedDot, erase_all_copy(dot, "\n"));
197 EXPECT_EQ("GGG", pc->Sequence);
198 }
199 }
200
201 TEST(PoaGraph, SmallMismatchTests)
202 {
203 // Mismatch at beginning
204 {
205 std::vector<std::string> reads;
206 reads += "GGG", "TGG";
207 std::unique_ptr<const PacBio::Poa::PoaConsensus> pc{
208 PoaConsensus::FindConsensus(reads, AlignMode::GLOBAL)};
209 std::string dot = pc->Graph.ToGraphViz();
210 std::string expectedDot =
211 "digraph G {"
212 "rankdir=\"LR\";"
213 "0[shape=Mrecord, label=\"{ ^ | 0 }\"];"
214 "1[shape=Mrecord, label=\"{ $ | 0 }\"];"
215 "2[shape=Mrecord, label=\"{ G | 1 }\"];"
216 "3[shape=Mrecord, label=\"{ G | 2 }\"];"
217 "4[shape=Mrecord, label=\"{ G | 2 }\"];"
218 "5[shape=Mrecord, label=\"{ T | 1 }\"];"
219 "0->2 ;"
220 "2->3 ;"
221 "3->4 ;"
222 "4->1 ;"
223 "5->3 ;"
224 "0->5 ;"
225 "}";
226 PoaConsensusTests::plotConsensus(pc.get(), "mismatch-at-beginning");
227 EXPECT_EQ(expectedDot, erase_all_copy(dot, "\n"));
228 EXPECT_EQ("GG", pc->Sequence);
229 }
230
231 // Mismatch in middle
232 {
233 std::vector<std::string> reads;
234 reads += "GGG", "GTG", "GTG";
235 std::unique_ptr<const PacBio::Poa::PoaConsensus> pc{
236 PoaConsensus::FindConsensus(reads, AlignMode::GLOBAL)};
237 std::string dot = pc->Graph.ToGraphViz();
238 std::string expectedDot =
239 "digraph G {"
240 "rankdir=\"LR\";"
241 "0[shape=Mrecord, label=\"{ ^ | 0 }\"];"
242 "1[shape=Mrecord, label=\"{ $ | 0 }\"];"
243 "2[shape=Mrecord, label=\"{ G | 3 }\"];"
244 "3[shape=Mrecord, label=\"{ G | 1 }\"];"
245 "4[shape=Mrecord, label=\"{ G | 3 }\"];"
246 "5[shape=Mrecord, label=\"{ T | 2 }\"];"
247 "0->2 ;"
248 "2->3 ;"
249 "3->4 ;"
250 "4->1 ;"
251 "5->4 ;"
252 "2->5 ;"
253 "}";
254 PoaConsensusTests::plotConsensus(pc.get(), "mismatch-in-middle");
255 EXPECT_EQ(expectedDot, erase_all_copy(dot, "\n"));
256 EXPECT_EQ("GTG", pc->Sequence);
257 }
258
259 // Mismatch at end
260 {
261 std::vector<std::string> reads;
262 reads += "GGG", "GGT";
263 std::unique_ptr<const PacBio::Poa::PoaConsensus> pc{
264 PoaConsensus::FindConsensus(reads, AlignMode::GLOBAL)};
265 std::string dot = pc->Graph.ToGraphViz();
266 std::string expectedDot =
267 "digraph G {"
268 "rankdir=\"LR\";"
269 "0[shape=Mrecord, label=\"{ ^ | 0 }\"];"
270 "1[shape=Mrecord, label=\"{ $ | 0 }\"];"
271 "2[shape=Mrecord, label=\"{ G | 2 }\"];"
272 "3[shape=Mrecord, label=\"{ G | 2 }\"];"
273 "4[shape=Mrecord, label=\"{ G | 1 }\"];"
274 "5[shape=Mrecord, label=\"{ T | 1 }\"];"
275 "0->2 ;"
276 "2->3 ;"
277 "3->4 ;"
278 "4->1 ;"
279 "5->1 ;"
280 "3->5 ;"
281 "}";
282 PoaConsensusTests::plotConsensus(pc.get(), "mismatch-at-end");
283 EXPECT_EQ(expectedDot, erase_all_copy(dot, "\n"));
284 EXPECT_EQ("GG", pc->Sequence);
285 }
286 }
287
288 TEST(PoaGraph, SmallDeletionTests)
289 {
290 // Deletion at beginning
291 {
292 std::vector<std::string> reads;
293 reads += "GAT", "AT";
294 std::unique_ptr<const PacBio::Poa::PoaConsensus> pc{
295 PoaConsensus::FindConsensus(reads, AlignMode::GLOBAL)};
296 std::string dot = pc->Graph.ToGraphViz();
297 std::string expectedDot =
298 "digraph G {"
299 "rankdir=\"LR\";"
300 "0[shape=Mrecord, label=\"{ ^ | 0 }\"];"
301 "1[shape=Mrecord, label=\"{ $ | 0 }\"];"
302 "2[shape=Mrecord, label=\"{ G | 1 }\"];"
303 "3[shape=Mrecord, label=\"{ A | 2 }\"];"
304 "4[shape=Mrecord, label=\"{ T | 2 }\"];"
305 "0->2 ;"
306 "2->3 ;"
307 "3->4 ;"
308 "4->1 ;"
309 "0->3 ;"
310 "}";
311 PoaConsensusTests::plotConsensus(pc.get(), "deletion-at-beginning");
312 EXPECT_EQ(expectedDot, erase_all_copy(dot, "\n"));
313 EXPECT_EQ("AT", pc->Sequence);
314 }
315
316 // Deletion in middle
317 {
318 std::vector<std::string> reads;
319 reads += "GAT", "GT";
320 std::unique_ptr<const PacBio::Poa::PoaConsensus> pc{
321 PoaConsensus::FindConsensus(reads, AlignMode::GLOBAL)};
322 std::string dot = pc->Graph.ToGraphViz();
323 std::string expectedDot =
324 "digraph G {"
325 "rankdir=\"LR\";"
326 "0[shape=Mrecord, label=\"{ ^ | 0 }\"];"
327 "1[shape=Mrecord, label=\"{ $ | 0 }\"];"
328 "2[shape=Mrecord, label=\"{ G | 2 }\"];"
329 "3[shape=Mrecord, label=\"{ A | 1 }\"];"
330 "4[shape=Mrecord, label=\"{ T | 2 }\"];"
331 "0->2 ;"
332 "2->3 ;"
333 "3->4 ;"
334 "4->1 ;"
335 "2->4 ;"
336 "}";
337 PoaConsensusTests::plotConsensus(pc.get(), "deletion-in-middle");
338 EXPECT_EQ(expectedDot, erase_all_copy(dot, "\n"));
339 }
340
341 // Deletion at end
342 {
343 std::vector<std::string> reads;
344 reads += "GAT", "GA";
345 std::unique_ptr<const PacBio::Poa::PoaConsensus> pc{
346 PoaConsensus::FindConsensus(reads, AlignMode::GLOBAL)};
347 std::string dot = pc->Graph.ToGraphViz();
348 std::string expectedDot =
349 "digraph G {"
350 "rankdir=\"LR\";"
351 "0[shape=Mrecord, label=\"{ ^ | 0 }\"];"
352 "1[shape=Mrecord, label=\"{ $ | 0 }\"];"
353 "2[shape=Mrecord, label=\"{ G | 2 }\"];"
354 "3[shape=Mrecord, label=\"{ A | 2 }\"];"
355 "4[shape=Mrecord, label=\"{ T | 1 }\"];"
356 "0->2 ;"
357 "2->3 ;"
358 "3->4 ;"
359 "4->1 ;"
360 "3->1 ;"
361 "}";
362 PoaConsensusTests::plotConsensus(pc.get(), "deletion-at-end");
363 EXPECT_EQ(expectedDot, erase_all_copy(dot, "\n"));
364 EXPECT_EQ("GA", pc->Sequence);
365 }
366 }
367
368 TEST(PoaConsensus, TestSimple)
369 {
370 std::vector<std::string> reads;
371 reads += "TTTACAGGATAGTCCAGT", "ACAGGATACCCCGTCCAGT", "ACAGGATAGTCCAGT",
372 "TTTACAGGATAGTCCAGTCCCC", "TTTACAGGATTAGTCCAGT", "TTTACAGGATTAGGTCCCAGT",
373 "TTTACAGGATAGTCCAGT";
374 std::unique_ptr<const PacBio::Poa::PoaConsensus> pc{
375 PoaConsensus::FindConsensus(reads, AlignMode::GLOBAL)};
376 PoaConsensusTests::plotConsensus(pc.get(), "simple");
377 EXPECT_EQ("TTTACAGGATAGTCCAGT", pc->Sequence);
378 }
379
380 TEST(PoaConsensus, TestOverhangSecond)
381 {
382 std::vector<std::string> reads;
383 reads += "TTTACAGGATAGTCCAGT", "TTTACAGGATAGTCCAGTAAA", "TTTACAGGATAGTCCAGTAAA";
384 std::unique_ptr<const PacBio::Poa::PoaConsensus> pc{
385 PoaConsensus::FindConsensus(reads, AlignMode::GLOBAL)};
386 EXPECT_EQ("TTTACAGGATAGTCCAGTAAA", pc->Sequence);
387 }
388
389 TEST(PoaConsensus, SmallSemiglobalTest)
390 {
391 std::vector<std::string> reads;
392 reads += "GGTGG", "GGTGG", "T";
393 std::unique_ptr<const PacBio::Poa::PoaConsensus> pc{
394 PoaConsensus::FindConsensus(reads, AlignMode::SEMIGLOBAL)};
395 PoaConsensusTests::plotConsensus(pc.get(), "small-semiglobal");
396 std::string expectedDot =
397 "digraph G {"
398 "rankdir=\"LR\";"
399 "0[shape=Mrecord, label=\"{ ^ | 0 }\"];"
400 "1[shape=Mrecord, label=\"{ $ | 0 }\"];"
401 "2[shape=Mrecord, label=\"{ G | 2 }\"];"
402 "3[shape=Mrecord, label=\"{ G | 2 }\"];"
403 "4[shape=Mrecord, label=\"{ T | 3 }\"];"
404 "5[shape=Mrecord, label=\"{ G | 2 }\"];"
405 "6[shape=Mrecord, label=\"{ G | 2 }\"];"
406 "0->2 ;"
407 "2->3 ;"
408 "3->4 ;"
409 "4->5 ;"
410 "5->6 ;"
411 "6->1 ;"
412 "4->1 ;"
413 "0->4 ;"
414 "}";
415 std::string dot = pc->Graph.ToGraphViz();
416 EXPECT_EQ(expectedDot, erase_all_copy(dot, "\n"));
417 EXPECT_EQ("GGTGG", pc->Sequence);
418 }
419
420 TEST(PoaConsensus, SmallTilingTest)
421 {
422 std::vector<std::string> reads;
423 reads += "GGGGAAAA", "AAAATTTT", "TTTTCCCC", "CCCCAGGA";
424 std::unique_ptr<const PacBio::Poa::PoaConsensus> pc{
425 PoaConsensus::FindConsensus(reads, AlignMode::SEMIGLOBAL)};
426 PoaConsensusTests::plotConsensus(pc.get(), "small-tiling");
427 EXPECT_EQ("GGGGAAAATTTTCCCCAGGA", pc->Sequence);
428 }
429
430 TEST(PoaConsensus, TestVerboseGraphVizOutput)
431 {
432 std::vector<std::string> reads;
433 reads += "GGG", "TGGG";
434 std::unique_ptr<const PacBio::Poa::PoaConsensus> pc{
435 PoaConsensus::FindConsensus(reads, AlignMode::GLOBAL)};
436 std::string dot =
437 pc->Graph.ToGraphViz(PoaGraph::COLOR_NODES | PoaGraph::VERBOSE_NODES, pc.get());
438
439 std::string expectedDot =
440 "digraph G {"
441 "rankdir=\"LR\";"
442 "0[shape=Mrecord, label=\"{ { 0 | ^ } | { 0 | 0 } | { 0.00 | 0.00 } "
443 "}\"];"
444 "1[shape=Mrecord, label=\"{ { 1 | $ } | { 0 | 0 } | { 0.00 | 0.00 } "
445 "}\"];"
446 "2[shape=Mrecord, style=\"filled\", fillcolor=\"lightblue\" ,"
447 " label=\"{ { 2 | G } | { 2 | 2 } | { 2.00 | 2.00 } }\"];"
448 "3[shape=Mrecord, style=\"filled\", fillcolor=\"lightblue\" ,"
449 " label=\"{ { 3 | G } | { 2 | 2 } | { 2.00 | 4.00 } }\"];"
450 "4[shape=Mrecord, style=\"filled\", fillcolor=\"lightblue\" ,"
451 " label=\"{ { 4 | G } | { 2 | 2 } | { 2.00 | 6.00 } }\"];"
452 "5[shape=Mrecord, label=\"{ { 5 | T } | { 1 | 2 } | { -0.00 | -0.00 } "
453 "}\"];"
454 "0->2 ;"
455 "2->3 ;"
456 "3->4 ;"
457 "4->1 ;"
458 "5->2 ;"
459 "0->5 ;}";
460
461 EXPECT_EQ(expectedDot, erase_all_copy(dot, "\n"));
462 }
463
464 TEST(PoaConsensus, TestLocalStaggered)
465 {
466 // Adapted from Pat's C# test
467 std::vector<std::string> reads;
468 reads += "TTTACAGGATAGTGCCGCCAATCTTCCAGT", "GATACCCCGTGCCGCCAATCTTCCAGTATATACAGCACGAGTAGC",
469 "ATAGTGCCGCCAATCTTCCAGTATATACAGCACGGAGTAGCATCACGTACGTACGTCTACACGTAATT",
470 "ACGTCTACACGTAATTTTGGAGAGCCCTCTCTCACG", "ACACGTAATTTTGGAGAGCCCTCTCTTCACG",
471 "AGGATAGTGCCGCCAATCTTCCAGTAATATACAGCACGGAGTAGCATCACGTACG",
472 "ATAGTGCCGCCAATCTTCCAGTATATACAGCACGGAGTAGCATCACGTACGTACGTCTACACGT";
473
474 // 4 is a magic number here. the .NET code had an entrenched
475 // assumption that sequences in POA were subreads from a ZMW, so
476 // the minCoverage was (numReads - 3), under assumption that basal
477 // coverage for CCS is (numReads-2) (beginning, end read).
478 // Application has to provide a sensible minCoverage.
479 std::unique_ptr<const PacBio::Poa::PoaConsensus> pc{
480 PoaConsensus::FindConsensus(reads, AlignMode::LOCAL, 4)};
481 PoaConsensusTests::plotConsensus(pc.get(), "local-staggered", false);
482 EXPECT_EQ("ATAGTGCCGCCAATCTTCCAGTATATACAGCACGGAGTAGCATCACGTACGTACGTCTACACGTAATT", pc->Sequence);
483 }
484
485 TEST(PoaConsensus, TestLongInsert)
486 {
487 // Adapted from Pat's C# test
488 std::vector<std::string> reads;
489 reads +=
490 "TTTACAGGATAGTGCCGCCAATCTTCCAGTGATACCCCGTGCCGCCAATCTTCCAGTATATACAGCACGA"
491 "GGTAGC",
492 "TTTACAGGATAGTGCCGGCCAATCTTCCAGTGATACCCCGTGCCGCCAATCTTCCAGTATATACAGCACG"
493 "AGTAGC",
494 "TTGTACAGGATAGTGCCGCCAATCTTCCAGTGATGGGGGGGGGGGGGGGGGGGGGGGGGGGACCCCGTGC"
495 "CGCCAATCTTCCAGTATATACAGCACGAGTAGC";
496 std::unique_ptr<const PacBio::Poa::PoaConsensus> pc{
497 PoaConsensus::FindConsensus(reads, AlignMode::GLOBAL)};
498 EXPECT_EQ(
499 "TTTACAGGATAGTGCCGCCAATCTTCCAGTGATACCCCGTGCCGCCAATCTTCCAGTATATACAGCACGA"
500 "GTAGC",
501 pc->Sequence);
502 }
503
504 TEST(PoaConsensus, TestSpanningReads)
505 {
506 std::string read1 = "GAAAG";
507 std::string read2 = "GATAG";
508 std::vector<std::string> reads{read1, read1, read1, read2, read2, read2};
509 std::unique_ptr<const PacBio::Poa::PoaConsensus> pc{
510 PoaConsensus::FindConsensus(reads, AlignMode::LOCAL)};
511 PoaConsensusTests::plotConsensus(pc.get(), "spanning-reads");
512
513 std::string dot =
514 pc->Graph.ToGraphViz(PoaGraph::VERBOSE_NODES | PoaGraph::COLOR_NODES, pc.get());
515 // We expect to get spanning reads of 6 for the middle A/T nodes,
516 // but each only has 3 reads passing through.
517 // The PoaGraph doesn't really expose an API, we can only check it
518 // by looking at the GraphViz output.
519
520 // clang-format off
521 std::string expectedDot =
522 "digraph G {"
523 "rankdir=\"LR\";"
524 "0[shape=Mrecord, label=\"{ { 0 | ^ } | { 0 | 0 } | { 0.00 | 0.00 } }\"];"
525 "1[shape=Mrecord, label=\"{ { 1 | $ } | { 0 | 0 } | { 0.00 | 0.00 } }\"];"
526 "2[shape=Mrecord, style=\"filled\", fillcolor=\"lightblue\" , label=\"{ { 2 | G } | { 6 | 6 } | { 6.00 | 6.00 } }\"];"
527 "3[shape=Mrecord, style=\"filled\", fillcolor=\"lightblue\" , label=\"{ { 3 | A } | { 6 | 6 } | { 6.00 | 12.00 } }\"];"
528 "4[shape=Mrecord, style=\"filled\", fillcolor=\"lightblue\" , label=\"{ { 4 | A } | { 3 | 6 } | { -0.00 | 12.00 } }\"];"
529 "5[shape=Mrecord, style=\"filled\", fillcolor=\"lightblue\" , label=\"{ { 5 | A } | { 6 | 6 } | { 6.00 | 18.00 } }\"];"
530 "6[shape=Mrecord, style=\"filled\", fillcolor=\"lightblue\" , label=\"{ { 6 | G } | { 6 | 6 } | { 6.00 | 24.00 } }\"];"
531 "7[shape=Mrecord, label=\"{ { 7 | T } | { 3 | 6 } | { -0.00 | 12.00 } }\"];"
532 "0->2 ;"
533 "2->3 ;"
534 "3->4 ;"
535 "4->5 ;"
536 "5->6 ;"
537 "6->1 ;"
538 "7->5 ;"
539 "3->7 ;"
540 "}";
541 // clang-format on
542
543 EXPECT_EQ(expectedDot, erase_all_copy(dot, "\n"));
544 }
545
546 TEST(PoaConsensus, NondeterminismRegressionTest)
547 {
548 //
549 // This is a regression test for a real-world case of
550 // nondeterminism found in the POA on a quiver job on Staph.
551 //
552 std::vector<std::string> reads;
553 reads +=
554 "TATCAATCAACGAAATTCGCCAATTCCGTCATGAATGTCAATATCTAACTACACTTTAGAATACATTCTT"
555 "TGACATGCCTGGCCTATTGATATTTCAATAAAATCAGACTATAAAGACAACTTACAAATGATCCTATAAA"
556 "TTAAAGATCGAGAATCTAAAGAGTGAAATTAAAGCTAATTACTGCTTTAAAAATTTTACGTGCACACAAA"
557 "AATGAATTTATCCTCATTATATCGAAAATACCATGAAGTATAGTAAGCTAACTTGAATATGATCATTAAT"
558 "CGGCTATATGATTATTTTGATAATGCAATGAGCATCAATCTGAATTTATGACCTATCATTCGCGTTGCAT"
559 "TTATTGAAGTGAAAATTCATGTACGCTTTTTTATTTTATTAATATAATCCTTGATATTGGTTATATACCA"
560 "CGCTGTCACATAATTTTCAATAAATTTTTCTACTAAATGAAGTGTCTGTTATCTATCAC";
561 reads +=
562 "TATCAACAACGAAAATGCGCAGTTACGTCATGATTTATGTCAAATAATCTAAACGACACTTTCAGAAATA"
563 "AATACATTCGAGAAGATGAATGCCTGGCGCAAAGTGATTATTTCAATAAAATATTTGTACCTTGAAAGAC"
564 "AATTTACAAATGAATGCTATAAAATTTAAATGGATCCGGAGAATCTTTAAAGTACGTGAAATTAAAGGCT"
565 "AAGATTACTGCGAAAAATTTTCGTGCACAAGAAATGAATGTTCCAGATTAGTATCGGAAAATAAGCCATG"
566 "AAGAAGCTAGCATTAACTTGAATATGATCGATTTAATCGGCAGTATTGGTAATTATCTTGATAAGCAATT"
567 "GAGCATCAACTGAAATTGAATGACTCTACATGCCTCGCTGAGTATGCGATTTATTGAAAGTGAAATTCAG"
568 "TAAAGTTTATTGTTATGAATAAATGCGTACTTGGATGAATATCCCGACGGTAGTTCAAGTGTAAATGGAG"
569 "TGAGGGGGTTCTTTCTTATAGAATAGTTTTATACTACTGATAAGGTGTAACCTGAGTGAGTCGTGATTTT"
570 "AGAGTTACTTGCGAAC";
571
572 std::set<std::string> answers;
573 for (int run = 0; run < 100; run++) {
574 std::unique_ptr<const PacBio::Poa::PoaConsensus> pc{
575 PoaConsensus::FindConsensus(reads, AlignMode::GLOBAL)};
576 #if 0
577 char fname[100];
578 sprintf(fname, "/tmp/gr%03d.dot", run);
579 pc->WriteGraphVizFile(fname, (PoaGraph::VERBOSE_NODES | PoaGraph::COLOR_NODES));
580 #endif
581 answers.insert(pc->Sequence);
582 }
583 ASSERT_EQ(1, answers.size());
584 }