GC content by c programming
1
0
Entering edit mode
3.4 years ago

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

c genome gene • 1.6k views
ADD COMMENT
0
Entering edit mode
3.4 years ago

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 COMMENT

Login before adding your answer.

Traffic: 1569 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