Created
June 7, 2016 22:12
-
-
Save indapa/5ad1c1ff95945ecacea235bae970c0a4 to your computer and use it in GitHub Desktop.
bwt.py
This file contains hidden or 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
import sys | |
import pdb | |
def bwt(s): | |
""" Return the burrougs wheele transform and suffix array for string s | |
based on Fig2 in Li & Durbin 2009 """ | |
table_rotation=[] | |
# Table of rotations of string | |
for i in range(len(s)): | |
foo=s[i:] | |
bar=s[:i] | |
table_rotation.append(foo + bar) | |
#pdb.set_trace() | |
sorted_table= sorted(table_rotation) | |
suffix_array= [ table_rotation.index(i) for i in sorted_table] | |
bwt= [ sorted_table[i][len(sorted_table[i])-1] for i in range(len(sorted_table)) ] | |
return (bwt, suffix_array) | |
def main(): | |
(transform, sa) = bwt('googol$') | |
print transform | |
print sa | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment