align_j = ''.join(align_j[::-1]) seq_result_str = ''.join(seq_result[::-1]) if flip: aln = AlignmentResult(align_i, align_j, seq_result_str , i, j, end_i, end_j, n_gaps_i, n_gaps_j, n_mmatch, score) else: aln = AlignmentResult(align_j, align_i, seq_result_str , j, i, end_j, end_i, n_gaps_j, n_gaps_i, n_mmatch, score) results.append(aln) return results # ----------------- test ------------------------------------------- mat, ind = rd.Read_BLO_Matrix(file_name="BLOSUM62.txt") alg = aligner(rd.Read_Two_Seq(), mat, ind, gap_open=-10, gap_extend=-0.5,gap_double=-10,max_hits=2) for i in alg: print(i) alg=[] alg = aligner(['ARAAV','ARAVVVARAV'], mat, ind, method='local', gap_open=-10,gap_extend=-0.5,gap_double=-10,max_hits=2) for i in alg: print(i) alg = [] alg = aligner(rd.Read_Two_Seq(), mat, ind, method="local", gap_open=-10,gap_extend=-0.5,gap_double=-10,max_hits=5) for i in alg: print(i) #print(len(i.seq1)) print("----------------")
from other_written.matrix import BLOSUM62 import ReadData as rd __all__ = ["AlignmentResult", "aligner"] IS_PY2 = False if sys.version_info.major == 2: IS_PY2 = True # Container for alignment result AlignmentResult = namedtuple('AlignmentResult', [ 'seq1', 'seq2', 'start1', 'start2', 'end1', 'end2', 'n_gaps1', 'n_gaps2', 'n_mismatches', 'score' ]) mat, index = rd.Read_BLO_Matrix(file_name="../BLOSUM62.txt") def aligner(seqj, seqi, method='global', gap_open=-7, gap_extend=-7, gap_double=-7, matrix=BLOSUM62, max_hits=1): '''Calculates the alignment of two sequences. The supported 'methods' are: * 'global' for a global Needleman-Wunsh algorithm * 'local' for a local Smith-Waterman alignment
def acc_identity(self): self.identity += 1 def acc_gap_count(self): self.gap_count += 1 def set_sequence_final_length(self, length): self.final_length = length def __str__(self): return "gap_count = %d; ideXntity = %d \n" % (self.gap_count, self.identity) mat, index = Data.Read_BLO_Matrix() def global_alignment(seqs=Sequence_Pair(), score=ScoreParam(-10, -0.5, mat, index), method="global", max_hits=1): assert method == "global" or "local" seqi = seqs.sequence_A seqj = seqs.sequence_B NONE, LEFT, UP, DIAG = range(4) # NONE is 0 GAP_CHAR = '-'