@@ -7,26 +7,117 @@ const int64_t mismatch_score = -2;
77const int64_t opening_gap_score = -5 ;
88const int64_t gap_extension_score = -2 ;
99
10+ // MARK: private methods
11+
12+ void dp_cell::score_s (const dp_cell& cell_s, const char c_one, const char c_two) {
13+ const int64_t s_candidate = cell_s.get_s_score ();
14+ const int64_t d_candidate = cell_s.get_d_score ();
15+ const int64_t i_candidate = cell_s.get_i_score ();
16+ const int64_t max_candidate = std::max (s_candidate, std::max (d_candidate, i_candidate));
17+ if (s_candidate == max_candidate) {
18+ this ->m_s_matches = cell_s.get_s_matches ();
19+ } else if (d_candidate == max_candidate) {
20+ this ->m_s_matches = cell_s.get_d_matches ();
21+ } else {
22+ this ->m_s_matches = cell_s.get_i_matches ();
23+ }
24+ this ->m_s_matches += (c_one == c_two ? 1 : 0 );
25+ this ->m_s_score = std::max (dp_cell::min_score, max_candidate + (c_one == c_two ? match_score : mismatch_score));
26+ }
27+
28+ void dp_cell::score_d (const dp_cell& cell_d) {
29+ const int64_t s_candidate = cell_d.get_s_score () + opening_gap_score + gap_extension_score;
30+ const int64_t d_candidate = cell_d.get_d_score () + gap_extension_score;
31+ const int64_t i_candidate = cell_d.get_i_score () + opening_gap_score + gap_extension_score;
32+ const int64_t max_candidate = std::max (s_candidate, std::max (d_candidate, i_candidate));
33+ if (s_candidate == max_candidate) {
34+ this ->m_d_matches = cell_d.get_s_matches ();
35+ } else if (d_candidate == max_candidate) {
36+ this ->m_d_matches = cell_d.get_d_matches ();
37+ } else {
38+ this ->m_d_matches = cell_d.get_i_matches ();
39+ }
40+ this ->m_d_score = std::max (dp_cell::min_score, max_candidate);
41+ }
42+
43+ void dp_cell::score_i (const dp_cell& cell_i) {
44+ const int64_t s_candidate = cell_i.get_s_score () + opening_gap_score + gap_extension_score;
45+ const int64_t d_candidate = cell_i.get_d_score () + opening_gap_score + gap_extension_score;
46+ const int64_t i_candidate = cell_i.get_i_score () + gap_extension_score;
47+ const int64_t max_candidate = std::max (s_candidate, std::max (d_candidate, i_candidate));
48+ if (s_candidate == max_candidate) {
49+ this ->m_i_matches = cell_i.get_s_matches ();
50+ } else if (d_candidate == max_candidate) {
51+ this ->m_i_matches = cell_i.get_d_matches ();
52+ } else {
53+ this ->m_i_matches = cell_i.get_i_matches ();
54+ }
55+ this ->m_i_score = std::max (dp_cell::min_score, max_candidate);
56+ }
57+
58+ // MARK: public methods
59+
1060dp_cell::dp_cell () :
11- m_i_score(0 ),
1261 m_s_score(0 ),
1362 m_d_score(0 ),
14- m_i_matches (0 ),
63+ m_i_score (0 ),
1564 m_s_matches(0 ),
16- m_d_matches(0 ) {}
65+ m_d_matches(0 ),
66+ m_i_matches(0 ) {
67+ }
1768
18- dp_cell::~dp_cell () {}
69+ dp_cell::~dp_cell () {
70+ }
1971
2072int64_t dp_cell::get_max_score (void ) const {
21- return std::max (this ->m_i_score , std::max (this ->m_s_score , this ->m_d_score ));
73+ return std::max (this ->m_s_score , std::max (this ->m_d_score , this ->m_i_score ));
2274}
2375
24- // MARK: getters
76+ int32_t dp_cell::get_max_score_matches (void ) const {
77+ const int64_t max_score = std::max (this ->m_s_score , std::max (this ->m_d_score , this ->m_i_score ));
78+ if (max_score == this ->m_s_score ) {
79+ return this ->m_s_matches ;
80+ } else if (max_score == this ->m_d_score ) {
81+ return this ->m_d_matches ;
82+ }
83+ return this ->m_i_matches ;
84+ }
2585
26- int64_t dp_cell::get_i_score (void ) const {
27- return this ->m_i_score ;
86+ void dp_cell::score_cell (const dp_cell& cell_s, const dp_cell& cell_d, const dp_cell& cell_i, const char c_one, const char c_two) {
87+ this ->score_s (cell_s, c_one, c_two);
88+ this ->score_d (cell_d);
89+ this ->score_i (cell_i);
90+ }
91+
92+ void dp_cell::reset_cell (void ) {
93+ this ->m_s_score = 0 ;
94+ this ->m_d_score = 0 ;
95+ this ->m_i_score = 0 ;
96+ this ->m_s_matches = 0 ;
97+ this ->m_d_matches = 0 ;
98+ this ->m_i_matches = 0 ;
2899}
29100
101+ void dp_cell::set_top_row (size_t col_idx) {
102+ this ->m_s_score = dp_cell::min_score;
103+ this ->m_d_score = dp_cell::min_score;
104+ this ->m_i_score = opening_gap_score + (static_cast <int64_t >(col_idx) * gap_extension_score);
105+ this ->m_s_matches = 0 ;
106+ this ->m_d_matches = 0 ;
107+ this ->m_i_matches = 0 ;
108+ }
109+
110+ void dp_cell::set_left_col (size_t row_idx) {
111+ this ->m_s_score = dp_cell::min_score;
112+ this ->m_d_score = opening_gap_score + (static_cast <int64_t >(row_idx) * gap_extension_score);
113+ this ->m_i_score = dp_cell::min_score;
114+ this ->m_s_matches = 0 ;
115+ this ->m_d_matches = 0 ;
116+ this ->m_i_matches = 0 ;
117+ }
118+
119+ // MARK: getters
120+
30121int64_t dp_cell::get_s_score (void ) const {
31122 return this ->m_s_score ;
32123}
@@ -35,16 +126,68 @@ int64_t dp_cell::get_d_score(void) const {
35126 return this ->m_d_score ;
36127}
37128
38- // MARK: setters
129+ int64_t dp_cell::get_i_score (void ) const {
130+ return this ->m_i_score ;
131+ }
39132
40- void dp_cell::set_i_score (const int64_t _i_score) {
41- this ->m_i_score = _i_score;
133+ int32_t dp_cell::get_s_matches (void ) const {
134+ return this ->m_s_matches ;
135+ }
136+
137+ int32_t dp_cell::get_d_matches (void ) const {
138+ return this ->m_d_matches ;
42139}
43140
44- void dp_cell::set_i_score (const int64_t _s_score) {
141+ int32_t dp_cell::get_i_matches (void ) const {
142+ return this ->m_i_matches ;
143+ }
144+
145+ // MARK: setters
146+
147+ void dp_cell::set_s_score (int64_t _s_score) {
45148 this ->m_s_score = _s_score;
46149}
47150
48- void dp_cell::set_i_score ( const int64_t _d_score) {
151+ void dp_cell::set_d_score ( int64_t _d_score) {
49152 this ->m_d_score = _d_score;
153+ }
154+
155+ void dp_cell::set_i_score (int64_t _i_score) {
156+ this ->m_i_score = _i_score;
157+ }
158+
159+ void dp_cell::set_s_matches (int32_t _s_matches) {
160+ this ->m_s_matches = _s_matches;
161+ }
162+
163+ void dp_cell::set_d_matches (int32_t _d_matches) {
164+ this ->m_d_matches = _d_matches;
165+ }
166+
167+ void dp_cell::set_i_matches (int32_t _i_matches) {
168+ this ->m_i_matches = _i_matches;
169+ }
170+
171+ // MARK: printers
172+
173+ void dp_cell::print_scores (std::ostream& os) const {
174+ os << " (s-[" << this ->m_s_score << " ], d-[" << this ->m_d_score << " ], i-[" << this ->m_i_score << " ])" ;
175+ }
176+
177+ void dp_cell::print_matches (std::ostream& os) const {
178+ os << " (s-" << this ->m_s_matches << " , d-" << this ->m_d_matches << " , i-" << this ->m_i_matches << " )" ;
179+ }
180+
181+ void dp_cell::print_all (std::ostream& os) const {
182+ os << " {(s-" << this ->m_s_score << " , d-" << this ->m_d_score << " , i-" << this ->m_i_score << " ), (s-"
183+ << this ->m_s_matches << " , d-" << this ->m_d_matches << " , i-" << this ->m_i_matches << " )}" ;
184+ }
185+
186+ std::string dp_cell::to_string (void ) const {
187+ std::ostringstream string_stream;
188+ string_stream
189+ << " {(s_score-[" << this ->m_s_score << " ], d_score-[" << this ->m_d_score << " ], i_score[" << this ->m_i_score
190+ << " ]), (s_match-[" << this ->m_s_matches << " ], d_match[" << this ->m_d_matches << " ], i_match[" << this ->m_d_matches
191+ << " ])}" ;
192+ return string_stream.str ();
50193}
0 commit comments