def setUp(self): """Define a few standard models and motifs""" ile_mod_0 = Module('NNNCUACNNNNN', '(((((..(((((') ile_mod_1 = Module('NNNNNUAUUGGGGNNN', ')))))......)))))') ile_rule_0 = Rule(0, 0, 1, 15, 5) ile_rule_1 = Rule(0, 7, 1, 4, 5) ile_motif = Motif([ile_mod_0, ile_mod_1], \ [ile_rule_0, ile_rule_1]) helices = [PairedRegion('NNN'), PairedRegion('NNNNN')] constants = [ConstantRegion('CUAC'), ConstantRegion('UAUUGGGG')] order = "H0 C0 H1 - H1 C1 H0" ile_model = SequenceModel(order=order, constants=constants, \ helices=helices, composition=BaseFrequency('UCAG')) self.ile_embedder = SequenceEmbedder(length=50, num_to_do=10, \ motif=ile_motif, model=ile_model, composition=BaseFrequency('UCAG')) short_ile_mod_0 = Module('NCUACNN', '(((..((') short_ile_mod_1 = Module('NNUAUUGGGGN', '))......)))') short_ile_rule_0 = Rule(0, 0, 1, 10, 3) short_ile_rule_1 = Rule(0, 5, 1, 1, 2) short_ile_motif = Motif([short_ile_mod_0, short_ile_mod_1], \ [short_ile_rule_0, short_ile_rule_1]) short_helices = [PairedRegion('N'), PairedRegion('NN')] short_constants = [ConstantRegion('CUAC'), ConstantRegion('UAUUGGGG')] short_order = "H0 C0 H1 - H1 C1 H0" short_ile_model = SequenceModel(order=short_order, \ constants=short_constants, \ helices=short_helices, composition=BaseFrequency('UCAG')) self.short_ile_embedder = SequenceEmbedder(length=50, num_to_do=10, \ motif=short_ile_motif, model=short_ile_model, \ composition=BaseFrequency('UCAG'))
def test_refresh_primers(self): """Module should appear in correct location with primers""" first_module = Module('AAAAA', '(((((') second_module = Module('UUUUU', ')))))') rule_1 = Rule(0, 0, 1, 4, 5) helix = Motif([first_module, second_module], [rule_1]) model = SequenceModel(constants=[ConstantRegion('AAAAA'), \ ConstantRegion('UUUUU')], order='C0 - C1', \ composition=BaseFrequency('A')) embedder = SequenceEmbedder(length=30, num_to_do=100, \ motif=helix, model=model, composition=BaseFrequency('CG'), \ positions=[3, 6], primer_5 = 'UUU', primer_3 = 'AAA') last = '' for i in range(100): embedder.refresh() curr = str(embedder) self.assertEqual(curr[0:3], 'UUU') self.assertEqual(curr[6:11], 'AAAAA') self.assertEqual(curr[14:19], 'UUUUU') self.assertEqual(curr.count('A'), 8) self.assertEqual(curr.count('U'), 8) self.assertEqual(curr[-3:], 'AAA') self.assertNotEqual(last, curr) last = curr
def setUp(self): """Defines a few standard motifs""" self.ile_mod_0 = Module("NNNCUACNNNNN", "(((((..(((((") self.ile_mod_1 = Module("NNNNNUAUUGGGGNNN", ")))))......)))))") self.ile_rule_0 = Rule(0, 0, 1, 15, 3) self.ile_rule_1 = Rule(0, 7, 1, 4, 5) self.ile = Motif([self.ile_mod_0, self.ile_mod_1], [self.ile_rule_0, self.ile_rule_1]) self.hh_mod_0 = Module("NNNNUNNNNN", "(((((.((((") self.hh_mod_1 = Module("NNNNCUGANGAGNNN", ")))).......((((") self.hh_mod_2 = Module("NNNCGAAANNNN", "))))...)))))") self.hh_rule_0 = Rule(0, 0, 2, 11, 5) self.hh_rule_1 = Rule(0, 6, 1, 3, 4) self.hh_rule_2 = Rule(1, 11, 2, 3, 4) self.hh = Motif([self.hh_mod_0, self.hh_mod_1, self.hh_mod_2], [self.hh_rule_0, self.hh_rule_1, self.hh_rule_2]) self.simple_0 = Module("CCCCC", "(((..") self.simple_1 = Module("GGGGG", "..)))") self.simple_r = Rule(0, 0, 1, 4, 3) self.simple = Motif([self.simple_0, self.simple_1], [self.simple_r])
def test_refresh_specific_position(self): """Should always find the module in the same position if specified""" first_module = Module('AAAAA', '(((((') second_module = Module('UUUUU', ')))))') rule_1 = Rule(0, 0, 1, 4, 5) helix = Motif([first_module, second_module], [rule_1]) model = SequenceModel(constants=[ConstantRegion('AAAAA'), \ ConstantRegion('UUUUU')], order='C0 - C1', \ composition=BaseFrequency('A')) embedder = SequenceEmbedder(length=30, num_to_do=100, \ motif=helix, model=model, composition=BaseFrequency('CG'), \ positions=[3, 6]) last = '' for i in range(100): embedder.refresh() curr = str(embedder) self.assertEqual(curr[3:8], 'AAAAA') self.assertEqual(curr[11:16], 'UUUUU') self.assertEqual(curr.count('A'), 5) self.assertEqual(curr.count('U'), 5) self.assertNotEqual(last, curr) last = curr
def setUp(self): """Defines a few standard motifs""" self.ile_mod_0 = Module('NNNCUACNNNNN', '(((((..(((((') self.ile_mod_1 = Module('NNNNNUAUUGGGGNNN', ')))))......)))))') self.ile_rule_0 = Rule(0, 0, 1, 15, 3) self.ile_rule_1 = Rule(0, 7, 1, 4, 5) self.ile = Motif([self.ile_mod_0, self.ile_mod_1], \ [self.ile_rule_0, self.ile_rule_1]) self.hh_mod_0 = Module('NNNNUNNNNN', '(((((.((((') self.hh_mod_1 = Module('NNNNCUGANGAGNNN', ')))).......((((') self.hh_mod_2 = Module('NNNCGAAANNNN', '))))...)))))') self.hh_rule_0 = Rule(0, 0, 2, 11, 5) self.hh_rule_1 = Rule(0, 6, 1, 3, 4) self.hh_rule_2 = Rule(1, 11, 2, 3, 4) self.hh = Motif([self.hh_mod_0, self.hh_mod_1, self.hh_mod_2], \ [self.hh_rule_0, self.hh_rule_1, self.hh_rule_2]) self.simple_0 = Module('CCCCC', '(((..') self.simple_1 = Module('GGGGG', '..)))') self.simple_r = Rule(0, 0, 1, 4, 3) self.simple = Motif([self.simple_0, self.simple_1], [self.simple_r])
class MotifTests(TestCase): """Tests of the Motif object, which has a set of Modules and Rules.""" def setUp(self): """Defines a few standard motifs""" self.ile_mod_0 = Module('NNNCUACNNNNN', '(((((..(((((') self.ile_mod_1 = Module('NNNNNUAUUGGGGNNN', ')))))......)))))') self.ile_rule_0 = Rule(0, 0, 1, 15, 3) self.ile_rule_1 = Rule(0, 7, 1, 4, 5) self.ile = Motif([self.ile_mod_0, self.ile_mod_1], \ [self.ile_rule_0, self.ile_rule_1]) self.hh_mod_0 = Module('NNNNUNNNNN', '(((((.((((') self.hh_mod_1 = Module('NNNNCUGANGAGNNN', ')))).......((((') self.hh_mod_2 = Module('NNNCGAAANNNN', '))))...)))))') self.hh_rule_0 = Rule(0, 0, 2, 11, 5) self.hh_rule_1 = Rule(0, 6, 1, 3, 4) self.hh_rule_2 = Rule(1, 11, 2, 3, 4) self.hh = Motif([self.hh_mod_0, self.hh_mod_1, self.hh_mod_2], \ [self.hh_rule_0, self.hh_rule_1, self.hh_rule_2]) self.simple_0 = Module('CCCCC', '(((..') self.simple_1 = Module('GGGGG', '..)))') self.simple_r = Rule(0, 0, 1, 4, 3) self.simple = Motif([self.simple_0, self.simple_1], [self.simple_r]) def test_init_bad_rule_lengths(self): """Motif init should fail if rules don't match module lengths""" bad_rule = Rule(0, 0, 1, 8, 6) self.assertRaises(ValueError, Motif, [self.simple_0, self.simple_1], \ [bad_rule]) def test_init_conflicting_rules(self): """Motif init should fail if rules overlap""" interferer = Rule(0, 2, 2, 20, 4) self.assertRaises(ValueError, Motif, [self.ile_mod_0, self.ile_mod_1, \ self.ile_mod_0], [self.ile_rule_0, interferer]) def test_matches_simple(self): """Test of simple match should work correctly""" index = '01234567890123456789012345678901' seq = 'AAACCCCCUUUGGGGGAAACCCCCUUUGGGGG' struct = ViennaStructure('((..((..))....))...(((.......)))') struct_2 = ViennaStructure('((((((..((())))))))).....(((.)))') #substring right, not pair self.assertEqual(self.simple.matches(seq, struct, [19, 27]), True) self.assertEqual(self.simple.matches(seq, struct_2, [19,27]), False) for first_pos in range(len(seq) - len(self.simple_0) + 1): for second_pos in range(len(seq) - len(self.simple_1) + 1): #should match struct only at one location match=self.simple.matches(seq, struct, [first_pos, second_pos]) if (first_pos == 19) and (second_pos == 27): self.assertEqual(match, True) else: self.assertEqual(match, False) #should never match in struct_2 self.assertEqual(self.simple.matches(seq, struct_2, \ [first_pos, second_pos]), False) #check that it doesn't fail if there are _two_ matches index = '01234567890123456789' seq = 'CCCCCGGGGGCCCCCGGGGG' struct = '(((....)))(((....)))' struct = ViennaStructure(struct) self.assertEqual(self.simple.matches(seq, struct, [0, 5]), True) self.assertEqual(self.simple.matches(seq, struct, [10,15]), True) #not allowed to cross-pair self.assertEqual(self.simple.matches(seq, struct, [0, 15]), False) def test_matches_ile(self): """Test of isoleucine match should work correctly""" index = '012345678901234567890123456789012345' seq_good = 'AAACCCCUACUUUUUCCCAAAAAUAUUGGGGGGGAA' seq_bad = 'AAACCCCUACUUUUUCCCAAAAAUAUUGGGCGGGAA' st_good = '...(((((..(((((...)))))......)))))..' st_bad = '((((((((..(((((...)))))...))))))))..' st_good = ViennaStructure(st_good) st_bad = ViennaStructure(st_bad) for first_pos in range(len(seq_good) - len(self.ile_mod_0) + 1): for second_pos in range(len(seq_good) - len(self.ile_mod_1) + 1): #seq_good and struct_good should match at one location match=self.ile.matches(seq_good,st_good,[first_pos,second_pos]) if (first_pos == 3) and (second_pos == 18): self.assertEqual(match, True) else: self.assertEqual(match, False) self.assertEqual(self.ile.matches(seq_good, st_bad, \ [first_pos, second_pos]), False) self.assertEqual(self.ile.matches(seq_bad, st_good, \ [first_pos, second_pos]), False) self.assertEqual(self.ile.matches(seq_bad, st_bad, \ [first_pos, second_pos]), False) def test_matches_hh(self): """Test of hammerhead match should work correctly""" index = '0123456789012345678901234567890123456' seq_good = 'CCCCUAGGGGCCCCCUGAAGAGAAAUUUCGAAAGGGG' seq_bad ='CCCCCAGGGGCCCCCUGAAGAGAAAUUUCGAAGGGGG' structure ='(((((.(((()))).......(((())))...)))))' struct = ViennaStructure(structure) self.assertEqual(self.hh.matches(seq_good, struct, [0, 10, 25]), True) self.assertEqual(self.hh.matches(seq_bad, struct, [0, 10, 25]), False) def test_structureMatches_hh(self): """Test of hammerhead structureMatch should work correctly""" index = '0123456789012345678901234567890123456' seq_good = 'CCCCUAGGGGCCCCCUGAAGAGAAAUUUCGAAAGGGG' seq_bad ='CCCCCAGGGGCCCCCUGAAGAGAAAUUUCGAAGGGGG' structure ='(((((.(((()))).......(((())))...)))))' struct = ViennaStructure(structure) self.assertEqual(self.hh.structureMatches(struct, [0, 10, 25]), True) self.assertEqual(self.hh.structureMatches(struct, [0, 10, 25]), True)