コード例 #1
0
def traceback(sequence1, sequence2):
    alignments = []
    alignmentA = ""
    alignmentB = ""
    i = len(sequence2) - 1
    j = len(sequence1) - 1

    max_number = max_number_semiglobal()

    try:
        j = global_alignment.matrix[len(global_alignment.matrix) -
                                    1].index(max_number)
        i = len(global_alignment.matrix) - 1
    except:
        j = len(global_alignment.matrix[0]) - 1
        i = 0
        while True:
            if (global_alignment.matrix[i][j] == max_number):
                break
            i += 1

    while (i > 0 or j > 0):
        if (i > 0 and j > 0 and global_alignment.matrix[i][j]
                == global_alignment.matrix[i - 1][j - 1] +
                global_alignment.getScore(sequence1, sequence2, i, j)):
            alignmentA = sequence1[j] + alignmentA
            alignmentB = sequence2[i] + alignmentB
            global_alignment.matrix[i][j] = 'D' + str(
                global_alignment.matrix[i][j])

            i = i - 1
            j = j - 1
        elif ((i > 0 and global_alignment.matrix[i][j]
               == global_alignment.matrix[i - 1][j] + global_alignment.GAP)
              or j == 0):
            alignmentA = "--" + alignmentA
            alignmentB = sequence2[i] + alignmentB
            global_alignment.matrix[i][j] = "A" + str(
                global_alignment.matrix[i][j])

            i = i - 1
        elif ((j > 0 and global_alignment.matrix[i][j]
               == global_alignment.matrix[i][j - 1] + global_alignment.GAP)
              or i == 0):
            alignmentA = sequence1[j] + alignmentA
            alignmentB = "--" + alignmentB
            global_alignment.matrix[i][j] = "I" + str(
                global_alignment.matrix[i][j])

            j = j - 1

    alignments.append(alignmentA)
    alignments.append(alignmentB)
    global_alignment.add_sequences(sequence1, sequence2)
    return alignments
コード例 #2
0
def fill_matrix(sequence1, sequence2):
     sequence1 = global_alignment.insert_gap(sequence1, 0)
     sequence2 = global_alignment.insert_gap(sequence2, 0)
 
    #  print(sequence1)
    #  print(sequence2)
 
     num_rows = len(global_alignment.matrix)
     for i in range(1,num_rows):
         num_cols = len(global_alignment.matrix[i])
         for j in range(1, num_cols):
             up = global_alignment.matrix[i-1][j] + global_alignment.GAP
             left = global_alignment.matrix[i][j-1] + global_alignment.GAP
             diagonal = global_alignment.matrix[i-1][j-1] + global_alignment.getScore(sequence1, sequence2, i, j)
 
             global_alignment.matrix[i][j] = max(up, left, diagonal, 0)
コード例 #3
0
def fill_matrix(sequence1, sequence2):
    sequence1 = global_alignment.insert_gap(sequence1, 0)
    sequence2 = global_alignment.insert_gap(sequence2, 0)

    num_rows = len(global_alignment.matrix)
    #print("num_rows - " + str(num_rows))
    for i in range(1, num_rows):
        #print("i - " + str(i))
        num_cols = len(global_alignment.matrix[i])
        #     print("num_cols - " + str(num_cols))
        for j in range(1, num_cols):
            #         print("j - " + str(j))
            up = global_alignment.matrix[i - 1][j] + global_alignment.GAP
            #         print("up done")
            left = global_alignment.matrix[i][j - 1] + global_alignment.GAP
            #         print("left done")
            diagonal = global_alignment.matrix[i - 1][
                j - 1] + global_alignment.getScore(sequence1, sequence2, i, j)
            #         print("diagonal done")
            global_alignment.matrix[i][j] = max(up, left, diagonal, 0)
コード例 #4
0
def traceback(sequence1, sequence2):
    alignments = []
    alignmentA = ""
    alignmentB = ""

    argmax = np.where(
        global_alignment.matrix == np.matrix(global_alignment.matrix).max())
    i = argmax[0][0]
    j = argmax[1][0]

    while ((i > 0 or j > 0) and global_alignment.matrix[i][j] != 0):
        if (i > 0 and j > 0 and global_alignment.matrix[i][j]
                == global_alignment.matrix[i - 1][j - 1] +
                global_alignment.getScore(sequence1, sequence2, i, j)):
            alignmentA = sequence1[j] + alignmentA
            alignmentB = sequence2[i] + alignmentB
            global_alignment.matrix[i][j] = 'D' + str(
                global_alignment.matrix[i][j])  #CAMINO
            i = i - 1
            j = j - 1
        elif (i > 0 and global_alignment.matrix[i][j]
              == global_alignment.matrix[i - 1][j] + global_alignment.GAP):
            alignmentA = "--" + alignmentA
            alignmentB = sequence2[i] + alignmentB
            global_alignment.matrix[i][j] = "A" + str(
                global_alignment.matrix[i][j])  #CAMINO
            i = i - 1
        else:
            alignmentA = sequence1[j] + alignmentA
            alignmentB = "--" + alignmentB
            global_alignment.matrix[i][j] = "I" + str(
                global_alignment.matrix[i][j])  #CAMINO
            j = j - 1

    alignments.append(alignmentA)
    alignments.append(alignmentB)

    global_alignment.add_sequences(sequence1, sequence2)
    return alignments