import RNApath RNApath.addSwigInterfacePath(3) import RNA import unittest from struct import * import locale locale.setlocale(locale.LC_ALL, 'C') seq1 = "CGCAGGGAUACCCGCG" struct1 = "(((.(((...))))))" struct11 = "(((.((.....)))))" seq2 = "GCGCCCAUAGGGACGC" struct2 = "((((((...))).)))" seq3 = "GCGCACAUAGUGACGC" struct3 = "(..(((...)))...)" align = [seq1,seq2,seq3] (struct, mfe) = RNA.fold(seq1) class GeneralTests(unittest.TestCase): def test_version(self): print("test version number") self.assertEqual(RNA.__version__, RNApath.VERSION_NUMBER) def test_hammingDistance(self): print("test_hammingDistance \t calculate a hamming distance") self.assertEqual(RNA.hamming(seq1,seq2),16) self.assertEqual(RNA.bp_distance(struct1,struct2),6) def test_temperature(self): print("test_temperature") self.assertEqual(RNA.cvar.temperature,37) def test_foldASequence(self): print("test_foldASequence") # new better interface (struct, mfe) = RNA.fold(seq1) self.assertEqual(struct,struct1) # check energy self.assertTrue(abs(RNA.energy_of_struct(seq1, struct1) - mfe) < 0.0001) def test_constrained_folding(self): print("test_constrained_folding") RNA.cvar.fold_constrained = 1 (struct,cmfe) = RNA.fold(seq1,"....xx....xx....") self.assertEqual(struct,'(((..........)))') self.assertTrue(abs(RNA.energy_of_struct(seq1, struct) - cmfe) < 0.0001) RNA.cvar.fold_constrained = 0 def test_tree_distance(self): print("test_tree_distance"); xstruc = RNA.expand_Full(struct1) T1 = RNA.make_tree(xstruc) xstruc = RNA.expand_Full(struct2) T2 = RNA.make_tree(xstruc) RNA.edit_backtrack = 1 tree_dist = RNA.tree_edit_distance(T1, T2) # print RNA::get_aligned_line(0), RNA::get_aligned_line(1),"\n" self.assertEqual(tree_dist,2) def test_cofold_andMore(self): print("test_cofold") RNA.cvar.cut_point = len(seq1)+1 (costruct,comfe) = RNA.cofold(seq1 + seq2) self.assertEqual(costruct,'(((.(((...))))))((((((...))).)))') cmfe = RNA.energy_of_struct(seq1 + seq2, costruct) self.assertTrue(abs(comfe - cmfe) < 1e-5) (x,ac,bc,fcab,cf) = RNA.co_pf_fold(seq1 + seq2, struct) self.assertTrue(cf