Aligning DNA Sequences

Mutating the NBA

Professor Farnsworth has once again descended into a moronic battle of science and wits against his archnemesis Professor Wernstrom, though this time it is a battle of honour on the basketball court. TheProfessor has decided to create a team of undefeatable mutants very unlike but not quite dissimilar to theones he used to fight the Globetrotters to defend earths dignity. His diabolical scheme is to use the DNAof the best NBA players to manufacture the perfect team. But he wants to use players who have a variedexpertise to make sure that each mutant is the best possible one for the team composition.
Help the Professor so that he is best able to analyze the sequence of any two players.
Input Format
The input consists of two lines, where each sequence and are the DNA sequence of the players.
Constraints
Output Format
First output the optimal score of aligning the two sequences. Assume that scoring matrix adds to thescore for a match and for a mismatch.
Then output an optimal alignment of the two sequences.
Sample Input 0
GAT
GAT
Sample Output 0
6G
AT
GAT
Sample Input 1
CAG
AAG
Sample Output 1
3C
AG
AAG
Sample Input 2
ACGCCG
ACCACG
Sample Output 2
8A
CGC_CG
AC_CACG

Solution

importjava.io.IOException;

importjava.util.HashMap;

public class Solution {

public static Answer recursion(String lineone, String linetwo) {

String prevResultKey = lineone + “?” + linetwo;

if (prevResults.containsKey(prevResultKey)) {

returnprevResults.get(prevResultKey);

}

if (lineone.equals(“”) || linetwo.equals(“”)) {

if(lineone.equals(“”)){

for(int i = 0; i <linetwo.length(); i++){

}

}

else if(linetwo.equals(“”)){

for(int i = 0; i <lineone.length(); i++){

}

}

} else {

linetwo.substring(1, linetwo.length()));

Answer removeFirstLineLetterScore = recursion(lineone.substring(1, lineone.length()), linetwo);

Answer removeSecondLineLetterScore = recursion(lineone, linetwo.substring(1, linetwo.length()));

removeFirstLineLetterScore.score -= 1;

removeSecondLineLetterScore.score -= 1;

if (lineone.substring(0, 1).equals(linetwo.substring(0, 1))) {

joinFirstLetterScore.score += 2;

}

else {

joinFirstLetterScore.score -= 1;

}

if (removeFirstLineLetterScore.score>= joinFirstLetterScore.score

&&removeFirstLineLetterScore.score>= removeSecondLineLetterScore.score) {

}

if (removeSecondLineLetterScore.score>= joinFirstLetterScore.score

&&removeSecondLineLetterScore.score>= removeFirstLineLetterScore.score) {

}

if (joinFirstLetterScore.score>= removeFirstLineLetterScore.score

&&joinFirstLetterScore.score>= removeSecondLineLetterScore.score) {

}

}

return null;

}

public static void main(String[] args) throws NumberFormatException, IOException {

}

}

String lineone, linetwo;

int score;

lineone = “”;

linetwo = “”;

score = 0;

}

public Answer(String l1, String l2, int s) {

lineone = l1;

linetwo = l2;

score = s;

}

public void Print(){

System.out.println(score);

System.out.println(lineone);

System.out.println(linetwo);

}

public String key() {

returnlineone + “?” + linetwo;

}

}

/**   public void Score(){

inttempscore = 0;

for(int i = 0; i <lineone.length(); i++){

if(lineone.substring(i, 1+i).equals(linetwo.substring(i, 1+i))){

tempscore+=2;

}

else{

tempscore-=1;

}

score = tempscore;

}

}*/

}