-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathancombc_example.Rmd
188 lines (140 loc) · 4.15 KB
/
ancombc_example.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
---
title: "Exploratory analysis for Comparative Metataxonomy"
author: "Roberto Siani"
date: "24.06.21"
---
# SETUP
Set up working environment: packages and default graphic themes.
```{r, cache = TRUE, echo = FALSE, include = FALSE}
# pacman to install and load libraries
if (!require("pacman")) install.packages(
"pacman",
verbose = F)
# BiocManager for Bioconductor libraries
if (!require("BiocManager")) install.packages(
"BiocManager",
verbose = F)
# devtools for GitHub repositories
if (!require("devtools")) install.packages(
"devtools",
verbose = F)
# GitHub libraries
pacman::p_load_gh(
"jbisanz/qiime2R",
"benjjneb/decontam",
"mikemc/speedyseq",
"adw96/breakaway",
"adw96/DivNet")
# install/load the remainder of libraries
pacman::p_load(
tidyverse,
vegan,
ape,
microbiome,
ggpubr,
patchwork,
hrbrthemes,
phangorn,
DECIPHER,
MicrobiotaProcess,
hues)
# load sensible themes and palettes
source("~/Desktop/library/scripts/helpeR.R")
theme_set(my_theme)
select = dplyr::select
transform = microbiome::transform
```
# INPUT
Congratulations, now that you have your phyloseq object prepared, you can finally start to explore the microbial wonderland in your samples
```{r, echo = FALSE, include = FALSE}
# load your uBiome dataset
load("~/Desktop/ancombc/uBiome_181021_1511.RData")
# again, take a good look at your results. Look at the sparsity and the percentage of singletons, select your variables of interest
summarize_phyloseq(uBiome)
## check your samples and groups
table(meta(uBiome)$Description, meta(uBiome)$Bacteria)
## set up palette
uBiome =
uBiome %>%
subset_samples(Bacteria == "WT1" | Bacteria == "LjR176")
palette_list =
list(
Description = c("#cc7722", "#2277cc"))
map(palette_list,
~swatches::show_palette(.x))
```
### ANCOM-BC
```{r}
p_load(ANCOMBC)
res_ancombc =
ancombc(uBiome,
formula = "Description",
p_adj_method = "fdr",
conserve = T)
## Description
res_df =
res_ancombc$res$beta %>%
as.data.frame() %>%
rownames_to_column("ASV") %>%
left_join(
res_ancombc$res$q_val %>%
as.data.frame() %>%
rownames_to_column("ASV"),
by = "ASV",
suffix = c("_beta", "_q")) %>%
left_join(
res_ancombc$res$W %>%
as.data.frame() %>%
rownames_to_column("ASV")) %>%
rename(DescriptionInoculated_W = DescriptionInoculated) %>%
mutate(DescriptionInoculated_DA = as.factor(case_when(
DescriptionInoculated_q > 0.01 & DescriptionInoculated_q <= 0.05 ~ "*",
DescriptionInoculated_q > 0.001 & DescriptionInoculated_q <= 0.01 ~ "**",
DescriptionInoculated_q > 0.0001 & DescriptionInoculated_q <= 0.001 ~ "***",
DescriptionInoculated_q <= 0.0001 ~ "****",
TRUE ~ "ns"))) %>%
pivot_longer(-ASV,
names_to = c("var", ".value"),
names_sep = "_") %>%
mutate(var = factor(var, levels = c("DescriptionInoculated"),
labels = c("<- Control|Treatment ->")))
res_df$DA = relevel(res_df$DA, ref = "ns")
plot_7 =
ggplot(res_df) +
geom_point(
aes(x = beta,
y = -log10(q + 1e-5),
color = DA)) +
scale_color_manual(values = michelangelo$grad3) +
facet_wrap(~var) +
theme(legend.position = "right") +
labs(y = expression(-log[10]~q-value))
relAbu_df =
res_df %>%
filter(q <= 0.05) %>%
left_join(tax_table(uBiome) %>%
as.data.frame() %>%
rownames_to_column("ASV")) %>%
mutate(Genus = vctrs::vec_as_names(Genus, repair = "unique") %>%
sub("...", "_", fixed = T, .))
plot_8 =
relAbu_df %>%
ggplot() +
geom_bar(aes(y = fct_reorder(Genus, W),
x = W,
fill = Phylum),
stat = "identity",
position = "dodge") +
scale_fill_iwanthue(hmin = 0,
hmax = 360,
cmin = 0,
cmax = 30,
lmin = 50,
lmax = 75) +
theme(axis.text.y = element_text(size = 12),
axis.title.y = element_blank(),
legend.position = "right",
strip.text = element_blank()) +
guides(fill = guide_legend(ncol = 1))
(plot_7 | plot_8) + plot_layout(widths = c(2, 1))
```