#include<stdio.h> /*I am a fish of C,I am writing a dynamic programming matrix for DNA alignment. */ #define p -0.005 /* the program is quite easy,just create a array first */ float f(int,int); int main() { float table[6][6]; /*then fill the array with some fixed number*/ int x,y,i; table[0][0]=p; for(i=1;i<=5;i++) table[i][0]=i*p; for(i=1;i<=5;i++) table[0][i]=i*p; for(x=1;x<=5;x++) /* then fill the array,just using some comparings*/ for(y=1;y<=5;y++) { float a,b,c; a=table[x-1][y-1]+f( x-1,y-1); b=table[x][y-1]+p; c=table[x-1][y]+p; if(a>=b&&a>=c) table[x][y]=a; if(b>=a&&b>=c) table[x][y]=b; if(c>=b&&c>=a) table[x][y]=c; } for(x=0;x<=5;x++) /*finally print the number out*/ for(y=0;y<=5;y++) { printf("%.6f\t",table[x][y]); if (y==5) printf("\n"); } return 0; } float f(int x,int y) { char seq1[6],seq2[6]; float r; seq1[6]="ACGTT"; seq2[6]="GCATG"; if (seq1[x]=='A'&&seq2[y]=='A'||seq1[x]=='T'&&seq2[y]=='T') r=0.99; if (seq1[x]=='G'&&seq2[y]=='G'||seq1[x]=='C'&&seq2[y]=='C') r=0.99; if(seq1[x]=='A'&&seq2[y]=='T'||seq1[x]=='T'&&seq2[y]=='A') r=0.002; if(seq1[x]=='A'&&seq2[y]=='G'||seq1[x]=='G'&&seq2[y]=='A') r=0.006; if(seq1[x]=='A'&&seq2[y]=='C'||seq1[x]=='C'&&seq2[y]=='A') r=0.002; if(seq1[x]=='T'&&seq2[y]=='G'||seq1[x]=='G'&&seq2[y]=='T') r=0.002; if(seq1[x]=='T'&&seq2[y]=='C'||seq1[x]=='C'&&seq2[y]=='T') r=0.002; if(seq1[x]=='G'&&seq2[y]=='C'||seq1[x]=='C'&&seq2[y]=='G') r=0.006; return(r); }
seq1[6]="ACGTT"; //You are assigning string to a single index. seq2[6]="GCATG";
char seq1[]="ACGTT",seq2[]="GCATG"; or char seq1[]={'A','C','G','T','T'};
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)