1 from obitools import location
5
7 _comp={'a': 't', 'c': 'g', 'g': 'c', 't': 'a',
8 'r': 'y', 'y': 'r', 'k': 'm', 'm': 'k',
9 's': 's', 'w': 'w', 'b': 'v', 'd': 'h',
10 'h': 'd', 'v': 'b', 'n': 'n', 'u': 'a',
11 '-': '-'}
12
13 _info={'complemented':True}
14
15 @staticmethod
16 - def _encode(seq,position=slice(None, None, -1)):
19
20 @staticmethod
23
24 @staticmethod
26 if isinstance(position, int):
27 return -(position+1)
28 elif isinstance(position, slice):
29 return slice(-(position.stop+1),
30 -(position.start+1),
31 -position.step)
32 elif isinstance(position, location.Location):
33 return location.ComplementLocation(position).simplify()
34
35 raise TypeError,"position must be an int, slice or Location instance"
36
37 @staticmethod
40
47
49 lseq = len(seq)
50 assert self._limits.stop <= lseq
51
52 - def _encode(self,seq,position=None):
53 return str(seq)[self._limits]
54
56 if isinstance(position, int):
57 if position < -self._len or position >= self._len:
58 raise IndexError,position
59 if position >=0:
60 return self._limits.start + position
61 else:
62 return self._limits.stop + position + 1
63 elif isinstance(position, slice):
64 return slice(-(position.stop+1),
65 -(position.start+1),
66 -position.step)
67 elif isinstance(position, location.Location):
68 return location.ComplementLocation(position).simplify()
69
70 raise TypeError,"position must be an int, slice or Location instance"
71