Question

3. Implement the function read_matrix_file that consumes a file name (string) as its parameter and returns...

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

Homework Answers

Answer #1

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')

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Python Write function stringCount() that takes two string inputs—a file name and a target string— and...
Python Write function stringCount() that takes two string inputs—a file name and a target string— and returns the number of occurrences of the target string in the file. >>> stringCount('example.txt', 'line') 4
Write a Python function that takes a filename as a parameter and returns the string 'rows'...
Write a Python function that takes a filename as a parameter and returns the string 'rows' if a file was written row by row, and 'columns' if the file was written column by column. You would call the function with a command like filetype = myfunc(filename).
Q1) Write a Python function partial_print, which takes one parameter, a string, and prints the first,...
Q1) Write a Python function partial_print, which takes one parameter, a string, and prints the first, third, fifth (and so on) characters of the strings, with each character both preceded and followed by the ^ symbol, and with a newline appearing after the last ^ symbol. The function returns no value; its goal is to print its output, but not to return it. Q2) Write a Python function called lines_of_code that takes a Path object as a parameter, which is...
In PYTHON please: Write a function named word_stats that accepts as its parameter a string holding...
In PYTHON please: Write a function named word_stats that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of words, and produces a particular group of statistics about the input. You should report the total number of words (as an integer) and the average word length (as an un-rounded number). For example, suppose the file tobe.txt contains the following text: To be or not to be, that is the...
Implement in python a function avg_val(lst), which returns the average value of the elements in list....
Implement in python a function avg_val(lst), which returns the average value of the elements in list. For example, given a list lst: [19, 2, 20, 1, 0, 18], the function should return 10. The name of the method should be avg_val and the method should take one parameter which is the list of values to test. Here is an example call to the function print(avg_val([19, 2, 20, 1, 0, 18]))
Python Write function words() that takes one input argument—a file name—and returns the list of actual...
Python Write function words() that takes one input argument—a file name—and returns the list of actual words (without punctuation symbols !,.:;?) in the file. >>> words('example.txt') ['The', '3', 'lines', 'in', 'this', 'file', 'end', 'with', 'the', 'new', 'line', 'character', 'There', 'is', 'a', 'blank', 'line', 'above', 'this', 'line']
The file named world_series_winners.txt contains a chronological list of the World Series winning teams from 1903...
The file named world_series_winners.txt contains a chronological list of the World Series winning teams from 1903 through 2009. (The first line in the file is the name of the team that won in 1903, and the last line is the name of the team that won in 2009. Note that the World Series was not played in 1904 or 1994.) Write a program q3.py that lets the user enter the name of a team and then displays to the screen...
Write a function called fun which has an object as its parameter and returns the name...
Write a function called fun which has an object as its parameter and returns the name of properties of that object in an array. For instance, if it receives {a:1,b:3}, as its parameter, it should return [a, b], or if it receives {u:4, k:3, h:5}, it should return [u, k, h]. Answer:(penalty regime: 10, 20, ... %)
Please create a python module named homework.py and implement the functions outlined below. Below you will...
Please create a python module named homework.py and implement the functions outlined below. Below you will find an explanation for each function you need to implement. When you are done please upload the file homework.py to Grader Than. Please get started as soon as possible on this assignment. This assignment has many problems, it may take you longer than normal to complete this assignment. This assignment is supposed to test you on your understanding of reading and writing to a...
Python 3 Implement the function condense, which takes a "passage" (a string containing multiple sentences separated...
Python 3 Implement the function condense, which takes a "passage" (a string containing multiple sentences separated by the '\n' character), and returns a condensed version of that passage based on the following logic: the frequency with which each word appears in the entire passage is computed a score for each sentence in the passage is computed by summing the frequency of each word in the sentence the sentences with the top 3 scores (we assume there are no ties) are...