In: Computer Science
1. Implement the function calculate_score that consumes three parameters, two strings and a list. The strings will each be ONE character and will represent a nucleotide. The list will be a nested int list representing a 4x4 score matrix. This function will return the value (int) from the nested int list at the location of the two referenced nucleotides.
a. An example call to calculate_score would be calculate_score(“A”, “T”, score_matrix). If we look at the alignment score table in the background section we can see that the cell at column “A” and row “T” holds the value 6. Similarly, if we consider this location via the indexes in score_matrix, we can use the index call score_matrix[1][2] to reach the value.
b. We can assume that the score matrix will always be a 4x4 nested int list in the same order as the matrix shown above.
c. You can use this index dictionary in your code for reference, or implement some other way to associate the string arguments to the appropriate index locations: {"G":0, "A":1, "T":2, "C":3}
d. Write three assert_equal statements.
In Python language
Python program for the provided problem statement
# import numpy and assert_equal
import numpy as np
import numpy.testing as npt
# this method returns the value of score_matrix at the specified inputs
def calculate_score(str1, str2, score_matrix):
# create dictionary
dictionary = {"G":0, "A":1, "T":2, "C":3}
# now, find list indexes using the inputs and dictionary
r = dictionary.get(str1) # row
c = dictionary.get(str2) # column
# return the score_matrix value at these indexes
return score_matrix[r][c]
# driver method
def main():
# create a 4X4 score matrix
score_matrix = [[5, 8, 91, 3],
[44, 11, 39, 31],
[25, 7, 72, 59],
[5, 8, 91, 3]]
# enter strings
str1 = input("Enter string #1: ")
str2 = input("Enter string #2: ")
# call method to find the value at provided inputs
value = calculate_score(str1, str2, score_matrix)
# display result
print("\nValue found in the score matrix: ", value, "\n")
# assert_equal() method checks whether the two objects are equal or not
# if yes then it will print None
# else it provides an assertion error
# print None if both strings are same otherwise assertion error
print(npt.assert_equal(str1, str2))
# print None because score_matrix[0] = score_matrix[3] = [5, 8, 91, 3]
print(npt.assert_equal(score_matrix[0], score_matrix[3]))
# print assertion error because score_matrix[0] = [5, 8, 91, 3]
# and score_matrix[1] = [44, 11, 39, 31]
print(npt.assert_equal(score_matrix[0], score_matrix[1]))
# program start here
main()
Python program Output
Test case 1: when strings are different
Test case 2: when strings are the same