PhylteR, a tool for analyzing, visualizing and filtering phylogenomics datasets

PhylteR detects, visualizes, and removes outlier sequences in phylogenomic datasets. An outlier is a taxon–gene association whose evolutionary distances are unusually discordant with the signal shared by the other genes. PhylteR can start from a collection of gene trees or directly from pairwise distance matrices, and it supports datasets in which some taxa are absent from some genes.

The package is designed for a common phylogenomic problem: a sequence may be misidentified, contaminated, paralogous, incorrectly aligned, or otherwise inconsistent with the dominant evolutionary signal. Instead of judging each gene tree in isolation or requiring a reference species tree, PhylteR compares all genes jointly and identifies the particular gene–taxon cells responsible for discordance.

How PhylteR works

  1. Gene trees are converted to patristic or nodal distance matrices. Users may also provide distance matrices directly through the R API.
  2. Missing taxa are added and their pairwise distances are imputed from the other genes. Each matrix can be normalized so that differences in overall evolutionary rate do not dominate the comparison.
  3. DISTATIS, an extension of multidimensional scaling for multiple distance matrices (Abdi et al. 2005), estimates a weighted compromise representing the signal shared across genes.
  4. For every taxon in every gene, PhylteR measures the distance between its gene-specific position and its position in the compromise. An adjusted boxplot rule for skewed distributions (Hubert & Vandervieren 2008) flags unusually large deviations. The optional island rule avoids incorrectly flagging neighbouring taxa displaced by a strong outlier.
  5. Candidate outliers are removed and the analysis is repeated. A proposed removal is retained only when it improves inter-gene concordance; iteration stops when the improvement falls below stop.criteria. Entire anomalous genes can also be detected using the k2 threshold.

The result records the initial and final analyses, accepted outliers, discarded genes, concordance scores, and the objects needed by PhylteR's summary and visualization functions. Taxon labels must be unique within each gene.

What is new in this version

This branch preserves PhylteR's statistical method and R API while making the existing algorithm faster, less memory-intensive, easier to run, and easier to validate:

On the audited Carnivora example (125 genes and 53 species), the default analysis was 2.43× faster (median 0.586 s versus 1.425 s). Synthetic tests showed a 2.26× speedup for missing-data imputation and a 39.81× speedup for repeated gene-to-compromise distance calculations. At 400 species × 150 genes, peak resident memory fell by 3.7% for DISTATIS and 7.2% for imputation. These measurements were made on one documented system and should not be read as universal performance guarantees. All reference comparisons preserved the outlier identities, their order, the optimization trajectory, and numerical results within tolerance. See the performance and correctness audit for the environment, complete results, limitations, and optimization roadmap.

The novelty of this release is therefore primarily computational and practical: it retains the published PhylteR procedure and results while reducing avoidable work, providing a non-interactive workflow, and adding an auditable correctness baseline for future optimization. The current implementation still holds dense distance matrices in memory and is not yet an out-of-core solution for very large datasets.

PhylteR builds on Phylo-MCOA (de Vienne et al. 2012) and is implemented in R with a small native C++ numerical core. For function documentation and a step-by-step biological example, visit the PhylteR website.

Note: if you don't use R or don't want to use R, containerized versions of phylter are also available (Docker and Singularity): https://damiendevienne.github.io/phylter/articles/phyltercontainer.html

if you use phylter, please cite: Comte, A., Tricou, T., Tannier, E., Joseph, J., Siberchicot, A., Penel, S., Allio, R., Delsuc, F., Dray, S., de Vienne, D.M. (2023). PhylteR: Efficient Identification of Outlier Sequences in Phylogenomic Datasets, Molecular Biology and Evolution, 40(11) msad234, https://doi.org/10.1093/molbev/msad234

Installation

The current release of PhylteR is available on CRAN.

Installation is as easy as typing what follows at the R command prompt:

install.packages("phylter")

To test the optimized version described above before it reaches CRAN, install this branch from GitHub:

  1. Install the release version of remotes from CRAN:
install.packages("remotes")
  1. Install the development version of phylter from GitHub:
remotes::install_github(
  "damiendevienne/phylter",
  ref = "perf/matrix-optimizations-cli-audit"
)

  1. Once installed, the package can be loaded:
library("phylter")

PhylteR requires R 4.0 or later. Package installation also requires the system libraries needed by its R dependencies.

Usage

A command-line frontend is included in exec/phylter. It accepts either a multi-Newick file or a directory containing one Newick tree per gene:

phylter --trees gene_trees.nwk --out analysis
phylter --trees gene_trees/ --out analysis --report --save-rds

The CLI uses the installed R package, so its scientific results are the same as those of the R API. It writes separate, headered TSV files for detected outliers and genes discarded during preparation, plus a text summary and session metadata. --report adds a PDF report and --save-rds saves the complete R result. Existing output files are not overwritten. Run phylter --help for all options, or see local installation and CLI usage for setup and the complete output contract.

Here is a brief introduction to the use phylter on a collection of gene trees. For more detailed explanations and a use case example, please visit https://damiendevienne.github.io/phylter/.

1. With the read.tree function from the ape package, read trees from external file and save as a list called trees.

if (!requireNamespace("ape", quietly = TRUE))
   install.packages("ape")
trees <- ape::read.tree("treefile.tre")

2. (optional) Read or get gene names somewhere (same order as the trees) and save it as a vector called names.

3. Run phylter on your trees (see details below for possible options).

results <- phylter(trees, gene.names = names)

Options

The phylter function is called as follows by default:

phylter(X, bvalue = 0, distance = "patristic", k = 3, k2 = k, Norm = "median", 
 Norm.cutoff = 0.001, gene.names = NULL, test.island = TRUE, 
 verbose = TRUE, stop.criteria = 1e-5, InitialOnly = FALSE, normalizeby = "row", 
 parallel = TRUE)

Arguments are as follows:

4. Analyze the results

To get the list of outliers detected by phylter, simply type:

results$Final$Outliers

In addition, many functions allow looking at the outliers detected and comparing before and after phyltering.

# Get a summary: nb of outliers, gain in concordance, etc.
summary(results)

# Show the number of species in each gene, and how many per gene are outliers
plot(results, "genes") 

# Show the number of genes where each species is found, and how many are outliers
plot(results, "species") 

# Compare before and after genes x species matrices, highlighting missing data and outliers 
# identified (not efficient for large datasets)
plot2WR(results) 

# Plot the dispersion of data before and after outlier removal. One dot represents one 
# gene x species association
plotDispersion(results) 

# Plot the genes x genes matrix showing pairwise correlation between genes
plotRV(results) 

# Plot optimization scores during optimization
plotopti(results) 

5. Save the results of the analysis to an external file, for example to perform cleaning on raw alignments or pruning gene trees based on the results from phylter.

write.phylter(results, file = "phylter.out")

References


For comments, suggestions and bug reports, please open an issue on this GitHub repository.