예제 #1
0
    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'))
예제 #2
0
    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
예제 #3
0
 def test_len(self):
     """Module len should work if seq and struct same length"""
     m = Module('CUAG', '....')
     self.assertEqual(len(m), 4)
     m = Module('', '')
     self.assertEqual(len(m), 0)
     m.Sequence = 'AUCGAUCGA'
     self.assertRaises(ValueError, m.__len__)
예제 #4
0
 def test_len(self):
     """Module len should work if seq and struct same length"""
     m = Module("CUAG", "....")
     self.assertEqual(len(m), 4)
     m = Module("", "")
     self.assertEqual(len(m), 0)
     m.Sequence = "AUCGAUCGA"
     self.assertRaises(ValueError, m.__len__)
예제 #5
0
    def test_matches(self):
        """Module matches should return correct result for seq/struct match"""
        empty = Module('', '')
        short_p = Module('AC', '((')
        short_u = Module('UU', '..')
        short_up = Module('UU', '((')
        long_all = Module('GGGACGGUUGGUUGGUU', ')))((..((....((((') #struct+seq
        long_seq = Module('GGGACGGUUGGUU', ')))))))))))))') #seq but not struct
        long_struct = Module('GGGGGGGGGGGGG', ')))((..((....') #struct, not seq
        long_none = Module('GGGGGGGGGGGGG', ')))))))))))))') #not struct or seq

        #test overall matching
        for matcher in [empty, short_p, short_u, short_up]:
            self.assertEqual(matcher.matches(long_all), True)
            for longer in [long_seq, long_struct, long_none]:
                if matcher is empty:
                    self.assertEqual(matcher.matches(longer), True)
                else:
                    self.assertEqual(matcher.matches(longer), False)
        #test specific positions
        positions = {3:short_p, 11:short_u, 7:short_up, 15:short_up}
        for module in [short_p, short_u, short_up]:
            for i in range(len(long_all)):
                result = module.matches(long_all, i)
                if positions.get(i, None) is module:
                    self.assertEqual(result, True)
                else:
                    self.assertEqual(result, False)
예제 #6
0
    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
예제 #7
0
 def test_init_good(self):
     """Module init should work if seq and struct same length"""
     m = Module('U', '.')
     self.assertEqual(m.Sequence, 'U')
     self.assertEqual(m.Structure, '.')
     m.Sequence = ''
     m.Structure = ''
     self.assertEqual(m.Sequence, '')
     self.assertEqual(m.Structure, '')
     m.Sequence = 'CCUAGG'
     m.Structure = '((..))'
     self.assertEqual(m.Sequence, 'CCUAGG')
     self.assertEqual(m.Structure, '((..))')
     m.Structure = ''
     self.assertRaises(ValueError, m.__len__)
예제 #8
0
 def test_init_good(self):
     """Module init should work if seq and struct same length"""
     m = Module("U", ".")
     self.assertEqual(m.Sequence, "U")
     self.assertEqual(m.Structure, ".")
     m.Sequence = ""
     m.Structure = ""
     self.assertEqual(m.Sequence, "")
     self.assertEqual(m.Structure, "")
     m.Sequence = "CCUAGG"
     m.Structure = "((..))"
     self.assertEqual(m.Sequence, "CCUAGG")
     self.assertEqual(m.Structure, "((..))")
     m.Structure = ""
     self.assertRaises(ValueError, m.__len__)
예제 #9
0
 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])
예제 #10
0
 def test_str(self):
    """Module str should contain sequence and structure"""
    m = Module('CUAG', '....')
    self.assertEqual(str(m), 'Sequence:  CUAG\nStructure: ....')
    m = Module('', '')
    self.assertEqual(str(m), 'Sequence:  \nStructure: ')