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 79 80 81 82 83 84 85 86 87 88 89 90
|
#include <iostream>
#include <cstdlib>
#include <string>
#include <cmath>
#include <sys/time.h>
using namespace std;
double similarity_score(char a,char b);
double find_array_max(double array[],int length);
int N_a,N_b;
string seq_a, seq_b;
int main(){
cout<<" tapez la premiere sequence"<<endl; cin>> seq_a;
cout<<" tapez la deuxieme sequence"<<endl; cin>> seq_b;
N_a = seq_a.length()+1; // get the actual lengths of the sequences
N_b = seq_b.length()+1;
double H[N_a+1][N_b+1];
for(int i=0;i<=N_a+1;i++){
H[i][0]=0;
}
for(int j=0;j<=N_b+1;j++){
H[0][j]=0;
}
double temp[3];
int I_i[N_a+1][N_b+1],I_j[N_a+1][N_b+1];
for(int i=1;i<=N_a;i++){
for(int j=1;j<=N_b;j++){
if(seq_a[i]==seq_b[j])
H[i][j] = H[i-1][j-1]+similarity_score(seq_a[i],seq_b[j]);
else
temp[0] = H[i-1][j]-similarity_score(seq_a[i],seq_b[j]);
temp[1] = H[i][j-1]-similarity_score(seq_a[i],seq_b[j]);
temp[2] = 0.;
H[i][j] = find_array_max(temp,3);
}
}
cout<<"**********************************************"<<endl;
cout<<" la matrice de scores est: "<<endl<<endl;
for(int i=0;i<=N_a-1;i++){
for(int j=0;j<=N_b-1;j++){
cout<<H[i][j]<<" ";
}
cout<<endl;
}
double H_max = 0.;
int i_max=0,j_max=0;
for(int i=0;i<=N_a-1;i++){
for(int j=0;j<=N_b-1;j++){
if(H[i][j]>H_max){
H_max = H[i][j];
i_max = i;
j_max = j;
}
}
}
double similarity_score(char a,char b){
double result;
result=100/(N_a-1);
return result;
}
double find_array_max(double array[],int length){
double max = array[0]; // start with max = first element
ind = 0;
for(int i = 1; i<length; i++){
if(array[i] > max){
max = array[i];
ind = i;
}
}
return max; // return highest value in array
}
} |
Partager