Write a program in DNA sequence analysis
in c++ coding the goal to provide a report of the number of each nucleotide within the sequence, and the percent each nucleotide makes up of the total.
Every DNA sequence consists of four nucleotides: Adenine, Thymine, Cytosine, and Guanine, referred to by the first letters of their chemical names (A, T, C, and G).
Output:
DNA sequence analysis:
29782 nucleotides in the sequence
Sequence breakdown:
Adenine: 8892 29.86%
Thymine: 9581 32.17%
Cytosine: 5462 18.34%
Guanine: 5847 19.63%
#include<iostream>
using namespace std;
int main(){
string dna = "GTCGTAGAATAGTCGTAGAATAGGGTAGGGTAATTAATTATAATATGC";
float n = dna.length();
float g=0, t=0, c=0, a=0;
for(int i=0; i<n; i++){
if(dna[i]=='G'){
g++;
}
else if(dna[i]=='C'){
c++;
}
else if(dna[i]=='A'){
a++;
}
else if(dna[i]=='T'){
t++;
}
}
cout<<"DNA sequence analysis:\n"<<n<<" nucleotides in the sequence\n";
cout<<"Adenine: "<<a<<" "<<(a/n) * 100<<"%"<<endl;
cout<<"Thymine: "<<t<<" "<<(t/n) * 100<<"%"<<endl;
cout<<"Cytosine: "<<c<<" "<<(c/n) * 100<<"%"<<endl;
cout<<"Guanine: "<<g<<" "<<(g/n) * 100<<"%"<<endl;
}
Comments
Leave a comment