Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#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 ;
}
Owner

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