Skip to content

Instantly share code, notes, and snippets.

@cocomoff
Created June 16, 2019 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cocomoff/54719f5c9b98dcad448f7e3907fe9d34 to your computer and use it in GitHub Desktop.
Save cocomoff/54719f5c9b98dcad448f7e3907fe9d34 to your computer and use it in GitHub Desktop.
BWT (figure 3.1)
# -*- 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