This function merges taxa that are sufficiently closely related in the tree in phy_tree(physeq). It is similar to tip_glom(), except that it uses the tree directly, rather than as the basis for hierarchical clustering.

tree_glom(physeq, resolution, criterion = "max_tip_depth", tax_adjust = 1L)

Arguments

physeq

phyloseq-class() or ape::phylo().

resolution

Phylogenetic resolution at which to merge taxa.

criterion

Criterion for determining whether to collapse taxa. See castor::collapse_tree_at_resolution() for details.

tax_adjust

0: no adjustment; 1: phyloseq-compatible adjustment; 2: conservative adjustment (see merge_taxa_vec() for details)

Value

A physeq object with new taxa reflecting the phylogenetically merged groups.

Details

This function uses castor::collapse_tree_at_resolution() from the castor package to determine the groups of taxa to be collapsed; see this function for details about the resolution and criterion parameters.

New taxa are named according to the most abundant taxon of each group. The tree, reference sequences, and (by default) the taxonomy table reflect these "archetype" taxa.

See also

castor::collapse_tree_at_resolution() for more information about the resolution and criterion parameters.

merge_taxa_vec() for more about tax_adjust and general merging behavior

tip_glom() for indirect phylogenetic merging

tax_glom() for merging using taxonomy

Examples

data(GlobalPatterns) ps1 <- subset_taxa(GlobalPatterns, Phylum == "Chlamydiae") ntaxa(ps1)
#> [1] 21
ps2 <- tree_glom(ps1, 0.05)
#> Error in tree_glom(ps1, 0.05): could not find function "tree_glom"
ntaxa(ps2)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'physeq' in selecting a method for function 'ntaxa': object 'ps2' not found
#> Found more than one class "phylo" in cache; using the first, from namespace 'phyloseq'
#> Also defined by ‘tidytree’
plot2 <- phy_tree(ps2) %>% ggtree + geom_tiplab() + geom_label(aes(x = branch, label = round(branch.length, 4)))
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'physeq' in selecting a method for function 'phy_tree': object 'ps2' not found
plot_grid(plot1, plot2)
#> Error in plot_grid(plot1, plot2): object 'plot2' not found