我需要對齊兩個DNA序列(它們是字符串)。匹配字符必須與垂直線|
對齊,並與空間不匹配。這裏是我的代碼,整個事情運作良好,我似乎無法找到一種方法來對齊字符串。全局序列比對
//Variable List
Scanner keyboard = new Scanner(System.in);
String s_one, s_two, aligner = " ";
int len_one = 0, len_two = 0, a = 0, total_pos = 0, total_neg = 0, total_score = 0;
char char_one = ' ', char_two = ' ', compare = ' ';
//End Variable List
System.out.println("Enter the first DNA sequence: ");
s_one = keyboard.next().toUpperCase();
System.out.println("Enter the second DNA sequence: ");
s_two = keyboard.next().toUpperCase();
len_one = s_one.length();
len_two = s_two.length();
while(len_one > a && len_two > a){
char_one = s_one.charAt(a);
char_two = s_two.charAt(a);
a++;
if(char_one == char_two){
total_pos += 2;
aligner = "|";
System.out.println(aligner);
}else if(char_one != char_two){
total_neg -= 1;
aligner = " ";
System.out.println(aligner);
}
}
//Output
total_score = total_pos + total_neg;
System.out.println(s_one);
System.out.println(s_two);
System.out.println("The total score is: " + total_score);
do{//Ask the user if they want to re-enter another DNA sequence
System.out.println("Would you like to re-enter another DNA sequence? Y/N");
compare = keyboard.next().charAt(0);
if(compare == 'y' || compare == 'Y'){
System.out.println("Enter the first DNA sequence: ");
s_one = keyboard.next().toUpperCase();
System.out.println("Enter the second DNA sequence: ");
s_two = keyboard.next().toUpperCase();
len_one = s_one.length();
len_two = s_two.length();
while(len_one > a && len_two > a){
char_one = s_one.charAt(a);
char_two = s_two.charAt(a);
a++;
if(char_one == char_two){
total_pos += 2;
}else if(char_one != char_two){
total_neg -= 1;
}
}
//Output
total_score = total_pos + total_neg;
System.out.println(s_one);
System.out.println();
System.out.println(s_two);
System.out.println("The total score is: " + total_score);
}
}while(compare == 'y' || compare == 'Y');
System.out.println("Thank You!");
比方說,我們有串1 = ABBABB和字符串2 = ABAAAB,我需要整個輸出看起來像這樣:
ABBABB
|| | |
ABAAAB
The total score is: 6
我只是不知道如何讓垂直線去正確的地方。
這將是你把你的電流輸出是什麼有用的,所以我/我們沒有運行它。 –