예제 #1
0
파일: test_pw.py 프로젝트: amirkdv/biseqt
def test_alignment_std_local(err):
    A = Alphabet('ACGT')
    M = MutationProcess(A, subst_probs=err, go_prob=err, ge_prob=err)
    subst_scores, (go_score, ge_score) = M.log_odds_scores()

    S = rand_seq(A, 100)
    T, tx = M.mutate(S)
    T = A.parse('A' * 100) + T + A.parse('G' * 100)
    mutation_aln = Alignment(S, T, tx)
    mutation_score = mutation_aln.calculate_score(subst_scores, go_score,
                                                  ge_score)

    aligner = Aligner(S, T, subst_scores=subst_scores, go_score=go_score,
                      ge_score=ge_score, alnmode=STD_MODE, alntype=LOCAL)
    with aligner:
        reported_score = aligner.solve()
        assert round(reported_score, 3) >= round(mutation_score, 3), \
            'optimal alignment scores better than the known transcript'
        alignment = aligner.traceback()
        aln_score = alignment.calculate_score(subst_scores, go_score, ge_score)
        assert round(aln_score, 3) == round(reported_score, 3), \
            'The alignment score should be calculated correctly'

        ori_len = Alignment.projected_len(alignment.transcript, on='origin')
        mut_len = Alignment.projected_len(alignment.transcript, on='mutant')
        assert ori_len <= len(S) and mut_len < len(T), \
            'Local alignments do not cover the entirety of both sequences'
예제 #2
0
def test_log_odds_scores():
    A = Alphabet('ACGT')
    # linear gap model
    P = MutationProcess(A, subst_probs=.1, ge_prob=.1, go_prob=.1)
    subst_scores, (go_score, ge_score) = P.log_odds_scores()
    assert go_score == 0. and ge_score < 0
    match_pos = [(i, i) for i in range(len(A))]
    mismatch_pos = [(i, j) for i, j in combinations(range(len(A)), 2)]
    assert all(subst_scores[i][j] < 0 for i, j in mismatch_pos)
    assert all(subst_scores[i][j] > 0 for i, j in match_pos)

    # affine gap model
    P = MutationProcess(A, subst_probs=.1, ge_prob=.2, go_prob=.1)
    subst_scores, (go_score, ge_score) = P.log_odds_scores()
    assert ge_score < 0

    # do mismatch scores go down if subst probs are decreased?
    P = MutationProcess(A, subst_probs=.01, ge_prob=.2, go_prob=.1)
    new_subst_scores, _ = P.log_odds_scores()
    assert new_subst_scores[0][1] < subst_scores[0][1], \
        'mismatch scores become more negative with lower mismatch probs'