Daniel Spångber's C code, when reading whole file. 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); | |
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. */ | |
nums=items-(ptr-m); | |
for (i=0; i<nums; i++) { | |
char c=*ptr++; | |
if ((c=='A') | (c=='T')) | |
at++; | |
else if ((c=='G') | (c=='C')) { | |
gc++; | |
} | |
} | |
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