Bioinformatics program with useless code

I wrote this program and I thought i was pretty sure that everything would check out but when I run it, it doesn't print out the final cout<< and I cant really figure out why. I know its probably something small but I just cant put my finger on it. its supposed to translate the RNA input into protein output but it wont budge. I just need to know what I'm doing wrong. All it does is print the RNA sequence but i need it to print the Amino acid equivalent to what ever codon is created ex.UUU=Phenylalanine if you have any incite please let me know
Thank You!!!

here's my code


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<iostream>
#include <string>
using namespace std;

int main()
{
	
	int numberOfCodons;
	int rnaLength;
	int beginIndex;
	int endIndex;
	int i,j,k;
	string codons[64] = {"UUU","UUC","UUA","UUG","UCU","UCC","UCA","UCG","UAU","UAC","UAA","UAG","UGU","UGC","UGA","UGG", 
						 "CUU","CUC","CUA","CUG","CCU","CCC","CCA","CCG","CAU","CAC","CAA","CAG","CGU","CGC","CGA","CGG",
						 "AUU","AUC","AUA","AUG","ACU","ACC","ACA","ACG","AAU","AAC","AAA","AAG","AGU","AGC","AGA","AGG",
						 "GUU","GUC","GUA","GUG","GCU","GCC","GCA","GCG","GAU","GAC","GAA","GAG","GGU","GGC","GGA","GGG"};
	string aminoAcids[64]={"Phenylalanine","Phenylalanine","Leucine","Leucine", "Serine","Serine","Serine","Serine","Tyrosine","Tyrosine", "Stop","Stop", "Cysteine","Cysteine","Stop", "Tryptophan",
						   "Leucine","Leucine","Leucine","Leucine","Proline","Proline","Proline","Proline","Histidine","Histidine","Glutamine","Glutamine","Arginine","Arginine","Arginine","Arginine",
						   "Isoleucine","Isoleucine","Isoleucine","Methionine","Threonine","Threonine","Threonine","Threonine","Asparagine","Asparagine","Lysine","Lysine","Serineine","Serineine","Arginine","Arginine",
							"Valine","Valine","Valine","Valine","Alanine","Alanine","Alanine","Alanine","Aspartate","Aspartate","Glutamate","Glutamate","Glycine","Glycine","Glycine","Glycine"};
	string codon=" ";
	string protein=" ";
	string RNA;
	cout<<"   To begin translation    "<<endl;
	cout<<"Please enter RNA sequence: "<<endl;
	cin>>RNA;
	cout<<endl;
	rnaLength=RNA.length();
	for(int i=0; i<RNA.length(); i+=3){
    
    cout<<RNA[i];
	if(i+1 < RNA.length())
        cout<<RNA[i+1];
	if(i+2 < RNA.length())
        cout<<RNA[i+2];
		cout<<" ";
}
	cout<<endl;
	numberOfCodons=rnaLength/3;
	beginIndex=0;
	cout<<"Total Number Of codons are: "<<numberOfCodons<<endl;
	for (i=0; i<numberOfCodons;i++)
	{
		beginIndex=beginIndex;
		endIndex=beginIndex+2;
		for(j=beginIndex;j<endIndex;j++)
		{
			codon.append(string(1,RNA[j]));
		//cout<<" ";
		//cout<<codon<<endl;
		
		}
	for (k=0;k<64;k++)
	{///////////this if statement is not working----------------------------
		if(codon==codons[k])
		{
			protein.append(aminoAcids[k]);
			
		
		}
		
	
	}
beginIndex=beginIndex+3;

	}
//heres the problem right here----------------------------
	cout<<protein<<endl;
	
	system("PAUSE");
		return 0;
}


if i say
if(codon<codons[k])
it will print the whole array I just need the corresponding protein or Amino Acid
Last edited on
What's the value of codon at line 55?

By the way, the loop on line 46 is very ugly. It can be replaced with
 
codon.append(RNA.substr(beginIndex,endIndex-beginIndex));
or with
 
codon.append(RNA.begin()+beginIndex,RNA.begin()+endIndex);

Also note that RNA[endIndex] is not appended to codon, because the for condition is j<endIndex, so codon.size()==2 (actually, there's probably another bug which makes this last statement false. I can't say for sure if it's a bug because I don't know what you're trying to accomplish).
the value can be what ever is imputed (oh that cin at line 26 shouldn't be commented out)
thanks for the tip also i know i gotta get better with my loops
the value can be what ever is imputed
Well, no. While its value certainly does depend on the user's input, it's not directly entered by the user.
Topic archived. No new replies allowed.