unifrac: Compute Weighted and Unweighted UniFrac distance matrices.

Description Usage Arguments Value Examples

Description

This is the function called internally by beta.div, but is made visible here so you can use it with matrices and trees without having to first convert them to BIOM objects.

Usage

1
unifrac(biom, weighted = TRUE, tree = NULL)

Arguments

biom

A matrix, simple_triplet_matrix, or BIOM object, as returned from read.biom. For matrices, the rows and columns are assumed to be the taxa and samples, respectively.

weighted

Use weighted UniFrac, which takes abundance into account rather than simply presence/absence.

tree

A phylo object providing a phylogenetic tree for the taxa names in biom. If tree=NULL, then the tree will be loaded from biom, if encoded there.

Value

A distance matrix of class dist.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
    library(rbiom)
    
    infile <- system.file("extdata", "hmp50.bz2", package = "rbiom")
    biom <- read.biom(infile)
    biom <- select(biom, 1:10)
    
    dm <- unifrac(biom)
    plot(hclust(dm), cex=.8)
    as.matrix(dm)[1:4,1:4]
    
    # Using a custom matrix and tree
    mtx <- matrix(sample.int(12*20), ncol=20)
    dimnames(mtx) <- list(LETTERS[1:12], letters[1:20])
    tree <- ape::as.phylo(hclust(dist(mtx)))
    
    dm <- unifrac(mtx, tree=tree)
    as.matrix(dm)[1:4,1:4]
    

rbiom documentation built on Nov. 5, 2021, 9:11 a.m.