Skip to content

Instantly share code, notes, and snippets.

@samuell
Created May 11, 2013 11:35
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save samuell/5559717 to your computer and use it in GitHub Desktop.
Daniel Spångberg's line by line C code with table optimization.
#include <stdio.h>
int main()
{
char buf[1000];
int gc=0;
int total=0;
char tablegc[256]={0,};
char tabletotal[256]={0,};
FILE *f=fopen("Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa","r");
tabletotal['A']=1;
tabletotal['T']=1;
tabletotal['C']=1;
tabletotal['G']=1;
tablegc['C']=1;
tablegc['G']=1;
while (fgets(buf,1000,f))
if (*buf!='>') {
char c, *ptr=buf;
while ((c=*ptr++)) {
total+=tabletotal[(int)c];
gc+=tablegc[(int)c];
}
}
fclose(f);
printf("%.10f\n",(100.*gc)/total);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment