# 邻接法

邻接法（Neighbor joining）是一种基于距离的算法，它从分类单元之间的成对进化距离矩阵构建一棵无根系统发育树。它以凝聚方式工作：从一棵星状树开始，反复连接能使总枝长减少最多的那一对操作分类单元（OTU），直到剩下三个 OTU，唯一的无根树随之确定。<sup>[1](https://academic.oup.com/mbe/article/4/4/406/1029664/The-neighbourjoining-method-a-new-method-for)</sup> 由于输出的是无根二叉分枝树，它不要求比对遵循分子钟。<sup>[2](https://cs.rice.edu/~ogilvie/comp571/neighbor-joining/)</sup>

| 关键事实 | 详情 |
|---|---|
| 输入与输出 | 成对进化距离矩阵；带估计枝长的无根二叉树<sup>[1](https://academic.oup.com/mbe/article/4/4/406/1029664/The-neighbourjoining-method-a-new-method-for)</sup> |
| 配对选择 | 最小化 Q 准则 \( Q(i,j) = (n-2)d(i,j) - \sum_{k} d(i,k) - \sum_{k} d(j,k) \)<sup>[3](https://www.math.canterbury.ac.nz/~m.steel/Non_UC/files/research/NJ.pdf)</sup> |
| 复杂度 | 对 n 个分类单元，时间复杂度 \( O(n^{3}) \)，空间复杂度 \( O(n^{2}) \)<sup>[4](http://www.stat.yale.edu/~jtc5/papers/NeighborJoining_Lacey-Chang_MathBiosci_06.pdf)</sup> |
| 准确性保证 | 若 \( l_{\infty} \) 距离误差低于最小边长的一半，则拓扑正确；在更大的半径内，没有方法能保证成功<sup>[5](https://csaws.cs.technion.ac.il/~moran/COURSES/papers/atteson99.pdf)</sup> |
| 起源 | 斋藤（Saitou）与根井（Nei），《分子生物学与进化》（Molecular Biology and Evolution）4(4):406–425，1987年7月<sup>[1](https://academic.oup.com/mbe/article/4/4/406/1029664/The-neighbourjoining-method-a-new-method-for)</sup> |
| 最著名的变体 | BIONJ，在速率变化的树上平均拓扑误差约降低20%<sup>[6](https://academic.oup.com/mbe/article-lookup/doi/10.1093/oxfordjournals.molbev.a025808)</sup> |
| 现代规模 | 基于 GPU 的距离方法可在不到7小时内从1000万条未比对序列重建树<sup>[7](https://zenodo.org/records/19586238)</sup> |

## 工作原理

在每个阶段，算法为每一对剩余分类单元计算一个值，并合并使 Q 准则最小的一对，通常写作：\( Q(i,j) = (n-2)\,d(i,j) - \sum_{k} d(i,k) - \sum_{k} d(j,k) \)，其中 n 是当前分类单元数。<sup>[3](https://www.math.canterbury.ac.nz/~m.steel/Non_UC/files/research/NJ.pdf)</sup> 对于真实的树度量，使 Q 最小的一对是一个“樱桃”（cherry），即通过单个内部节点相连的一对叶节点，这正是该方法应当首先连接的对象。<sup>[8](https://ar5iv.labs.arxiv.org/html/cs/0602041)</sup> 布莱恩特（Bryant）证明，Q 准则是唯一的线性、置换等变且一致的选择准则。<sup>[8](https://ar5iv.labs.arxiv.org/html/cs/0602041)</sup>

该准则有一种优化解释：使用树长的广义公式，NJ 贪心地最小化平衡最小进化（BME）得分，在每一步选择使整棵树长度减少最多的那一对。<sup>[3](https://www.math.canterbury.ac.nz/~m.steel/Non_UC/files/research/NJ.pdf)</sup> 对于纯加性树——即没有回复替换或平行替换的树——该方法已被证明在每一步都选择真正的邻居并恢复正确的无根树；从 n 个分类单元开始，NJ 执行 \( n - 3 \) 次连接，留下三个 OTU，它们定义最终的无根拓扑。<sup>[1](https://academic.oup.com/mbe/article/4/4/406/1029664/The-neighbourjoining-method-a-new-method-for)</sup> 贪心最小化并不总能达到全局最优：NJ 区域不是凸的，而且高度不相关的树在 BME 下可能同为最优，因此 NJ 并不总是输出 BME 最优树。<sup>[9](https://link.springer.com/article/10.1186/1748-7188-3-5)</sup>

## 如何执行

实践者在 \( n \times n \) 距离矩阵上运行以下循环：<sup>[2](https://cs.rice.edu/~ogilvie/comp571/neighbor-joining/)</sup>

1. 计算 Q 矩阵，每个元素 \( Q(i,j) = (n-2) \cdot d(i,j) - \sum_{k} d(i,k) - \sum_{k} d(j,k) \)。
2. 合并非对角线 Q 值最低的一对 f、g。
3. 以枝长 \( L_{A} = d(f,g)/2 + \bigl(\sum_{k} d(f,k) - \sum_{k} d(g,k)\bigr) / 2(n-2) \) 和 \( L_{B} = d(f,g) - L_{A} \) 连接新节点 u，这一方案本质上与最小二乘法相同。<sup>[1](https://academic.oup.com/mbe/article/4/4/406/1029664/The-neighbourjoining-method-a-new-method-for)</sup>
4. 更新到新节点的距离，\( d(u,k) = \bigl(d(f,k) + d(g,k) - d(f,g)\bigr)/2 \)，并将矩阵缩减一行一列。
5. 重复直到剩下三个 OTU，此时只存在唯一一棵无根树。<sup>[1](https://academic.oup.com/mbe/article/4/4/406/1029664/The-neighbourjoining-method-a-new-method-for)</sup>

标准算法运行时间为 \( O(n^{3}) \)，空间为 \( O(n^{2}) \)，这就是它受到一线生物学家欢迎、用于大型数据集的原因。<sup>[4](http://www.stat.yale.edu/~jtc5/papers/NeighborJoining_Lacey-Chang_MathBiosci_06.pdf)</sup> 距离通常来自校正后的成对差异；一种常见选择是由比对计算出的朱克斯–坎托距离（Jukes–Cantor distance）\( d = -0.75 \ln\bigl(1 - (4/3)p\bigr) \)。<sup>[2](https://cs.rice.edu/~ogilvie/comp571/neighbor-joining/)</sup> 实现中将更新推广为 \( D(n,k) = a \cdot D(i,k) + (1-a) \cdot D(j,k) - a \cdot D(n,i) - (1-a) \cdot D(n,j) \)，其中 \( a = 1/2 \) 重现原始的等方差方案，其他值遵循加斯屈埃尔（Gascuel）的 BIONJ 方差模型；软件随后可用中点法对无根结果重新定根。<sup>[10](https://www.mathworks.com/help/bioinfo/ref/seqneighjoin.html)</sup>

## 起源

它建立在更早的距离方法之上：萨塔思（Sattath）与特沃斯基（Tversky）1977年的加性树程序，<sup>[11](https://doi.org/10.1007/bf02293654)</sup> 李（Li）1981年发表于《美国国家科学院院刊》（PNAS）的方法——该方法校正 UPGMA 以处理不等进化速率，并使用菲奇–马戈利阿什（Fitch–Margoliash）枝长估计且不允许负枝长，<sup>[12](https://doi.org/10.1073/pnas.78.2.1085)</sup> 以及 UPGMA 和法里斯（Farris）方法本身。在原始模拟中，NJ 和萨塔思–特沃斯基方法在恢复正确无根树方面通常优于 UPGMA、法里斯方法、李方法以及立野（Tateno）及其同事的改良法里斯方法。<sup>[1](https://academic.oup.com/mbe/article/4/4/406/1029664/The-neighbourjoining-method-a-new-method-for)</sup>

数学基础后来才得以确立。斋藤与根井以及斯图迪尔（Studier）与开普勒（Keppler）最初的一致性证明受到米尔金（Mirkin，1996）的质疑，但由加斯屈埃尔（1997）和阿特森（Atteson，1999）修补，布莱恩特（2005）后来给出了一个简单的一致性证明。<sup>[3](https://www.math.canterbury.ac.nz/~m.steel/Non_UC/files/research/NJ.pdf)</sup> 德斯佩尔（Desper）与加斯屈埃尔2002年的 BME 算法将该准则与显式的树长优化联系起来，并促成了 FastME 软件。<sup>[13](https://doi.org/10.1089/106652702761034136)</sup>

## 变体

**BIONJ** 遵循 NJ 的凝聚式方案，但使用距离估计的方差与协方差的一阶模型。<sup>[6](https://academic.oup.com/mbe/article-lookup/doi/10.1093/oxfordjournals.molbev.a025808)</sup> 在速率变化的模型树上，相对 NJ 的平均误差降低约为20%，在速率高度变化且最大成对差异接近每位点1.0个替换时升至50%以上。<sup>[6](https://academic.oup.com/mbe/article-lookup/doi/10.1093/oxfordjournals.molbev.a025808)</sup> **FastME** 应用 BME 准则并进行拓扑重排，在模拟中显示出比 NJ 更好的拓扑准确性，这一结果由温（Vinh）与冯·黑泽勒（von Haeseler，2005）在多达5000个分类单元的系统发育树上得到确认。<sup>[3](https://www.math.canterbury.ac.nz/~m.steel/Non_UC/files/research/NJ.pdf)</sup>

侧重速度的变体包括埃利亚斯（Elias）与拉格伦（Lagergren）的快速邻接法（FNJ），达到最优的 \( O(n^{2}) \) 运行时间，<sup>[14](https://doi.org/10.1016/j.tcs.2008.12.040)</sup> 谢尼曼（Sheneman）、埃文斯（Evans）和福斯特（Foster）的 Clearcut，是松弛邻接法的一种快速实现，<sup>[15](https://doi.org/10.1093/bioinformatics/btl478)</sup> 豪（Howe）、贝特曼（Bateman）和德宾（Durbin）的 QuickTree，用于构建巨大的蛋白质序列树，<sup>[16](https://doi.org/10.1093/bioinformatics/18.11.1546)</sup> 以及迈伦德（Mailund）与佩德森（Pedersen）的 QuickJoin。<sup>[17](https://doi.org/10.1093/bioinformatics/bth359)</sup> RapidNJ 使用带排序距离矩阵的分支定界启发式来缩短平均运行时间，但与标准 NJ 一样需要 \( O(n^{2}) \) 空间。<sup>[18](https://www.scitepress.org/Papers/2010/27157/27157.pdf)</sup> RapidNJ 和 NINJA 保证精确的 NJ 树，而松弛邻接法和 FNJ 只对加性距离矩阵保证这一点。<sup>[19](https://doi.org/10.1093/bioinformatics/btac774)</sup> 克劳森（Clausen）于2022年提出的动态邻接法（DNJ）和启发式邻接法（HNJ），在不增加内存的情况下将 NJ 扩展到数百万个分类单元；DNJ 保证在 \( O(d \cdot n^{2}) \) 时间和 \( O(n^{2}) \) 空间内生成精确的 NJ 树。<sup>[19](https://doi.org/10.1093/bioinformatics/btac774)</sup> 王（Wang）及其同事于2023年提出的 DecentTree 是 NJ 和 BIONJ 的优化并行 C++ 实现，也是唯一一个在12小时内完成每一项分析的受测实现，代价是内存约为 RapidNJ 的1.5–3倍。<sup>[20](https://doi.org/10.1093/bioinformatics/btad536)</sup> 普赖斯（Price）、德哈尔（Dehal）和阿金（Arkin）的 FastTree 使用序列谱而非完整距离矩阵来计算大型最小进化树。<sup>[21](https://doi.org/10.1093/molbev/msp077)</sup>

## 应用

NJ 仍被广泛用于为更昂贵的最大似然方法生成起始树，从诸如 [SARS-CoV-2](https://www.edgepedia.org/zh/sars-cov-2) 基因组等超大型比对中快速建树，以及为比对算法提供指导树。<sup>[22](https://www.ovid.com/journals/bioinf/fulltext/10.1093/bioinformatics/btad536~decenttree-scalable-neighbour-joining-for-the-genomic-era)</sup> 基于 NJ 的距离矩阵是 MASH、Minimap2、MINTyper、KMA 和 EverGreen 等软件的基础，这一点已在全球和国家层面对细菌病原体和 SARS-CoV-2 的监测中得到验证。<sup>[19](https://doi.org/10.1093/bioinformatics/btac774)</sup> 在分治流程中，NJMerge 用约束树扩展 NJ，并在某些模型下具有统计一致性，可在具有低度或中度不完全谱系分选的1000个分类单元、1000个基因的数据集上降低物种树误差中位数。<sup>[23](https://link.springer.com/article/10.1186/s13015-019-0151-x)</sup> 在最大规模上，基于 GPU 的 DIPPER 工具结合分治策略、放置策略和即时距离计算器，达到 \( O(N \log N) \) 运行时间和 \( O(N) \) 空间，可在单块 NVIDIA RTX A6000 上于不到7小时内从1000万条未比对序列重建系统发育树。<sup>[7](https://zenodo.org/records/19586238)</sup>

## 局限与替代方法

NJ 的输出是无根树，因此与 UPGMA 和 WPGMA 不同，它不要求多序列比对是沿超度量树上的分子钟生成的；代价是 NJ 本身不提供根，需要根的软件会另行执行重新定根步骤，例如中点定根。<sup>[2](https://cs.rice.edu/~ogilvie/comp571/neighbor-joining/)</sup><sup> • </sup><sup>[10](https://www.mathworks.com/help/bioinfo/ref/seqneighjoin.html)</sup> 其主要统计弱点是易受距离估计误差影响：对毛虫树的分析表明，对于多项式长度的序列，NJ 准则很可能被一个非邻居叶对最小化，这表明它容易受到大量不精确距离估计的影响。<sup>[4](http://www.stat.yale.edu/~jtc5/papers/NeighborJoining_Lacey-Chang_MathBiosci_06.pdf)</sup> 阿特森的保证在这个意义上是紧的：当 \( l_{\infty} \) 误差低于最小边长的一半时，NJ 能正确重建拓扑，而在更大的半径内，没有方法能被保证成功。<sup>[5](https://csaws.cs.technion.ac.il/~moran/COURSES/papers/atteson99.pdf)</sup>

模拟证据支持其在大规模下的实际准确性：当序列数从32增加到4096时，树准确性仅下降约5%，即使存在广泛的速率变化或核苷酸组成偏倚与转换/颠换偏好；在该研究中，用似然法估计所有成对距离最多校正了60%的 NJ 树错误，这表明许多失败可追溯到距离矩阵而非算法本身。<sup>[24](https://pmc.ncbi.nlm.nih.gov/articles/PMC491989/)</sup> 与统计方法相比，权衡在于精度与规模：最大似然和贝叶斯方法精度更高，但运行时间相比 NJ 很高，且不能很好地扩展到大型数据集。<sup>[18](https://www.scitepress.org/Papers/2010/27157/27157.pdf)</sup>

## References

1. [The neighbor-joining method: a new method for reconstructing phylogenetic trees (Saitou & Nei, MBE 1987)](https://academic.oup.com/mbe/article/4/4/406/1029664/The-neighbourjoining-method-a-new-method-for)
2. [Neighbor joining, Rice COMP 571 course notes (with Python implementation)](https://cs.rice.edu/~ogilvie/comp571/neighbor-joining/)
3. [Neighbor-Joining Revealed (Gascuel & Steel, MBE 23(11):1997–2000, 2006)](https://www.math.canterbury.ac.nz/~m.steel/Non_UC/files/research/NJ.pdf)
4. [Lacey & Chang (Mathematical Biosciences 2006): NJ signal-to-noise analysis](http://www.stat.yale.edu/~jtc5/papers/NeighborJoining_Lacey-Chang_MathBiosci_06.pdf)
5. [Atteson: The performance of neighbor-joining methods of phylogenetic reconstruction (Algorithmica 1999)](https://csaws.cs.technion.ac.il/~moran/COURSES/papers/atteson99.pdf)
6. [BIONJ: an improved version of the NJ algorithm based on a simple model of sequence data (Gascuel, MBE 1997)](https://academic.oup.com/mbe/article-lookup/doi/10.1093/oxfordjournals.molbev.a025808)
7. [DIPPER: DIstance-based Phylogenetic PlacER (Zenodo software release record)](https://zenodo.org/records/19586238)
8. [Why neighbor-joining works (Mihaescu, Levy, Pachter, arXiv cs/0602041)](https://ar5iv.labs.arxiv.org/html/cs/0602041)
9. [On the optimality of the neighbor-joining algorithm (Algorithms for Molecular Biology, 2008)](https://link.springer.com/article/10.1186/1748-7188-3-5)
10. [MathWorks seqneighjoin documentation](https://www.mathworks.com/help/bioinfo/ref/seqneighjoin.html)
11. [Shmuel Sattath, Amos Tversky (1977). Additive Similarity Trees. Psychometrika.](https://doi.org/10.1007/bf02293654)
12. [W H Li (1981). Simple method for constructing phylogenetic trees from distance matrices.. Proceedings of the National Academy of Sciences.](https://doi.org/10.1073/pnas.78.2.1085)
13. [Richard Desper, Olivier Gascuel (2002). Fast and Accurate Phylogeny Reconstruction Algorithms Based on the Minimum-Evolution Principle. Journal of Computational Biology.](https://doi.org/10.1089/106652702761034136)
14. [Isaac Elias, Jens Lagergren (2008). Fast neighbor joining. Theoretical Computer Science.](https://doi.org/10.1016/j.tcs.2008.12.040)
15. [Luke Sheneman, Jason Evans, James A. Foster (2006). Clearcut: a fast implementation of relaxed neighbor joining. Bioinformatics.](https://doi.org/10.1093/bioinformatics/btl478)
16. [Kevin Howe, Alex Bateman, Richard Durbin (2002). QuickTree: building huge Neighbour-Joining trees of protein sequences. Bioinformatics.](https://doi.org/10.1093/bioinformatics/18.11.1546)
17. [Thomas Mailund, Christian N. S. Pedersen (2004). QuickJoin, fast neighbour-joining tree reconstruction. Bioinformatics.](https://doi.org/10.1093/bioinformatics/bth359)
18. [Building very large neighbour-joining trees (ERapidNJ, SCITEPRESS 2010)](https://www.scitepress.org/Papers/2010/27157/27157.pdf)
19. [Philip T L C Clausen (2022). Scaling neighbor joining to one million taxa with dynamic and heuristic neighbor joining. Bioinformatics.](https://doi.org/10.1093/bioinformatics/btac774)
20. [Weiwen Wang and colleagues (2023). DecentTree: scalable Neighbour-Joining for the genomic era. Bioinformatics.](https://doi.org/10.1093/bioinformatics/btad536)
21. [M. N. Price, P. S. Dehal, A. P. Arkin (2009). FastTree: Computing Large Minimum Evolution Trees with Profiles instead of a Distance Matrix. Molecular Biology and Evolution.](https://doi.org/10.1093/molbev/msp077)
22. [DecentTree: scalable Neighbour-Joining for the genomic era (Bioinformatics, btad536, 2023)](https://www.ovid.com/journals/bioinf/fulltext/10.1093/bioinformatics/btad536~decenttree-scalable-neighbour-joining-for-the-genomic-era)
23. [Statistically consistent divide-and-conquer pipelines for phylogeny estimation using NJMerge](https://link.springer.com/article/10.1186/s13015-019-0151-x)
24. [Prospects for inferring very large phylogenies by using the neighbor-joining method (Tamura, Nei, Kumar, PNAS 2004)](https://pmc.ncbi.nlm.nih.gov/articles/PMC491989/)

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

Topic: 生命与健康 › 生物学基础 › 演化与生命史 › 系统发育学与系统分类学

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/neighbor-joining

English original: https://www.edgepedia.org/neighbor-joining
