# coding=utf-8 def BWTEncode(str): str = str + '#' size = len(str) bwtstr = ['0'] * size result = [] result.append(str) for j in range(size): for i in range(size): if i == size-1: bwtstr[0] = str[i] else: bwtstr[i+1] = str[i] bstr = '' for i in range(len(bwtstr)): bstr += bwtstr[i] if j == size-1: break else: result.append(bstr) str = bstr result = sorted(result) l = '' for i in range(len(result)): l += result[i][-1] return l def strtolist(str): result = [] for i in range(len(str)): result.append(str[i]) return result def listtostr(list)
Python实现BWT算法()
最新推荐文章于 2024-03-06 09:54:18 发布
本文介绍了如何使用Python实现Burrows-Wheeler转换(BWT)算法,包括编码和解码过程。首先定义了BWTEncode函数进行BWT编码,接着通过getf和getlf函数获取首字符和末字符序列,最后的BWTDecode函数完成解码。示例中展示了对字符串'banana'的BWT编码和解码操作。
摘要由CSDN通过智能技术生成