示例#1
0
def construct_alignment(l, c, trace, s1, s2, op):
    current = (l, c)
    path = ["", ""]
    deletedpath = False
    while current != (0, 0):
        all_previous = trace[current]
        previous = all_previous[0]
        direction = all_previous[0][1]
        if len(all_previous) > 1:
            op += 1
            if not deletedpath:
                del trace[current][0]
                deletedpath = True
        if direction == "diag":
            path[0] += s1[current[1] - 1]
            path[1] += s2[current[0] - 1]
        elif direction == "down":
            path[0] += "-"
            path[1] += s2[current[0] - 1]
        elif direction == "right":
            path[0] += s1[current[1] - 1]
            path[1] += "-"
        else:
            #free taxi ride
            pass
        current = previous[0]

    distance = hamming_d(path[0], path[1])
    return [path[0][::-1], path[1][::-1], distance], op
示例#2
0
def construct_alignment(l, c, trace, s1, s2, op):
    current = (l, c)
    path = ["", ""]
    deletedpath = False
    while current != (0, 0):
        all_previous = trace[current]
        previous = all_previous[0]
        direction = all_previous[0][1]
        if len(all_previous) > 1:
            op += 1
            if not deletedpath:
                del trace[current][0]
                deletedpath = True
        if direction == "diag":
            path[0] += s1[current[1] - 1]
            path[1] += s2[current[0] - 1]
        elif direction == "down":
            path[0] += "-"
            path[1] += s2[current[0] - 1]
        elif direction == "right":
            path[0] += s1[current[1] - 1]
            path[1] += "-"
        else:
            #free taxi ride
            pass
        current = previous[0]

    distance = hamming_d(path[0], path[1])
    return [path[0][::-1], path[1][::-1], distance], op
示例#3
0
def distance(pattern, dna):
    k = len(pattern)
    d = 0
    for s in dna:
        hd = k
        for i in range(len(s) - k):
            p = s[i:i + k]
            nhd = hamming_d(pattern, p)
            if nhd < hd:
                hd = nhd
        d += hd
    return d
示例#4
0
def distance(pattern, dna):
    k = len(pattern)
    d = 0
    for s in dna:
        hd = k
        for i in range(len(s) - k):
            p = s[i:i + k]
            nhd = hamming_d(pattern, p)
            if nhd < hd:
                hd = nhd
        d += hd
    return d
示例#5
0
def construct_alignment_all(start, trace, s1, s2, op, choice_track, retrack):
    should_retrack = False
    if len(choice_track) > 0:
        path = choice_track[-1][0]
        current = choice_track[-1][1]
        retrack.append((current, trace[(current, 0)][0]))
        del trace[(current, 0)][0]
        if len(trace[current]) == 1:
            del choice_track[-1]
            should_retrack = True
    else:
        current = start
        path = ["", ""]
    while current[0] != (0, 0):
        all_previous = trace[current]
        previous = all_previous[0]
        # direction = all_previous[0][1]
        atual = current[1]
        if len(all_previous) > 1:
            op += 1
            choice_track.append([path[:], current])
        #middle matrix is diagonal
        if atual == 0:
            path[0] += s1[current[0][1] - 1]
            path[1] += s2[current[0][0] - 1]
        #lower matrix is down
        elif atual == -1:
            path[0] += "-"
            path[1] += s2[current[0][0] - 1]
        #upper matrix is right
        elif atual == 1:
            path[0] += s1[current[0][1] - 1]
            path[1] += "-"
        else:
            #free taxi ride
            pass
        current = previous
    if should_retrack:
        for r in retrack[:]:
            trace.setdefault(r[0], []).append(r[1])
            retrack.remove(r)
    distance = hamming_d(path[0], path[1])
    return [path[0][::-1], path[1][::-1], distance], op
示例#6
0
def construct_alignment_all(start, trace, s1, s2, op, choice_track, retrack):
    should_retrack = False
    if len(choice_track) > 0:
        path = choice_track[-1][0]
        current = choice_track[-1][1]
        retrack.append((current, trace[(current, 0)][0]))
        del trace[(current, 0)][0]
        if len(trace[current]) == 1:
            del choice_track[-1]
            should_retrack = True
    else:
        current = start
        path = ["", ""]
    while current[0] != (0, 0):
        all_previous = trace[current]
        previous = all_previous[0]
        # direction = all_previous[0][1]
        atual = current[1]
        if len(all_previous) > 1:
            op += 1
            choice_track.append([path[:], current])
        #middle matrix is diagonal
        if atual == 0:
            path[0] += s1[current[0][1] - 1]
            path[1] += s2[current[0][0] - 1]
        #lower matrix is down
        elif atual == -1:
            path[0] += "-"
            path[1] += s2[current[0][0] - 1]
        #upper matrix is right
        elif atual == 1:
            path[0] += s1[current[0][1] - 1]
            path[1] += "-"
        else:
            #free taxi ride
            pass
        current = previous
    if should_retrack:
        for r in retrack[:]:
            trace.setdefault(r[0], []).append(r[1])
            retrack.remove(r)
    distance = hamming_d(path[0], path[1])
    return [path[0][::-1], path[1][::-1], distance], op
示例#7
0
def construct_alignment_all(l, c, trace, s1, s2, op, choice_track, retrack):
    should_retrack = False
    if len(choice_track) > 0:
        path = choice_track[-1][0]
        current = choice_track[-1][1]
        retrack.append((current, trace[current][0]))
        del trace[current][0]
        if len(trace[current]) == 1:
            del choice_track[-1]
            should_retrack = True
    else:
        current = (l, c)
        path = ["", ""]
    while current != (0, 0):
        all_previous = trace[current]
        previous = all_previous[0]
        direction = all_previous[0][1]
        if len(all_previous) > 1:
            op += 1
            choice_track.append([path[:], current])
        if direction == "diag":
            path[0] += s1[current[1] - 1]
            path[1] += s2[current[0] - 1]
        elif direction == "down":
            path[0] += "-"
            path[1] += s2[current[0] - 1]
        elif direction == "right":
            path[0] += s1[current[1] - 1]
            path[1] += "-"
        else:
            #free taxi ride
            pass
        current = previous[0]
    if should_retrack:
        for r in retrack[:]:
            trace.setdefault(r[0], []).append(r[1])
            retrack.remove(r)
    distance = hamming_d(path[0], path[1])
    return [path[0][::-1], path[1][::-1], distance], op
示例#8
0
def construct_alignment_all(l, c, trace, s1, s2, op, choice_track, retrack):
    should_retrack = False
    if len(choice_track) > 0:
        path = choice_track[-1][0]
        current = choice_track[-1][1]
        retrack.append((current, trace[current][0]))
        del trace[current][0]
        if len(trace[current]) == 1:
            del choice_track[-1]
            should_retrack = True
    else:
        current = (l, c)
        path = ["", ""]
    while current != (0, 0):
        all_previous = trace[current]
        previous = all_previous[0]
        direction = all_previous[0][1]
        if len(all_previous) > 1:
            op += 1
            choice_track.append([path[:], current])
        if direction == "diag":
            path[0] += s1[current[1] - 1]
            path[1] += s2[current[0] - 1]
        elif direction == "down":
            path[0] += "-"
            path[1] += s2[current[0] - 1]
        elif direction == "right":
            path[0] += s1[current[1] - 1]
            path[1] += "-"
        else:
            #free taxi ride
            pass
        current = previous[0]
    if should_retrack:
        for r in retrack[:]:
            trace.setdefault(r[0], []).append(r[1])
            retrack.remove(r)
    distance = hamming_d(path[0], path[1])
    return [path[0][::-1], path[1][::-1], distance], op
示例#9
0
def score_real_motif(mots, cons):
    count = 0.0
    for m in mots:
        count += hamming_d(m, cons)
    return count
示例#10
0
def score_real_motif(mots, cons):
    count = 0.0
    for m in mots:
        count += hamming_d(m, cons)
    return count