calculateUnifrac: Calculate weighted or unweighted (Fast) Unifrac distance

calculateUnifracR Documentation

Calculate weighted or unweighted (Fast) Unifrac distance

Description

This function calculates the Unifrac distance for all sample-pairs in a TreeSummarizedExperiment object. The function utilizes rbiom:unifrac().

Usage

calculateUnifrac(x, tree, ...)

## S4 method for signature 'ANY,phylo'
calculateUnifrac(x, tree, weighted = FALSE, ...)

## S4 method for signature 'TreeSummarizedExperiment,missing'
calculateUnifrac(
  x,
  assay.type = assay_name,
  assay_name = exprs_values,
  exprs_values = "counts",
  tree.name = tree_name,
  tree_name = "phylo",
  transposed = FALSE,
  ...
)

runUnifrac(
  x,
  tree,
  weighted = FALSE,
  node.label = nodeLab,
  nodeLab = NULL,
  ...
)

Arguments

x

a numeric matrix or a TreeSummarizedExperiment object containing a tree.

Please note that runUnifrac expects a matrix with samples per row and not per column. This is implemented to be compatible with other distance calculations such as dist as much as possible.

tree

if x is a matrix, a phylo object matching the matrix. This means that the phylo object and the columns should relate to the same type of features (aka. microorganisms).

...

optional arguments not used.

weighted

TRUE or FALSE: Should use weighted-Unifrac calculation? Weighted-Unifrac takes into account the relative abundance of species/taxa shared between samples, whereas unweighted-Unifrac only considers presence/absence. Default is FALSE, meaning the unweighted-Unifrac distance is calculated for all pairs of samples.

assay.type

a single character value for specifying which assay to use for calculation.

assay_name

a single character value for specifying which assay to use for calculation. (Please use assay.type instead. At some point assay_name will be disabled.)

exprs_values

a single character value for specifying which assay to use for calculation. (Please use assay.type instead.)

tree.name

a single character value for specifying which tree will be used in calculation. (By default: tree.name = "phylo")

tree_name

Deprecated. Use tree.name instead.

transposed

Logical scalar, is x transposed with cells in rows, i.e., is Unifrac distance calculated based on rows (FALSE) or columns (TRUE). (By default: transposed = FALSE)

node.label

if x is a matrix, a character vector specifying links between rows/columns and tips of tree. The length must equal the number of rows/columns of x. Furthermore, all the node labs must be present in tree.

nodeLab

Deprecated. Use node.label instead.

Details

Please note that if calculateUnifrac is used as a FUN for runMDS, the argument ntop has to be set to nrow(x).

Value

a sample-by-sample distance matrix, suitable for NMDS, etc.

References

http://bmf.colorado.edu/unifrac/

See also additional descriptions of Unifrac in the following articles:

Lozupone, Hamady and Knight, “Unifrac - An Online Tool for Comparing Microbial Community Diversity in a Phylogenetic Context.”, BMC Bioinformatics 2006, 7:371

Lozupone, Hamady, Kelley and Knight, “Quantitative and qualitative (beta) diversity measures lead to different insights into factors that structure microbial communities.” Appl Environ Microbiol. 2007

Lozupone C, Knight R. “Unifrac: a new phylogenetic method for comparing microbial communities.” Appl Environ Microbiol. 2005 71 (12):8228-35.

Examples

data(esophagus)
library(scater)
calculateUnifrac(esophagus, weighted = FALSE)
calculateUnifrac(esophagus, weighted = TRUE)
# for using calculateUnifrac in conjunction with runMDS the tree argument
# has to be given separately. In addition, subsetting using ntop must
# be disabled
esophagus <- runMDS(esophagus, FUN = calculateUnifrac, name = "Unifrac",
                    tree = rowTree(esophagus),
                    assay.type = "counts",
                    ntop = nrow(esophagus))
reducedDim(esophagus)

FelixErnst/mia documentation built on June 19, 2024, 3:51 a.m.