tax_select: Subset phyloseq object by (partial) taxa names

View source: R/tax_select.R

tax_selectR Documentation

Subset phyloseq object by (partial) taxa names

Description

Convenient name-based taxa selection/filtering of phyloseq object, including approximate name matching. Takes a phyloseq with tax table and a (partial) taxonomic name, or a list/vector of taxonomic names (full or partial matches).

Usage

tax_select(
  ps,
  tax_list,
  ranks_searched = "all",
  strict_matches = FALSE,
  n_typos = 1,
  deselect = FALSE
)

Arguments

ps

phyloseq object

tax_list

e.g. c('g__Bifidobacterium', 'g__Akkermansia', 'g__Bacteroides', 'g__Streptococcus')

ranks_searched

'all' or a list of which taxonomic ranks should be searched for the names in tax_list?

strict_matches

only perfect full name matches allowed if TRUE

n_typos

how many typos to allow in each name? uses agrep approximate matching if > 0

deselect

if TRUE, the matching taxa will be REMOVED instead!

Details

tax_select will also search the otu names/rownames, BUT only for perfect matches.

Value

phyloseq object with fewer taxa

See Also

ps_select for selecting variables in phyloseq sample_data

agrep for the function that powers the approximate matching in tax_select

Examples

# Get example phyloseq object data
data("dietswap", package = "microbiome")
pSeq <- dietswap

# SELECTION EXAMPLES #
a <- pSeq %>% tax_select(tax_list = "Bif", n_typos = 0, ranks_searched = "Genus")
b <- pSeq %>% tax_select(tax_list = "Bifidobacterium", n_typos = 0)
c <- pSeq %>% tax_select(tax_list = "Bif", n_typos = 1)
identical(a, b) # TRUE
identical(a, c) # FALSE

pSeq %>% tax_select(tax_list = "Bifidobactrium") # default 1 typo allowed
one <- pSeq %>% tax_select(tax_list = "Akkarmensia", n_typos = 2)
two <- pSeq %>% tax_select(tax_list = "Akkermansia", n_typos = 0)
identical(one, two) # TRUE

# DESELECTION EXAMPLE # #
pSeq %>% tax_select(tax_list = "Bif", strict_matches = FALSE, deselect = TRUE)
# Incorrect example
# pSeq %>% tax_select(tax_list = "Bif", strict_matches = TRUE) # fails

david-barnett/microViz documentation built on April 17, 2025, 4:25 a.m.