# 双序列比对

双序列比对将两条生物学序列——无论是DNA、RNA还是蛋白质——排成一一对应的共线性关系，在需要处插入空位，使相似的位置对齐。形式上说，序列S和T的全局比对，是扩展序列S′与T′之间的一种对应关系，其中任意两个空位都不相互对应。<sup>[1](https://www.ncbi.nlm.nih.gov/books/NBK464187/)</sup> 在数据库检索中，通常更倾向于使用局部相似性度量，因为cDNA可能需要与部分测序的基因进行比较。

| 关键事实 | 说明 |
|---|---|
| 输出 | 两条序列带空位的一一对应共线性关系，并附带一个得分<sup>[1](https://www.ncbi.nlm.nih.gov/books/NBK464187/)</sup> |
| 精确动态规划开销 | 长度为\( m \)和\( n \)时，需\( O(m \cdot n) \)时间和空间；空间可降至O(min{m, n})<sup>[1](https://www.ncbi.nlm.nih.gov/books/NBK464187/)</sup> |
| 替换打分 | 对数几率矩阵\( s_{ij} = \log\left( \frac{q_{ij}}{p_i \cdot p_j} \right) \)；PAM系列与BLOSUM系列<sup>[1](https://www.ncbi.nlm.nih.gov/books/NBK464187/)</sup> |
| 空位打分 | 长度为\( k \)的空位采用仿射罚分\( g_k = -(a + b \cdot k) \)<sup>[1](https://www.ncbi.nlm.nih.gov/books/NBK464187/)</sup> |
| 显著性 | \( E(s) \approx K \cdot m \cdot n \cdot \exp(-\lambda \cdot s) \)，即E值<sup>[2](https://link.springer.com/article/10.1186/1471-2105-9-332)</sup> |
| 启发式速度 | 带空位BLAST的运行速度约为原始BLAST的三倍，同时灵敏度有所提高<sup>[3](https://doi.org/10.1093/nar/25.17.3389)</sup> |
| GPU吞吐量 | CUDASW++4.0在H100 GPU上最高达到5.71 TCUPS<sup>[4](https://link.springer.com/article/10.1186/s12859-024-05965-6)</sup> |

## 工作原理

**比对是一个优化问题。** 得分的计算方式是：将替换矩阵（如NUC42或BLOSUM62）给出的逐位置匹配得分相加，再减去打开空位的罚分以及每个空位位置的罚分。<sup>[5](https://www.dnastar.com/manuals/MegAlignPro/18.1/en/topic/choosing-a-pairwise-alignment-method)</sup> 替换得分是对数几率：\( s_{ij} = \log\left( \frac{q_{ij}}{p_i \cdot p_j} \right) \)，其中\( q_{ij} \)是字母\( i \)和\( j \)在相关序列精确比对的列中出现的目标频率，\( p_i \)、\( p_j \)是背景概率。PAM系列和BLOSUM系列源于在不同进化分歧下估计这些目标频率的不同方法。<sup>[1](https://www.ncbi.nlm.nih.gov/books/NBK464187/)</sup>

空位采用仿射打分，\( g_k = -(a + b \cdot k) \)<sup>[1](https://www.ncbi.nlm.nih.gov/books/NBK464187/)</sup>，等价于长度为\( k \)的空位得分为\( -(\alpha + (k-1) \cdot \beta) \)，其中\( \alpha \)和\( \beta \)分别是打开和延伸空位的正代价。<sup>[4](https://link.springer.com/article/10.1186/s12859-024-05965-6)</sup> 将延伸得分设得低于打开得分，有利于产生较少但较大的空位，这与生物体内插入缺失的发生方式相符。<sup>[6](https://www.mi.fu-berlin.de/wiki/pub/ABI/SequenceAlignmentWS14/alignment.pdf)</sup>

[动态规划](https://www.edgepedia.org/zh/dynamic-programming)填充一个部分得分矩阵。对于带仿射空位的局部比对，一种递推式为

\[ H(i,j) = \max\{ H(i-1,j-1) + \sigma(q_{i-1}, s_{j-1}),\ E(i,j),\ F(i,j),\ 0 \} \]

其中\( \sigma \)是替换函数，对蛋白质通常采用BLOSUM或PAM矩阵；而\( E(i,j) = \max\{ E(i-1,j) - \beta,\ H(i-1,j) - \alpha \} \)用于追踪某条序列中的空位。<sup>[4](https://link.springer.com/article/10.1186/s12859-024-05965-6)</sup> 最优局部比对得分等于\( H \)中的最大值，可在线性空间\( O(\min\{m, n\}) \)和二次时间\( O(m \cdot n) \)内算出。<sup>[4](https://link.springer.com/article/10.1186/s12859-024-05965-6)</sup> 动态规划比对保证给出得分尽可能高的比对。<sup>[7](https://globin.bx.psu.edu/courses/fall2001/DP.pdf)</sup>

得分的[统计显著性](https://www.edgepedia.org/zh/statistical-significance)遵循Karlin–Altschul极值框架：得分至少为\( s \)的局部比对数目近似服从泊松分布，均值为\( E(s) \approx K \cdot m \cdot n \cdot \exp(-\lambda \cdot s) \)，其中\( \lambda \)和\( K \)由打分矩阵和平均序列组成算出。当\( E(s) < 0.01 \)时，E值近似于P值。<sup>[2](https://link.springer.com/article/10.1186/1471-2105-9-332)</sup>

## 操作步骤

**首先选择比对模式。** 全局比对器要求结果中包含两条序列的全部范围；局部比对则寻找得分最高的片段对。半全局比对是一种中间模式，不对末端空位罚分，适用于一条序列是另一条序列的子序列的情形。<sup>[8](https://dl.acm.org/doi/10.1145/3763229)</sup> 对同一对序列，三种模式可能给出非常不同的结果。<sup>[5](https://www.dnastar.com/manuals/MegAlignPro/18.1/en/topic/choosing-a-pairwise-alignment-method)</sup>

其余步骤是：选择适合这些序列的打分矩阵和空位罚分；用所选模式的递推式填充动态规划矩阵，计入匹配、错配和空位项；从最大元素（局部）或最后一个单元格（全局）出发回溯，恢复出比对。<sup>[6](https://www.mi.fu-berlin.de/wiki/pub/ABI/SequenceAlignmentWS14/alignment.pdf)</sup> 对于长度为\( m \)和\( n \)的序列，标准算法需要\( O(m \cdot n) \)时间和空间，空间可降至\( O(\min\{m, n\}) \)。<sup>[1](https://www.ncbi.nlm.nih.gov/books/NBK464187/)</sup> 对于长序列，精确动态规划可能过慢，此时改用BLAST、FASTA等启发式方法；这些方法在多数情况下表现良好，但对某些序列对会错过最佳比对。<sup>[6](https://www.mi.fu-berlin.de/wiki/pub/ABI/SequenceAlignmentWS14/alignment.pdf)</sup>

## 起源

该问题的动态规划表述，见于Saul B. Needleman与Christian D. Wunsch于1970年发表在《Journal of Molecular Biology》上的论文《A general method applicable to the search for similarities in the amino acid sequence of two proteins》；该文提出了一种可用计算机实现的方法，用于寻找蛋白质氨基酸序列中的相似性。<sup>[9](https://doi.org/10.1016/0022-2836%2870%2990057-4)</sup> 已发表的论述区分了同一问题的两种表述：一些算法最小化距离度量，而Needleman–Wunsch表述则最大化相似性度量。<sup>[10](https://cs.brown.edu/courses/csci1810/fall-2023/resources/ch1_readings/Myers-Overview-Seq-Comp-Algs%202.pdf)</sup>

此后有两个里程碑式的工作留有书目记录。带空位BLAST与[PSI-BLAST](https://www.edgepedia.org/zh/psi-blast)——新一代蛋白质数据库检索程序——由S. Altschul在1997年《Nucleic Acids Research》的论文中报道。<sup>[3](https://doi.org/10.1093/nar/25.17.3389)</sup> CUDASW++3.0通过结合CPU与GPU的SIMD指令加速Smith–Waterman蛋白质数据库检索，由Yongchao Liu、Adrianto Wirawan和Bertil Schmidt于2013年在《BMC Bioinformatics》上报道。<sup>[11](https://doi.org/10.1186/1471-2105-14-117)</sup>

## 变体

**启发式词方法以最优性换取速度。** 最早的词（k元组）[启发式](https://www.edgepedia.org/zh/heuristic)方法以FASTA程序套件的名义出现。<sup>[8](https://dl.acm.org/doi/10.1145/3763229)</sup> FASTA用哈希找出所有匹配的k元组（DNA取4到6），将邻近的元组连成种子，再对高得分对之间的空隙应用Smith–Waterman。<sup>[12](https://www.comp.nus.edu.sg/~wongls/psZ/practical-bioinformatician/ch10-binmaseq/ch10-binmaseq.pdf)</sup> BLAST采用了扩展的种子-扩展词方法，二十多年来成为最广为接受的检索程序。<sup>[8](https://dl.acm.org/doi/10.1145/3763229)</sup> 它启发式地尝试计算最大片段对（MSP）得分，即两条序列中长度相同且得分最高的片段对。<sup>[13](https://courses.cs.duke.edu/spring26/compsci260/resources/AlignmentPapers/1990.blast.pdf)</sup> 带空位BLAST新增了一个触发扩展的判据，以及一种带空位扩展启发式：只考虑得分不低于当前最高分减去\( X_g \)的比对，运行速度约为原始版本的三倍，对弱相似性的灵敏度也有所增强。<sup>[3](https://doi.org/10.1093/nar/25.17.3389)</sup> PSI-BLAST自动将统计显著的BLAST比对合并为位置特异性得分矩阵，用于迭代检索。<sup>[3](https://doi.org/10.1093/nar/25.17.3389)</sup> 间隔种子模型能以BLAST的速度接近Smith–Waterman的灵敏度。<sup>[12](https://www.comp.nus.edu.sg/~wongls/psZ/practical-bioinformatician/ch10-binmaseq/ch10-binmaseq.pdf)</sup>

**精确快速比对重新回归。** 波前比对算法（WFA）在\( O(n \cdot s) \)时间和\( O(s^2) \)内存内计算精确的带空位仿射比对，其中\( n \)是序列长度，\( s \)是最优比对得分，提供与经典算法相同的最优性保证。<sup>[14](https://academic.oup.com/bioinformatics/article-abstract/39/2/btad074/7030690)</sup> 后来的一篇综述则将WFA族方法表述为按得分进行的动态规划，复杂度为\( O(N \cdot D) \)，其中\( N \)是两条序列长度之和，\( D \)是比对得分；在这些长度约定下，两个界是渐近等价的。<sup>[15](https://link.springer.com/article/10.1186/s13059-025-03606-6)</sup> 在硬件上，WFA-GPU在长噪声序列上优于原始的多线程WFA实现，而CUDASW++4.0在H100 GPU上达到最高5.71 TCUPS的Smith–Waterman吞吐量，比包括CUDASW++3.0在内的以往GPU方法提升了一个数量级。<sup>[16](https://pmc.ncbi.nlm.nih.gov/articles/PMC10697739/)</sup><sup> • </sup><sup>[4](https://link.springer.com/article/10.1186/s12859-024-05965-6)</sup> 作为库选项，Biopython的`Bio.Align.PairwiseAligner`使用Needleman–Wunsch、Smith–Waterman、Gotoh（三状态）和Waterman–Smith–Beyer算法执行全局和局部比对。<sup>[17](https://biopython.org/docs/dev/Tutorial/chapter_pairwise.html)</sup>

## 应用

数据库检索是经典用途：用局部比对将查询序列与数据库比较，这是将cDNA与部分测序基因比较时更受青睐的度量。<sup>[13](https://courses.cs.duke.edu/spring26/compsci260/resources/AlignmentPapers/1990.blast.pdf)</sup> 全局比对适合两条序列都必须完整计入的情形，例如将CDS或mRNA序列比对到含内含子的基因，或将因转座元件等原因产生大片段插入而不同的两条序列进行比对。<sup>[5](https://www.dnastar.com/manuals/MegAlignPro/18.1/en/topic/choosing-a-pairwise-alignment-method)</sup> 半全局比对适合一条序列是另一条序列子序列的情形。<sup>[8](https://dl.acm.org/doi/10.1145/3763229)</sup> 双序列比对也作为组件运行在更快的流程中：FASTA只在通过哈希找到的种子锚点之间应用完整的Smith–Waterman。<sup>[12](https://www.comp.nus.edu.sg/~wongls/psZ/practical-bioinformatician/ch10-binmaseq/ch10-binmaseq.pdf)</sup> GPU上的精确带空位仿射比对如今服务于长读长工作负载，WFA-GPU针对的正是长而嘈杂的序列。<sup>[16](https://pmc.ncbi.nlm.nih.gov/articles/PMC10697739/)</sup>

## 局限与替代方案

**低相似度下灵敏度下降。** 对于与查询序列相似度较低的蛋白质，Smith–Waterman局部比对的可靠性急剧下降，即所谓的“暮光区”匹配。<sup>[18](https://doi.org/10.23919/ecc.2003.7086563)</sup> 启发式比对器还增加了第二种损失模式：它们会错过某些序列对的最佳比对。<sup>[6](https://www.mi.fu-berlin.de/wiki/pub/ABI/SequenceAlignmentWS14/alignment.pdf)</sup>

速度与灵敏度的权衡可以量化。无空位比对（如原始BLAST风格）随序列长度线性扩展，其结果对打分系统依赖较弱，但对弱序列相似性不敏感；带空位比对算法则需要长得多的运行时间，随序列长度呈二次依赖。<sup>[19](https://www.thp.uni-koeln.de/~lassig/docs/2000c.pdf)</sup> 精确方法以这种二次代价保持最大灵敏度，GPU实现则报告了大幅加速。<sup>[4](https://link.springer.com/article/10.1186/s12859-024-05965-6)</sup><sup> • </sup><sup>[16](https://pmc.ncbi.nlm.nih.gov/articles/PMC10697739/)</sup>

统计显著性有其条件。Karlin–Altschul模型的有效性依赖于一些限制性假设，包括所比较序列中的残基分布不应“过于不同”。<sup>[2](https://link.springer.com/article/10.1186/1471-2105-9-332)</sup>

在大规模场景下，基于比对的方法通常耗时较长，难以应对下一代测序的数据量，而无比对比较方法提供了一种完全避免构建比对的替代方案。<sup>[20](https://pmc.ncbi.nlm.nih.gov/articles/PMC4017329/)</sup>

## References

1. [Sequence Alignment - Handbook of Discrete and Combinatorial Mathematics (NCBI Bookshelf)](https://www.ncbi.nlm.nih.gov/books/NBK464187/)
2. [Evolution of biological sequences implies an extreme value distribution of type I for both global and local pairwise alignment scores (BMC Bioinformatics, 2008)](https://link.springer.com/article/10.1186/1471-2105-9-332)
3. [S. Altschul (1997). Gapped BLAST and PSI-BLAST: a new generation of protein database search programs. Nucleic Acids Research.](https://doi.org/10.1093/nar/25.17.3389)
4. [CUDASW++4.0: ultra-fast GPU-based Smith–Waterman protein sequence database search](https://link.springer.com/article/10.1186/s12859-024-05965-6)
5. [Choosing a pairwise alignment method, MegAlign Pro user guide](https://www.dnastar.com/manuals/MegAlignPro/18.1/en/topic/choosing-a-pairwise-alignment-method)
6. [Sequence Alignment lecture notes (FU Berlin)](https://www.mi.fu-berlin.de/wiki/pub/ABI/SequenceAlignmentWS14/alignment.pdf)
7. [Notes on Dynamic-Programming Sequence Alignment (Gusfield, via PSU course page)](https://globin.bx.psu.edu/courses/fall2001/DP.pdf)
8. [A Survey on Sequence Alignment Algorithms and State-of-the-Art Aligners](https://dl.acm.org/doi/10.1145/3763229)
9. [A general method applicable to the search for similarities in the amino acid sequence of two proteins (Journal of Molecular Biology, 1970)](https://doi.org/10.1016/0022-2836%2870%2990057-4)
10. [An Overview of Sequence Comparison Algorithms in Molecular Biology](https://cs.brown.edu/courses/csci1810/fall-2023/resources/ch1_readings/Myers-Overview-Seq-Comp-Algs%202.pdf)
11. [Yongchao Liu, Adrianto Wirawan, Bertil Schmidt (2013). CUDASW++ 3.0: accelerating Smith-Waterman protein database search by coupling CPU and GPU SIMD instructions. BMC Bioinformatics.](https://doi.org/10.1186/1471-2105-14-117)
12. [Homology Search Methods (The Practical Bioinformatician, ch. 10)](https://www.comp.nus.edu.sg/~wongls/psZ/practical-bioinformatician/ch10-binmaseq/ch10-binmaseq.pdf)
13. [Basic local alignment search tool (BLAST, 1990)](https://courses.cs.duke.edu/spring26/compsci260/resources/AlignmentPapers/1990.blast.pdf)
14. [Optimal gap-affine alignment in O(s) space (Bioinformatics)](https://academic.oup.com/bioinformatics/article-abstract/39/2/btad074/7030690)
15. [A survey of sequence-to-graph mapping algorithms in the pangenome era | Genome Biology | Springer Nature Link](https://link.springer.com/article/10.1186/s13059-025-03606-6)
16. [WFA-GPU: gap-affine pairwise read-alignment using GPUs](https://pmc.ncbi.nlm.nih.gov/articles/PMC10697739/)
17. [Pairwise sequence alignment, Biopython documentation](https://biopython.org/docs/dev/Tutorial/chapter_pairwise.html)
18. [Alignment algorithms revisited: Alignment algorithms for low similarity protein sequence comparisons](https://doi.org/10.23919/ecc.2003.7086563)
19. [Scaling Laws and Similarity Detection in Sequence Alignment with Gaps](https://www.thp.uni-koeln.de/~lassig/docs/2000c.pdf)
20. [New developments of alignment-free sequence comparison: measures, statistics and next-generation sequencing](https://pmc.ncbi.nlm.nih.gov/articles/PMC4017329/)

---
*Initially written Sep 29, 2026 · Reviewed: Sep 30, 2026 · Edited: Oct 15, 2026 · Last review: Sep 30, 2026*

Topic: 生命与健康 › 生物学基础 › 遗传学与基因组参考资料 › Genomics, sequencing, and genome resources › Sequence assembly, alignment, and mapping

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/pairwise-sequence-alignment

English original: https://www.edgepedia.org/pairwise-sequence-alignment
