# ____ ____ ____ _________ ____ ____ ____ ____ ____ ____ ____ # ||A |||L |||G ||| |||D |||y |||n |||P |||r |||o |||g || # ||__|||__|||__|||_______|||__|||__|||__|||__|||__|||__|||__|| # |/__\|/__\|/__\|/_______\|/__\|/__\|/__\|/__\|/__\|/__\|/__\| # Template by Claire Lemaitre (2025) # Code by ___ import random import time # ____________________________________________________________________________ # | | # | Dynamic matrix | # |____________________________________________________________________________| class DynamicMatrix: ''' Stores a matrix |S|x|T| (|S|+1 lines and |T|+1columns), sequences S and T and the score system (match, mismatch, gap) Defines some global alignment functions ''' # --| Constructor |--------------------------------------------------------- def __init__(self, S, T, sc_match, sc_mismatch, sc_gap): ''' DynamicMatrix constructor ''' self.S=S self.T=T self.sc_gap=sc_gap self.sc_match=sc_match self.sc_mismatch=sc_mismatch # NOTE. Initializing the matrix with '_' allows for the Python code to # crash when a non-initialized cell is used in an integer comparison. self.matrix = [['_' for j in range(len(T)+1)] for i in range(len(S)+1)] # --| Public methods |------------------------------------------------------ def printMatrix(self): ''' Display the matrix in a pretty way ''' width = 4 vide = " " line = f"{vide:>{2*width}}" for j in range(0,len(self.T)): line += f"{self.T[j]:>{width}}" print(line) line = f"{vide:>{width}}" for j in range(0,len(self.T)+1): line += f"{self.matrix[0][j]:>{width}}" print(line) for i in range(1,len(self.S)+1): line = f"{self.S[i-1]:>{width}}" for j in range(0,len(self.T)+1): line += f"{self.matrix[i][j]:>{width}}" print(line)