Created
May 11, 2013 11:35
-
-
Save samuell/5559717 to your computer and use it in GitHub Desktop.
Daniel Spångberg's line by line C code with table optimization.
This file contains hidden or 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> | |
| 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