joey711 / phyloseq

phyloseq is a set of classes, wrappers, and tools (in R) to make it easier to import, store, and analyze phylogenetic sequencing data; and to reproducibly share that data and analysis with others. See the phyloseq front page:
http://joey711.github.io/phyloseq/
582 stars 187 forks source link

how is it possible to perform PERMANOVA with phyloseq? #689

Closed AndreaQ7 closed 7 years ago

AndreaQ7 commented 7 years ago

Hi I'm trying to perform a PERMANOVA on bray curtis distance matrix. I was following the M. Berry tutorial on phyloseq ( http://deneflab.github.io/MicrobeMiseq/demos/mothur_2_phyloseq.html ) but i found a limit in the permanova section. Indeed I have samples that have been sample 4 times under the column "Treatment" of my sample_data and I would like to compare each category with the other for the distance matrix. Does someone knows how to perform this kind of analysis with phyloseq? Thank you all

vmikk commented 7 years ago

@AndreaQ7 It should be quite straightforward to perform a PERMANOVA. Does this code works for you?

library(vegan)
metadata <- as(sample_data(physeq), "data.frame")

adonis(distance(physeq, method="bray") ~ Treatment,
       data = metadata)

where physeq is your phyloseq-object

AndreaQ7 commented 7 years ago

Hi Vmikk thanks for your help it works but it is not exactly what i'm looking for. In fact thanks your script i can obtain a general p-value for the bray curtis distance matrix, but what i would like to understand is which is the p value associated to every group of treatment. I mean within the "Treatment" column I have T0 , T10, T20, T30 thus the same individuals have been sampled 4 time during a treatment, and I would like to understand the bray distance p value between T0-T10 or T10-T20 and so on....

vmikk commented 7 years ago

If you are talking about multiple pairwise comparisons, you may start with a for-loop:

To get all treatment combinations try:

combn(x = levels(metadata$Treatment), m = 2)

Do not forget to adjust p-values for multiple comparisons (e.g., Bonferroni correction).

AndreaQ7 commented 7 years ago

for your last command line I obtain this message Error in combn(x = levels(metadata$Treatment), m = 2) : n < m

vmikk commented 7 years ago

It's difficult to suggest somithing without a reproducible example.

With combn you should obtain a matrix with 2 rows and N columns, where N is the number of pairwise combinations. E.g., cbn <- combn(x = letters[1:4], m = 2) The main idea is that you may loop through each column of cbn like:

for(i in 1:ncol(cbn)){
 subset_samples(physeq, SampleType %in% cbn[,i])
**... your code here ...**
}
AndreaQ7 commented 7 years ago

ok now it works thanks :)

restivve commented 4 years ago

How can I get this to print as a matrix? Right now it is printing each pairwise combination, but doesn't tell me which 2 sites it is comparing.

cbn <- combn(x=levels(met_df$Site), m = 2) for(i in 1:ncol(cbn)){ physeq_subs <- subset_samples(dat_lessKK, Site %in% cbn[,i]) metadata_sub <- as(sample_data(physeq_subs), "data.frame") permanova_sites <-adonis(distance(physeq_subs, method="bray") ~ Site, data = metadata_sub) }

andrebolerbarros commented 2 years ago

Can this also be performed using pairwise.perm.manova function from RVaideMemoire package?

https://www.rdocumentation.org/packages/RVAideMemoire/versions/0.9-81-2/topics/pairwise.perm.manova

It's easier and already includes the p-value adjustment