Question

In: Computer Science

1. Implement the function calculate_score that consumes three parameters, two strings and a list. The strings...

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

Solutions

Expert Solution

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


Related Solutions

Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
using python 1. #Write a function called multiply_file_by_index. This function #should take two parameters, both strings....
using python 1. #Write a function called multiply_file_by_index. This function #should take two parameters, both strings. The first string is #the filename of a file to which to write (output_file), and #the second string is the filename of a file from which to read #(input_file). # #In the input file, there will be an integer on every line. #To the output file, you should write the integer from the #original file multiplied by the line number on which it #appeared....
Design and implement a function with two input parameters, A and B. The functions then calculates...
Design and implement a function with two input parameters, A and B. The functions then calculates the result of the floor division of A over B (A//B). You are not allowed to use the floor division operator. Look at here: https://simple.wikipedia.org/wiki/Division_(mathematics) - For instance the function for 20 and 6 will return 3.
Part 1 1. Implement the binary search function. The function should take as formal parameters an...
Part 1 1. Implement the binary search function. The function should take as formal parameters an array of integers, its size and target, and returns (a) in the case of successful search – the position (index) of the target in the array (b) in the case of unsuccessful search – an exception with the message “Unsuccessful search” thrown from the function to the user. 2. The binary search works correctly only when the input is sorted. This requirement should be...
Code in Python 1. A function named get_score has been defined which consumes no parameters and...
Code in Python 1. A function named get_score has been defined which consumes no parameters and returns an int value. Call get_score and print the result. 2.A function named area_rectangle has been defined which consumes two parameters that are both float values and returns a float value. Call area_rectangle with arguments of variables named length and width and print the result. 3. Assume a function called calculate_cone_volume is already defined. The function has 2 parameters: height and radius (in that...
Write a method that concatenates two strings passed as parameters.    Version #1 - assign to...
Write a method that concatenates two strings passed as parameters.    Version #1 - assign to the 1st parameter the concatenation of both parameters. Perform the concatenation using the + operator. We are assuming reference parameter work that way (they don't).    Version #2 - fine. return the value of the 1st param after concatenating to it the second parameter then.    Version #3 - Let's do it the proper way now, I say. Create a temporary String reference variable...
- Design and implement a function with no input parameters. The function keeps receiving a number...
- Design and implement a function with no input parameters. The function keeps receiving a number from input (user) and adds the numbers together. The application keeps doing it until the user enter 0. Then the application will stop and print the total sum and average of the numbers the user had entered.
Design a function in python that takes a list of strings as an argument and determines...
Design a function in python that takes a list of strings as an argument and determines whether the strings in the list are getting decreasingly shorter from the front to the back of the list
4. Implement the function read_info_file that consumes a file name (string) as its parameter and returns...
4. Implement the function read_info_file that consumes a file name (string) as its parameter and returns a list of strings - one element for each line in the file. These lines should have all the whitespace removed from both ends of the line. a. See the formatting of the individual_info data file. Consider how a file can be read into the program. In Python language
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT