YuLab-SMU / MicrobiotaProcess

:microbe: A comprehensive R package for deep mining microbiome
https://www.sciencedirect.com/science/article/pii/S2666675823000164
183 stars 37 forks source link

PCoA ordination of beta diversity along with genera and other environmental factors? #78

Open marwa38 opened 2 years ago

marwa38 commented 2 years ago

Hi .. This is not an issue but sort of discussion or know-how question if you don't mind.

Any guidance on how to create PCoA while taking into account the genus level of microbiota along with other environmental factors?

Something similar to this figure: image

xiangpin commented 2 years ago

I think you want to perform the rda or cca analysis. You can use mp_cal_rda or mp_cal_cca to do it, then use mp_plot_ord to visualize the result.

library(MicrobiotaProcess)
data(mouse.time.mpse)
genus.abun <- mouse.time.mpse %>% mp_rrarefy() %>% mp_cal_abundance(.abundance=RareAbundance) %>% mp_extract_abundance(taxa.class=Genus, rmun=T)
# In this example, I just randomly select some genus 
> genus.abun %>% dplyr::filter(label %in% c("g__Turicibacter", "g__Neisseria","g__Anaeroplasma", "g__Oscillibacter")) %>% tidyr::unnest(RareAbundanceBySample)
# A tibble: 76 × 6
   label            nodeClass Sample RareAbundance RelRareAbundanceBySam…¹ time
   <fct>            <chr>     <chr>          <int>                   <dbl> <chr>
 1 g__Oscillibacter Genus     F3D0              57                   2.26  Early
 2 g__Oscillibacter Genus     F3D1              76                   3.02  Early
 3 g__Oscillibacter Genus     F3D141             6                   0.238 Late
 4 g__Oscillibacter Genus     F3D142             0                   0     Late
 5 g__Oscillibacter Genus     F3D143            14                   0.556 Late
 6 g__Oscillibacter Genus     F3D144            14                   0.556 Late
 7 g__Oscillibacter Genus     F3D145            12                   0.477 Late
 8 g__Oscillibacter Genus     F3D146            54                   2.14  Late
 9 g__Oscillibacter Genus     F3D147            13                   0.516 Late
10 g__Oscillibacter Genus     F3D148             8                   0.318 Late
# … with 66 more rows, and abbreviated variable name ¹​RelRareAbundanceBySample
# ℹ Use `print(n = ...)` to see more rows
genus.abun %<>% dplyr::filter(label %in% c("g__Turicibacter", "g__Neisseria","g__Anaeroplasma", "g__Oscillibacter")) %>% tidyr::unnest(RareAbundanceBySample)
> genus.abun %>% dplyr::select(label, Sample, RelRareAbundanceBySample) %>% tidyr::pivot_wider(id_cols=Sample, names_from=label, values_from=RelRareAbundanceBySample)
# A tibble: 19 × 5
   Sample g__Oscillibacter g__Turicibacter g__Neisseria g__Anaeroplasma
   <chr>             <dbl>           <dbl>        <dbl>           <dbl>
 1 F3D0              2.26            1.43        0               1.23
 2 F3D1              3.02            0           0               1.03
 3 F3D141            0.238           2.10        0               0
 4 F3D142            0               2.07        0               0
 5 F3D143            0.556           1.59        0               0
 6 F3D144            0.556           3.26        0.0794          0
 7 F3D145            0.477           1.95        0.0397          0.0397
 8 F3D146            2.14            0.834       0               0
 9 F3D147            0.516           2.54        0               0.199
10 F3D148            0.318           2.42        0               0
11 F3D149            0.318           1.47        0               0
12 F3D150            0.913           0.635       0               0
13 F3D2              1.91            0           0               0.318
14 F3D3              0.715           0.278       0               0.318
15 F3D5              2.98            0.874       0               0
16 F3D6              2.38            0           0               0.0397
17 F3D7              1.35            0           0               0.318
18 F3D8              1.71            0.119       0               0.318
19 F3D9              1.59            0           0               0.596
mouse.time.mpse %>% mp_rrarefy() %>% dplyr::left_join(genus.abun, by='Sample') %>% mp_cal_rda(.abundance=RareAbundance, .formula=~g__Oscillibacter + g__Turicibacter + g__Neisseria + g__Anaeroplasma) %>% mp_plot_ord(.group=time, bg.colour='white')

xx

marwa38 commented 1 year ago

Many thanks :)

marwa38 commented 1 year ago

I can't update you if it worked with me or not because I am still stuck at rarefaction thing https://github.com/YuLab-SMU/MicrobiotaProcess/issues/76 @xiangpin