Пример #1
0
def check_spelling(checked_word, dist, word_list):
    '''
    Iterates through word_list and returns the set of all words that are within 
    edit distance dist of the string checked_word.
    '''
    # Set constants 
    ALPHABET = set(list(string.ascii_lowercase))
    DIAG_SCORE = 2
    OFF_DIAG_SCORE = 1
    DASH_SCORE = 0
    # contruct scoring matrix over all lower case letters
    scoring_matrix = student.build_scoring_matrix(ALPHABET, DIAG_SCORE, OFF_DIAG_SCORE, DASH_SCORE)
    # Init list to store words
    close_words = []
    # Loop over word in word_list
    for word in word_list:
        # compute alignment matrix
        alignment_matrix = student.compute_alignment_matrix(checked_word, word, scoring_matrix, True)
        # compute score of global alignments
        score, align_x, align_y = student.compute_global_alignment(checked_word, word, scoring_matrix, alignment_matrix)
        # calculate edit distance
        edit_distance = len(checked_word) + len(word) - score
        # Compare edit_distance and dist
        if edit_distance <= dist:
            # save word
            close_words.append(word)
    return close_words
Пример #2
0
def answer_Q7():
    alphabet = set(['A', 'C', 'T', 'G'])
    diag_score = 2
    off_diag_score = 1
    dash_score = 0
    
    seq_x = 'AA' 
    seq_y = 'TAAT'
    
    scoring_matrix = student.build_scoring_matrix(alphabet, diag_score, off_diag_score, dash_score)
    alignment_matrix = student.compute_alignment_matrix(seq_x, seq_y, scoring_matrix, True)
    
    score, align_x, align_y = student.compute_global_alignment(seq_x, seq_y, scoring_matrix, alignment_matrix)
    
    edit_distance = len(seq_x) + len(seq_y) - score
    
    return (diag_score, off_diag_score, dash_score)
"""
Algorithmic Thinking - Module 4 Project
Mark Hess
Dynamic Programming and Sequence Alignment
Computing Alginments of sequences
Test File
"""
import Project_4

TEST1 = True
TEST2 = True
TEST3 = False
TEST4 = False

if TEST1:
	print (Project_4.build_scoring_matrix(set(['A', 'C', 'T', 'G']), 6, 2, -4))
	#expected {'A': {'A': 6, 'C': 2, '-': -4, 'T': 2, 'G': 2}, 'C': {'A': 2, 'C': 6, '-': -4, 'T': 2, 'G': 2},
	#'-': {'A': -4, 'C': -4, '-': -4, 'T': -4, 'G': -4}, 'T': {'A': 2, 'C': 2, '-': -4, 'T': 6, 'G': 2},
	#'G': {'A': 2, 'C': 2, '-': -4, 'T': 2, 'G': 6}}

if TEST2:
	print (Project_4.compute_alignment_matrix('', '', {'A': {'A': 6, 'C': 2, '-': -4, 'T': 2, 'G': 2},
		'C': {'A': 2, 'C': 6, '-': -4, 'T': 2, 'G': 2}, '-': {'A': -4, 'C': -4, '-': -4, 'T': -4, 'G': -4},
		'T': {'A': 2, 'C': 2, '-': -4, 'T': 6, 'G': 2}, 'G': {'A': 2, 'C': 2, '-': -4, 'T': 2, 'G': 6}}, True))
	#expected [[0]] but received []
	print (Project_4.compute_alignment_matrix('A', 'A', {'A': {'A': 6, 'C': 2, '-': -4, 'T': 2, 'G': 2},
		'C': {'A': 2, 'C': 6, '-': -4, 'T': 2, 'G': 2}, '-': {'A': -4, 'C': -4, '-': -4, 'T': -4, 'G': -4},
		'T': {'A': 2, 'C': 2, '-': -4, 'T': 6, 'G': 2}, 'G': {'A': 2, 'C': 2, '-': -4, 'T': 2, 'G': 6}}, True))
	#expected [[0, -4], [-4, 6]]
	print (Project_4.compute_alignment_matrix('ATG', 'ACG', {'A': {'A': 6, 'C': 2, '-': -4, 'T': 2, 'G': 2},
		'C': {'A': 2, 'C': 6, '-': -4, 'T': 2, 'G': 2}, '-': {'A': -4, 'C': -4, '-': -4, 'T': -4, 'G': -4},
Пример #4
0
Algorithmic Thinking - Module 4 Project
Mark Hess

Dynamic Programming and Sequence Alignment
Computing Alginments of sequences
Test File
"""
import Project_4

TEST1 = False
TEST2 = False
TEST3 = True
TEST4 = True

if TEST1:
	print Project_4.build_scoring_matrix(set(['A', 'C', 'T', 'G']), 6, 2, -4) 
	#expected {'A': {'A': 6, 'C': 2, '-': -4, 'T': 2, 'G': 2}, 'C': {'A': 2, 'C': 6, '-': -4, 'T': 2, 'G': 2}, 
	#'-': {'A': -4, 'C': -4, '-': -4, 'T': -4, 'G': -4}, 'T': {'A': 2, 'C': 2, '-': -4, 'T': 6, 'G': 2}, 
	#'G': {'A': 2, 'C': 2, '-': -4, 'T': 2, 'G': 6}}

if TEST2:
	print Project_4.compute_alignment_matrix('', '', {'A': {'A': 6, 'C': 2, '-': -4, 'T': 2, 'G': 2}, 
		'C': {'A': 2, 'C': 6, '-': -4, 'T': 2, 'G': 2}, '-': {'A': -4, 'C': -4, '-': -4, 'T': -4, 'G': -4}, 
		'T': {'A': 2, 'C': 2, '-': -4, 'T': 6, 'G': 2}, 'G': {'A': 2, 'C': 2, '-': -4, 'T': 2, 'G': 6}}, True)
	#expected [[0]] but received []
	print Project_4.compute_alignment_matrix('A', 'A', {'A': {'A': 6, 'C': 2, '-': -4, 'T': 2, 'G': 2}, 
		'C': {'A': 2, 'C': 6, '-': -4, 'T': 2, 'G': 2}, '-': {'A': -4, 'C': -4, '-': -4, 'T': -4, 'G': -4}, 
		'T': {'A': 2, 'C': 2, '-': -4, 'T': 6, 'G': 2}, 'G': {'A': 2, 'C': 2, '-': -4, 'T': 2, 'G': 6}}, True)
	#expected [[0, -4], [-4, 6]]
	print Project_4.compute_alignment_matrix('ATG', 'ACG', {'A': {'A': 6, 'C': 2, '-': -4, 'T': 2, 'G': 2}, 
		'C': {'A': 2, 'C': 6, '-': -4, 'T': 2, 'G': 2}, '-': {'A': -4, 'C': -4, '-': -4, 'T': -4, 'G': -4},