def nw_bio(seq1, seq2, cost_table): aligner = PairwiseAligner(alphabet=list(set(seq1 + seq2))) aligner.match_score = cost_table[0] aligner.mismatch_score = cost_table[1] aligner.gap_score = cost_table[2] alignments = aligner.align(seq1, seq2) formated_alignments = [] for i in range(len(alignments)): als = str(alignments[i]).split("\n") formated_alignments.append([als[0], als[2], int(alignments[i].score)]) return formated_alignments
def nw_bio_mat(seq1, seq2, cost_mat, key): aligner = PairwiseAligner(alphabet=key) matrix = {} for i in range(len(key)): for j in range(0, len(key)): matrix[(key[i], key[j])] = cost_mat[i * len(key) + j] aligner.substitution_matrix = substitution_matrices.Array(data=matrix) aligner.gap_score = cost_mat[len(key)**2] alignments = aligner.align(seq1, seq2) formated_alignments = [] for i in range(len(alignments)): als = str(alignments[i]).split("\n") formated_alignments.append([als[0], als[2], int(alignments[i].score)]) return formated_alignments