Question: Please write this in Python, thank you Problem 3: You can use the same test cases from above to test this part. Your task is
Please write this in Python, thank you
Problem 3:



You can use the same test cases from above to test this part.
Your task is to author a function, encode(string), which accepts one sequence. The input sequence can be comprised of 4 letters (A,1,C,G) or other letters. The function should return a nested list [list1,list2.listN], where N is the total number of letters in sequence, and each list i is a unique list for each type of letters defined as following: If the letter is 'A', the list is [1,0,0,0] . If the letter is 'T', the list is [0,1,0,0] . If the letter is 'C', the list is [0,0,1,0] . If the letter is 'G', the list is [0,0,0,1] o If the letter is none of the letters above, the list is [0,0,0,0] For instance, if the sequence is 'ACCGTM', the result from the function should be [[1,0,0,0], [0,0,1,0], [0,0,1,0], [0,0,0,1], [0,1,0,0], [0,0,0,0]] A G T M Testing Here we provide several tests cases for you to test your function: . AGGTGCGX ACNCTGA o TGCAAAG AASECVFF o To extend problem 3, your task is to author a function, encode_pairs(string), which accepts one sequence. The input sequence can be comprised of 4 letters (A,1,C,G) or other letters The function should return a nested list [list1,list2,...listN], where N is the number of all possible two-letter pairs found in string, and each list i is a unique list for each pair of letters (i.e., AT, CG, AC, GT) we can get from the sequence. We still use the following list for each type of letter: . If the letter is 'A', the list is [1,0,0,0] . If the letter is 'T', the list is [0,1,0,0] . If the letter is 'C', the list is [0,0,1,0] . If the letter is 'G', the list is [0,0,0,1] o If the letter is none of the letters above, the list is [0,0,0,0] Given any two-letter string, we need concatenate the list representation of the two letters into a combined list. For instance, o if the letters are 'AT', the list will be [1,0,0,0,0,1,0,0] o if the letters are 'GT', the list will be [0,0,0,1,0,1,0,0] o if the letters are 'AC, the list will be [1,0,0,0,0,0,1,0] o if the letters are 'XC, the list will be [0,0,0,0,0,0,1,0] You are required to generate all possible two-letters string from the given sequence, and then convert each two letter pair into the list as defined above, O o o o For instance, if the string is 'ACCG, the result from the function should first generate pairs, and then print out its list representation: AA ->[1,0,0,0] + [1,0,0,0] [1,0,0,0,1,0,0,0] CC ->[0,0,1,0] + [0,0,1,0]-> [0,0,1,0,0,0,1,0] + GG ->[0,0,0,1] + [0,0,0,1]-> [0,0,0,1,0,0,0,1] AC ->(1,0,0,0] + [0,0,1,0] -> [1,0,0,0,0,0,1,0] CA ->[0,0,1,0] + [1,0,0,0] -> [0,0,1,0,1,0,0,0] AG ->[1,0,0,0] + [0,0,0,1] -> [1,0,0,0,0,0,0,1] GA ->[0,0,0,1] + [1,0,0,0] -> [0,0,0,1,1,0,0,0] CG ->[0,0,1,0] + [0,0,0,1] [0,0,1,0,0,0,0,1) GC ->[0,0,0,1] + [0,0,1,0] -> [0,0,0,1,0,0,1,0] Therefore, the return list from the function is [[1,0,0,0,1,0,0,0], [0,0,1,0,0,0,1,0], [0,0,0,1,0,0,0,1), [1,0,0,0,0,0,1,0], [0,0,1,0,1,0,0,0), (1,0,0,0,0,0,0,1), [0,0,0,1,1,0,0,0], [0,0,1,0,0,0,0,1), [0,0,0,1,0,0,1,0]] Note 1: For this question only, the order of pairs in the results is not necessary fixed. Note 2: No duplicate pairs are shown in the output. i.e., for sequence 'ACCG), the encoding for 'AC' should only be printed once
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
