ifndef DataReader define DataReader include string include fstream Уда

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef DataReader
#define DataReader
#include <string>
#include <fstream>
//Удаление всех пробелов из строки
inline void SpaceErase(std::string &str) {
for(int i = 0; i < str.length(); i++) {
if(str[i] == ' ') {
str.erase(i,1);
i--;
}
}
}
inline int** ReadData(std::string &name1, std::string &seq1, std::string &name2,
std::string &seq2, std::string &alphabet, int* index_arr,
char* file_name1, char* file_name2
) {
//Чтение входных данных=======================================================
seq1 = ""; seq2 = ""; //последовательности
//Чтение последовательностей--------------------------------------------------
std::fstream fs;
int seq_num = 0;
fs.open (file_name1, std::fstream::in);
for (std::string tek_line; std::getline(fs, tek_line); ) {
if (tek_line[0] == '>') {
(seq_num) ? name2 = tek_line : name1 = tek_line;
seq_num++;
continue;
}
SpaceErase(tek_line);
(seq_num > 1) ? seq2 += tek_line : seq1 += tek_line;
}
fs.close();
//Чтение алфавита и таблицы очков---------------------------------------------
fs.open (file_name2, std::fstream::in);
std::getline(fs, alphabet);
SpaceErase(alphabet);
for (int i = 0; i < alphabet.length(); i++) {
index_arr[alphabet[i]] = i;
}
int** score_matrix = new int* [alphabet.length()];
for (int i = 0; i < alphabet.length(); i++) {
score_matrix[i] = new int [alphabet.length()];
}
for (int i = 0; i < alphabet.length(); i++) {
for (int j = 0; j < alphabet.length(); j++) {
fs >> score_matrix[i][j];
}
}
fs.close();
return score_matrix;
}
#endif