def test_fixedDot2ct(self): file_path = getcwd() + sep + "Fixit" file_path2 = getcwd() + sep + "Fixed" title = [">mouseSeq.dot"] title2 = [">mouseSeq.ct"] cts = [ "GAAGUACAAUAUGUAACCG", ".(.{{((.....)))}}.." ] cts2 = [ "1 G 0 2 0 1", "2 A 1 3 15 2", "3 A 2 4 0 3", "4 G 3 5 17 4", "5 U 4 6 16 5", "6 A 5 7 14 6", "7 C 6 8 13 7", "8 A 7 9 0 8", "9 A 8 10 0 9", "10 U 9 11 0 10", "11 A 10 12 0 11", "12 U 11 13 0 12", "13 G 12 14 7 13", "14 U 13 15 6 14", "15 A 14 16 2 15", "16 A 15 17 5 16", "17 C 16 18 4 17", "18 C 17 19 0 18", "19 G 18 20 0 19" ] dot2ct(cts, title, file_path) file_path += "(ct)" self.assertTrue(isfile(file_path)) ct2dot(cts2, title2, file_path2)
def test_FailDot2ct(self): file_path = getcwd() + sep + "seq-test" title = [">mouseSeq.dot"] cts = [ "CAGCACGACACUAGCAGUCAGUGUCAGACUGCAGACAGCACGACACUAGCAGUCAGUGUCAGACUGCAGACAGCACGACACUAGCAGUCAGUGUCAGACUGCAGA", "..(((((...(((((...()))))...))))).....)))))...))))).." ] dot2ct(cts, title, file_path) file_path += "(ct)" self.assertFalse(isfile(file_path))
def test_dot2ct(self): file_path = getcwd() + sep + "seq-test" title = [">mouseSeq.dot"] cts = [ "CAGCACGACACUAGCAGUCAGUGUCAGACUGCAGACAGCACGACACUAGCAGUCAGUGUCAGACUGCAGACAGCACGACACUAGCAGUCAGUGUCAGACUGCAGA", "..(((((...(((((...(((((...(((((.....)))))...))))).....(((((...(((((.....)))))...))))).....)))))...))))).." ] file_1 = open("seq3(ct)").read() dot2ct(cts, title, file_path) file_path += "(ct)" file_2 = open("seq-test(ct)").read() self.assertTrue(isfile(file_path)) self.assertEqual(file_1, file_2) remove(file_path)
def test_fixedDot2ct(self): file_path = getcwd() + sep + "Fixit" file_path2 = getcwd() + sep + "Fixed" title = [">mouseSeq.dot"] title2 = [">mouseSeq.ct"] cts = ["GAAGUACAAUAUGUAACCG", ".(.{{((.....)))}}.."] cts2 = [ "1 G 0 2 0 1", "2 A 1 3 15 2", "3 A 2 4 0 3", "4 G 3 5 17 4", "5 U 4 6 16 5", "6 A 5 7 14 6", "7 C 6 8 13 7", "8 A 7 9 0 8", "9 A 8 10 0 9", "10 U 9 11 0 10", "11 A 10 12 0 11", "12 U 11 13 0 12", "13 G 12 14 7 13", "14 U 13 15 6 14", "15 A 14 16 2 15", "16 A 15 17 5 16", "17 C 16 18 4 17", "18 C 17 19 0 18", "19 G 18 20 0 19" ] dot2ct(cts, title, file_path) file_path += "(ct)" self.assertTrue(isfile(file_path)) ct2dot(cts2, title2, file_path2)
def multil(cts, title, file_name): dot_form = "[AUGC]{2,}" bracket_form = "[\.\<\[\{\(\)\>\]\}\s]{2,}" finally_form = [] dot = [] bracket = [] title = title file_name = file_name for x in range(0, len(cts)): if re.match(dot_form, cts[x]): dot.append(re.match(dot_form, cts[x]).group()) elif re.match(bracket_form, cts[x]): bracket.append(re.match(bracket_form, cts[x]).group()) if len(dot) == len(bracket): finally_form.append(''.join(dot)) finally_form.append(''.join(bracket)) x = input('Choose save format:' + '\n' + '0 - All formats' + '\n' + '1 - Connect (.ct)' + '\n' + '2 - Basepair (.bpseq)' + '\n' + '3 - RNAML (.XML)' + '\n') try: if x == '0': dot2ct(finally_form, title, file_name) dot2bpseq(finally_form, title, file_name) dot2rnaml(finally_form, title, file_name) elif x == '1': dot2ct(finally_form, title, file_name) elif x == '2': dot2bpseq(finally_form, title, file_name) elif x == '3': dot2rnaml(finally_form, title, file_name) except: print("Invalid input format") else: print("Invalid input format")
elif re.match(bracket_form, file_lines[x]): bracket.append(re.match(bracket_form, file_lines[x]).group()) for x in dot: t = 0 while t < len(bracket): if len(x) == len(bracket[t]): input_form.append(x) input_form.append(bracket[t]) t += 1 y = input('Multiline (y/n)?' + '\n') try: if y == 'y': fromdot(file_lines, title, file_name) else: x = input( 'Choose save format:' + '\n' + '0 - All formats' + '\n' + '1 - Connect (.ct)' + '\n' + '2 - Basepair (.bpseq)' + '\n' + '3 - RNAML (.XML)' + '\n') if x == '0': dot2ct(input_form, title, file_name) dot2bpseq(input_form, title, file_name) dot2rnaml(input_form, title, file_name) elif x == '1': dot2ct(input_form, title, file_name) elif x == '2': dot2bpseq(input_form, title, file_name) elif x == '3': dot2rnaml(input_form, title, file_name) except: print("Invalid input format") except: print('File not found')
for x in dot: t = 0 while t < len(bracket): if len(x) == len(bracket[t]): input_form.append(x) input_form.append(bracket[t]) t += 1 y = input('Multiline (y/n)?' + '\n') try: if y == 'y': multil(file_lines, title, file_name) else: x = input('Choose save format:' + '\n' + '0 - All formats' + '\n' + '1 - Connect (.ct)' + '\n' + '2 - Basepair (.bpseq)' + '\n' + '3 - RNAML (.XML)' + '\n') if x == '0': dot2ct(input_form, title, file_name) dot2bpseq(input_form, title, file_name) dot2rnaml(input_form, title, file_name) elif x == '1': dot2ct(input_form, title, file_name) elif x == '2': dot2bpseq(input_form, title, file_name) elif x == '3': dot2rnaml(input_form, title, file_name) except: print("Invalid input format") except: print('File not found')