Skip to content

Instantly share code, notes, and snippets.

@chadbrewbaker
Created February 5, 2012 21:20
Show Gist options
  • Save chadbrewbaker/1747996 to your computer and use it in GitHub Desktop.
Save chadbrewbaker/1747996 to your computer and use it in GitHub Desktop.
Caluclates the AT - CG ratio of a file containing "ATCG\n"
// Caluclates the AT - CG ratio of a file containing "ATCG\n"
// Usage: atcgratio.out INFILE
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;
int main(int argc,char **argv)
{
string line;
size_t at_count =0;
size_t cg_count =0;
size_t i;
char c;
ifstream in(argv[1],ios::in);
if(!in.is_open()) return EXIT_FAILURE;
while(getline(in,line,'\n')){
for(i=0;i<line.size();i++) {
c=line.at(i);
if(c == 'A' || c == 'T')
at_count++;
if(c == 'C' || c == 'G')
cg_count++;
}
}
in.close();
std::cout << "AT count: " << at_count << endl;
std::cout << "CG count: " << cg_count << endl;
std::cout << "ratio " << ((double)at_count / (double)cg_count) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment