-
Notifications
You must be signed in to change notification settings - Fork 10
/
CoAbundantTaxa.Rmd
executable file
·85 lines (72 loc) · 2.58 KB
/
CoAbundantTaxa.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
title: "Identify Co-abundant taxa groups"
author: "Leo Lahti, Sudarshan Shetty et al."
bibliography:
- bibliography.bib
output:
BiocStyle::html_document:
number_sections: no
toc: yes
toc_depth: 4
toc_float: true
self_contained: true
thumbnails: true
lightbox: true
gallery: true
use_bookdown: false
highlight: haddock
---
<!--
%\VignetteIndexEntry{microbiome tutorial}
%\VignetteEngine{knitr::rmarkdown}
%\usepackage[utf8]{inputenc}
%\VignetteEncoding{UTF-8}
-->
**Co-abundant groups of taxa**
Get data
```{r cag-1}
library(microbiome)
pseq <- atlas1006
pseq.rel <- microbiome::transform(pseq, "compositional")
```
Identify co-abundant taxa.
```{r cag-2}
# get median abundances
median_abund = apply(abundances(pseq.rel), MARGIN = 1, FUN = median)
# select taxa with median abundance of more than or equal to 0.01
abundant_taxa = abundances(pseq)[median_abund >= 0.01, ]
# check how many taxa
nrow(abundant_taxa)
# check which taxa
rownames(abundant_taxa)
```
Use Spearman's correlation to identify which of the co-abundant groups show correlation.
```{r cag-1b}
# cor() is from `stats` package
spearman_matrix = cor(t(abundant_taxa), method = "spearman")
# hclust() is from `stats` package
spearman_tree = hclust(dist(spearman_matrix), method = "ward")
plot(spearman_tree)
```
Using the `heat` function in `microbiome pkg` now compare the correlation with the tree above.
```{r plot-heat}
spearman_long_df <- reshape2::melt(spearman_matrix)
head(spearman_long_df)
heat(spearman_long_df, "Var1","Var2",
order.rows = TRUE, order.cols = TRUE) +
theme_bw() + theme(axis.text.x = element_text(angle = 90))
```
Validation of CAGs
```{r}
# Validation of CAGs
# Randomly split the dataset, compute a correlation matrix and run a Mantel test
subsample = sample(c(1:300), size = 220, replace = F)
train_data = abundant_taxa[,subsample]
test_data = abundant_taxa[,-subsample]
train_spearman = cor(t(train_data), method = "spearman")
test_spearman = cor(t(test_data), method = "spearman")
vegan::mantel(as.dist(train_spearman), as.dist(test_spearman), permutations=999)
```
Further reading:
[de la Cuesta-Zuluaga, J., Corrales-Agudelo, V., Velásquez-Mejía, E.P. et al. Gut microbiota is associated with obesity and cardiometabolic disease in a population in the midst of Westernization. Sci Rep 8, 11356 (2018).](https://doi.org/10.1038/s41598-018-29687-x)
[Claesson, M., Jeffery, I., Conde, S. et al. Gut microbiota composition correlates with diet and health in the elderly. Nature 488, 178–184 (2012).](https://doi.org/10.1038/nature11319)