Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
C++
#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);
}


however, it just can't run out.Help me please!
Posted
Updated 1-Jan-15 19:07pm
v2
Comments
Member 10641779 2-Jan-15 0:12am    
Don't use these many `if`, Use (if - else if), it will be better.
Member 11346971 2-Jan-15 1:05am    
many thanks!
Member 10641779 2-Jan-15 1:52am    
u r welcome, happy new year :)

1 solution

You have this problem in your code:
C++
seq1[6]="ACGTT"; //You are assigning string to a single index.
seq2[6]="GCATG";

You can write like this:
C++
char seq1[]="ACGTT",seq2[]="GCATG";
or
char seq1[]={'A','C','G','T','T'};


Hope it will help you.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900