Exemple #1
0
def degenerate_dna_pairwise_aligner(seq1, seq2: str, substitution_matrix):
    with warnings.catch_warnings():
        warnings.filterwarnings('ignore', category=EfficiencyWarning)
        forward = DegenerateDNA(seq2)
        lpa1 = local_pairwise_align(seq1, forward, 3, 1, substitution_matrix)
        reverse = DegenerateDNA(reverse_complement(seq2))
        lpa2 = local_pairwise_align(seq1, reverse, 3, 1, substitution_matrix)
        if lpa1[1] >= lpa2[1]:
            return lpa1[0], lpa1[1]  # TabularMSA, score
        return lpa2[0], lpa2[1]
Exemple #2
0
def proteinAlign(seq1,
                 seq2,
                 gap_open_penalty,
                 gap_extend_penalty,
                 local=False):
    seq1 = seq1.upper()
    seq2 = seq2.upper()

    if local:
        aln, score, _ = local_pairwise_align(Protein(seq1), Protein(seq2),
                                             gap_open_penalty,
                                             gap_extend_penalty, blosum50)
    else:
        aln, score, _ = global_pairwise_align(Protein(seq1),
                                              Protein(seq2),
                                              gap_open_penalty,
                                              gap_extend_penalty,
                                              blosum50,
                                              penalize_terminal_gaps=True)

    response = {
        'aln1':
        str(aln[0]),
        'aln2':
        str(aln[1]),
        'score':
        score,
        'similarity':
        float('{:.2f}'.format(aln[0].match_frequency(aln[1], relative=True) *
                              100))
    }

    return response
Exemple #3
0
    def test_local_pairwise_align_custom_alphabet(self):
        custom_substitution_matrix = make_identity_substitution_matrix(
            5, -4, alphabet=CustomSequence.definite_chars)

        custom_msa, custom_score, custom_start_end = local_pairwise_align(
            CustomSequence("YWXXZZYWXXWYYZWXX"),
            CustomSequence("YWWXZZZYWXYZWWX"), 5.0, 0.5,
            custom_substitution_matrix)

        # Expected values computed by running an equivalent alignment using the
        # DNA alphabet with the following mapping:
        #
        #     W X Y Z
        #     | | | |
        #     A C G T
        #
        self.assertEqual(
            custom_msa,
            TabularMSA([CustomSequence('WXXZZYWXXWYYZWXX'),
                        CustomSequence('WXZZZYWX^^^YZWWX')]))
        self.assertEqual(custom_score, 41.0)
        self.assertEqual(custom_start_end, [(1, 16), (2, 14)])
Exemple #4
0
 def sw_calc_best_x(comb):
     best = -99999999999
     target = list_to_str(y)
     for i in list(comb):
         x = list_to_str(i)
         #            print(x)
         #            print(target)
         alignment, score, pos = local_pairwise_align(
             SyscallSequence(list_to_str(i)),
             SyscallSequence(target),
             gap_open_penalty=-2,
             gap_extend_penalty=-0.01,
             substitution_matrix=matrix)
         print(alignment)
         print(score)
         if score > best:
             best = score
             best_alignment = alignment
             _best_x = x
     print("----- Best alignment: -----")
     print("score: ", best)
     print(best_alignment)
     return _best_x
Exemple #5
0
 def test_local_pairwise_align_type_mismatch(self):
     with self.assertRaisesRegex(TypeError,
                                 "same type: 'DNA' != 'RNA'"):
         local_pairwise_align(DNA('ACGT'), RNA('ACGU'), 1.0, 1.0, {})
Exemple #6
0
 def test_local_pairwise_align_invalid_type(self):
     with self.assertRaisesRegex(TypeError,
                                 'GrammaredSequence.*Sequence'):
         local_pairwise_align(DNA('ACGT'), Sequence('ACGT'), 1.0, 1.0, {})
Exemple #7
0
 def test_local_pairwise_align_invalid_type(self):
     with six.assertRaisesRegex(self, TypeError, 'IUPACSequence.*Sequence'):
         local_pairwise_align(DNA('ACGT'), Sequence('ACGT'), 1.0, 1.0, {})