Question
Problem 2. (Recovering the Alignment) Write a program alignment.py that reads from standard input, the output produced by edit_distance.py, ie, input strings x and y,
Problem 2. (Recovering the Alignment) Write a program alignment.py that reads from standard input, the output produced by edit_distance.py, ie, input strings x and y, and the opt matrix. The program should then recover an optimal alignment, and write to standard output the edit distance between x and y and the alignment itself.
Hints Read from standard input the sequences x and y as strings, and the matrix opt as a 2D array of integers Write the edit distance between x and y, ie, the value of opt[0][0] Recover and output the alignment, starting at opt[0][0] and ending at opt[M - 1][N - 1], as follows: If opt[i][j] equals opt[i + 1][j] + 2, then align x[i] with a gap and penalty of 2, and increment i by 1 Otherwise if opt[i][j] equals opt[i][j + 1] + 2, then align a gap with y[j] and penalty of 2, and increment j by 1 Otherwise, align x[i] with y[j] and penalty of 0/1 based on whether x[i] and y[j] match or not, and increment both i and j by 1 If x (or y) is exhausted before y (or x), align a character from y (or x) with a gap and penalty of 2
Please help!!!
Problem 2. (Recovering the Alignment) Write a program alignment.py that reads from standard input, the output produced by edit distance.py, ie, input strings x and y, and the opt matrix. The program should then recover an optimal alignment, and write to standard output the edit distance between x and y and the alignment itself. Hints * Read from standard input the sequences x and y as strings, and the matrix opt as a 2D array of integers Write the edit distance between x and y, ie, the value of opt [o] [o] Recover and output the alignment, starting at opt Co] to] and ending at opt [M 11 CN 1], as follows: If opt i] j] equals opt[i + 1]j] 2, then align xCi] with a gap and penalty of 2, and increment i by 1 Otherwise if opt [i] j] equals opt [i]j + 1] + 2, then align a gap with ylj] and penalty of 2, and increment j by 1 Otherwise, align x[il with ylj] and penalty of 0/1 based on whether x[i] and ylj] match or not, and increment both i and j by 1 If r (or y) is exhausted before y (or ), align a character from y (or ) witha gap and penalty of 2 Test cases with unique optimal alignments: $ python3 edit-distance.py dat a/ endgaps7.txt 1 > python3 alignment.py Edit distance4 t t o a a o -a 2 $ python3 edit-distance.py dat a/fli10.txt l python3 alignment.py Edit distance = 2 T TO G GO G G O C T 1 G G O G G O A T 1 ,C) C CO import stdarray import stdio # Read x, y, and opt from standard input # Compute M and N # Write edit distance between x and y. # Recover and write an optimal alignment while i python3 alignment.py Edit distance4 t t o a a o -a 2 $ python3 edit-distance.py dat a/fli10.txt l python3 alignment.py Edit distance = 2 T TO G GO G G O C T 1 G G O G G O A T 1 ,C) C CO import stdarray import stdio # Read x, y, and opt from standard input # Compute M and N # Write edit distance between x and y. # Recover and write an optimal alignment while iStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started