Created
May 10, 2013 17:12
-
-
Save samuell/5555848 to your computer and use it in GitHub Desktop.
Daniel Spångber's C code, when reading whole file, and using table to count. See http://saml.rilspace.org/node/248
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define MAXFLEN 70000000 /* Larger than the file. */ | |
int main() | |
{ | |
char *m=malloc(MAXFLEN); | |
char tablegc[256]; | |
char tableat[256]; | |
int gc=0; | |
int at=0; | |
FILE *f=fopen("Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa","r"); | |
int items=fread(m,1,MAXFLEN,f); /* Read the whole file into memory. */ | |
char *ptr=m; | |
int nums, i; | |
while (*ptr++!='\n'); /* Find end of first line. */ | |
for (i=0; i<256; i++) | |
tablegc[i]=0; | |
for (i=0; i<256; i++) | |
tableat[i]=0; | |
tableat['A']=1; | |
tableat['T']=1; | |
tablegc['C']=1; | |
tablegc['G']=1; | |
nums=items-(ptr-m); | |
for (i=0; i<nums; i++) { | |
char c=*ptr++; | |
at+=tableat[(int)c]; | |
gc+=tablegc[(int)c]; | |
} | |
fclose(f); | |
free(m); | |
int total = at + gc; | |
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