同编辑距离算法的一种实现。

homoeditdistance的Python项目详细描述


同音编辑距离

DOI

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']))

如何运行单元测试

确保安装了unittestPython包,并从克隆的存储库中运行python3 -m unittest。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JFrame中的Java多线程   java Servlet异常映射   java无法从输出流读取   swing Java带来的小程序GUI问题   java什么原因导致错误“'void'类型此处不允许”以及如何修复它?   Java选择器select(长)与selectNow的区别   java自定义arraylist<mygames>获得不同   java Icepdf注释让页面消失   java反向整数数组   java I在生成同步“无法解析配置的所有依赖项”时遇到此错误:app:debugRuntimeClasspath   多个虚拟机上的java线程访问单个DB实例上的表,有时会导致性能低下和异常   swing更改Java中的默认按钮,使其看起来“更好”   java慢速MQ主题订阅。并行化不能提高性能   java运行Boggle Solver需要一个多小时。我的代码怎么了?   数据库中的java循环与应用程序中的java循环   正则表达式匹配${123…456}并在Java中提取2个数字?   java如何制作我们软件的试用版   Java内存参数计算   从另一个类调用方法时出现java问题