treetune is an R package for pruning phylogenetic trees.
It provides R implementations of the tree-pruning algorithms from the Python
treepruner package.
The package is designed for phylogenetic trees that may contain unusually long branches, erroneous taxa, contamination, sequencing artifacts, or other tips that can distort downstream evolutionary analyses.
- Prune trees using one of three algorithms:
CPA— Circular Pruning AlgorithmIQR— Interquartile Range-based pruningPSFA— Primitive Straight-Forward Approach
- Protect selected tips from pruning where supported by the algorithm.
- Save the pruned tree as a Newick file.
- Combine two pruning algorithms in a single workflow using
combine_algorithms().
Install the development version from GitHub:
install.packages("remotes")
remotes::install_github("ELTEbioinformatics/treetune")Load the package:
library(treetune)treetune expects a phylogenetic tree file in one of the following formats:
.nwk.newick.tree
prune_tree_PSFA() identifies the longest edge and calculates the sizes of the two components resulting from its removal.
If the size of the smaller component is within the tolerance range and the edge was excessively long, removes it.
prune_tree_CPA() prunes the trees to make them roughly circular.
It chooses a random "root" and removes leaves that are beyond a specified distance.
The number of chosen roots is set by the user. Among all the pruned trees, the algorithm picks the best one.
Two conditions must be satisfied:
-Do not remove too many leaves.
-It should not be possible to significantly reduce the radius by removing only a few nodes.
prune_tree_IQR() uses an interquartile range-based rule to identify outlier
branch lengths or tips for pruning.
Each pruning function returns the pruned tree and the percentage of tips remaining.
The pruned tree is also written to disk using the filename supplied to output.
combine_algorithms() runs two pruning algorithms sequentially.
This is useful when you want to apply two different pruning strategies to the
same tree. For example, you may first remove extreme long-branch outliers using
IQR, then refine the tree shape using CPA.
library(treetune)
# Input tree
tree_file <- "example_tree.nwk"
# Run one pruning algorithm
cpa_result <- prune_tree_CPA(
tree_file = tree_file,
threshold = 90,
output = "cpa_pruned_tree.nwk"
)
# Inspect the result
cpa_result$percent_remaining
plot(cpa_result$tree)
# Run two algorithms sequentially
combined_result <- combine_algorithms(
tree_file = tree_file,
algorithms = c("IQR", "CPA"),
total_percent_remaining = 90,
prune_percentages = c(4, 6),
output = "combined_tree.nwk"
)
# Inspect the final tree
combined_result$percent_remaining_original
plot(combined_result$tree)If you use treetune, please cite this GitHub repository.
This R package is based on the Python treepruner package:
treepruner: A Python package for pruning phylogenetic trees.
https://pypi.org/project/treepruner/