# 史密斯-沃特曼算法

史密斯-沃特曼算法（Smith–Waterman algorithm）是一种动态规划方法，用于寻找两个生物序列的最优局部比对，即一个序列的某个子串与另一个序列的某个子串之间得分最高的比对。[坦普尔·F·史密斯](https://www.edgepedia.org/zh/temple-f-smith)（Temple F. Smith）与迈克尔·S·沃特曼（Michael S. Waterman）于1981年在《分子生物学杂志》（*Journal of Molecular Biology*）上发表该算法，作为对1970年尼德曼-翁施全局比对算法（Needleman–Wunsch global alignment algorithm）的改进<sup>[1](https://pubmed.ncbi.nlm.nih.gov/7265238/)</sup><sup> • </sup><sup>[2](https://academic.oup.com/bioinformatics/article/35/19/3547/5474902)</sup>。

| 关键事实 | 详情 |
|---|---|
| 原始论文 | 《共有分子子序列的识别》，《分子生物学杂志》147(1)：195–197，1981年3月25日，作者坦普尔·F·史密斯与迈克尔·S·沃特曼<sup>[1](https://pubmed.ncbi.nlm.nih.gov/7265238/)</sup> |
| 解决的问题 | 最优局部比对：两个输入序列的子串之间得分最高的比对<sup>[2](https://academic.oup.com/bioinformatics/article/35/19/3547/5474902)</sup> |
| 核心改进 | 将得分为负的单元格置零，并从得分最高的单元格而非矩阵角落开始回溯<sup>[3](https://link.springer.com/article/10.1007/s10791-026-09911-3)</sup> |
| 复杂度 | 对于长度分别为n和m的序列，时间复杂度为O(nm)；完整实现中内存与两序列长度的乘积成正比<sup>[2](https://academic.oup.com/bioinformatics/article/35/19/3547/5474902)</sup><sup> • </sup><sup>[4](https://emboss.sourceforge.net/apps/release/6.0/emboss/apps/water.html)</sup> |
| 空位处理 | 由Gotoh算法（1982）扩展至仿射空位罚分<sup>[2](https://academic.oup.com/bioinformatics/article/35/19/3547/5474902)</sup> |
| 实际作用 | 保证得到最优局部比对，但对于大规模数据库搜索而言过慢，此类场景改用BLAST等启发式工具<sup>[3](https://link.springer.com/article/10.1007/s10791-026-09911-3)</sup><sup> • </sup><sup>[5](https://uol.de/f/5/inst/biologie/ag/systematik/download/Publications/Papers/alignmentMCS2011.pdf)</sup> |

## 背景：全局比对与局部比对

尼德曼与翁施于1970年发表了首个全局比对算法。全局比对对齐两条序列的完整长度，适用于长度相近的序列，例如直系同源基因或蛋白质<sup>[6](https://www.ebi.ac.uk/training/online/courses/guide-to-sequence-analysis-tools/sequence-alignment/pairwise-sequence-alignment/)</sup><sup> • </sup><sup>[7](https://academic.oup.com/bib/article/7/1/113/1745401)</sup>。局部比对则聚焦于最佳匹配区域，舍弃不匹配的部分，适合长度不同或仅共享一个保守结构域的序列<sup>[6](https://www.ebi.ac.uk/training/online/courses/guide-to-sequence-analysis-tools/sequence-alignment/pairwise-sequence-alignment/)</sup><sup> • </sup><sup>[7](https://academic.oup.com/bib/article/7/1/113/1745401)</sup>。

1981年的原始论文将问题表述为：在长序列集合中识别同源程度最高的子序列。该问题仅对无内部插入或缺失的连续片段才简单直接；一般情形需要扩展序列度量——该度量原本用于衡量将一个序列转换为另一个序列所需的最少事件数<sup>[8](https://cs.brown.edu/courses/csci1820/spring-2022/resources/Smith_Waterman_1981.pdf)</sup>。

## 算法原理

与尼德曼-翁施算法一样，史密斯-沃特曼算法填充一个二维评分矩阵，两条序列分别沿两个轴排列，单元格(i, j)保存的是第一条序列以位置i结尾、第二条序列以位置j结尾的前缀的最佳得分。递推公式为<sup>[3](https://link.springer.com/article/10.1007/s10791-026-09911-3)</sup>：

\[ F(i, j) = \max\left\{ 0,\; F(i-1, j-1) + s(x_i, y_j),\; F(i-1, j) + d,\; F(i, j-1) + d \right\} \]

其中\( s(x_i, y_j) \)为比对元素的匹配或不匹配得分，\( d \)为插入或缺失的空位罚分<sup>[3](https://link.springer.com/article/10.1007/s10791-026-09911-3)</sup>。

与尼德曼-翁施算法的三点差异造就了局部而非全局的行为<sup>[5](https://uol.de/f/5/inst/biologie/ag/systematik/download/Publications/Papers/alignmentMCS2011.pdf)</sup>：

1. 评分函数中不匹配取负值而非零。
2. 递推式中加入一个等于零的项，使单元格最小值保持为零；比对实际上在累计得分将要变负的位置重新开始<sup>[3](https://link.springer.com/article/10.1007/s10791-026-09911-3)</sup>。
3. 矩阵遍历的起点和终点可位于矩阵中任意位置。回溯从得分最高的单元格开始（可能存在多个得分相同的最高单元格），一直进行到值为零的单元格为止<sup>[5](https://uol.de/f/5/inst/biologie/ag/systematik/download/Publications/Papers/alignmentMCS2011.pdf)</sup><sup> • </sup><sup>[9](https://www.nature.com/articles/srep02619)</sup>。

其结果是，序列中不匹配的部分被舍弃，只报告相似性集中的区域<sup>[5](https://uol.de/f/5/inst/biologie/ag/systematik/download/Publications/Papers/alignmentMCS2011.pdf)</sup>。

## 评分与统计解释

比对需要一套评分体系：相同或相似字符取正的匹配得分，不匹配取负的罚分，空位取负的罚分以抑制过多的插入或缺失<sup>[6](https://www.ebi.ac.uk/training/online/courses/guide-to-sequence-analysis-tools/sequence-alignment/pairwise-sequence-alignment/)</sup>。对于蛋白质序列，通常使用BLOSUM62等替换矩阵<sup>[5](https://uol.de/f/5/inst/biologie/ag/systematik/download/Publications/Papers/alignmentMCS2011.pdf)</sup>。

局部比对的一个特有性质是：在无关序列模型下，最优局部比对得分服从极值分布。由此可以计算期望值：两条无关序列产生至少与观测值一样高的局部比对得分的频率。期望值低，说明这些序列可能同源，或共享蛋白质结构域、基序等同源元件<sup>[5](https://uol.de/f/5/inst/biologie/ag/systematik/download/Publications/Papers/alignmentMCS2011.pdf)</sup>。

这里的最优性是一种形式性质：给定评分函数，算法输出得分尽可能最高的比对。[统计显著性](https://www.edgepedia.org/zh/statistical-significance)和生物学相关性则须另行评估<sup>[10](https://www.ncbi.nlm.nih.gov/books/NBK20261/)</sup>。

## 计算成本与启发式方法

对于长度为n和m的序列，该算法运行时间为O(nm)，这使得它对于大规模序列搜索而言计算需求过高<sup>[2](https://academic.oup.com/bioinformatics/article/35/19/3547/5474902)</sup>。真正的史密斯-沃特曼实现还需要与序列长度乘积成正比的内存；例如EMBOSS的`water`程序在比对长度分别为10,000,000和1,000的序列时，所需内存与10,000,000,000个字符成正比（分布在两个数组中，一个存整数，一个存浮点数），其文档建议序列较长的用户改用`supermatcher`或`matcher`等替代工具<sup>[4](https://emboss.sourceforge.net/apps/release/6.0/emboss/apps/water.html)</sup>。

对于数据库规模的查询，则改用启发式近似方法。BLAST通过短种子词的无空位比较识别高分片段对，然后对其进行延伸；结果常常并非最优，但比最优动态规划算法快得多<sup>[9](https://www.nature.com/articles/srep02619)</sup>。在基本实现中，BLAST至少比史密斯-沃特曼算法快约50倍，代价是无法保证找到最优局部比对<sup>[5](https://uol.de/f/5/inst/biologie/ag/systematik/download/Publications/Papers/alignmentMCS2011.pdf)</sup>。在需要寻找序列匹配片段的生物学问题中——例如比较不同基因组中的同源基因或寻找共享的蛋白质结构域——史密斯-沃特曼方法仍然有用<sup>[2](https://academic.oup.com/bioinformatics/article/35/19/3547/5474902)</sup>。

## 扩展与实现

Gotoh算法（1982）将尼德曼-翁施算法和史密斯-沃特曼算法同时扩展至仿射空位罚分，即k个连续插入或缺失的罚分为一个空位打开罚分加上k个空位延伸罚分<sup>[2](https://academic.oup.com/bioinformatics/article/35/19/3547/5474902)</sup>。

标准算法只报告单一的最佳局部比对。当两条序列共享不止一个共同区域时——例如一种蛋白质含有一个结构域的单拷贝，另一种含有两个拷贝——单一局部比对可能遗漏第二个及后续的匹配<sup>[4](https://emboss.sourceforge.net/apps/release/6.0/emboss/apps/water.html)</sup>。沃特曼-埃格特算法（Waterman–Eggert algorithm，《分子生物学杂志》197:723–728）通过返回多个最高得分局部比对来解决这一问题；EMBOSS的`matcher`程序通过X. Huang和W. Miller开发的线性空间版本实现了该算法<sup>[11](https://emboss.bioinformatics.nl/cgi-bin/emboss/help/matcher)</sup>。

标准实现包括EMBOSS的`water`工具（用于史密斯-沃特曼局部比对）以及`needle`工具（用于尼德曼-翁施全局比对）<sup>[4](https://emboss.sourceforge.net/apps/release/6.0/emboss/apps/water.html)</sup><sup> • </sup><sup>[12](https://biopython.org/DIST/docs/tutorial/Tutorial-1.79.pdf)</sup>。GPU加速实现（如SW#）已被开发出来，将精确的动态规划局部比对推广到全基因组规模<sup>[13](https://arxiv.org/abs/1304.5966)</sup>。

## References

1. [Smith TF, Waterman MS (1981). Identification of common molecular subsequences. J. Mol. Biol. 147(1):195–7. PubMed.](https://pubmed.ncbi.nlm.nih.gov/7265238/)
2. [Evolution of biosequence search algorithms: a brief survey. Bioinformatics (2019).](https://academic.oup.com/bioinformatics/article/35/19/3547/5474902)
3. [A comprehensive systematic literature review of multiple sequence alignment algorithms. Discover Computing, Springer Nature.](https://link.springer.com/article/10.1007/s10791-026-09911-3)
4. [EMBOSS: water, documentation.](https://emboss.sourceforge.net/apps/release/6.0/emboss/apps/water.html)
5. [Molecular Homology and Sequence Alignment (Lecture C1, Bininda-Emonds), University of Oldenburg.](https://uol.de/f/5/inst/biologie/ag/systematik/download/Publications/Papers/alignmentMCS2011.pdf)
6. [Pairwise sequence alignment, EMBL-EBI Training.](https://www.ebi.ac.uk/training/online/courses/guide-to-sequence-analysis-tools/sequence-alignment/pairwise-sequence-alignment/)
7. [Pairwise sequence alignment, Briefings in Bioinformatics (2006).](https://academic.oup.com/bib/article/7/1/113/1745401)
8. [Smith TF, Waterman MS (1981). Identification of Common Molecular Subsequences, reprint PDF, Brown University.](https://cs.brown.edu/courses/csci1820/spring-2022/resources/Smith_Waterman_1981.pdf)
9. [A comparative assessment and analysis of 20 representative sequence alignment methods for protein structure prediction. Scientific Reports (2013).](https://www.nature.com/articles/srep02619)
10. [Principles and Methods of Sequence Analysis. NCBI Bookshelf.](https://www.ncbi.nlm.nih.gov/books/NBK20261/)
11. [EMBOSS: matcher, documentation.](https://emboss.bioinformatics.nl/cgi-bin/emboss/help/matcher)
12. [Biopython Tutorial, EMBOSS needle and water.](https://biopython.org/DIST/docs/tutorial/Tutorial-1.79.pdf)
13. [SW# - GPU enabled exact alignments on genome scale. arXiv.](https://arxiv.org/abs/1304.5966)

---
*Initially written Oct 15, 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/smith-waterman-algorithm

English original: https://www.edgepedia.org/smith-waterman-algorithm
