Entering edit mode
3.3 years ago
banerjeesourya1
•
0
how to find GC content in a given DNA sequence by c programming ? Not in any other language.
how to find GC content in a given DNA sequence by c programming ? Not in any other language.
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.
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.