Skip to content

ELTEbioinformatics/treetune

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

treetune

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.

Features

  • Prune trees using one of three algorithms:
    • CPA — Circular Pruning Algorithm
    • IQR — Interquartile Range-based pruning
    • PSFA — 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().

Installation

Install the development version from GitHub:

install.packages("remotes")
remotes::install_github("ELTEbioinformatics/treetune")

Load the package:

library(treetune)

Input

treetune expects a phylogenetic tree file in one of the following formats:

  • .nwk
  • .newick
  • .tree

Algorithms

PSFA: Primitive Straight-Forward Approach

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.

CPA: Circular Pruning Algorithm

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.

IQR: Interquartile Range-based pruning

prune_tree_IQR() uses an interquartile range-based rule to identify outlier branch lengths or tips for pruning.

Output

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.

Combining algorithms

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.

Example workflow

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)

Citation

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/

About

treetune R package for pruning phylogenetic trees

Resources

License

Stars

5 stars

Watchers

3 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages