同编辑距离算法的一种实现。
homoeditdistance的Python项目详细描述
同音编辑距离
homo插入是将一个相等字符的字符串(我们也称为块)插入到另一个字符串中。homo删除是反向操作,即删除这样的块。我们考虑以下问题:给定两个字符串,将一个字符串转换为另一个字符串所需的homo插入或删除的最少数量是多少?我们把这个数字称为homo编辑距离。在
参考文献
该算法在以下出版物中进行了描述:
- M、 布兰德,N.K.Tran,P.Spohr,S.Schrinner,G.W.Klau。同音编辑距离问题。bioRxiv,冷泉港实验室,内政部:待定
从存储库安装
pip3 install homoeditdistance
从源安装
^{pr2}$如何在命令行上运行
Python包附带了一个命令行工具hed
,可用于运行算法的演示。它的源代码位于demonstration.py。它还可以帮助您了解如何调用函数。如果您刚刚克隆了存储库,那么可以使用
python3 -m homoeditdistance
帮助
usage: hed [-h] -s STRING1 -t STRING2 [-a] [-b]
Given two strings, find their homo-edit distance
optional arguments:
-h, --help show this help message and exit
-s STRING1, --string1 STRING1
first string. Use quotation marks around your string
(e.g. "STRING")for the empty string or strings with
special characters
-t STRING2, --string2 STRING2
second string
-a, --all show all optimal subsequences
-b, --backtrace print transformation steps
示例
输出hed -s "TCAGACT" -t "TAGGCTT" -a -b
The homo-edit distance between TCAGACT and TAGGCTT is 4
The following optimal subsequences were found, and obtained using the listed operations:
TAGCT
Possible optimal sequence of operations:
s: TCAGACT t: TAGGCTT
Deleting substring 1 -> 2 (C) from s
Deleting: C Result: T-AGACT
Deleting substring 4 -> 5 (A) from s
Deleting: A Result: T-AG-CT
Deleting substring 3 -> 4 (G) from t
Deleting: G Result: TAG-CTT
Deleting substring 6 -> 7 (T) from t
Deleting: T Result: TAG-CT-
如何在自己的代码中使用
两个字符串之间的Homo编辑距离
fromhomoeditdistanceimporthomoEditDistancestring1="TCAGACT"string2="TAGGCTT"print('The homo-edit-distance of {} and {} is {}.'.format(string1,string2,homoEditDistance(string1,string2,0)['hed']))
如何运行单元测试
确保安装了unittest
Python包,并从克隆的存储库中运行python3 -m unittest
。在
- 项目
标签: