-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNeedlemanWunsch.cpp
78 lines (56 loc) · 1.52 KB
/
NeedlemanWunsch.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int gap_penalty = -1;
void printMatrix(int **matrix) {
for (int i=0; i < sizeof(matrix[0]); i++) {
for (int j=0; j < sizeof(matrix[1]); j++) {
cout << matrix[i][j] << endl;
}
}
}
int score(const char &a, const char &b) {
if (a == b)
return 1;
return -1;
}
// Score not passed two characters
int score(const char &a) {
return gap_penalty;
}
int findMaxIndex (const int scores[], int numCount) {
int maxIndex = 0;
for (int i=0; i < numCount; i++) {
if (scores[i] > maxIndex)
maxIndex=i;
}
}
int main (int argc, char* argv[]) {
for (int i=0; i < argc; i++) {
//cout << argv[i] << endl;
}
string seq1 = argv[1];
string seq2 = argv[2];
int scoreMatrix[seq1.length() + 1][seq2.length() + 1];
for (int i=0; i < seq1.length() + 1; i++) {
scoreMatrix[i][0] = i * gap_penalty;
}
for (int j=0; j < seq2.length() + 1; j++) {
scoreMatrix[0][j] = j * gap_penalty;
}
for (int i=0; i < seq1.length() + 1; i++) {
for (int j=0; j < seq2.length() + 1; j++) {
char lettera = seq1[i-1];
char letterb = seq2[j-1];
int scores[3];
// Diagonal
scores[0] = scoreMatrix[i-1][j-1] + score(lettera,letterb);
// Up
scores[1] = scoreMatrix[i-1][j] + gap_penalty;
// Left
scores[2] = scoreMatrix[i][j-1] + gap_penalty;
int maxIndex = findMaxIndex(scores,3);
}
}
}