def nw_verbose(seq1, seq2, cost_table=None, cost_mat=None, key=None, timer=1): ''' Animated the needleman algorithm, on each iteration it clears the terminal, print the table and the path taken then wait for a specific amount of time Args: seq1: the first sequence to align seq2: the second sequence to align cost_table: contains the match, mismatch and the gap cost in this order (mutual exlusive with cost_mat) cost_mat: contains the cost matrix and the gap at the end (mutual exlusive with cost_table and used with key) key: the order of the letters in the cost matrix (mutual exlusive with cost_table) timer: timer to sleep on each iteration Returns: None ''' alg, alg_mat, path = needleman(seq1, seq2, cost_table=cost_table, cost_mat=cost_mat, key=key, verbose=True) alg.append(create_aligner_str(alg[0], alg[1])) path.append((-1, -1)) seen = [] for coord in path: clear() print_nw_table(seq1, seq2, alg, alg_mat, coord, seen) seen.append(coord) sleep(timer)
def test_needlman_mat(): for t in TEST_CASES_MAT: #----------- Our Implementation ----------- m1 = needleman(t[0], t[1], cost_mat=t[2], key=t[3]) #---------------- Bio Seq ---------------- m2 = nw_bio_mat(t[0], t[1], cost_mat=t[2], key=t[3]) #------------------ Test ------------------ assert m1 in m2
def test_needlman(): for t in TEST_CASES_NORMAL: #----------- Our Implementation ----------- m = needleman(t[0], t[1], t[2]) #---------------- Bio Seq ----------------- m2 = nw_bio(t[0], t[1], t[2]) #------------------ Test ------------------ assert m in m2
def test_needleman_random_gen(): for _ in range(0, EPOCHS) : #----------- Generating random arguments ----------- cost_table = [ random.randint(-10, 10), random.randint(-10, 0), random.randint(-10, 0) ] args = arg_generator(N=NW_RUNS, stride=1, type=STRINGS, variant_arg_pos=[0, 1], static_args=[cost_table], start=1, same_size=False, lower=(NW_RUNS//2)+1, upper=NW_RUNS) for arg in args: #------------------ Test ------------------ assert needleman(*arg) in nw_bio_generic(*arg)
def test_needleman_mat_random_gen(): for i in range(0, EPOCHS) : #----------- Generating random arguments ----------- key = ''.join(list(set(random.choices(string.ascii_lowercase, k=i+2)))) cost_mat = [ random.randint(-10, 10) for _ in range(len(key) ** 2 + 1) ] args = arg_generator(N=NW_RUNS, stride=1, type=STRINGS, samples=key, variant_arg_pos=[0, 1], static_args=[None, cost_mat, key], start=1, same_size=False, lower=(NW_RUNS//2)+1, upper=NW_RUNS) for arg in args: #------------------ Test ------------------ assert needleman(*arg) in nw_bio_generic(*arg)