コード例 #1
0
def draw_horizontal_needleman_wunsch_line_diagram(image,
                                                  rounding,
                                                  coordinate_buffer_a,
                                                  coordinate_buffer_b,
                                                  should_copy=False):
    """

    :param image:                   image data to draw on
    :param rounding:                rounding value
    :param coordinate_buffer_a:     coordinates of the first buffer [(x,y)]
    :param coordinate_buffer_b:     coordinates of the second buffer [(x,y)]
    :param should_copy:             Indicates if the image should be copied b4
    :return:                        the updated image, the buffer with needleman wunsch data (dictionary with "kind", "data")
    """

    im = None
    if should_copy:
        im = image.copy()
    else:
        im = image

    buffer_nw_a = []
    buffer_nw_b = []

    rounding_half = rounding / 2

    for i in range(0, len(coordinate_buffer_a)):
        buffer_nw_a.append(
            nw.round_with_offset(rounding_half, rounding,
                                 coordinate_buffer_a[i][0]))

    for i in range(0, len(coordinate_buffer_b)):
        buffer_nw_b.append(
            nw.round_with_offset(rounding_half, rounding,
                                 coordinate_buffer_b[i][0]))

    solution = nw.needleman_wunsch(buffer_nw_a, buffer_nw_b)

    color = (0, 0, 0, 1)

    current_x = solution[0]["data"]
    current_y = 3

    for i in range(0, len(solution)):
        if solution[i]["kind"] == "delete" or solution[i][
                "kind"] == "missmatch":
            continue
        x = solution[i]["data"]
        im = drw.draw_line(im, (current_x, current_y), (x, current_y), color)
        current_x = x
        im = drw.draw_line(im, (current_x, current_y),
                           (current_x, current_y + 3), color)
        current_y += 3

    return im, solution
コード例 #2
0
def draw_vertical_combined_needleman_wunsch_line_diagram(
        image, rounding, buffers, should_copy=False):
    """

    :param image:                   image data to draw on
    :param rounding:                rounding value
    :param buffers:                 a buffer of coordinate lists
    :param should_copy:             Indicates if the image should be copied b4
    :return:                        the updated image data and the solution of the needleman wunsch
    """

    im = None
    if should_copy:
        im = image.copy()
    else:
        im = image

    buffers_needle = []

    rounding_half = rounding / 2

    for i in range(0, len(buffers)):
        tmp_buffer = []
        for j in range(0, len(buffers[i])):
            tmp_buffer.append(
                nw.round_with_offset(rounding_half, rounding,
                                     buffers[i][j][1]))
        buffers_needle.append(tmp_buffer)

    current_solution = buffers_needle[0]
    for i in range(1, len(buffers_needle)):
        sol_buffer = nw.needleman_wunsch(buffers_needle[i], current_solution)
        current_solution = nw.to_usable_buffer(sol_buffer)

    color = (0, 0, 0, 1)

    current_x = 3
    current_y = current_solution[0]

    for i in range(0, len(current_solution)):
        y = current_solution[i]
        im = drw.draw_line(im, (current_x, current_y), (current_x, y), color)
        current_y = y
        im = drw.draw_line(im, (current_x, current_y),
                           (current_x + 3, current_y), color)
        current_x += 3

    return im, current_solution