def test_sequences_blosum(): scores = read_substitution_matrix( Path(__file__).parent / "rsrc" / "substitution.txt") substitution = alignment.make_substitution_fn(scores) s1 = "AGACTAGTTAC" s2 = "CGAGACGT" value, scores, paths = alignment.needleman_wunsch( s1, s2, substitution=substitution) algn, s1a1, s2a1 = alignment.best_alignment(paths, s1, s2, gap='-') algn_sol1 = [list('--AGACTAGTTAC'), list('CGAGAC--G-T--')] assert s1a1 == algn_sol1[0] assert s2a1 == algn_sol1[1]
def test_substitution_function(): scores = read_substitution_matrix( Path(__file__).parent / "rsrc" / "substitution.txt") substitution = alignment.make_substitution_fn(scores, gap=0.5) assert substitution('A', 'B') == (1, 0.5) assert substitution('A', 'A') == (-20.0, 0.5) assert substitution('A', 'C') == (3.0, 0.5) # test just changing gap function substitution2 = alignment.make_substitution_fn({}, gap=0.5) assert substitution2('A', 'A') == (-1, 0.5) assert substitution2('G', 'C') == (1, 0.5) assert alignment._default_substitution_fn('A', 'A') == (-1, 1) assert alignment._default_substitution_fn('G', 'C') == (1, 1)
def test_sequences_custom(): scores = read_substitution_matrix( Path(__file__).parent / "rsrc" / "substitution.txt") substitution = alignment.make_substitution_fn(scores) s1 = "CCAGG" s2 = "CCGA" value, scores, paths = alignment.needleman_wunsch(s1, s2) algn, s1a1, s2a1 = alignment.best_alignment(paths, s1, s2, gap='-') algn_sol1 = [list("CCAGG"), list("CC-GA")] assert value == 1 assert s1a1 == algn_sol1[0] assert s2a1 == algn_sol1[1] value, scores, paths = alignment.needleman_wunsch( s1, s2, substitution=substitution) algn, s1a2, s2a2 = alignment.best_alignment(paths, s1, s2, gap='-') algn_sol2 = [list("CC-AGG"), list("CCGA--")] assert s1a2 == algn_sol2[0] assert s2a2 == algn_sol2[1]