Skip to content

Commit 8f28eed

Browse files
committed
.config mods complete
1 parent 756eca6 commit 8f28eed

File tree

8 files changed

+82
-10
lines changed

8 files changed

+82
-10
lines changed

bin/app

71.6 KB
Binary file not shown.

input/alignment-params.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
match 2
1+
match 1
22
mismatch -2
33
h -5
44
g -2

makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,20 @@ clean:
2626

2727
run-sample: $(TARGET)
2828
@if [ -f $(TARGET) ]; then \
29-
./$(TARGET) input/base-sample.fasta; \
29+
./$(TARGET) \
30+
input/alignment-params.config \
31+
input/base-sample.fasta \
32+
; \
3033
else \
3134
echo "Error: Executable $(TARGET) not found. Please build it first."; \
3235
exit 1; \
3336
fi
3437

3538
run-brca2: $(TARGET)
3639
@if [ -f $(TARGET) ]; then \
37-
./$(TARGET) input/Human-Mouse-BRCA2-cds.fasta; \
40+
./$(TARGET) \
41+
input/Human-Mouse-BRCA2-cds.fasta \
42+
; \
3843
else \
3944
echo "Error: Executable $(TARGET) not found. Please build it first."; \
4045
exit 1; \

obj/io/io_utils.o

158 KB
Binary file not shown.

obj/wrapper/program_wrapper.o

504 Bytes
Binary file not shown.

src/io/io_utils.cpp

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ namespace io_utils {
5858
std::string& out_string_one,
5959
std::string& out_string_two,
6060
std::string& out_string_one_name,
61-
std::string& out_string_two_name) {
62-
61+
std::string& out_string_two_name
62+
) {
6363
out_string_one.clear();
6464
out_string_two.clear();
6565
out_string_one_name.clear();
@@ -122,4 +122,48 @@ namespace io_utils {
122122
std::sort(out_string.begin(), out_string.end());
123123
return true;
124124
}
125+
126+
bool load_alignment_params(
127+
const char* file_path,
128+
int64_t& out_match_score,
129+
int64_t& out_mismatch_score,
130+
int64_t& out_opening_gap_score,
131+
int64_t& out_gap_extension_score
132+
) {
133+
std::ifstream input_stream(file_path);
134+
if (!input_stream.is_open()) {
135+
return false;
136+
}
137+
std::unordered_map<std::string, int64_t> param_map = {
138+
{"match", 0},
139+
{"mismatch", 0},
140+
{"g", 0},
141+
{"h", 0}
142+
};
143+
std::string buffer;
144+
int8_t total_params = 0;
145+
while (std::getline(input_stream, buffer)) {
146+
if (buffer.empty()) {
147+
continue;
148+
}
149+
try {
150+
std::stringstream read_stream(buffer);
151+
std::string key;
152+
std::string val;
153+
read_stream >> key >> val;
154+
if (param_map.find(key) != param_map.end()) {
155+
param_map[key] = static_cast<int64_t>(std::stoi(val));
156+
++total_params;
157+
}
158+
} catch (...) {
159+
continue;
160+
}
161+
}
162+
input_stream.close();
163+
out_match_score = param_map["match"];
164+
out_mismatch_score = param_map["mismatch"];
165+
out_opening_gap_score = param_map["h"];
166+
out_gap_extension_score = param_map["g"];
167+
return total_params == 4;
168+
}
125169
}

src/io/io_utils.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
#include <string>
55
#include <fstream>
66
#include <unordered_set>
7+
#include <unordered_map>
78
#include <algorithm>
9+
#include <sstream>
810

911
namespace io_utils {
1012
bool load_one_gene(const char*, std::string&, std::string&);
1113
bool load_one_gene(const char*, std::string&);
1214
bool load_two_genes(const char*, std::string&, std::string&, std::string&, std::string&);
1315
bool load_alphabet(const char*, std::string&);
16+
bool load_alignment_params(const char*, int64_t&, int64_t&, int64_t&, int64_t&);
1417
}
1518

1619
#endif

src/wrapper/program_wrapper.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,39 @@ program_wrapper& program_wrapper::get_instance(void) {
1313
}
1414

1515
void program_wrapper::run_program(const int arg_count, const char* const* arg_vector) {
16-
if (arg_count != 2) {
16+
if (arg_count != 3) {
1717
throw std::runtime_error("error, not enough command line args");
1818
}
1919
std::string gene_one;
2020
std::string gene_two;
2121
std::string gene_one_name;
2222
std::string gene_two_name;
23-
if (!io_utils::load_two_genes(arg_vector[1], gene_one, gene_two, gene_one_name, gene_two_name)) {
23+
if (!io_utils::load_two_genes(arg_vector[2], 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-
// TODO: load parameters from .config file
27-
int64_t result1 = alignment::execute_global_alignment(gene_one, gene_two, 1, -2, -5, -2);
28-
int32_t result2 = alignment::execute_modified_global_alignment(gene_one, gene_two, 1, -2, -5, -2);
26+
int64_t match_score;
27+
int64_t mismatch_score;
28+
int64_t opening_gap_score;
29+
int64_t gap_extension_score;
30+
if (!io_utils::load_alignment_params(arg_vector[1], match_score, mismatch_score, opening_gap_score, gap_extension_score)) {
31+
throw std::runtime_error("error, not able to load alignment parameters from file");
32+
}
33+
int64_t result1 = alignment::execute_global_alignment(
34+
gene_one,
35+
gene_two,
36+
match_score,
37+
mismatch_score,
38+
opening_gap_score,
39+
gap_extension_score
40+
);
41+
int32_t result2 = alignment::execute_modified_global_alignment(
42+
gene_one,
43+
gene_two,
44+
match_score,
45+
mismatch_score,
46+
opening_gap_score,
47+
gap_extension_score
48+
);
2949
std::cout << result1 << std::endl;
3050
std::cout << result2 << std::endl;
3151
}

0 commit comments

Comments
 (0)