Beispiel #1
0
def test_popcnt():
    x = 466311136197825
    y = x
    c = 0
    while y > 0:
        c += y & 1
        y >>= 1
    j = bits.popcnt(x)
    assert c == j
Beispiel #2
0
def ham(x, y):
    """
    Compute the Hamming distance between two k-mers `x` and `y`.

    Although *k* is not a parameter, *k*-mers longer than 30bp are not
    guaranteed to produce correct results.
    """
    z = x ^ y
    # NB: if k > 32, the constant below will need extending.
    v = (z | (z >> 1)) & m1
    return popcnt(v)
Beispiel #3
0
 def grp(itms):
     z = len(itms)
     u = unionfind()
     for i in xrange(z):
         for j in xrange(i + 1, z):
             d0 = lev(K, itms[i], itms[j])
             if d0 <= d:
                 u.union(i, j)
     idx = {}
     for i in xrange(z):
         j = u.find(i)
         if j not in idx:
             idx[j] = []
         idx[j].append(i)
     for ys in idx.itervalues():
         if len(ys) == 1:
             continue
         zs = [itms[y] for y in ys]
         m = 0
         for z in zs:
             m |= 1 << ((z >> T) & 3)
         if popcnt(m) == 1:
             continue
         yield zs
Beispiel #4
0
def ham(x, y):
    "Compute the hamming distance between two k-mers."
    z = x ^ y
    # NB: if k > 32, the constant below will need extending.
    v = (z | (z >> 1)) & m1
    return popcnt(v)