Beta diversity wrapper
Arguments
- counts
An OTU abundance matrix where each column is a sample, and each row is an OTU. Any object coercible with
as.matrix()
can be given here, as well asphyloseq
,rbiom
,SummarizedExperiment
, andTreeSummarizedExperiment
objects.- metric
The name of a beta diversity metric. Current options are
c('bray_curtis', 'sorenson', 'canberra', 'euclidean', 'gower', 'jaccard', 'kulczynski', 'manhattan', 'unweighted_unifrac', 'weighted_unifrac', 'normalized_unifrac', 'generalized_unifrac', 'variance_adjusted_unifrac')
. Supports flexible name matching - see details section below. Options are also available vianames(metrics$beta)
.- ...
Additional options to pass through to the called function. I.e.
tree
,weighted
,pairs
,alpha
, orcpus
.
Details
Flexible name matching
Case insensitive and partial matching. Any runs of non-alpha characters are
converted to underscores. E.g. metric = 'Bray Curtis
selects Bray-Curtis.
UniFrac names can be shortened to the first letter plus "unifrac". E.g.
uunifrac
, w_unifrac
, or V UniFrac
. These also support partial matching,
but the primary options take precedence. For instance metric = 'g'
selects Gower, whereas metric = 'gu'
selects Generalized UniFrac.
Finished code should always use the full primary option name to avoid ambiguity with future additions to the metrics list.
Examples
# Example counts matrix
ex_counts
#> Saliva Gums Nose Stool
#> Streptococcus 162 793 22 1
#> Bacteroides 2 4 2 611
#> Corynebacterium 0 0 498 1
#> Haemophilus 180 87 2 1
#> Propionibacterium 1 1 251 0
#> Staphylococcus 0 1 236 1
# Bray-Curtis distances
beta_div(ex_counts, 'bray_curtis')
#> Saliva Gums Nose
#> Gums 0.5905768
#> Nose 0.9601770 0.9704797
#> Stool 0.9916667 0.9906729 0.9926199
# Kulczynski distances
beta_div(ex_counts, 'k')
#> Saliva Gums Nose
#> Gums 0.4925704
#> Nose 0.9475164 0.9703510
#> Stool 0.9909509 0.9903586 0.9921546
# Generalized UniFrac distances
beta_div(ex_counts, 'GUniFrac', tree = ex_tree)
#> Saliva Gums Nose
#> Gums 0.4471644
#> Nose 0.8215129 0.7607876
#> Stool 0.9727827 0.9784242 0.9730332