A phylogenetic visualization toolkit for creating "tree of trees" representations, where each tip of a main phylogenetic tree is associated with its own subtree. This project combines tree visualization with consensus tree computation using Frequency Difference Consensus Tree (FDCT) methods.
This repository provides tools for:
- Creating hierarchical "tree of trees" visualizations using Python (toytree/toyplot)
- Computing Frequency Difference Consensus Trees (FDCT) using a Python wrapper for FACT2
- Working with phylogenetic trees in Newick format
tree_of_trees/
├── data/ # Data files and tree datasets
├── scripts/
│ └── python/
│ ├── tree_of_trees_toytree.py # Main visualization script
│ └── fdct/ # FDCT consensus tree module
│ ├── fdct.py # Python wrapper for FACT2
│ ├── example.py # Usage examples
│ ├── setup.sh # Setup script for FACT2
│ └── README.md # FDCT module documentation
└── README.md
The tree_of_trees_toytree.py script creates sophisticated visualizations where:
- A main phylogenetic tree serves as the backbone structure
- Each leaf node displays an associated subtree
- Uses toytree and toyplot libraries for rendering
The FDCT module provides a Python wrapper for computing Frequency Difference Consensus Trees:
- Processes multiple phylogenetic trees to find consensus
- Supports taxa encoding/decoding for non-integer identifiers
- Returns consensus trees in Newick format
- Python 3.x
- Required Python libraries:
- toytree
- toyplot
- numpy
To use the FDCT functionality:
cd scripts/python/fdct
bash setup.shThis script will:
- Fetch FACT2 source code from https://github.com/Mesh89/FACT2
- Download the required BOOST library
- Compile FACT2
- Generate the FACT++ executable
Note: The setup script has been tested on Linux systems and GitHub Codespaces.
import toytree
import toyplot
# Define your main tree
main_tree_newick = "(16:0.1115,(...))"
# Define subtrees for each tip
subtrees_newick = {
"1": "(0:1.0,(1:1.0,4:1.0):1.0,(3:1.0,2:1.0):1.0);",
"2": "(0:1.0,(1:1.0,3:1.0):1.0,(2:1.0,4:1.0):1.0);",
# ... more subtrees
}
# Run tree_of_trees_toytree.py to generate visualizationfrom fdct import fdct
# List of trees in Newick format
trees = [
"(0:1.0,(1:1.0,4:1.0):1.0,(3:1.0,2:1.0):1.0);",
"(0:1.0,(1:1.0,3:1.0):1.0,(2:1.0,4:1.0):1.0);",
# ... more trees
]
# Compute consensus tree
consensus = fdct(trees, exec="path/to/FACT++", encode=False)
print(consensus)
# If taxa are not integers, use encode=True
consensus = fdct(trees, exec="path/to/FACT++", encode=True)- input: List of trees as Newick strings
- exec: Path to the FACT++ executable
- encode: Set to
Trueif taxa identifiers are not integers (default:False)
Returns the consensus tree as a Newick string. Note that the consensus tree does not include branch lengths.
See scripts/python/fdct/example.py for a complete working example of FDCT usage with sample phylogenetic trees.
- FACT2 (Frequency-based Aggregate Consensus Tree): https://github.com/Mesh89/FACT2
- Toytree documentation: https://toytree.readthedocs.io/
MIT License
Contributions are welcome! Please feel free to submit a Pull Request.
For questions or issues, please open an issue on GitHub or contact the tahiri-lab team.