Skip to content

Instantly share code, notes, and snippets.

@samuell
Last active December 17, 2015 05:09
  • 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/5555793 to your computer and use it in GitHub Desktop.
#include <string>
#include <fstream>
#include <iostream>
int main() {
std::fstream fs("Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa", std::ios::in);
int a = 0;
int t = 0;
int g = 0;
int c = 0;
if ( fs.is_open() ) {
std::string line;
while (std::getline(fs, line)) {
if(*(line.begin()) != '>') {
for(std::string::const_iterator pos = line.begin(); pos!=line.end() ; ++pos){
switch (*pos){
case 'A' :
a++;
break;
case 'C' :
c++;
break;
case 'G' :
g++;
break;
case 'T' :
t++;
break;
default:
break;
}
}
}
}
//std::cout << "gcCount: " << gcCount << " / totalBaseCount: "<< totalBaseCount << " = " ;
int totalBaseCount = a + t + g + c;
int gcCount = g + c;
std::cout << ( (float)gcCount / (float)totalBaseCount ) * 100 << std::endl ;
} else {
std::cout << "can't open file" ;
}
return 0 ;
}
@samuell
Copy link
Author

samuell commented May 10, 2013

Compile flags used:

g++ -ogc_cpp -O3 gc.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment