Merge taxa in x into a smaller set of taxa defined by the vector group. Taxa whose value in group is NA will be dropped. New taxa will be named according to the most abundant taxon in each group (phyloseq and otu_table objects) or the first taxon in each group (all other phyloseq component objects).

merge_taxa_vec(x, group, reorder = FALSE, tax_adjust = 1L)

# S4 method for phyloseq
merge_taxa_vec(x, group, reorder = FALSE, tax_adjust = 1L)

# S4 method for otu_table
merge_taxa_vec(x, group, reorder = FALSE)

# S4 method for taxonomyTable
merge_taxa_vec(x, group, reorder = FALSE, tax_adjust = 1L)

# S4 method for phylo
merge_taxa_vec(x, group)

# S4 method for XStringSet
merge_taxa_vec(x, group, reorder = FALSE)

Arguments

x

A phyloseq object or component object

group

A vector with one element for each taxon in physeq that defines the new groups. see base::rowsum().

reorder

Logical specifying whether to reorder the taxa by their group values. Ignored if x has (or is) a phylogenetic tree.

tax_adjust

0: no adjustment; 1: phyloseq-compatible adjustment; 2: conservative adjustment

Details

If x is a phyloseq object with a phylogenetic tree, then the new taxa will be ordered as they are in the tree. Otherwise, the taxa order can be controlled by the reorder argument, which behaves like the reorder argument in base::rowsum(). reorder = FALSE will keep taxa in the original order determined by when the member of each group first appears in taxa_names(x); reorder = TRUE will order new taxa according to their corresponding value in group.

The tax_adjust argument controls the handling of taxonomic disagreements within groups. Setting tax_adjust == 0 causes no adjustment; the taxonomy of the new group is set to the archetype taxon (see below). Otherwise, disagreements within a group at a given rank cause the values at lower ranks to be set to NA. If tax_adjust == 1 (the default), then a rank where all taxa in the group are already NA is not counted as a disagreement, and lower ranks may be kept if the taxa agree. This corresponds to the original phyloseq behavior. If tax_adjust == 2, then these NAs are treated as a disagreement; all ranks are set to NA after the first disagreement or NA.

See also

Merging functions that use this function: tax_glom(), tip_glom(), tree_glom()

base::rowsum()

phyloseq::merge_taxa()

Examples

if (FALSE) { # Create 97% OTUs from a phyloseq object with reference sequences # Assume ps is a phyloseq object with refseq slot dna <- refseq(ps) nproc <- 1 # Increase to use multiple processors aln <- DECIPHER::AlignSeqs(dna, processors = nproc) d <- DECIPHER::DistanceMatrix(aln, processors = nproc) clusters <- DECIPHER::IdClusters( d, method = "complete", cutoff = 0.03, processors = nproc ) ps0 <- merge_taxa_vec( ps, group = clusters$cluster, ) }