This is in Pyton. Implement Local and Global sequence alignment that can also tr
ID: 3852462 • Letter: T
Question
This is in Pyton.
Implement Local and Global sequence alignment that can also traceback, and develop webpage.
Thanks!
Online sequence alignment for siring matching to reference genomes. Create an online tool that allows users search the genomes of various organisms. For this project, you will implement a global sequence alignment tool. In addition to implementing this algorithm, you must also develop a web page to allow users to find a matching strand of DNA against various genomes. As this is not a web development course, not much emphasis will be placed on the inner workings of a web server or the interface, but you will gain a very brief introduction into Python web development using web.py. The interface will be similar to Figure 1. You will need to use the web.py library. Here is a nice basic tutorial for web.py. http: //webpy.org/docs/0.3/tutorial To get you started with this library, we have included a basic example online tool that concatenates two input strings. You can use the code for this tool as a starting point, and make necessary changes to obtain a sequence alignment tool. A sequence alignment tool interface which supports both global and local alignment between two given sequences. Return your code and summarize your approach in a brief write-up.Explanation / Answer
Code:
import argparse
import os
import re
import sys
match = 2
mismatch = -1
gap = -1
seq1 = None
seq2 = None
def main():
try:
parse_cmd_line()
except ValueError as err:
print('error:', err)
return
rows = len(seq1) + 1
cols = len(seq2) + 1
score_matrix, start_pos = create_score_matrix(rows, cols)
seq1_aligned, seq2_aligned = traceback(score_matrix, start_pos)
assert len(seq1_aligned) == len(seq2_aligned), 'aligned strings are not the same size'
alignment_str, idents, gaps, mismatches = alignment_string(seq1_aligned, seq2_aligned)
alength = len(seq1_aligned)
print()
print(' Identities = {0}/{1} ({2:.1%}), Gaps = {3}/{4} ({5:.1%})'.format(idents,
alength, idents / alength, gaps, alength, gaps / alength))
print()
for i in range(0, alength, 60):
seq1_slice = seq1_aligned[i:i+60]
print('Query {0:<4} {1} {2:<4}'.format(i + 1, seq1_slice, i + len(seq1_slice)))
print(' {0}'.format(alignment_str[i:i+60]))
seq2_slice = seq2_aligned[i:i+60]
print('Sbjct {0:<4} {1} {2:<4}'.format(i + 1, seq2_slice, i + len(seq2_slice)))
print()
def create_score_matrix(rows, cols):
score_matrix = [[0 for col in range(cols)] for row in range(rows)]
max_score = 0
max_pos = None # The row and columbn of the highest score in matrix.
for i in range(1, rows):
for j in range(1, cols):
score = calc_score(score_matrix, i, j)
if score > max_score:
max_score = score
max_pos = (i, j)
score_matrix[i][j] = score
assert max_pos is not None, 'the x, y position with the highest score was not found'
return score_matrix, max_pos
def calc_score(matrix, x, y):
similarity = match if seq1[x - 1] == seq2[y - 1] else mismatch
diag_score = matrix[x - 1][y - 1] + similarity
up_score = matrix[x - 1][y] + gap
left_score = matrix[x][y - 1] + gap
return max(0, diag_score, up_score, left_score)
def traceback(score_matrix, start_pos):
END, DIAG, UP, LEFT = range(4)
aligned_seq1 = []
aligned_seq2 = []
x, y = start_pos
move = next_move(score_matrix, x, y)
while move != END:
if move == DIAG:
aligned_seq1.append(seq1[x - 1])
aligned_seq2.append(seq2[y - 1])
x -= 1
y -= 1
elif move == UP:
aligned_seq1.append(seq1[x - 1])
aligned_seq2.append('-')
x -= 1
else:
aligned_seq1.append('-')
aligned_seq2.append(seq2[y - 1])
y -= 1
move = next_move(score_matrix, x, y)
aligned_seq1.append(seq1[x - 1])
aligned_seq2.append(seq1[y - 1])
return ''.join(reversed(aligned_seq1)), ''.join(reversed(aligned_seq2))
def alignment_string(aligned_seq1, aligned_seq2):
idents, gaps, mismatches = 0, 0, 0
alignment_string = []
for base1, base2 in zip(aligned_seq1, aligned_seq2):
if base1 == base2:
alignment_string.append('|')
idents += 1
elif '-' in (base1, base2):
alignment_string.append(' ')
gaps += 1
else:
alignment_string.append(':')
mismatches += 1
return ''.join(alignment_string), idents, gaps, mismatches
def print_matrix(matrix):
for row in matrix:
for col in row:
print('{0:>4}'.format(col))
print()
class ScoreMatrixTest(unittest.TestCase):
def test_matrix(self):
global seq1, seq2
seq1 = 'AGCACACA'
seq2 = 'ACACACTA'
rows = len(seq1) + 1
cols = len(seq2) + 1
matrix_to_test, max_pos = create_score_matrix(rows, cols)
self.assertEqual(known_matrix, matrix_to_test)
if __name__ == '__main__':
sys.exit(main()) without changing the pin settings
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.