Skip to content

Repository files navigation

phylogenetic-tree-cpp

A C++ tool for constructing phylogenetic trees from biological sequence data using four distance-based algorithms. Takes DNA/protein sequences in FASTA format, computes evolutionary distances, and outputs trees in Newick format.

Project Details

  • College: CVR College of Engineering, Hyderabad
  • Department: Computer Science and Engineering
  • Academic Year: 2025–2026
  • Guide: Dr. C. Ramesh, Professor & Associate Dean, Dept. of CSE

Features

Four tree construction algorithms:

  • Neighbor-Joining (NJ): Fast, widely used, O(n³) complexity
  • Fitch-Margoliash (FM): Weighted least squares optimization, accurate branch lengths
  • UPGMA: Ultrametric trees, assumes molecular clock, O(n²) complexity
  • Minimum Evolution (ME): Minimizes total branch length, good for varying evolutionary rates

Three distance calculation methods:

  • Fractional k-mer count (default) — normalized k-mer frequency differences
  • Mahalanobis distance (-m) — accounts for k-mer correlation
  • Cosine distance (-c) — compares k-mer profile vectors

Sample Input Files

File Sequences Description
test.fasta 2 Pseudomonas & Stenotrophomonas genomes
Orthologs.fasta 5 Orthologous genes across 5 species
Orthologs2.fasta 5 Second set of orthologous genes
nucOrth.fasta 5 Nucleotide orthologs

Compilation

g++ -o phylogenetic-tree-cpp main.cpp tree.cpp neighbor_joining.cpp fitch_margoliash.cpp upgma.cpp minimum_evolution.cpp tree_io.cpp operations.cpp eval.cpp -std=c++11

Usage

./phylogenetic-tree-cpp <input.fasta> [options]

Options

Flag Description
-nj Neighbor-Joining (default)
-fm Fitch-Margoliash
-upgma UPGMA
-me Minimum Evolution
-m Mahalanobis distance
-c Cosine distance
-k INT K-mer length (default: 8)
-v Verbose output

Examples

# Basic run — Neighbor-Joining
./phylogenetic-tree-cpp test.fasta

# UPGMA algorithm
./phylogenetic-tree-cpp test.fasta -upgma

# Fitch-Margoliash algorithm
./phylogenetic-tree-cpp test.fasta -fm

# Minimum Evolution algorithm
./phylogenetic-tree-cpp test.fasta -me

# Mahalanobis distance with k-mer length 6
./phylogenetic-tree-cpp Orthologs.fasta -m -k 6

# Cosine distance with verbose output
./phylogenetic-tree-cpp nucOrth.fasta -c -v

Output

The program generates output.txt in Newick format, for example:

(Pseudomonas:1.109149, Stenotrophomonas:1.109149);

This can be visualized using:

  • FigTree — desktop application
  • iTOL (Interactive Tree of Life) — online at itol.embl.de

Project Structure

phylogenetic-tree-cpp/
├── main.cpp                  # Entry point, argument parsing
├── tree.hpp                  # Header — structs and declarations
├── tree.cpp                  # Tree class implementation
├── neighbor_joining.cpp      # NJ algorithm
├── fitch_margoliash.cpp      # FM algorithm
├── upgma.cpp                 # UPGMA algorithm
├── minimum_evolution.cpp     # ME algorithm
├── operations.cpp            # K-mer distance calculations
├── tree_io.cpp               # FASTA reading, file writing
├── eval.cpp                  # Bootstrap analysis
├── me.cpp                    # ME standalone demo
├── test.fasta                # Sample input (2 sequences)
├── Orthologs.fasta           # Sample input (5 sequences)
├── Orthologs2.fasta          # Sample input (5 sequences)
├── nucOrth.fasta             # Sample input (5 sequences)
└── output.txt                # Sample output (Newick tree)

How It Works

Input FASTA file
      ↓
Read & parse DNA sequences
      ↓
Count k-mer frequencies
      ↓
Compute pairwise distance matrix
      ↓
Run selected algorithm (NJ / UPGMA / FM / ME)
      ↓
Output Newick tree → output.txt

Contributors

  • R. Himabindhu — 23B81A05CN
  • J. Nimitha — 23B81A05CZ
  • K. Sai Hruthik — 23B81A05DJ — GitHub

References

  • Saitou & Nei (1987) — The Neighbor-Joining Method, Molecular Biology and Evolution
  • Fitch & Margoliash (1967) — Construction of Phylogenetic Trees, Science
  • Sneath & Sokal (1973) — Numerical Taxonomy

About

C++ tool for constructing phylogenetic trees from DNA sequences using NJ, UPGMA, Fitch-Margoliash and Minimum Evolution algorithms

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages