Exemplo n.º 1
0
 def test_make_trans(self):
     """make_trans should return trans table mapping chars to default"""
     a = make_trans()
     self.assertEqual('abc123'.translate(a), 'abc123')
     a = make_trans('a', 'x')
     self.assertEqual('abc123'.translate(a), 'xbc123')
     a = make_trans('ac', 'xa')
     self.assertEqual('abc123'.translate(a), 'xba123')
     a = make_trans('ac', 'xa', '.')
     self.assertEqual('abc123'.translate(a), 'x.a...')
     self.assertRaises(ValueError, make_trans, 'ac', 'xa', 'av')
Exemplo n.º 2
0
        """
        mismatches = 0
        if pairs is None:
            try:
                pairs = sequence.Alphabet.Pairs
            except AttributeError:
                pairs = sequence.Pairs
            
        for up, down in self.directed():
            curr = (sequence[up], sequence[down])
            if curr not in pairs:
                mismatches += 1
        return mismatches
    
        
wuss_to_vienna_table = make_trans('<([{>)]} ', '(((()))) ', '.')

def wuss_to_vienna(data):
    """Converts WUSS format string to Vienna format.

    Any pseudoknots or unrecognized chars will convert to unpaired bases.
    Spaces will be preserved.
    """
    return ViennaStructure(data.translate(wuss_to_vienna_table))


class StructureString(str):
    """Base class for ViennaStructure and WussStructure. Immutable.
    
    StructureString holds a structure and a energy. By default energy is 
    set to None.