Exemplo n.º 1
0
def test_needleman_comparison_equal():
    '''
    Tests score comparison of equal alignments
    '''
    seq1 = "GCATGCU"
    seq2 = "GATTACA"
    needle1 = minineedle.NeedlemanWunsch(seq1, seq2)
    needle1.change_matrix(minineedle.ScoreMatrix(1, -1, -1))
    needle1.align()
    needle2 = minineedle.NeedlemanWunsch(seq1, seq2)
    needle2.change_matrix(minineedle.ScoreMatrix(1, -1, -1))
    needle2.align()
    assert (needle1 == needle2)
Exemplo n.º 2
0
def test_needleman_comparison_lower():
    '''
    Tests score comparison of different alignments
    '''
    seq1 = "GCATGCU"
    seq2 = "GATTACA"
    seq3 = "LLLLLLL"
    needle1 = minineedle.NeedlemanWunsch(seq1, seq2)
    needle1.change_matrix(minineedle.ScoreMatrix(1, -1, -1))
    needle1.align()
    needle2 = minineedle.NeedlemanWunsch(seq1, seq3)
    needle2.change_matrix(minineedle.ScoreMatrix(1, -1, -1))
    needle2.align()
    assert (needle1 > needle2)
Exemplo n.º 3
0
def nwalign_and_compute_nw_score_naive(line_numbers_model, line_numbers_gaze):
    if not line_numbers_model:
        return 0

    model = transform_line_order_to_sequence(line_numbers_model)
    gaze = transform_line_order_to_sequence(line_numbers_gaze)

    seq_model = ms.Sequence('Model', model)
    seq_gaze = ms.Sequence('Actual', gaze)

    alignment = minineedle.NeedlemanWunsch(seq_model, seq_gaze)
    alignment.change_matrix(minineedle.ScoreMatrix(match=3, miss=-3, gap=-2))

    try:
        alignment.align()
        #print(alignment)

        score = alignment.get_score()
        #print('score: ', str(score))
    except ZeroDivisionError as e:
        print('ZeroDivisionError when comparing the following numbers')
        print('repeated ', line_numbers_model)
        print('gaze     ', line_numbers_gaze)

        score = 0

    return score
Exemplo n.º 4
0
def test_strange_alignment():
    seq1 = "TG--TA--CTA"
    seq2 = "GG--TGA--CTA"
    needle = minineedle.NeedlemanWunsch(seq1, seq2)
    needle.change_matrix(minineedle.ScoreMatrix(2, -2, -3))
    needle.align()
    needle.gap_character = "+"
    assert (needle.get_aligned_sequences("str")[0] == "TG--T+A--CTA")
Exemplo n.º 5
0
def test_needleman_get_aligned_sequences_string():
    seq1 = "GCATGCU"
    seq2 = "GATTACA"
    needle = minineedle.NeedlemanWunsch(seq1, seq2)
    needle.align()
    seq_a, seq_b = needle.get_aligned_sequences("str")
    assert (isinstance(seq_a, str))
    assert (isinstance(seq_b, str))
Exemplo n.º 6
0
def test_gap_change_alignment_before():
    seq1 = "TGTTACGG"
    seq2 = "GGTTGACTA"
    needle = minineedle.NeedlemanWunsch(seq1, seq2)
    needle.change_matrix(minineedle.ScoreMatrix(3, -3, -2))
    needle.gap_character = "-gap-"
    needle.align()
    seq1, _ = needle.get_aligned_sequences(sequence_format="str")
    assert (seq1 == "TGTT-gap-ACGG")
Exemplo n.º 7
0
def test_needleman_alignment_score_different():
    '''
    Tests if score is correctly computed.
    '''
    seq1 = ["G", "C", "A", "T", "G", "C", "U"]
    seq2 = "GATTACA"
    needle = minineedle.NeedlemanWunsch(seq1, seq2)
    needle.change_matrix(minineedle.ScoreMatrix(1, -1, -1))
    needle.align()
    assert (needle.get_score() == 0)
Exemplo n.º 8
0
def test_needleman_alignment_identity():
    '''
    Tests if score is correctly computed.
    '''
    seq1 = "GCATGCU"
    seq2 = "GATTACA"
    needle = minineedle.NeedlemanWunsch(seq1, seq2)
    needle.change_matrix(minineedle.ScoreMatrix(1, -1, -1))
    needle.align()
    assert (needle.get_identity() == 50.0)
Exemplo n.º 9
0
def test_needleman_alignment_integers():
    '''
    Tests if algorithm can handle integers
    '''
    seq1 = [1, 2, 3, 5, 1]
    seq2 = [1, 2, 9, 9, 9, 3, 5, 1]
    needle = minineedle.NeedlemanWunsch(seq1, seq2)
    needle.change_matrix(minineedle.ScoreMatrix(1, -1, -1))
    needle.align()
    assert (needle.get_score() == 2)
Exemplo n.º 10
0
def test_iterable_false():
    '''
    Tests if non-iterable objects are rejected by NeedlemanWunsch.
    '''
    seq1 = "ACTG"
    seq2 = 1
    try:
        minineedle.NeedlemanWunsch(seq1, seq2)
        assert (1 == 0)
    except TypeError:
        assert (1 == 1)
Exemplo n.º 11
0
def test_iterable_true():
    '''
    Tests if iterable objects are accepted by NeedlemanWunsch.
    '''
    seq1 = "ACTG"
    seq2 = "ACTG"
    try:
        minineedle.NeedlemanWunsch(seq1, seq2)
        assert (1 == 1)
    except Exception:
        assert (1 == 0)
Exemplo n.º 12
0
def test_iterable_different():
    '''
    Tests if iterable (lists) objects are accepted by NeedlemanWunsch.
    '''
    seq1 = ['A', 'C', 'T', 'G']
    seq2 = "ACTG"
    try:
        minineedle.NeedlemanWunsch(seq1, seq2)
        assert (1 == 1)
    except Exception:
        assert (1 == 0)
Exemplo n.º 13
0
def test_needleman_get_aligned_sequences_wrong():
    seq1 = "GCATGCU"
    seq2 = "GATTACA"
    needle = minineedle.NeedlemanWunsch(seq1, seq2)
    needle.align()
    try:
        seq_a, seq_b = needle.get_aligned_sequences("wrong")
        assert (0 == 1)
    except ValueError:
        assert (1 == 1)
    else:
        assert (0 == 1)
Exemplo n.º 14
0
def test_needleman_alignment_residue_mix():
    '''
    Tests if algorithm can handle different types in list
    '''
    seq1 = [1, "C", "A", 2, "G", "C", "U"]
    seq2 = ["G", "A", "T", "T", "A", "C", "A"]
    needle = minineedle.NeedlemanWunsch(seq1, seq2)
    needle.change_matrix(minineedle.ScoreMatrix(1, -1, -1))
    needle.align()
    try:
        assert (1 == 1)
    except ValueError:
        assert (1 == 0)
Exemplo n.º 15
0
def test_needleman_to_string():
    '''
    Tests string formatting of alignment object.
    '''
    seq1 = "GCATGCU"
    seq2 = "GATTACA"
    needle = minineedle.NeedlemanWunsch(seq1, seq2)
    needle.change_matrix(minineedle.ScoreMatrix(1, -1, -1))
    needle.align()
    assert (
        str(needle) ==
        """Alignment of SEQUENCE 1 and SEQUENCE 2:\n\tGCA-TGCU\n\tG-ATTACA\n"""
    )
Exemplo n.º 16
0
def test_change_matrix_true():
    '''
    Tests if ScoreMatrix object is accepted by NeedlemanWunsch's change_matrix
    method. 
    '''
    seq1 = "ACTG"
    seq2 = "ACTG"
    matrix = minineedle.ScoreMatrix(1, -1, -1)
    needle = minineedle.NeedlemanWunsch(seq1, seq2)

    try:
        needle.change_matrix(matrix)
        assert (1 == 1)
    except ValueError:
        assert (1 == 0)
Exemplo n.º 17
0
def test_change_matrix_false():
    '''
    Tests if non-ScoreMatrix object is rejected by NeedlemanWunsch's change_matrix
    method. 
    '''
    seq1 = "ACTG"
    seq2 = "ACTG"
    matrix = "NOT A MATRIX"
    needle = minineedle.NeedlemanWunsch(seq1, seq2)

    try:
        needle.change_matrix(matrix)
        assert (1 == 0)
    except ValueError:
        assert (1 == 1)
Exemplo n.º 18
0
def test_needleman_alignment():
    '''
    Checks if align method works
    '''
    seq1 = "GCATGCU"
    seq2 = "GATTACA"
    needle = minineedle.NeedlemanWunsch(seq1, seq2)
    needle.change_matrix(minineedle.ScoreMatrix(1, -1, -1))
    needle.align()
    assert (needle._alseq1 == [
        "G", "C", "A", minineedle.Gap(), "T", "G", "C", "U"
    ])
    assert (needle._alseq2 == [
        "G", minineedle.Gap(), "A", "T", "T", "A", "C", "A"
    ])
Exemplo n.º 19
0
def test_needleman_dynamic_matrix():
    '''
    Checks if alignment score matrix is correct.
    '''
    seq1 = "GCATGCU"
    seq2 = "GATTACA"
    needle = minineedle.NeedlemanWunsch(seq1, seq2)
    needle.change_matrix(minineedle.ScoreMatrix(1, -1, -1))
    needle.align()
    expected_matrix = [[0, -1, -2, -3, -4, -5, -6, -7],
                       [-1, 1, 0, -1, -2, -3, -4, -5],
                       [-2, 0, 0, 1, 0, -1, -2, -3],
                       [-3, -1, -1, 0, 2, 1, 0, -1],
                       [-4, -2, -2, -1, 1, 1, 0, -1],
                       [-5, -3, -3, -1, 0, 0, 0, -1],
                       [-6, -4, -2, -2, -1, -1, 1, 0],
                       [-7, -5, -3, -1, -2, -2, 0, 0]]
    assert (needle._nmatrix == expected_matrix)
Exemplo n.º 20
0
def test_needleman_pointer_matrix():
    '''
    Tests if pointer matrix is correct.
    '''
    seq1 = "GCATGCU"
    seq2 = "GATTACA"
    needle = minineedle.NeedlemanWunsch(seq1, seq2)
    needle.change_matrix(minineedle.ScoreMatrix(1, -1, -1))
    needle.align()
    expected_matrix = [
        [None, 'left', 'left', 'left', 'left', 'left', 'left', 'left'],
        ['up', 'diag', 'left', 'left', 'left', 'diag', 'left', 'left'],
        ['up', 'up', 'diag', 'diag', 'left', 'left', 'left', 'left'],
        ['up', 'up', 'diag', 'up', 'diag', 'left', 'left', 'left'],
        ['up', 'up', 'diag', 'up', 'diag', 'diag', 'diag', 'diag'],
        ['up', 'up', 'diag', 'diag', 'up', 'diag', 'diag', 'diag'],
        ['up', 'up', 'diag', 'up', 'up', 'diag', 'diag', 'left'],
        ['up', 'up', 'up', 'diag', 'left', 'diag', 'up', 'diag']
    ]
    assert (needle._pmatrix == expected_matrix)
Exemplo n.º 21
0
def test_get_gap_character():
    seq1 = "TGTTACGG"
    seq2 = "GGTTGACTA"
    alignment = minineedle.NeedlemanWunsch(seq1, seq2)
    assert (alignment.gap_character == "-")