Find start codon in a sequence - C programming
1
0
Entering edit mode
8.4 years ago

Hi everyone,

I'm looking for some help to fix my program. I know it's not working, but I don't know how to make it work in C. If you could help me that would be awesome :)

//function that returns 1 if the codon is a start codon, or 0 if not.

int estStart(char seq[])
{
    int I = 0;

    if ((seq[i]=='A') & (seq[i+1]=='T') & (seq[i+2]=='G'))
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

//function that returns 1 if the codon is a stop codon, or 0 if not.

int estStop(char seq[])
{
    int I = 0;

   ** if (((seq[i]=='T') & (seq[i+1]=='A') & (seq[i+2]=='A')) || ((seq[i]=='T') & (seq[i+1]=='A') & (seq[i+2]=='G')) || ((seq[i]=='T') & (seq[i+1]=='G') & (seq[i+2]=='A')))**
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

//Function that returns index of the first start we can find, that is in the same phase as the stop codon.
int FindFisrtStart(char seq[], int start, int stop)
{
    int i, j, codon_start=0, codon_stop=0, found=0;

    for (j=start; j<stop; j++)
    {
        codon_stop = estStop([i, i+2]);

        if (codon_stop == 1)
        {
            for (i=start; i<stop; i++)
            {
                codon_start = estStart(seq[i,i+2]);

                if ((codon_start == 1) & (i%3 == j%3))
                {
                    found = i;
                    I = stop; //out of the 2nd "for"
                    j = stop; // out of the 1st "for"
                    return found; //we found what we needed
                }
            }
        }
    }

    if (trouve == 0)
    {
        return -1; //we didn't found
    }

}

First question:

Is there any way to make this line shorter:

if (((seq[i]=='T') & (seq[i+1]=='A') & (seq[i+2]=='A')) || ((seq[i]=='T') & (seq[i+1]=='A') & (seq[i+2]=='G')) || ((seq[i]=='T') & (seq[i+1]=='G') & (seq[i+2]=='A')))**

Second question:

I know this [i, i+2] doesn't work in C.

But how do you write it then? How do you get access to this characters inside the chain?

Third question:

Is there any other error you can see?

Thank you so much for your help!

c-programming • 3.0k views
ADD COMMENT
1
Entering edit mode
8.4 years ago

use pointers

static int  estStop(const char* seq)
{
    return (strncmp(seq,"TAA",3)==0 || strncmp(seq,"ATG",3)==0 || ... ?1:0);
}

(...)

codon_stop = estStop(&seq[i]);

(...)

ADD COMMENT

Login before adding your answer.

Traffic: 3106 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6