Thursday, 16 October 2014

Code to find ratio of AT and GC

using namespace std;

#include<iostream>
#include<string>


int count( string &s, int& a_count, int& t_count, int& g_count, int& c_count, float &at , float &gc)
{
for(int i=0;i<s.size();i++)
{

    if(s[i]=='A')
    {
        a_count++;
    }
    else if(s[i]=='T')
    {
        t_count++;
    }
    else if(s[i]=='G')
    {
        g_count++;
    }
    else if(s[i]=='C')
    {
        c_count++;
    }
}
at= ((a_count+t_count)*100/s.size());
gc= ((c_count+g_count)*100/s.size());
return (a_count);
return (t_count);
return (g_count);
return (c_count);
return at;
return gc;

}

int main()
{
    int a_count=0;
    int t_count=0;
    int g_count=0;
    int c_count=0;
    float at=0.0;
    float gc=0.0;
    string s;
    cout<<"Enter a sequence: "<<endl;
    cin>>s;
    cout<<"The size of sequence is: "<<s.size()<<endl;
    count(s,a_count,t_count,g_count,c_count,at,gc);
    cout<<"The number of A: "<<a_count<<endl;
    cout<<"The number of T: "<<t_count<<endl;
    cout<<"The number of G: "<<g_count<<endl;
    cout<<"The number of C: "<<c_count<<endl;
    cout<<"Ratio of A "<< ((a_count)/s.size())*100)<<endl;
    cout<<"Ratio of T "<< ((t_count)/s.size())*100)<<endl;
    cout<<"Ratio of G "<< ((g_count)/s.size())*100)<<endl;
    cout<<"Ratio of C "<< ((c_count)/s.size())*100)<<endl;
    cout<<"Ratio of AT " << at<<endl;
    cout<<"Ratio of GC " << gc<<endl;
   
    return 0;
}   

No comments:

Post a Comment