Skip to content

Commit f2dea7f

Browse files
committed
done?
1 parent 33db8e4 commit f2dea7f

File tree

6 files changed

+37
-22
lines changed

6 files changed

+37
-22
lines changed

bin/app

-280 Bytes
Binary file not shown.

obj/alignment/alignment.o

1.09 KB
Binary file not shown.

obj/wrapper/program_wrapper.o

8 Bytes
Binary file not shown.

src/alignment/alignment.cpp

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,12 @@ namespace alignment {
77
std::vector<dp_cell> cur_dp_row(col_size, dp_cell());
88
std::vector<dp_cell> prev_dp_row(col_size, dp_cell());
99

10-
// temp
11-
std::ofstream s("./output.txt");
12-
13-
// prev_dp_row[0].print_scores(s);
14-
// s << " ";
15-
1610
for (size_t i = 1; i < col_size; ++i) {
1711
prev_dp_row[i].set_top_row(i);
18-
// prev_dp_row[i].print_scores(s);
19-
// s << " ";
2012
}
2113

2214
for (size_t row_idx = 1; row_idx < row_size; ++row_idx) {
2315
cur_dp_row[0].set_left_col(row_idx);
24-
// cur_dp_row[0].print_scores(s);
25-
// s << " ";
2616
for (size_t col_idx = 1; col_idx < col_size; ++col_idx) {
2717
cur_dp_row[col_idx].score_cell(
2818
prev_dp_row[col_idx-1],
@@ -31,21 +21,46 @@ namespace alignment {
3121
string_one[row_idx-1],
3222
string_two[col_idx-1]
3323
);
34-
// cur_dp_row[col_idx].print_scores(s);
35-
// s << " ";
3624
}
37-
// s << std::endl;
3825
std::swap(prev_dp_row, cur_dp_row);
3926
}
27+
return prev_dp_row.back().get_max_score();
28+
}
4029

41-
s << prev_dp_row.back().to_string() << std::endl;
30+
int32_t execute_modified_global_alignment(const std::string& string_one, const std::string& string_two) {
31+
const size_t row_size = string_one.size() + 1;
32+
const size_t col_size = string_two.size() + 1;
33+
std::vector<dp_cell> cur_dp_row(col_size, dp_cell());
34+
std::vector<dp_cell> prev_dp_row(col_size, dp_cell());
4235

43-
s.close();
36+
for (size_t i = 1; i < col_size; ++i) {
37+
prev_dp_row[i].set_top_row(i);
38+
}
4439

45-
return prev_dp_row.back().get_max_score();
46-
}
40+
int64_t max_score = 0;
41+
int32_t max_score_matches = 0;
42+
43+
for (size_t row_idx = 1; row_idx < row_size; ++row_idx) {
44+
cur_dp_row[0].set_left_col(row_idx);
45+
for (size_t col_idx = 1; col_idx < col_size; ++col_idx) {
46+
cur_dp_row[col_idx].score_cell(
47+
prev_dp_row[col_idx-1],
48+
prev_dp_row[col_idx],
49+
cur_dp_row[col_idx-1],
50+
string_one[row_idx-1],
51+
string_two[col_idx-1]
52+
);
53+
54+
const int64_t temp_max_score = cur_dp_row[col_idx].get_max_score();
4755

48-
// int32_t execute_modified_global_alignment(const std::string& string_one, const std::string& string_two) {
49-
// throw std::runtime_error("not implemented");
50-
// }
56+
if (temp_max_score > max_score) {
57+
max_score = temp_max_score;
58+
max_score_matches = cur_dp_row[col_idx].get_max_score_matches();
59+
}
60+
}
61+
std::swap(prev_dp_row, cur_dp_row);
62+
}
63+
64+
return max_score_matches;
65+
}
5166
}

src/alignment/alignment.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace alignment {
1313
int64_t execute_global_alignment(const std::string&, const std::string&);
14-
// int32_t execute_modified_global_alignment(const std::string&, const std::string&);
14+
int32_t execute_modified_global_alignment(const std::string&, const std::string&);
1515
}
1616

1717
#endif

src/wrapper/program_wrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ void program_wrapper::run_program(const int arg_count, const char* const* arg_ve
2323
if (!io_utils::load_two_genes(arg_vector[1], gene_one, gene_two, gene_one_name, gene_two_name)) {
2424
throw std::runtime_error("error, not able to load genes from file");
2525
}
26-
int64_t result = alignment::execute_global_alignment(gene_one, gene_two);
26+
int64_t result = alignment::execute_modified_global_alignment(gene_one, gene_two);
2727
std::cout << result << std::endl;
2828
}

0 commit comments

Comments
 (0)