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): """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_init(self): """SequenceModel should init OK with Isoleucine motif.""" helices = [PairedRegion('NNN'), PairedRegion('NNNNN')] constants = [ConstantRegion('CUAC'), ConstantRegion('UAUUGGGG')] order = "H0 C0 H1 - H1 C1 H0" isoleucine = SequenceModel(order=order, constants=constants, \ helices=helices) isoleucine.Composition = BaseFrequency('UCAG') #print #print for i in range(10): isoleucine.refresh() #print list(isoleucine) #print isoleucine.Composition = BaseFrequency('UCAG') isoleucine.GU = False #print for i in range(10): isoleucine.refresh()
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 test_init(self): """ConstantRegion should always return current template.""" #test blank region model r = ConstantRegion() self.assertEqual(str(r.Current), '') self.assertEqual(len(r), 0) #now assign it to a template r.Template = ('ACGUUCGA') self.assertEqual(str(r.Current), 'ACGUUCGA') self.assertEqual(len(r), len('ACGUUCGA')) #check that refresh doesn't break anything r.refresh() self.assertEqual(str(r.Current), 'ACGUUCGA') self.assertEqual(len(r), len('ACGUUCGA')) #check composition self.assertEqual(r.Composition, None) d = {'A':3, 'U':10} r.Composition = Freqs(d) self.assertEqual(r.Composition, d) #check that composition doesn't break the update r.refresh() self.assertEqual(str(r.Current), 'ACGUUCGA') self.assertEqual(len(r), len('ACGUUCGA'))