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....
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
Python This part involves creating a function that will manage a List of unique strings. The...
Python This part involves creating a function that will manage a List of unique strings. The function is passed a string and a list as arguments. It passes a list back. The function to add a word to a List if word does not exist in the List. If the word does exist in the List, the function does nothing. Create a test program that takes a string as input and then calls the function over and over until the...
This function will be given a list of strings and a character. You must remove all...
This function will be given a list of strings and a character. You must remove all occurrences of the character from each string in the list. The function should return the list of strings with the character removed. Signature: public static ArrayList<String> removeChar(String pattern, ArrayList<String> list)
Write code for a short method that does the following: accepts two strings as parameters, first...
Write code for a short method that does the following: accepts two strings as parameters, first name, and last name; Outputs the following message, concatenated together in one line of output:
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT