def test_NW_score(hmat, decs, lecs): """Test for similarity in old and new alignment scoring Complete NW version """ s1 = '6.2.1:2.3.1:1.2.4:2.7.1:4.2.1:5.4.2:2.7.2:1.2.1:4.1.2:2.7.1:5.3.1:5.4.2:3.1.3' s1_ = '2.3.1:1.2.4:2.7.1:5.4.2:2.7.2:1.2.1' # s2 = '1.2.4:2.3.1:2.3.3:4.1.1' # s3 = '6.3.3:6.3.4:5.4.99:6.3.2:4.3.2:2.4.2:3.2.2' ss1 = s1.split(':') ss1_ = s1_.split(':') # ss2 = s2.split(':') # ss3 = s3.split(':') ess = [ss1, ss1_] for ii, i in enumerate(ess): for ji, j in enumerate(ess): score_old = nw.NW(hmat, lecs, ':'.join(i), ':'.join(j))[2] score_new = nwx.NW(hmat, decs, i, j)[2] assert abs(score_old - score_new) <= 1e-2 score_old_loc = nw.NW(hmat, lecs, ':'.join(i), ':'.join(j), local=True, localize=True)[2] score_new_loc = nwx.NW(hmat, decs, i, j, localize=True)[2] assert abs(score_old_loc - score_new_loc) <= 1e-2
def align(ess_pair, nrdic): """Wraper for easy align ESS Arguments: - `ess_pair`: tuple. Pair of ess ids """ assert len(ess_pair) == 2, "Must be a pair of ess id" id1, id2 = ess_pair ess1 = nrdic[id1] ess2 = nrdic[id2] result = NW.NW(hmat, ecs, ess1, ess2, local=True) score = result[2] data = np.array([id1, id2, score], dtype=np.float32) return data
def aliall_old(ind, seqs, mat, ecs): """Align the sequences in the specified index (ind) versus all the rest of sequences Keyword Arguments: ind -- seqs -- """ seq1 = seqs[ind] result = [] print(ind) for i in range(ind + 1, len(seqs)): seq2 = seqs[i] s1, s2, sco = nw.NW(mat, ecs, seq1, seq2) result.append(sco) return result
def align_ess_vs_real(rid, nrdic): """Wraper for easy align ESS One random ESS versus all the real Arguments: - `rid`: nrdic, ress id (randome ess id) """ assert rid in nrdic, "ress must be in nrdic" ress = nrdic[rid] # ress = random ess scores = np.zeros(len(realdic), dtype=np.float32) for nrid, v in realdic.iteritems(): ess = v['ec3'] result = NW.NW(hmat, ecs, ess, ress, local=True) score = result[2] scores[nrid - 1] = score # fill mat scomat[:, rid - 1] = scores
ss2 = s2.split(':') ss3 = s3.split(':') ess = [ss1, ss2, ss3, ss1_] print("Test ESS:") print('-' * 45) print('1\t', nw.s1) print('2\t', nw.s2) print('3\t', nw.s3) print('4\t', nw.s1_) print('-' * 45, '\n') print('\tSCORES') print('-' * 45) print('\t| Old\t| New') print('s1-s2\t|Sco\tLoc\t|Sco\tLoc') print('-' * 45) line = '{}-{}\t|{:.3}\t{:.3}\t|{:.3}\t{:.3}' for ii, i in enumerate(ess): for ji, j in enumerate(ess): sold = nw.NW(nw.hmat, lecs, ':'.join(i), ':'.join(j))[2] snew = nwx.NW(nw.hmat, decs, i, j)[2] soldl = nw.NW(nw.hmat, lecs, ':'.join(i), ':'.join(j), local=True, localize=True)[2] snewl = nwx.NW(nw.hmat, decs, i, j, localize=True)[2] print(line.format(ii, ji, sold, soldl, snew, snewl))
decs = nw.decs import pyximport pyximport.install() import dlist import nw_ec_alignx as nwx # subval = nw.__FastSubValues(nw.hmat, decs, nw.ss1, nw.ss2) # align = dlist.FastNW(subval, nw.ss1, nw.ss2) # arrow = align[1] # arrowint = arrow.astype(np.int) # back_ = dlist.backtrace(arrowint, nw.ss1, nw.ss2) # back = nw.backtrace(arrow, nw.s1, nw.s2) %timeit - n 100 nw.NW(nw.hmat, lecs, nw.s1, nw.s2) %timeit - n 100 dlist.NW_(nw.hmat, decs, nw.ss1, nw.ss2) %timeit - n 100 nwx.NW(nw.hmat, decs, nw.ss1, nw.ss2) ess = [nw.ss1, nw.ss2, nw.ss3, nw.ss1_] print('\tOld\t|\tNew') print('Sco\tLoc\t|Sco\tLoc') print('---------------------') line = '{:.3}\t{:.3}\t|{:.3}\t{:.3}' for i in ess: for j in ess: sold = nw.NW(nw.hmat, lecs, ':'.join(i), ':'.join(j))[2] snew = nwx.NW(nw.hmat, decs, i, j)[2] soldl = nw.NW(nw.hmat, lecs, ':'.join(i), ':'.join(j), local=True, localize=True)[2]