def test_acceptance_02(self): nus = Nussinov('GGAAACCGAAAC') ret = nus.compute() self.assertEqual(len(ret), 3) self.assertIn(ret,([(0,6), (1,5), (7,11)], [(0,11), (1,5), (6,7)]) )
def test_acceptance_01(self): nus = Nussinov('GGGAAAUCC') ret = nus.compute() self.assertEqual(len(ret), 3) self.assertIn(ret, ([(1, 8), (2, 7), (3, 6)], [(1, 8), (2, 7), (4, 6)], [(1, 8), (2, 7), (5, 6)]))
def solve(self, sequence, min_padding=0, tie_break_permute=None, prettify=False): """ sequence: string of RNA bases represented as A,U,G,C min_padding: minimum distance between two paired bases tie_break_permute: None or order in which to break ties prettify: True if pretty dot paranthesis is to be returned, otherwise False return: the number of pairings and the dot parantheses notation """ if self.mode == 'greedy': gr = GreedySolver(sequence) score = gr.solve() dot_p = gr.dot_parentheses(prettify) return score, dot_p elif self.mode == 'nussinov': nv = Nussinov(sequence) score = nv.solve(min_padding, tie_break_permute) dot_p = nv.dot_parentheses(prettify) return score, dot_p elif self.mode == 'zuker': zk = ZukerFreier(sequence) score = zk.solve() dot_p = zk.dot_parentheses() return score, dot_p raise ValueError('mode is not set')
def test_fill_matrix(): nussinov = Nussinov() sequence = "GGUCCAC" d = [[Cell(i, j) for j in range(len(sequence) + 1)] for i in range(len(sequence) + 1)] nussinov.fill_matrix(d, sequence)
def test_acceptance_01(self): nus = Nussinov('GGGAAAUCC') ret = nus.compute() self.assertEqual(len(ret), 3) self.assertIn(ret, ([(1,8), (2,7), (3,6)], [(1,8), (2,7), (4,6)], [(1,8), (2,7), (5,6)]) )
def RunAlgorithm(self): i = 0 text = self.RnaCodeTextEdit.toPlainText() TextList = text.split(QRegExp("\\s+")) if TextList.count() -1 == 0 : msgBox = QMessageBox() msgBox.setText("Can't run algorithm without data!") msgBox.exec_() return self.ResultTabView.setRowCount(TextList.count()) for line in TextList: nuss = Nussinov(line) ret = nuss.compute() item1 = QTableWidgetItem(line) item2 = QTableWidgetItem(QString(("%s\n" % (ret)) )) self.ResultTabView.setItem(i,0,item1) self.ResultTabView.setItem(i,1,item2) i = i + 1 #self.ResultTabView. .write("%s %s\n" % (len(ret), ret)) self.ResultTabView.resizeColumnsToContents()
def RunAlgorithm(self): i = 0 text = self.RnaCodeTextEdit.toPlainText() TextList = text.split(QRegExp("\\s+")) if TextList.count() - 1 == 0: msgBox = QMessageBox() msgBox.setText("Can't run algorithm without data!") msgBox.exec_() return self.ResultTabView.setRowCount(TextList.count()) for line in TextList: nuss = Nussinov(line) ret = nuss.compute() item1 = QTableWidgetItem(line) item2 = QTableWidgetItem(QString(("%s\n" % (ret)))) self.ResultTabView.setItem(i, 0, item1) self.ResultTabView.setItem(i, 1, item2) i = i + 1 #self.ResultTabView. .write("%s %s\n" % (len(ret), ret)) self.ResultTabView.resizeColumnsToContents()
def test_nussinov_guideline(): nussinov = Nussinov() structures, amount_pairs = nussinov.run("data/nussinov_guideline.fasta", True) structures_seq1 = structures[0] amount_pair_seq1 = amount_pairs[0] assert amount_pair_seq1 == 11 assert '(((((()())(.((()..))..)...))))' in structures_seq1 structures_seq2 = structures[1] amount_pair_seq2 = amount_pairs[1] assert amount_pair_seq2 == 24 assert '((((.((((((((((...)))))..)(((()))))()()))((((...)))))...))))' in structures_seq2 structures_seq3 = structures[2] amount_pair_seq3 = amount_pairs[2] assert amount_pair_seq3 == 26 assert '(..(((((.())())((.((((()))(((()())))(().))))(.((())))).).))).' in structures_seq3 structures_seq4 = structures[3] amount_pair_seq4 = amount_pairs[3] assert amount_pair_seq4 == 27 assert '(((((()(()(((.....(.(((((.()((.)))((()()))).)((().)).)..))))))).))))' in structures_seq4 structures_seq5 = structures[4] amount_pair_seq5 = amount_pairs[4] assert amount_pair_seq5 == 35 assert '(()((.))(()(((.)((((.(().).)()))())((()(().).)(((..))(()))))((((((())))))())))).' in structures_seq5 structures_seq6 = structures[5] amount_pair_seq6 = amount_pairs[5] assert amount_pair_seq6 == 63 assert '(((()((((((.((()((((((()(((((())(().((())..))).)()((((...).))(()())(())())((.)))()()())))))(.)))))))(()((()(((((.)))))).))(((..))())).)))()..)..))' in structures_seq6
#!/usr/bin/python from file_reader import * from nussinov import Nussinov if __name__ == "__main__": input_path = 'test_data' output_path = 'out' out = open(output_path, 'w') reader = FileReader(input_path) for line in reader: nuss = Nussinov(line) ret = nuss.compute() out.write("%s %s\n" % (len(ret), ret)) out.close()
def setUp(self): self.basic_data = 'ACGU' self.basic = Nussinov(self.basic_data)
def test_acceptance_03(self): nus = Nussinov('GCGCGCGCGCGCGCGCGCGCGCGC') ret = nus.compute() self.assertEqual(len(ret), 12)
class NussinovTest(unittest.TestCase): def setUp(self): self.basic_data = 'ACGU' self.basic = Nussinov(self.basic_data) def test_compute_return(self): ret = self.basic.compute() self.assertIsInstance(ret, list) def test_init_matrix(self): self.basic._init_matrix() self.assertEqual(len(self.basic.matrix), len(self.basic_data)) for i in xrange(len(self.basic_data)): for j in xrange(len(self.basic_data)): if i-1 <= j: self.assertEqual(self.basic.matrix[i][j], 0) else: self.assertEqual(self.basic.matrix[i][j], -1) def test_fill_diagonal(self): self.basic._fill_diagonal(1) self.assertEqual(self.basic.matrix[1][2], 1) self.basic._fill_diagonal(2) self.basic._fill_diagonal(3) self.assertEqual(self.basic.matrix[0][3], 2) def test_build_matrix(self): self.basic._build_matrix() self.assertEqual(self.basic.matrix[0][3], 2) self.assertEqual(self.basic.matrix[1][2], 1) def test_generate_trace(self): self.basic._build_matrix() self.basic._generate_trace() def test_acceptance_01(self): nus = Nussinov('GGGAAAUCC') ret = nus.compute() self.assertEqual(len(ret), 3) self.assertIn(ret, ([(1,8), (2,7), (3,6)], [(1,8), (2,7), (4,6)], [(1,8), (2,7), (5,6)]) ) def test_acceptance_02(self): nus = Nussinov('GGAAACCGAAAC') ret = nus.compute() self.assertEqual(len(ret), 3) self.assertIn(ret,([(0,6), (1,5), (7,11)], [(0,11), (1,5), (6,7)]) ) def test_acceptance_03(self): nus = Nussinov('GCGCGCGCGCGCGCGCGCGCGCGC') ret = nus.compute() self.assertEqual(len(ret), 12)
import os from nussinov import Nussinov from utils import FastaReader, pairs2parentheses, print_matrix if __name__ == "__main__": nus = Nussinov() #seq = "ACCAGCU" seq = "GCGCUCUGAUGAGGCCGCAAGGCCGAAACUGCCGCAAGGCAGUCAGCGC" nus.seq = seq nus.fill_matrix() print_matrix(nus.V_matrix, seq=seq) pairs = nus.get_pairs() print(pairs) print(seq) parentheses = pairs2parentheses(pairs, len(seq)) print(parentheses) print(parentheses.count("("))
class NussinovTest(unittest.TestCase): def setUp(self): self.basic_data = 'ACGU' self.basic = Nussinov(self.basic_data) def test_compute_return(self): ret = self.basic.compute() self.assertIsInstance(ret, list) def test_init_matrix(self): self.basic._init_matrix() self.assertEqual(len(self.basic.matrix), len(self.basic_data)) for i in xrange(len(self.basic_data)): for j in xrange(len(self.basic_data)): if i - 1 <= j: self.assertEqual(self.basic.matrix[i][j], 0) else: self.assertEqual(self.basic.matrix[i][j], -1) def test_fill_diagonal(self): self.basic._fill_diagonal(1) self.assertEqual(self.basic.matrix[1][2], 1) self.basic._fill_diagonal(2) self.basic._fill_diagonal(3) self.assertEqual(self.basic.matrix[0][3], 2) def test_build_matrix(self): self.basic._build_matrix() self.assertEqual(self.basic.matrix[0][3], 2) self.assertEqual(self.basic.matrix[1][2], 1) def test_generate_trace(self): self.basic._build_matrix() self.basic._generate_trace() def test_acceptance_01(self): nus = Nussinov('GGGAAAUCC') ret = nus.compute() self.assertEqual(len(ret), 3) self.assertIn(ret, ([(1, 8), (2, 7), (3, 6)], [(1, 8), (2, 7), (4, 6)], [(1, 8), (2, 7), (5, 6)])) def test_acceptance_02(self): nus = Nussinov('GGAAACCGAAAC') ret = nus.compute() self.assertEqual(len(ret), 3) self.assertIn(ret, ([(0, 6), (1, 5), (7, 11)], [(0, 11), (1, 5), (6, 7)])) def test_acceptance_03(self): nus = Nussinov('GCGCGCGCGCGCGCGCGCGCGCGC') ret = nus.compute() self.assertEqual(len(ret), 12)
def test_acceptance_02(self): nus = Nussinov('GGAAACCGAAAC') ret = nus.compute() self.assertEqual(len(ret), 3) self.assertIn(ret, ([(0, 6), (1, 5), (7, 11)], [(0, 11), (1, 5), (6, 7)]))