Question: Create a function called memoAlignScore ( S 1 , S 2 , gap, substitutionMatrix,memo ) We have already developed a function alignScore that computes the

Create a function called memoAlignScore(S1, S2, gap, substitutionMatrix,memo)
We have already developed a function alignScore that computes the alignment score.
def alignScore(S1, S2, gap, substitutionMatrix):
''' Returns the sequence alignment score for S1 and S2.'''
if S1=="": return gap * len(S2)
elif S2=="" : return gap * len(S1)
else:
option1= substitutionMatrix[(S1[0], S2[0])]+ alignScore(S1[1:], S2[1:], gap, substitutionMatrix)
option2= gap + alignScore(S1[1:], S2, gap , substitutionMatrix)
option3= gap + alignScore(S1, S2[1:], gap , substitutionMatrix)
return max(option1, option2, option3)
Your first task is to implement a memoized version of alignScore, memoAlignScore(S1, S2, gap, substitutionMatrix,memo), where memo is a dictionary. You can start it off as {}.
Test your memoAlignScore function carefully. Here are some examples of the memoAlignScore function in action:
>>> memoAlignScore('','',-9,blosum62,{})
0
>>> memoAlignScore('','FGTSK',-9,blosum62,{})
-45
>>> memoAlignScore('IVEKGYY','AVEYY',-9,blosum62,{})
4
>>> memoAlignScore('CIEAFGTSKQKRALNSRRMNAVGNDIVSTAVTKAAADVIDAKGVTALIQDVAQD','RDLPIWTSVDWKSLPATEIFNKAFSQGSDEAMYDYMAVYKKSCPQTRR',-9,blosum62,{})
-48

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!