← Back to list

Decoding Evolutionary Paths: Neighbor Joining (NJ) Method for Constructing Phylogenetic Trees

How species connected through evolution? Neighbor Joining-efficient method used to construct phylogenetic trees based on pairwise distance.

Monika Mate · 2025-07-09 20:16 · 2 claps · 4.1 min read
#phylogenetics #biotechnology #evolutionary-biology #methodology #steps
Open on Medium ↗
Wiki topics: BTC · Biotechnology EVO · Evolution & Ecology 💻 · Programming 📟 · Gadgets & IoT 🎬 · Film & Television

Decoding Evolutionary Paths: Neighbor Joining (NJ) Method for Constructing Phylogenetic Trees

The evolutionary relationships between different species are like unwinding threads that connects them over time. Constructing a phylogenetic tree is crucial for visualizing diversification and shared common ancestors. Among various methods, the Neighbor-Joining (NJ) method stands out for its efficiency and accuracy.

The NJ method constructs phylogenetic trees by using distance matrix to determine the closest evolutionary relationships among taxa. This method is applicable in generating both phylogenetic and phenetic trees. The evolutionary distance yields phylogenetic trees and trait-based similarities yields phenetic trees.

Let’s construct a phylogenetic tree with NJ method

It includes two essential stages: Initiation and Iteration.

  • Initiation:

Begins with the distance matrix. Define a set of leaf nodes (T) and determine their count (L). These nodes represent the terminal ends of the tree and do not have any child node.

  • Iteration:

Perform repeated calculations, updating relationships step-by-step, until the complete tree structure is derived.

Stage 1: Initiation

The distance matrix or starting matrix shows number of species and pairwise distance between them.

Starting matrix for constructing the phylogenetic tree using NJ method

Starting matrix for constructing the phylogenetic tree using NJ method

From the above matrix,

Set of leaf nodes (T) = {A, B, C, D}

Number of leaf nodes (L) = 4

Stage 2: Iteration 1

Step 1: Calculate net divergence (r) of each node

The formula for calculating net divergence is —

r(i) = [1/(L-2)] * [d(ij) + d(ik) + d(il)]

i,j,k,l are the leaf nodes and L is the number of nodes

Using above formula, I calculated net divergence for each node in the starting matrix —

Net divergence calculations for each node

Net divergence calculations for each node

Step 2: Adjusting distance (D) for each node pair

Formula for adjusting distance foe each node pair —

D(ij) = d(ij) - [r(i) + r(j)]

Using this formula, the adjusted distance for each node pair is —

calculations for adjusting distance for each node pair

calculations for adjusting distance for each node pair

The pair of nodes with the smallest adjusted distance are neighbors. In this case there is tie between the pairs (AB) and (CD). Let’s consider pair (AB) for further calculations.

Step 3: Create a new node ‘Z’ that connects A and B.

Create a new node ‘Z’ which will be a parent node connecting child nodes A and B. To calculate the distance child to parent, the formula is

d(ik) = [d(ij) + r(i) + r(j)] / 2

here, k is parent node and i and j are child nodes.

Distance calculations from each neighbor node to the connecting node

Distance calculations from each neighbor node to the connecting node

The above calculation denotes the distance between A and B from node ‘Z’. From this, the first two branches of the tree can be drawn as follows —

First two branches of the phylogenetic tree

First two branches of the phylogenetic tree

Step 4: Reconstructing the distance matrix

The child nodes (A and B) are now replaced by node ‘Z’ which will change the distance matrix, but we will need to calculate the distance of remaining nodes from this new node.

Reconstructing the distance matrix

Reconstructing the distance matrix

Calculating the distance from new node to non-child nodes using the formula—

d(mk) = [d(im) + d(jm) - d(ij)] / 2

here, m is non-child node.

Using the formula, the distance for non-child node to new node are —

From this distance calculations, the updated matrix will be —

Iteration 2:

Step 5: Using the updated distance matrix, calculating net divergence (r) of each node.

Set of leaf nodes (T) = {Z, C, D}

Number of leaf nodes (L) = 3

Net divergence of each node using updated distance matrix

Net divergence of each node using updated distance matrix

Step 6: Adjusting distance (D) for each node pair

calculations for adjusting distance for each node

calculations for adjusting distance for each node

All of the pairs are tied for lowest adjusted distance, let’s select the first pair in the list (ZC).

Step 7: Define a new node (Y) that connects the neighbors Z and C.

Calculating distance from each neighbor node to the connecting new node (Y). Here Y is parent node and Z & C are child nodes.

Calculations for parent to child node

Calculations for parent to child node

From this distance, the phylogenetic tree will look like —

Step 8: Calculating remaining distance

Calculation for remaining distances

Calculation for remaining distances

The final phylogenetic tree derived from the calculations will look like following -

Final phylogenetic tree using NJ method

Final phylogenetic tree using NJ method

The NJ method is an effective approach for constructing phylogenetic trees. It does not assume any molecular clock of constant rate of evolution and can handle genetic as well as morphological data. By using an iterative clustering process based on distance matrix, it provides a reliable way to infer evolutionary relationships. The only drawback is it can cause loss of evolutionary signals as it reduces sequence data into pairwise distance.


메타데이터
post_id
324fba11ebb3
slug
decoding-evolutionary-paths-neighbor-joining-nj-method-for-constructing-phylogenetic-trees-324fba11ebb3
url
https://medium.com/@monikammate/decoding-evolutionary-paths-neighbor-joining-nj-method-for-constructing-phylogenetic-trees-324fba11ebb3
canonical_url
https://medium.com/@monikammate/decoding-evolutionary-paths-neighbor-joining-nj-method-for-constructing-phylogenetic-trees-324fba11ebb3
author_url
https://medium.com/@monikammate
status
ok
fetched_at
2026-06-09 15:37:30