Lecture Notes on 09 Jan 2023 # File: DNA.py # Description: # Student Name: # Student UT EID: # Partner Name: # Partner UT EID: # Course Name: CS 313E # Unique Number: # Date Created: # Date Last Modified: import sys # function to test other functions def test_cases (): # test all sub_strings() assert all_substrings ("a") == ["a"] assert all_substrings ("abc") == ["abc", "ab", "bc", "a", "b", "c"] assert all_substrings ("") == [] # test longest_subsequence() assert longest_subsequence ("a", "a") == ["a"] assert longest_subsequence ("abcd", "bc") == ["bc"] assert longest_subsequence ("abcd", "xyz") == [] # return the result return "all test cases passed" # Input: s a string # Output: a list of all substrings of s def all_substrings (s): # a list of all substrings of s result = [] # define a window wnd = len(s) # get all substrings while (wnd > 0): idx = 0 while (idx + wnd) <= len(s): sub_str = s[idx:idx+wnd] result.append (sub_str) idx += 1 wnd = wnd - 1 # return the result return result # Input: s1 and s2 are two strings that represent strands of DNA # Output: returns a sorted list of substrings that are the longest # common subsequence. The list is empty if there are no # common subsequences. def longest_subsequence (s1, s2): return def main(): # test all functions print (test_cases()) # read the number of pairs line = sys.stdin.readline() line = line.strip() num_pairs = int (line) # for each pair call the longest_subsequence for i in range (num_pairs): line = sys.stdin.readline() s1 = line.strip() line = sys.stdin.readline() s2 = line.strip() # convert the strings to upper case s1 = s1.upper() s2 = s2.upper() # get the longest subsequences result = longest_subsequence (s1, s2) # print the result if (len(result) == 0): print ("No Common Sequence Found") else: for item in result: print (item) # insert blank line print() if __name__ == "__main__": main()