unifrac {rbiom}R Documentation

Compute Weighted and Unweighted UniFrac distance matrices.

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

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

    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]
    

[Package rbiom version 1.0.3 Index]