Created
June 16, 2019 23:28
-
-
Save cocomoff/54719f5c9b98dcad448f7e3907fe9d34 to your computer and use it in GitHub Desktop.
BWT (figure 3.1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
if __name__ == '__main__': | |
T = "abracadabra$" | |
lT = len(T) | |
print("Input:", T) | |
sa = [T[i:] for i in range(lT)] | |
isa = list(zip(range(lT), sa)) | |
sorted_isa = sorted(isa, key=lambda x: x[1]) | |
iSA = [x[0] for x in sorted_isa] | |
wSA = [x[1] for x in sorted_isa] | |
print(iSA) | |
print(wSA) | |
# compute BWT | |
# TB[i] = T[SA[i] - 1] SA[i] > 0 | |
# = T[n-1] SA[i] = 0 | |
TB = "" | |
for i in range(lT): | |
if iSA[i] == 0: | |
TB += T[lT - 1] | |
else: | |
TB += T[iSA[i] - 1] | |
print("TB:", TB) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment