python对象的序列对齐。
paired的Python项目详细描述
配对
paired是一个python包,用于任意序列的成对对齐。
python有很多用于序列对齐和扭曲的优秀软件包,但主要用于生物或数字数据。paired对任意python对象的列表执行全局对齐,并允许您定义元素对的匹配和评分方式。
基本用法
importpairedseq_1='The quick brown fox jumped over the lazy dog'.split(' ')seq_2='The brown fox leaped over the lazy dog'.split(' ')alignment=paired.align(seq_1,seq_2)print(alignment)# [(0, 0), (1, None), (2, 1), (3, 2), (4, 3), (5, 4), (6, 5), (7, 6), (8, 7)]fori_1,i_2inalignment:print((seq_1[i_1]ifi_1isnotNoneelse'').ljust(15),end='')print(seq_2[i_2]ifi_2isnotNoneelse'')# The The# quick # brown brown# fox fox# jumped leaped# over over# the the# lazy lazy# dog dog
自定义分数
paired使用Needleman-Wunsch algorithm。可以指定不同操作(匹配、不匹配、间隙)的评分:
alignment=paired.align(seq_1,seq_2,match_score=5,mismatch_score=-1,gap_score=-5)
自定义相似性
默认情况下,如果element_1 == element_2
匹配两个元素。paired还允许您传递函数来返回给定元素对的匹配/不匹配分数。例如,可以对字符串的区分大小写和不区分大小写的匹配给出不同的分数:
defscorer(a,b):ifa==b:return2elifa.lower()==b.lower():return1else:return-1alignment=paired.align(seq_1,seq_2,scorer=scorer,gap_score=-3)
安装
paired位于PyPi上,可以与pip一起安装。它没有依赖关系。
pip install paired
API
pairwise.align(x, y, match_score=1, mismatch_score=-1, gap_score=-1, scorer=None)
得到两个序列的全局对齐。
参数:
- x,y(list):要对齐的对象序列。
- match\u score(numeric):配对元素时的分数。
- mismatch\u score(numeric):配对不匹配元素时的分数。
- gap\u score(numeric):当一个元素没有与其他元素配对时,插入/删除的分数。
- scorer(callable):函数,接受两个元素作为输入,并根据它们的匹配程度返回数值分数。如果通过
None
,则使用的默认函数相当于lamdba a, b: match_score if a==b else mismatch_score
。
返回:
- alignment(list of tuples):对齐的序列,作为分别进入
x
和y
的索引对的列表。间隙用None
而不是整数索引表示。