Skip to contents

Get summary taxa abundances.

Usage

taxa_sums(
  biom,
  rank = -1,
  sort = NULL,
  lineage = FALSE,
  unc = "singly",
  transform = "none"
)

taxa_means(
  biom,
  rank = -1,
  sort = NULL,
  lineage = FALSE,
  unc = "singly",
  transform = "none"
)

taxa_apply(
  biom,
  FUN,
  rank = -1,
  sort = NULL,
  lineage = FALSE,
  unc = "singly",
  transform = "none",
  ...
)

Arguments

biom

An rbiom object, such as from as_rbiom(). Any value accepted by as_rbiom() can also be given here.

rank

What rank(s) of taxa to display. E.g. "Phylum", "Genus", ".otu", etc. An integer vector can also be given, where 1 is the highest rank, 2 is the second highest, -1 is the lowest rank, -2 is the second lowest, and 0 is the OTU "rank". Run biom$ranks to see all options for a given rbiom object. Default: -1.

sort

Sort the result. Options: NULL, "asc", or "desc", where NULL will not sort the result. "asc" will sort in ascending order (smallest to largest), and "desc" in descending order (largest to smallest). Ignored when the result is not a simple numeric vector. Default: NULL

lineage

Include all ranks in the name of the taxa. For instance, setting to TRUE will produce Bacteria; Actinobacteria; Coriobacteriia; Coriobacteriales. Otherwise the taxa name will simply be Coriobacteriales. You want to set this to TRUE when unc = "asis" and you have taxa names (such as Incertae_Sedis) that map to multiple higher level ranks. Default: FALSE

unc

How to handle unclassified, uncultured, and similarly ambiguous taxa names. Options are:

"singly" -

Replaces them with the OTU name.

"grouped" -

Replaces them with a higher rank's name.

"drop" -

Excludes them from the result.

"asis" -

To not check/modify any taxa names.

Default: "singly"

Abbreviations are allowed.

transform

Transformation to apply. Options are: c("none", "rank", "log", "log1p", "sqrt", "percent"). "rank" is useful for correcting for non-normally distributions before applying regression statistics. Default: "none"

FUN

The function to apply to each row of the taxa_matrix().

...

Optional arguments to FUN.

Value

For taxa_sums and taxa_means, a named numeric vector. For taxa_apply, a named vector or list with the results of FUN. The names are the taxa IDs.

See also

Examples

    library(rbiom) 
    
    taxa_sums(hmp50) %>% head(4)
#>     Abiotrophia Acidaminococcus   Acinetobacter  Actinobacillus 
#>             135              62              44             242 
    
    taxa_means(hmp50, 'Family') %>% head(5)
#>  Acidaminococcaceae    Actinomycetaceae       Aerococcaceae      Alcaligenaceae 
#>               14.58               16.92                2.86               11.28 
#> Alicyclobacillaceae 
#>                0.12 
    
    taxa_apply(hmp50, max) %>% head(5)
#>     Abiotrophia Acidaminococcus   Acinetobacter  Actinobacillus     Actinomyces 
#>              78              59              42             100             105 
    
    taxa_apply(hmp50, fivenum) %>% head(5)
#> $Abiotrophia
#> [1]  0  0  0  1 78
#> 
#> $Acidaminococcus
#> [1]  0  0  0  0 59
#> 
#> $Acinetobacter
#> [1]  0  0  0  0 42
#> 
#> $Actinobacillus
#> [1]   0   0   0   2 100
#> 
#> $Actinomyces
#> [1]   0   0   1  21 105
#>