Пример #1
0
def find_center_string_fast(S):
    # Contains pairwise distances from s to s
    score_matrix = np.full((len(S), len(S)), None)
    # Distances from s to s is 0
    for i in range(len(S)):
        score_matrix[i, i] = 0  
    # Iterate through possible centers, S[i]
    for i in range(len(S)):
        # Score for S[i]
        sum_scores = 0
        # Iterate through all other strings, S[j]
        for j in range(len(S)):
            # If we have NOT already computed the distance from S[i] to S[j], do this
            if(score_matrix[i, j] == None):
                score = pa.calculate_alignment_matrix(sub_matrix, gap_cost, S[i], S[j])[len(S[i]), len(S[j])]
                # Distance from S[i] to S[j] is equal to the distance from S[j] to S[i]
                score_matrix[i, j] = score
                score_matrix[j, i] = score
            sum_scores += score_matrix[i, j] 
    # Calculate total scores for S[i]'s
    total_scores = [sum(score) for score in score_matrix]
    # The min score index
    best_score_index = np.argmin(total_scores)
    # Return string with min score (= center)
    return S[best_score_index]
Пример #2
0
def multiple_align(S, center):
    M = []
    S.remove(center)
    for s in S:
        A_matrix = pa.calculate_alignment_matrix(sub_matrix, gap_cost, center, s)
        # optimal alignment
        A = pa.backtrack_nonrec(A_matrix, center, s, sub_matrix, gap_cost, "", "", len(center), len(s))
        if(s != S[0]):
            M = extend_M_with_A(M, A)
        else:
            M = A
    return M
Пример #3
0
def find_center_string(S):
    print("Finding center string...")
    sum_scores_list = []
    for pos_cen in S: # possible center
        sum_scores = 0
        for s in S:

            sum_scores += pa.calculate_alignment_matrix(sub_matrix, gap_cost, pos_cen, s)[len(pos_cen), len(s)]
        #print("sum_scores: ", sum_scores)
        sum_scores_list.append(sum_scores)
    index_of_min_score = np.argmin(sum_scores_list)
    return S[index_of_min_score]