为了简单起见,我粘贴了整个内容,但我们应该使用的测试用例是CAGTTTAGCTAGAAA,当我这样做时,我得到一个错误,因为它说它太长但错误在哪里,这只是假设将它们分组为3以便稍后可以根据它们的组进行转换。
public class Soutar_bioinformatics
{
public static void main (String[] args)
{
//Variable declaration
int DNAstrandlength, DNAsplit;
String strandDNA;
Scanner DNAInfo = new Scanner (System.in);
//Welcome
System.out.println ("**********************************************");
System.out.println ("Welcome to Matthew's Bioinformatics");
System.out.println ("**********************************************");
//Input
System.out.println ("Please enter a DNA Strand!");
strandDNA = DNAInfo.next();
DNAstrandlength = strandDNA.length();
if (DNAstrandlength % 3 != 0)
{
System.out.println ("The DNA sequence enterered is not valid, please insert a correct sequence.");
strandDNA = DNAInfo.next();
}
//Processing
ArrayList<String> DNAarray = DNAsplit(strandDNA); // Calls the DNA split method
//Goodbye
System.out.println ("**********************************************");
System.out.println ("Thank you for using Matthew's Program");
System.out.println ("**********************************************");
}
private static ArrayList<String> DNAsplit (String text)
{
ArrayList<String> DNAsplit = new ArrayList <String>();
for (int i = 0; 1 < text.length(); i += 3)
{
DNAsplit.add(text.substring(i, Math.min(i + 3, text.length())));
}
String [] codonArray = DNAsplit.toArray (new String[DNAsplit.size()]);
System.out.print ("\f");
System.out.println ("The Amino acids are: ");
for (int j = 0; j < codonArray.length; j = j + 1)
{
//First Column
codonArray[j] = codonArray[j].replace ("TTT", "F");
codonArray[j] = codonArray[j].replace("TCT", "S");
codonArray[j] = codonArray[j].replace("TAT", "Y");
codonArray[j] = codonArray[j].replace("TGT","C");
codonArray[j] = codonArray[j].replace("CTT", "L");
codonArray[j] = codonArray[j].replace("CCT", "P");
codonArray[j] = codonArray[j].replace("CAT", "H");
codonArray[j] = codonArray[j].replace("CGT", "R");
codonArray[j] = codonArray[j].replace("ATT" , "I");
codonArray[j] = codonArray[j].replace("ACT", "T");
codonArray[j] = codonArray[j].replace("AAT", "N");
codonArray[j] = codonArray[j].replace("AGT", "S");
codonArray[j] = codonArray[j].replace("GTT", "V");
codonArray[j] = codonArray[j].replace("GCT" , "A");
codonArray[j] = codonArray[j].replace("GAT" , "D");
codonArray[j] = codonArray[j].replace("GGT", "G");
codonArray[j] = codonArray[j].replace ("TTT", "F");
//Second Column
codonArray[j] = codonArray[j].replace("TCT", "S");
codonArray[j] = codonArray[j].replace("TAT", "Y");
codonArray[j] = codonArray[j].replace("TGT", "C");
codonArray[j] = codonArray[j].replace("CTT", "L");
codonArray[j] = codonArray[j].replace("CCT", "P");
codonArray[j] = codonArray[j].replace("CAT", "H");
codonArray[j] = codonArray[j].replace("CGT", "R");
codonArray[j] = codonArray[j].replace("ATT" , "I");
codonArray[j] = codonArray[j].replace("ACT", "T");
codonArray[j] = codonArray[j].replace("AAT", "N");
codonArray[j] = codonArray[j].replace("AGT", "S");
codonArray[j] = codonArray[j].replace("GTT", "V");
codonArray[j] = codonArray[j].replace("GCT" ,"A");
codonArray[j] = codonArray[j].replace("GAT" , "D");
codonArray[j] = codonArray[j].replace("GGT", "G");
//Third Coloumn
codonArray[j] = codonArray[j].replace ("TTA", "L");
codonArray[j] = codonArray[j].replace ("TCA", "S");
codonArray[j] = codonArray[j].replace ("TAA", "STOP");
codonArray[j] = codonArray[j].replace ("TGA", "STOP");
codonArray[j] = codonArray[j].replace ("CTA", "L");
codonArray[j] = codonArray[j].replace ("CCA", "P");
codonArray[j] = codonArray[j].replace ("CAA", "Q");
codonArray[j] = codonArray[j].replace ("CGA", "R");
codonArray[j] = codonArray[j].replace ("ATA", "I");
codonArray[j] = codonArray[j].replace ("ACA", "T");
codonArray[j] = codonArray[j].replace ("AAA", "K");
codonArray[j] = codonArray[j].replace ("AGA", "R");
codonArray[j] = codonArray[j].replace ("GTA", "V");
codonArray[j] = codonArray[j].replace ("GCA", "A");
codonArray[j] = codonArray[j].replace ("GAA", "E");
codonArray[j] = codonArray[j].replace ("GGA", "E");
//Fourth Column
codonArray[j] = codonArray[j].replace ("TTG", "L");
codonArray[j] = codonArray[j].replace ("TCG", "S");
codonArray[j] = codonArray[j].replace ("TAG", "STOP");
codonArray[j] = codonArray[j].replace ("TGG", "W");
codonArray[j] = codonArray[j].replace ("CTG", "L");
codonArray[j] = codonArray[j].replace ("CCG", "P");
codonArray[j] = codonArray[j].replace ("CAG", "Q");
codonArray[j] = codonArray[j].replace ("CGG", "R");
codonArray[j] = codonArray[j].replace ("ATG", "M");
codonArray[j] = codonArray[j].replace ("ACG", "T");
codonArray[j] = codonArray[j].replace ("AAG", "K");
codonArray[j] = codonArray[j].replace ("AGG", "R");
codonArray[j] = codonArray[j].replace ("GTG", "V");
codonArray[j] = codonArray[j].replace ("GCG", "A");
codonArray[j] = codonArray[j].replace ("GAG", "E");
codonArray[j] = codonArray[j].replace ("GGG", "G");
System.out.print (codonArray[j] + " ");
if (codonArray[j].contains ("STOP"))
{
break;
}
}
return DNAsplit;
}
}
答案 0 :(得分:1)
DNASplit函数中的代码有一个简单的错误。
for (int i = 0; 1 < text.length(); i += 3)
{
DNAsplit.add(text.substring(i, Math.min(i + 3, text.length())));
}
for循环中的1应为i。