mia
mia copied to clipboard
Rarified beta diversity calculations
Would be nice to have beta diversity calculations with rarefaction, as described in Pat Schloss recent preprint.
Now, this can be achieved by using vegan::avgdist
function as follows.
I am not sure if we need to create a new wrapper for this in mia or anything. Although it could be potentially simplified. But not much.
Shall we just explain in OMA how it works? What do you think?
library(mia)
library(vegan)
library(scater)
data(GlobalPatterns)
tse <- GlobalPatterns
x <- assay(tse, "counts")
tse <- runMDS(tse, assay.type="counts",
ntop=nrow(GlobalPatterns), # runMDS option; set to total number of features in tse so that they are not filtered
FUN = avgdist, # Custom distance that includes rarefaction, from vegan package
sample=min(colSums(assay(tse, "counts"))), # rarefaction depth (min read count over samples)
distfun=vegdist, # Use vegdist distance function
dmethod = "bray", # Bray-Curtis dissimilarity
iterations = 10, # 10x rarefaction for distance calculations should be fine
)
p <- scater::plotReducedDim(tse, "MDS")
print(p)