Exemplo n.º 1
0
def app4_q7():
    """
    app4_q7
    """
    seq_x = 'example'
    seq_y = 'sample'
    alphabet = 'abcdefghijklmnopqrstvuwxyz'


    diag_score = 2
    off_diag_score = 1
    dash_score = 0

    scoring_matrix = p4.build_scoring_matrix(alphabet, diag_score, off_diag_score, dash_score)
    # print('Scoring matrix')
    # pprint(scoring_matrix)
    alignment_matrix = p4.compute_alignment_matrix(seq_x, seq_y, scoring_matrix, True)
    # print('Alignment matrix')
    # pprint(alignment_matrix)
    global_alignment = p4.compute_global_alignment(seq_x, seq_y, scoring_matrix, alignment_matrix)
    # print('global_alignment')
    # pprint(global_alignment)

    # print('\n\n')
    score = len(seq_x) + len(seq_y) - global_alignment[0]
    print('edit distance:', score)
Exemplo n.º 2
0
def generate_null_distribution(seq_x, seq_y, scoring_matrix, num_trials):
    """

    :param seq_x:
    :param seq_y:
    :param scoring_matrix:
    :param num_trials:
    """
    scoring_distribution = dict()
    for dummy in range(num_trials):
        new_y = list(seq_y)
        random.shuffle(new_y)
        random_seq_y = "".join(new_y)

        alignment_matrix = p4.compute_alignment_matrix(seq_x, random_seq_y, scoring_matrix, False)
        aligment_max_position = p4.compute_max_position(alignment_matrix)
        
        #local_alignment = p4.compute_local_alignment(seq_x, random_seq_y, scoring_matrix, alignment_matrix)
        score = alignment_matrix[aligment_max_position[0]][aligment_max_position[1]]

        if score not in scoring_distribution.keys():
            scoring_distribution[score] = 1
        else:
            scoring_distribution[score] += 1

    return scoring_distribution
Exemplo n.º 3
0
def hw4_q12():

    seq_x = 'AA'
    seq_y = 'TAAT'

    alphabet = 'ACTG'
    diag_score = 10
    off_diag_score = 4 
    dash_score = -6
    
    scoring_matrix = p4.build_scoring_matrix(alphabet, diag_score, off_diag_score, dash_score)
    alignment_matrix = p4.compute_alignment_matrix(seq_x, seq_y, scoring_matrix, False)
    local_alignment = p4.compute_local_alignment(seq_x, seq_y, scoring_matrix, alignment_matrix)
    pprint(local_alignment)
Exemplo n.º 4
0
def check_spelling(checked_word, dist, word_list):
    """

    :param checked_word:
    :param dist:
    :param word_list:
    """
    diag_score = 2
    off_diag_score = 1
    dash_score = 0
    alphabet = 'abcdefghijklmnopqrstvuwxyz'

    ans = []
    scoring_matrix = p4.build_scoring_matrix(alphabet, diag_score, off_diag_score, dash_score)
    for each_word in word_list:
        alignment_matrix = p4.compute_alignment_matrix(checked_word, each_word, scoring_matrix, True)
        global_alignment = p4.compute_global_alignment(checked_word, each_word, scoring_matrix, alignment_matrix)
        score = len(checked_word) + len(each_word) - global_alignment[0]
        if score == dist:
            ans.append(each_word)
    return ans