1 '''
2 Created on 2 juil. 2009
3
4 @author: coissac
5 '''
6
7
8
10 i=0
11 while(x):
12 i+=1
13 x&=x-1
14 return i
15
17 '''
18 Iterate thought the list of all DNA word of
19 size `size`.
20
21 @param size: size of the DNA word
22 @type size: int
23
24 @return: an iterator on DNA word (int)
25 @rtype: iterator
26 '''
27
28 maxi=4**size
29 return xrange(maxi)
30
32 '''
33 estimate Hamming distance between two words of the same size.
34
35 @param w1: the first word
36 @type w1: str
37 @param w2: the second word
38 @type w2: str
39
40 @return: the count of difference between the two words
41 @rtype: int
42 '''
43
44 diff = (~(w1 & w2) & (w1 | w2))
45 diff = (diff | (diff >> 1)) & 0x55555555
46 dist = bitCount(diff)
47 return dist
48
50 mask = (1 << (size << 1))-1
51 good = 0x55555555
52 maxi=0
53 shift = word
54 while good:
55 maxi+=1
56 shift>>=2
57 mask>>=2
58 id = (word & shift) | (~word & ~shift)
59 good&= id & (id>>1) & mask
60 return maxi
61
63 mask = (1 << (size << 1))-1
64 id = ~word
65 good= id & (id>>1) & 0x55555555 & mask
66 return bitCount(good)
67
71
77
79 mask = (1 << (size << 1))-1
80 good = ((word & 0x55555555) | (~word & 0xAAAAAAAA))
81 good &= (good >> 1) & 0x55555555 & mask
82 return bitCount(good)
83
85 mask = (1 << (size << 1))-1
86 good = ((word & 0xAAAAAAAA) | (~word & 0x55555555))
87 good &= (good >> 1) & 0x55555555 & mask
88 return bitCount(good)
89
95
96
98 return ''.join(['acgt'[(word >> i) & 3] for i in xrange(size*2-2,-1,-2)])
99