Debian Codegraph @

tests/src/align/test_GlobalLocalAlignment.cpp

raw
1 #include <pbcopper/align/GlobalLocalAlignment.h>
2
3 #include <pbcopper/utility/Stopwatch.h>
4
5 #include <gtest/gtest.h>
6
7 #include <string>
8 #include <vector>
9
10 TEST(Align_GlobalLocalAlignment, perfect_match)
11 {
12 using namespace PacBio::Align;
13 const std::string both{"GATTACA"};
14 GlobalLocalParameters params{4, -4, -3, -3, -2, -2};
15 GlobalLocalResult result = GlobalLocalAlign(both, both, params);
16 EXPECT_EQ(params.MatchScore * both.size(), result.MaxScore);
17 EXPECT_EQ(both.size() - 1, result.EndPos);
18 }
19
20 TEST(Align_GlobalLocalAlignment, deletion)
21 {
22 using namespace PacBio::Align;
23 const std::string read{"GTTACA"};
24 const std::string qry{"GATTACA"};
25 GlobalLocalParameters params{10, -4, -1, -3, -2, -2};
26 GlobalLocalResult result = GlobalLocalAlign(qry, read, params);
27 EXPECT_EQ(params.MatchScore * read.size() + params.DeletionPenalty, result.MaxScore);
28 EXPECT_EQ(read.size() - 1, result.EndPos);
29 }
30
31 TEST(Align_GlobalLocalAlignment, insertion)
32 {
33 using namespace PacBio::Align;
34 const std::string read{"GATTACA"};
35 const std::string qry{"GTTACA"};
36 GlobalLocalParameters params{10, -4, -1, -3, -2, -2};
37 GlobalLocalResult result = GlobalLocalAlign(qry, read, params);
38 EXPECT_EQ(params.MatchScore * qry.size() + params.InsertionPenalty, result.MaxScore);
39 EXPECT_EQ(read.size() - 1, result.EndPos);
40 }
41
42 TEST(Align_GlobalLocalAlignment, branch)
43 {
44 using namespace PacBio::Align;
45 const std::string read{"GATTAACA"};
46 const std::string qry{"GATTACA"};
47 GlobalLocalParameters params{10, -5, -4, -3, -1, -2};
48 GlobalLocalResult result = GlobalLocalAlign(qry, read, params);
49 EXPECT_EQ(params.MatchScore * qry.size() + params.BranchPenalty, result.MaxScore);
50 EXPECT_EQ(read.size() - 1, result.EndPos);
51 }
52
53 TEST(Align_GlobalLocalAlignment, merge)
54 {
55 using namespace PacBio::Align;
56 const std::string read{"GATACA"};
57 const std::string qry{"GATTACA"};
58 GlobalLocalParameters params{10, -5, -4, -3, -1, -2};
59 GlobalLocalResult result = GlobalLocalAlign(qry, read, params);
60 EXPECT_EQ(params.MatchScore * read.size() + params.MergePenalty, result.MaxScore);
61 EXPECT_EQ(read.size() - 1, result.EndPos);
62 }
63
64 TEST(Align_GlobalLocalAlignment, perfect_match_openend)
65 {
66 using namespace PacBio::Align;
67 const std::string target{"GATTACAT"};
68 const std::string query{"GATTACA"};
69 GlobalLocalParameters params{4, -4, -3, -3, -2, -2};
70 GlobalLocalResult result = GlobalLocalAlign(query, target, params);
71 EXPECT_EQ(params.MatchScore * query.size(), result.MaxScore);
72 EXPECT_EQ(query.size() - 1, result.EndPos);
73 }
74
75 TEST(Align_GlobalLocalAlignment, perfect_match_openbegin)
76 {
77 using namespace PacBio::Align;
78 const std::string target{"TTAAGAGATTACA"};
79 const std::string query{"GATTACA"};
80 GlobalLocalParameters params{4, -4, -3, -3, -2, -2};
81 GlobalLocalResult result = GlobalLocalAlign(query, target, params);
82 EXPECT_EQ(params.MatchScore * query.size(), result.MaxScore);
83 EXPECT_EQ(target.size() - 1, result.EndPos);
84 }
85
86 TEST(Align_GlobalLocalAlignment, perfect_match_infix)
87 {
88 using namespace PacBio::Align;
89 const std::string target{"TTAAGAGATTACATTTAT"};
90 const std::string query{"GATTACA"};
91 GlobalLocalParameters params{4, -4, -3, -3, -2, -2};
92 GlobalLocalResult result;
93 result = GlobalLocalAlign(query, target, params);
94 EXPECT_EQ(params.MatchScore * query.size(), result.MaxScore);
95 EXPECT_EQ(12, result.EndPos);
96 }
97
98 #if 0
99 TEST(Align_GlobalLocalAlignment, random)
100 {
101 using namespace PacBio::Align;
102 const std::string target{"AGTAGGAGTAGTTAGGTATAAA"};
103 const std::string query{"GTGTTAAAGTGTTAAA"};
104 std::string target2{
105 "GTATGAGTAGAGGTAGTAGTATGTAGTAGTAGTGTAGTAGTGTAGTAGTAGTGTAGTAGTGTATGGATAGTAGAGTAGAT"};
106 for (int32_t i = 0; i < 8; ++i) {
107 target2 = target2 + target2;
108 }
109 std::cerr << target2.size() << '\n';
110 const std::string query2{"TGATAGAGTATGAGTA"};
111 GlobalLocalParameters params{4, -4, -3, -3, -2, -2};
112 GlobalLocalResult result;
113 std::vector<int32_t> matrix;
114 PacBio::Utility::Stopwatch t;
115 const int32_t rounds = 5000;
116 GlobalLocalStorage storage{};
117 for (int32_t i = 0; i < rounds * 1000; ++i) {
118 result = GlobalLocalAlign(query, target, params, storage);
119 }
120 t.Freeze();
121 int64_t time = t.ElapsedNanoseconds() / rounds / 1000;
122 std::cerr << t.PrettyPrintNanoseconds(time) << '\n';
123 t.Reset();
124 for (int32_t i = 0; i < rounds; ++i) {
125 result = GlobalLocalAlign(query2, target2, params, storage);
126 }
127 t.Freeze();
128 time = t.ElapsedNanoseconds() / rounds;
129 std::cerr << t.PrettyPrintNanoseconds(time) << '\n';
130 }
131 #endif