Question
This is the said code above: # Two sequences seqa = CGTATGCTAGCTTATTTGC seqb = TAACTAGCGATTGCGC # Match, mismatch and gap penalties match = 1 mismatch
This is the said code above:
# Two sequences seqa = "CGTATGCTAGCTTATTTGC" seqb = "TAACTAGCGATTGCGC" # Match, mismatch and gap penalties match = 1 mismatch = -1 gap = -2
def needleman_wunsch_alignment(seqa, seqb, match, mismatch, gap): # length of two sequences n = len(seqa) m = len(seqb) # Initialize scoring matrix with zeros and gap scores for first row and column score = [0] * (n+1) for i in range(n+1): score[i] = [0] * (m+1) # Fill out first column for i in range(0, n + 1): score[i][0] = gap * i # Fill out first row for j in range(0, m + 1): score[0][j] = gap * j # Fill out all other values in the score matrix for i in range(1, n + 1): for j in range(1, m + 1): # Calculate the score by checking the top, left, and diagonal cells if (seqa[i-1] == seqb[j-1]): match_score = score[i - 1][j - 1] + match else: match_score = score[i - 1][j - 1] + mismatch delete_score = score[i - 1][j] + gap insert_score = score[i][j - 1] + gap # Record the maximum score from the three possible scores calculated above score[i][j] = max(match_score, delete_score, insert_score)
# Create variables to store alignment aligna = "" alignb = "" # Traceback, start from the bottom right cell in matrix i = n j = m # Use i and j to keep track of where we are in the matrix, end at an edge while i > 0 and j > 0: score_current = score[i][j] score_diagonal = score[i-1][j-1] score_up = score[i][j-1] score_left = score[i-1][j] # Check to figure out which cell the current score was calculated from, # then update i and j to correspond to that cell. if (seqa[i-1] == seqb[j-1]): match_score = match else: match_score = mismatch if score_current == score_diagonal + match_score: aligna += seqa[i-1] alignb += seqb[j-1] i -= 1 j -= 1 elif score_current == score_left + gap: aligna += seqa[i-1] alignb += '-' i -= 1 elif score_current == score_up + gap: aligna += '-' alignb += seqb[j-1] j -= 1
# Finish tracing up to the top left cell if edge reached but either i or j is not zero while i > 0: aligna += seqa[i-1] alignb += '-' i -= 1 while j > 0: aligna += '-' alignb += seqb[j-1] j -= 1 # Since we traversed the score matrix from the bottom right, our two sequences will be reversed. # These two lines reverse the order of the characters in each sequence. # Alternate solution is to prepend string using aligna = seq[i-1] + aligna, so that no reverse is needed aligna = aligna[::-1] alignb = alignb[::-1] return(aligna, alignb)
output1, output2 = needleman_wunsch_alignment(seqa, seqb, match, mismatch, gap)
print(output1 + " " + output2)
Write a new function using the code above that prints "There is only one best alignment" or "There are multiple best alignments" depending on whether there is only a single highest scoring alignment, or whether there are multiple alignments with the same highest score. Apply this function to the given sequences. \# Match, mismatch and gap penalties match =1 mismatch =1 gap =2 \# Two sequences to align seqa = "CGTATGCTAGCTTATTTGC" seqb = "TAACTAGCGATTGCGC" \# Two more sequences to align seqc = "ATCGATGCTACGATCGAATG" seqd = "ATTTACCGTGCGTCAAStep 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