Question: GC content by c programming
0
gravatar for banerjeesourya1
6 weeks ago by
banerjeesourya10 wrote:

how to find GC content in a given DNA sequence by c programming ? Not in any other language.

C gene genome • 174 views
ADD COMMENTlink modified 6 weeks ago by Alex Reynolds31k • written 6 weeks ago by banerjeesourya10
0
gravatar for Alex Reynolds
6 weeks ago by
Alex Reynolds31k
Seattle, WA USA
Alex Reynolds31k wrote:

One way is to read DNA sequence into a char [] or terminated char * and loop over each character:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int
main(int argc, const char** argv)
{
    unsigned int gc = 0;
    const char * sequence = "gtcctttTctaGacAtaNNaggtgggaCat";
    size_t sequence_len = strlen(sequence);

    for (size_t i = 0; i < sequence_len; i++) {
        char residue = (char) toupper(sequence[i]);
        switch (residue) {
            case 'C':
            case 'G':
                gc++;
                break;
            case 'A':
            case 'T':
            case 'N':
            default:
                break;
        }
    }

    fprintf(stdout, "GC content: %f\n", (float) gc / sequence_len);

    return EXIT_SUCCESS;
}

Multiply the fraction by 100 to get a percentage.

ADD COMMENTlink modified 6 weeks ago • written 6 weeks ago by Alex Reynolds31k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 932 users visited in the last hour