-
Notifications
You must be signed in to change notification settings - Fork 0
/
naives.cpp
44 lines (40 loc) · 973 Bytes
/
naives.cpp
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
#include<iostream>
#include<vector>
std::string reference = "AGCATCGATCGATCGATCGATCGATTGTCGATCGATCGATGT";
std::string pattern = "AGT";
std::string join(std::vector<int> &occ){
std::string s;
unsigned int i = 0, c = 0;
const std::string delimeter = ",";
while(i != occ.size() - 1){
s += std::to_string(occ[i]) + delimeter;
i += 1;
}
s += std::to_string(occ[i]);
return s;
}
std::vector<int> naives(std::string &ref, std::string &patt, const unsigned int threshold){
std::vector<int> occ;
for(int i = 0; i < (ref.length() - patt.length() + 1); i++){
bool match = true;
unsigned int mismatch = 0;
for(int j = 0; j < patt.length(); j++){
if(ref[i+j] != patt[j]){
mismatch += 1;
if(mismatch > threshold){
match = false;
break;
}
}
}
if(match){
occ.push_back(i);
}
}
return occ;
}
int main(){
std::vector<int> occurences = naives(reference, pattern, 1);
std::cout << join(occurences) << std::endl;
return 0;
}