I'm doing a program that takes an RNA sequence and out put it's protein synthesis. it takes a input string, make into a string that contains only 4 element A,U,C,G, (ignore everything else) split them into groups of 3 (something like splitting "UAGCGU" into [UAG,CGU]), each of the 3 letters co-response to a type of protein.
the total number of AUCGs contains in the original input is a strictly a multiple of three. and there will be no stop code.
every triple formed by AUCG got a meaning in protein synthesis.
I got the input, the AUCG string and the split right, came to problem on matching the triples into proteins. here's the entire code:
import java.util.List;
import java.util.Scanner;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
public class hw1q4 {
public static void main(String[] args) throws IOException {
Scanner Scn = new Scanner(System.in);
String Origin = Scn.nextLine();
String input = "";
String answer = "";
String[] triples;
for(int i = 0; i < Origin.length(); i++){
if(Origin.charAt(i) == 'A' || Origin.charAt(i) == 'U' || Origin.charAt(i) == 'C' || Origin.charAt(i) == 'G'){
input += Origin.charAt(i);
}
}
triples = RNASpliter(input);
//System.out.println(Array.get(triples, 0));
for(int j = 0; j < triples.length; j++){
//System.out.println(Array.get(triples, j));
if(Array.get(triples, j).toString() == "CUU"
|| Array.get(triples, j).toString() == "CUC" || Array.get(triples, j).toString() == "CUA" || Array.get(triples, j).toString() == "CUG"
|| Array.get(triples, j).toString() == "UUA" || Array.get(triples, j).toString() == "UUG"){
answer += "leu";
}
else if(Array.get(triples, j) == "UCU" || Array.get(triples, j) == "UCC" || Array.get(triples, j) == "UCA" || Array.get(triples, j) == "UCG"){
answer += "ser";
}
else if(Array.get(triples, j) == "CCU" || Array.get(triples, j) == "CCC" || Array.get(triples, j) == "CCA" || Array.get(triples, j) == "CCG"){
answer += "pro";
}
else if(Array.get(triples, j) == "CGU" || Array.get(triples, j) == "CGC" || Array.get(triples, j) == "CGA" || Array.get(triples, j) == "CGG"
||Array.get(triples, j) == "AGA" || Array.get(triples, j) == "AGG"){
answer += "arg";
}
else if(Array.get(triples, j) == "ACU" || Array.get(triples, j) == "ACC" || Array.get(triples, j) == "ACA" || Array.get(triples, j) == "ACG"){
answer += "thr";
}
else if(Array.get(triples, j) == "GUU" || Array.get(triples, j) == "GUC" || Array.get(triples, j) == "GUA" || Array.get(triples, j) == "GUG"){
answer += "val";
}
else if(Array.get(triples, j) == "GCU" || Array.get(triples, j) == "GCC" || Array.get(triples, j) == "GCA" || Array.get(triples, j) == "GCG"){
answer += "ala";
}
else if(Array.get(triples, j) == "GGU" || Array.get(triples, j) == "GGC" || Array.get(triples, j) == "GGA" || Array.get(triples, j) == "GGG"){
answer += "gly";
}
else if(Array.get(triples, j) == "UUU" || Array.get(triples, j) == "UUC"){
answer += "phe";
}
else if(Array.get(triples, j) == "UAU" || Array.get(triples, j) == "UAC"){
answer += "tyr";
}
else if(Array.get(triples, j) == "UGU" || Array.get(triples, j) == "UGC"){
answer += "cys";
}
else if(Array.get(triples, j) == "CAU" || Array.get(triples, j) == "CAC"){
answer += "his";
}
else if(Array.get(triples, j) == "CAA" || Array.get(triples, j) == "CAG"){
answer += "gln";
}
else if(Array.get(triples, j) == "AUU" || Array.get(triples, j) == "AUC" || Array.get(triples, j) == "AUA"){
answer += "lle";
}
else if(Array.get(triples, j) == "AAU" || Array.get(triples, j) == "AAC"){
answer += "asn";
}
else if(Array.get(triples, j) == "AAA" || Array.get(triples, j) == "AAG"){
answer += "lys";
}
else if(Array.get(triples, j) == "AGU" || Array.get(triples, j) == "CGC"){
answer += "ser";
}
else if(Array.get(triples, j) == "GAU" || Array.get(triples, j) == "GAC"){
answer += "asp";
}
else if(Array.get(triples, j) == "GAA" || Array.get(triples, j) == "GAG"){
answer += "glu";
}
else if(Array.get(triples, j) == "AUG"){
answer += "met";
}
else if(Array.get(triples, j) == "UGG"){
answer += "trp";
} else{
break;
}
}
System.out.println(answer);
}
private static String[] RNASpliter(String Sqc) {
List<String> triples = new ArrayList<>();
int length = Sqc.length();
for (int i = 0; i < length; i += 3) {
triples.add(Sqc.substring(i, i + 3));
}
return triples.toArray(new String[0]);
}
}
the thing i want is, for example, if the triples are [CUU,UCU],the answer string should be "leuser"
I tried to print something right after the declaration of the for loop(in the code) and the result indicates that the loop goes straightly to the "else" statement and break out the loop, and the answer string remains null.
the test result indicates that non of the conditions in my if and if else statement are matched. that is weird because it seems OK to me.....could anyone please tell me where I did wrong? thank you very much!
Aucun commentaire:
Enregistrer un commentaire