Tom*_*nks 0 python bioinformatics dna-sequence biopython pairwise
我有 DNA 序列数据。例如,
X="ACGGGT"
Y="ACGGT"
Run Code Online (Sandbox Code Playgroud)
我想知道对齐分数,因此我使用了biopythonpairwise2函数。例如,
from Bio import pairwise2
from Bio.pairwise2 import format_alignment
alignments = pairwise2.align.globalxx(X, Y)
for a in alignments:
print(format_alignment(*a))
Run Code Online (Sandbox Code Playgroud)
这成功地显示了 DNA 比对,但我只需要如下的分数。有没有办法只显示分数?
我使用了biopython,但如果有更好的方法,我们将不胜感激。
取每个对齐元组的第三项(或者为了获得最佳分数,仅解析参数score_only):
>>> from Bio import pairwise2
>>> X="ACGGGT"
>>> Y="ACGGT"
>>> alignments = pairwise2.align.globalxx(X, Y)
>>> [a[2] for a in alignments]
[5.0, 5.0, 5.0]
>>> pairwise2.align.globalxx(X, Y, score_only=True)
5.0
Run Code Online (Sandbox Code Playgroud)
另请参阅较新的Bio.Align模块,它对于许多用例来说可能性能更高。如果你只想要最好的分数,你可以使用aligner.score()Markus的评论:
>>> from Bio import Align
>>> aligner = Align.PairwiseAligner()
>>> alignments = aligner.align(X,Y)
>>> [a.score for a in alignments]
[5.0, 5.0, 5.0]
>>> aligner.score(X, Y)
5.0
Run Code Online (Sandbox Code Playgroud)
如果您只想要分数,那么避免生成完整对齐是这两个模块最快且最有效的内存方式。