-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharchaea_analysis.Rmd
226 lines (137 loc) · 5.83 KB
/
archaea_analysis.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
---
title: "Characterization of dairy cow rumen bacterial and archaeal communities associated with grass silage and maize silage based diets (Archaea)"
output: word_document
---
```{r, eval=FALSE}
dir.create("archaea")
dir.create("archaea/figures")
dir.create("archaea/tables")
```
```{r}
library(ggplot2)
library(ape)
library(plyr)
library(vegan)
library(RColorBrewer)
library(reshape2)
library(data.table)
library(microbiome)
library(dplyr)
library(phyloseq)
library(knitr) #for interactive tables
library(picante)
```
## Read phyloseq
```{r}
pseq.1 <- readRDS("./input/pseq_archaea.rds")
```
## PD table
```{r}
dir.create("./archaea/PD")
my_colors <- c("#CBD588", "#5F7FC7", "orange","#DA5724", "#508578", "#CD9BCD", "#AD6F3B", "#673770","#D14285", "#652926", "#C84248", "#8569D5", "#5E738F","#D1A33D", "#8A7C64", "#599861", "steelblue" )
set.seed(8729)
otu_table_ps1 <- as.data.frame(pseq.1@otu_table)
metadata_table_ps1 <- as.data.frame(pseq.1@sam_data)
treefile_p1 <- pseq.1@phy_tree
df.pd <- pd(t(otu_table_ps1), treefile_p1,include.root=F)
knitr::kable(df.pd)
write.csv(df.pd, "./archaea/PD/phylogenetic_diversity_10_17.csv")
```
## Plot PD
Figure 5B
```{r}
colnames(metadata_table_ps1)
metadata_table_ps1$PhylogeneticDiversity <- df.pd$PD
library(ggpubr)
lev <- levels(metadata_table_ps1$Timepoint) # get the variables
# make a pairwise list that we want to compare.
L.pairs <- combn(seq_along(lev), 2, simplify = FALSE, FUN = function(i)lev[i])
#str(metadata_table_ps1)
metadata_table_ps1$Diet
plot.pd <- ggplot(metadata_table_ps1, aes(Timepoint, PhylogeneticDiversity)) + geom_boxplot(aes(fill = Timepoint)) + geom_point(size = 3) + theme(axis.text.x = element_text(size=14, angle = 90)) + scale_fill_manual(values = c("forestgreen", "steelblue")) + theme_bw()
print(plot.pd)
#write.csv(metadata_table_ps1, "./bacteria/PD/metadata_table_ps1.csv")
ggsave("./archaea/PD/phylogenetic_diversity_archaea_timepoint.pdf", height = 6, width = 7)
## Figure 5A
plot.pd.diet <- ggplot(metadata_table_ps1, aes(Diet, PhylogeneticDiversity)) + geom_boxplot(aes(fill = Diet)) + geom_point(size = 3) + theme(axis.text.x = element_text(size=14, angle = 90)) + scale_fill_manual(values = c("tomato", "olivedrab4", "lightseagreen","mediumpurple", "#508578")) + theme_bw()
print(plot.pd.diet)
ggsave("./archaea/PD/PD_diet.pdf", height = 6, width = 7)
```
## Test PD
```{r}
kruskal.test(metadata_table_ps1$PhylogeneticDiversity, metadata_table_ps1$Diet, p.adj = "fdr")
pairwise.wilcox.test(metadata_table_ps1$PhylogeneticDiversity, metadata_table_ps1$Diet, p.adj = "fdr")
pairwise.wilcox.test(metadata_table_ps1$PhylogeneticDiversity, metadata_table_ps1$Timepoint, p.adj = "fdr")
pairwise.wilcox.test(metadata_table_ps1$PhylogeneticDiversity, metadata_table_ps1$Block, p.adj = "fdr")
ggpubr::ggqqplot(metadata_table_ps1, "PhylogeneticDiversity")
```
```{r}
ggdensity(metadata_table_ps1$PhylogeneticDiversity,
main = "Density plot of PD values")
shapiro.test(metadata_table_ps1$PhylogeneticDiversity)
pairwise.t.test(metadata_table_ps1$PhylogeneticDiversity, metadata_table_ps1$Timepoint, p.adj = "fdr")
kruskal.test(metadata_table_ps1$PhylogeneticDiversity, metadata_table_ps1$Diet)
kruskal.test(metadata_table_ps1$PhylogeneticDiversity, metadata_table_ps1$Day_Timepoint)
#pairwise.wilcox.test(metadata_table_ps1$PhylogeneticDiversity, metadata_table_ps1$Diet,
# p.adjust.method = "fdr")
kruskal.test(metadata_table_ps1$PhylogeneticDiversity, metadata_table_ps1$Block, p.adj = "fdr")
# pairwise.wilcox.test(metadata_table_ps1$PhylogeneticDiversity, metadata_table_ps1$Block, p.adj = "fdr")
```
##weighted plot
Supplementary Figure S3
```{r}
#For plotting weighted
ps1.rel <- microbiome::transform(pseq.1, "compositional")
set.seed(49275) #set seed for reproducible rooting of the tree
ordu.wt.uni = ordinate(ps1.rel, "PCoA", "unifrac", weighted = TRUE)
wt.unifrac <- plot_ordination(ps1.rel, ordu.wt.uni,
color = "Diet",
shape = "Timepoint")
wt.unifrac <- wt.unifrac + scale_fill_manual(values = c("tomato", "olivedrab4", "lightseagreen","mediumpurple", "#508578")) +
ggtitle("Weighted UniFrac relative abundance") +
geom_point(size = 5) + theme_bw()
print(wt.unifrac)
ggsave("./archaea/figures/PCoA_weighted_archaea_coloured by timepoint.pdf", height = 6, width = 7)
```
##unweighted plot
Figure 5C
```{r}
#unweighted analysis for archaea
set.seed(475) #set seed for reproducible rooting of the tree
ordu.unwt.uni = ordinate(ps1.rel, "PCoA", "unifrac", weighted = F)
unwt.unifrac <- plot_ordination(ps1.rel, ordu.unwt.uni,
color = "Diet",
shape = "Timepoint") +
ggtitle("Unweighted UniFrac relative abundance") +
geom_point(size = 5) + theme_bw()
print(unwt.unifrac)
ggsave("./archaea/figures/PCoA_unweighted_archaea_coloured by timepoint.pdf", height = 6, width = 7)
```
```{r}
metadf <- data.frame(sample_data(ps1.rel))
set.seed(28567)
unifrac.dist <- UniFrac(ps1.rel,
weighted = TRUE,
normalized = TRUE,
parallel = FALSE,
fast = TRUE)
```
```{r}
set.seed(92661694)
adonis(unifrac.dist ~ Diet*Timepoint, data = metadf)
```
```{r}
set.seed(285667)
unwt.unifrac.dist <- UniFrac(ps1.rel,
weighted = FALSE,
normalized = TRUE,
parallel = FALSE,
fast = TRUE)
```
```{r}
set.seed(961694)
adonis(unwt.unifrac.dist ~ Diet*Timepoint, data = metadf)
```
```{r}
sessionInfo()
```