3. Implement the function read_matrix_file that consumes a file name (string) as its parameter and returns a nested list of ints (4x4 matrix) associated with the scores aligning G, A, T, and C.
a. The nested list for the provided alignment_matrix text file would be: [[10,5,3,-5],[5,9,6,7], [3,6,12,8],[-5,7,8,10]].
Python language, txt file, sorry
PYTHON CODE
def read_matrix_file(filename:str):
file = open(filename,'r')
#All lines in # are for your understanding
##this is a nested list, let me break it up for you to
understand
#file.readlines() returns a list of elements in the file where each
element is a line in the file
#for x in file.readlines() traverses each line in the file, x
contains char '\n' at the end
#x.split('\n')[0] gets the string without the char '\n' now split
using ' ' gives a list of all numbers as string
#now this list of strings should form another inner list which is
one element of the outer list
#in this step the the string number are traversed and converted to
int and we have our nested list!
outList = [[int(i) for i in x.split('\n')[0].split(' ')] for x in
file.readlines()]
#return the outList
return outList
#calling the function
read_matrix_file('alignment_text.txt')
Get Answers For Free
Most questions answered within 1 hours.