def test_compute_global_alignment():
    """
    Test the function compute_global_alignment function
    """
    suite = poc_simpletest.TestSuite()
    scoring_matrix = proj4_solution.build_scoring_matrix(set(["A", "C", "T", "G"]), 10, 4, -6)
    alignment_matrix = proj4_solution.compute_alignment_matrix("AA", "TAAT", scoring_matrix, True)
    global_alignment_sequence = proj4_solution.compute_global_alignment("AA", "TAAT", scoring_matrix, alignment_matrix)
    print global_alignment_sequence
    suite.run_test(global_alignment_sequence, (8, "-AA-", "TAAT"), "Error Found")

    global_alignment_sequence = proj4_solution.compute_global_alignment(
        "ACTACT",
        "AGCTA",
        {
            "A": {"A": 2, "C": 1, "-": 0, "T": 1, "G": 1},
            "C": {"A": 1, "C": 2, "-": 0, "T": 1, "G": 1},
            "-": {"A": 0, "C": 0, "-": 0, "T": 0, "G": 0},
            "T": {"A": 1, "C": 1, "-": 0, "T": 2, "G": 1},
            "G": {"A": 1, "C": 1, "-": 0, "T": 1, "G": 2},
        },
        [
            [0, 0, 0, 0, 0, 0],
            [0, 2, 2, 2, 2, 2],
            [0, 2, 3, 4, 4, 4],
            [0, 2, 3, 4, 6, 6],
            [0, 2, 3, 4, 6, 8],
            [0, 2, 3, 5, 6, 8],
            [0, 2, 3, 5, 7, 8],
        ],
    )
    print global_alignment_sequence
    suite.run_test(global_alignment_sequence, (8, "A-CTACT", "AGCTA--"), "Error Found")

    global_alignment_sequence = proj4_solution.compute_global_alignment(
        "ACTACT",
        "GGACTGCTTCTGG",
        {
            "A": {"A": 2, "C": 1, "-": 0, "T": 1, "G": 1},
            "C": {"A": 1, "C": 2, "-": 0, "T": 1, "G": 1},
            "-": {"A": 0, "C": 0, "-": 0, "T": 0, "G": 0},
            "T": {"A": 1, "C": 1, "-": 0, "T": 2, "G": 1},
            "G": {"A": 1, "C": 1, "-": 0, "T": 1, "G": 2},
        },
        [
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
            [0, 1, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
            [0, 1, 2, 3, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6],
            [0, 1, 2, 4, 4, 6, 7, 7, 7, 7, 7, 7, 7, 7],
            [0, 1, 2, 4, 6, 6, 7, 9, 9, 9, 9, 9, 9, 9],
            [0, 1, 2, 4, 6, 8, 8, 9, 11, 11, 11, 11, 11, 11],
        ],
    )
    print global_alignment_sequence
    suite.run_test(global_alignment_sequence, (11, "--A---CTACT--", "GGACTGCTTCTGG"), "Error Found")

    suite.report_results()
def global_alignment_consensus():
    """
    Question: 2
    """
    ans_similar = []
    local_alignments = local_alignment_eyeless_protein()
    consensus_seq = provided.read_protein(provided.CONSENSUS_PAX_URL)
    scoring_matrix = provided.read_scoring_matrix(provided.PAM50_URL)
    for idx in range(1, 3):
        seq_x = local_alignments[idx]
        seq_x = seq_x.replace("-", "")
        alignment_matrix = student.compute_alignment_matrix(seq_x, consensus_seq, scoring_matrix, True)
        global_alignment = student.compute_global_alignment(seq_x, consensus_seq, scoring_matrix, alignment_matrix)
        similar_count = 0
        for letter1, letter2 in zip(global_alignment[1], global_alignment[2]):
            if letter1 == letter2:
                similar_count += 1
        ans_similar.append(float(similar_count * 100) / len(global_alignment[1]))
    return ans_similar
Exemple #3
0
def global_alignment_consensus():
    """
    Question: 2
    """
    ans_similar = []
    local_alignments = local_alignment_eyeless_protein()
    consensus_seq = provided.read_protein(provided.CONSENSUS_PAX_URL)
    scoring_matrix = provided.read_scoring_matrix(provided.PAM50_URL)
    for idx in range(1, 3):
        seq_x = local_alignments[idx]
        seq_x = seq_x.replace("-", "")
        alignment_matrix = student.compute_alignment_matrix(
            seq_x, consensus_seq, scoring_matrix, True)
        global_alignment = student.compute_global_alignment(
            seq_x, consensus_seq, scoring_matrix, alignment_matrix)
        similar_count = 0
        for letter1, letter2 in zip(global_alignment[1], global_alignment[2]):
            if letter1 == letter2:
                similar_count += 1
        ans_similar.append(
            float(similar_count * 100) / len(global_alignment[1]))
    return ans_similar
def test_compute_global_alignment():
    """
    Test the function compute_global_alignment function
    """
    suite = poc_simpletest.TestSuite()
    scoring_matrix = proj4_solution.build_scoring_matrix(
        set(['A', 'C', 'T', 'G']), 10, 4, -6)
    alignment_matrix = proj4_solution.compute_alignment_matrix(
        'AA', 'TAAT', scoring_matrix, True)
    global_alignment_sequence = proj4_solution.compute_global_alignment(
        'AA', 'TAAT', scoring_matrix, alignment_matrix)
    print global_alignment_sequence
    suite.run_test(global_alignment_sequence, (8, '-AA-', 'TAAT'),
                   "Error Found")

    global_alignment_sequence = proj4_solution.compute_global_alignment(
        'ACTACT', 'AGCTA', {
            'A': {
                'A': 2,
                'C': 1,
                '-': 0,
                'T': 1,
                'G': 1
            },
            'C': {
                'A': 1,
                'C': 2,
                '-': 0,
                'T': 1,
                'G': 1
            },
            '-': {
                'A': 0,
                'C': 0,
                '-': 0,
                'T': 0,
                'G': 0
            },
            'T': {
                'A': 1,
                'C': 1,
                '-': 0,
                'T': 2,
                'G': 1
            },
            'G': {
                'A': 1,
                'C': 1,
                '-': 0,
                'T': 1,
                'G': 2
            }
        }, [[0, 0, 0, 0, 0, 0], [0, 2, 2, 2, 2, 2], [0, 2, 3, 4, 4, 4],
            [0, 2, 3, 4, 6, 6], [0, 2, 3, 4, 6, 8], [0, 2, 3, 5, 6, 8],
            [0, 2, 3, 5, 7, 8]])
    print global_alignment_sequence
    suite.run_test(global_alignment_sequence, (8, 'A-CTACT', 'AGCTA--'),
                   "Error Found")

    global_alignment_sequence = proj4_solution.compute_global_alignment(
        'ACTACT', 'GGACTGCTTCTGG', {
            'A': {
                'A': 2,
                'C': 1,
                '-': 0,
                'T': 1,
                'G': 1
            },
            'C': {
                'A': 1,
                'C': 2,
                '-': 0,
                'T': 1,
                'G': 1
            },
            '-': {
                'A': 0,
                'C': 0,
                '-': 0,
                'T': 0,
                'G': 0
            },
            'T': {
                'A': 1,
                'C': 1,
                '-': 0,
                'T': 2,
                'G': 1
            },
            'G': {
                'A': 1,
                'C': 1,
                '-': 0,
                'T': 1,
                'G': 2
            }
        }, [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
            [0, 1, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
            [0, 1, 2, 3, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6],
            [0, 1, 2, 4, 4, 6, 7, 7, 7, 7, 7, 7, 7, 7],
            [0, 1, 2, 4, 6, 6, 7, 9, 9, 9, 9, 9, 9, 9],
            [0, 1, 2, 4, 6, 8, 8, 9, 11, 11, 11, 11, 11, 11]])
    print global_alignment_sequence
    suite.run_test(global_alignment_sequence,
                   (11, '--A---CTACT--', 'GGACTGCTTCTGG'), "Error Found")

    suite.report_results()