-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathR-commands_sulfate-cellulose-biogas.Rmd
204 lines (152 loc) · 8.56 KB
/
R-commands_sulfate-cellulose-biogas.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
---
title: "Commands for taxonomic analysis (16S rRNA gene and ITS2) of Pachnoda butana gut - Cellulose degradation, sulfate reduction and biogas production analyses"
output: html_notebook
---
```{r}
rm (list = ls())
```
# 16S
```{r}
library(phyloseq)
physeqObjest <- import_biom("16S/qiime2/table-with-taxonomy-json2.biom",
refseqArgs=NULL, parseFunction = parse_taxonomy_default,
parallel=FALSE)
```
```{r}
# METADATA
mapfile = read.csv("./metadata.csv", header = TRUE, sep=",")
samples = mapfile[,1]
rownames(mapfile) = samples
mapfile = mapfile[,2:length(colnames(mapfile))]
colnames(otu_table(physeqObjest))
rownames(mapfile)
ord = match(colnames(otu_table(physeqObjest)), rownames(mapfile), )
mapfile = mapfile[ord,]
sampledata = sample_data(mapfile)
physeq1 = merge_phyloseq(physeqObjest, sampledata)
sample_sums(physeq1)
```
```{r}
physeq1 = subset_taxa(physeq1, (Rank1 !="d__Eukaryota") | is.na(Rank1))
physeq1 = subset_taxa(physeq1, (Rank2 !="p__Vertebrata") | is.na(Rank2))
physeq1 = subset_taxa(physeq1, (Rank5 !="f__Mitochondria") | is.na(Rank5))
physeq1 = subset_taxa(physeq1, (Rank4 !="o__Chloroplast") | is.na(Rank4))
physeq1_Bacteria = subset_taxa(physeq1, (Rank1 !="d__Bacteria"))
physeq1_Archaea = subset_taxa(physeq1, (Rank1 !="d__Archaea"))
```
```{r echo=FALSE, reuslts=FALSE, warning=FALSE, comment=FALSE}
physeq_R6 <- tax_glom(physeq1_Bacteria, taxrank = rank_names(physeq1_Bacteria)[6], NArm = FALSE)
physeq_R6_rel = transform_sample_counts(physeq_R6, function(x) x / sum(x)*100 )
sample_sums(physeq_R6_rel)
colnames(otu_table(physeq_R6_rel))
all = phyloseq_to_df(physeq_R6_rel, sorting = NULL)
write.table(all, row.names = FALSE, file = "./relativeAbundance_Genus_Bacteria.csv", quote = FALSE, sep = '\t', dec = '.')
physeq_R6 <- tax_glom(physeq1_Archaea, taxrank = rank_names(physeq1_Archaea)[6], NArm = FALSE)
physeq_R6_rel = transform_sample_counts(physeq_R6, function(x) x / sum(x)*100 )
sample_sums(physeq_R6_rel)
colnames(otu_table(physeq_R6_rel))
all = phyloseq_to_df(physeq_R6_rel, sorting = NULL)
write.table(all, row.names = FALSE, file = "./relativeAbundance_Genus_Archaea.csv", quote = FALSE, sep = '\t', dec = '.')
```
# ITS
```{r}
library(phyloseq)
physeqObjest <- import_biom("ITS/qiime2/table-with-taxonomy-json2.biom",
refseqArgs=NULL, parseFunction = parse_taxonomy_default,
parallel=FALSE)
```
```{r}
# METADATA
mapfile = read.csv("./metadata.csv", header = TRUE, sep=",")
samples = mapfile[,1]
rownames(mapfile) = samples
mapfile = mapfile[,2:length(colnames(mapfile))]
colnames(otu_table(physeqObjest))
rownames(mapfile)
ord = match(colnames(otu_table(physeqObjest)), rownames(mapfile), )
mapfile = mapfile[ord,]
sampledata = sample_data(mapfile)
physeq1 = merge_phyloseq(physeqObjest, sampledata)
sample_sums(physeq1)
```
```{r}
physeq1 = subset_taxa(physeq1, (Rank1 !="d__Eukaryota") | is.na(Rank1))
physeq1 = subset_taxa(physeq1, (Rank2 !="p__Vertebrata") | is.na(Rank2))
physeq1 = subset_taxa(physeq1, (Rank5 !="f__Mitochondria") | is.na(Rank5))
physeq1 = subset_taxa(physeq1, (Rank4 !="o__Chloroplast") | is.na(Rank4))
physeq1_Fungi = subset_taxa(physeq1, (Rank1 !="k__Fungi"))
```
```{r echo=FALSE, reuslts=FALSE, warning=FALSE, comment=FALSE}
physeq_R6 <- tax_glom(physeq1_Fungi, taxrank = rank_names(physeq1_Fungi)[6], NArm = FALSE)
physeq_R6_rel = transform_sample_counts(physeq_R6, function(x) x / sum(x)*100 )
sample_sums(physeq_R6_rel)
colnames(otu_table(physeq_R6_rel))
all = phyloseq_to_df(physeq_R6_rel, sorting = NULL)
write.table(all, row.names = FALSE, file = "./relativeAbundance_Genus_Fungi.csv", quote = FALSE, sep = '\t', dec = '.')
```
# Make joined plot
## Bacteria plot
```{r}
library(ggplot2)
library(tidyr)
library(dplyr)
data <- read.csv("Bacteria_joined_top_filtered.csv", header = TRUE, sep=",")
data$Taxonomy <- factor(data$Taxonomy, # Factor levels in decreasing order
levels = data$Taxonomy[order(data$Biogas, decreasing = TRUE)])
# Utilizamos la función gather para convertir las columnas A, B, C, D, E en una sola columna "Condition"
df_gathered <- gather(data, key = "Condition", value = "Abundance", Biogas:Celulose_anaerobic)
# Creamos el gráfico con ggplot2
bacteria_plot = ggplot(df_gathered, aes(x = Taxonomy, y = Abundance, fill = Condition)) + theme_light() +
geom_bar(stat = "identity", position = position_dodge2(reverse=TRUE, padding = 0), color = "black") +
labs(title = "Bacteria", x = "", y = "Abundance (%)", fill = "Condition") +
coord_flip() +
scale_x_discrete(limits = rev(levels(df_gathered$Taxonomy))) +
# scale_fill_discrete(name = "Condición", labels = c("A", "B", "C", "D", "E")) +
scale_fill_manual(values = c('#cf9302', '#05a187', '#80c4b8', '#a11046', '#cc93a8'), labels = c("Biogas", "Cellulose - Aerobic medium", "Cellulose - Anaerobic medium", "Sulfate - Synthetic medium", "Sulfate - Polluted water"))
bacteria_plot = bacteria_plot + theme(panel.background = element_rect(fill = "white", colour = "grey"), plot.title = element_text(size = 18, face = "bold", hjust = 0.5), axis.text = element_text(size = 13), axis.title = element_text(size = 13, face = "bold"))
bacteria_plot
```
## Archaea plot
```{r}
data <- read.csv("Archaea_joined_top.csv", header = TRUE, sep=",")
data$Taxonomy <- factor(data$Taxonomy, # Factor levels in decreasing order
levels = data$Taxonomy[order(data$Biogas, decreasing = TRUE)])
# Utilizamos la función gather para convertir las columnas A, B, C, D, E en una sola columna "Condition"
df_gathered <- gather(data, key = "Condition", value = "Abundance", Biogas:Celulose_anaerobic)
# Creamos el gráfico con ggplot2
archaea_plot = ggplot(df_gathered, aes(x = Taxonomy, y = Abundance, fill = Condition)) + theme_light() +
geom_bar(stat = "identity", position = position_dodge2(reverse=TRUE, padding = 0), color = "black") +
labs(title = "Archaea", x = "", y = "Abundance (%)", fill = "Condition") +
coord_flip() +
scale_x_discrete(limits = rev(levels(df_gathered$Taxonomy))) +
# scale_fill_discrete(name = "Condición", labels = c("A", "B", "C", "D", "E")) +
scale_fill_manual(values = c('#cf9302', '#05a187', '#80c4b8', '#a11046', '#cc93a8'), labels = c("Biogas", "Cellulose - Aerobic medium", "Cellulose - Anaerobic medium", "Sulfate - Synthetic medium", "Sulfate - Polluted water"))
archaea_plot = archaea_plot + theme(panel.background = element_rect(fill = "white", colour = "grey"), plot.title = element_text(size = 18, face = "bold", hjust = 0.5), axis.text = element_text(size = 13), axis.title = element_text(size = 13, face = "bold"))
archaea_plot
```
## Fungi plot
```{r}
data <- read.csv("Fungi_joined_top_filtered.csv", header = TRUE, sep=",")
data$Taxonomy <- factor(data$Taxonomy, # Factor levels in decreasing order
levels = data$Taxonomy[order(data$Biogas, decreasing = TRUE)])
# Utilizamos la función gather para convertir las columnas A, B, C, D, E en una sola columna "Condition"
df_gathered <- gather(data, key = "Condition", value = "Abundance", Biogas:Celulose_anaerobic)
# Creamos el gráfico con ggplot2
fungi_plot = ggplot(df_gathered, aes(x = Taxonomy, y = Abundance, fill = Condition)) + theme_light() +
geom_bar(stat = "identity", position = position_dodge2(reverse=TRUE, padding = 0), color = "black") +
labs(title = "Fungi", x = "", y = "Abundance (%)", fill = "Condition") +
coord_flip() +
scale_x_discrete(limits = rev(levels(df_gathered$Taxonomy))) +
# scale_fill_discrete(name = "Condición", labels = c("A", "B", "C", "D", "E")) +
scale_fill_manual(values = c('#cf9302', '#05a187', '#80c4b8', '#a11046', '#cc93a8'), labels = c("Biogas", "Cellulose - Aerobic medium", "Cellulose - Anaerobic medium", "Sulfate - Synthetic medium", "Sulfate - Polluted water"))
fungi_plot = fungi_plot + theme(panel.background = element_rect(fill = "white", colour = "grey"), plot.title = element_text(size = 18, face = "bold", hjust = 0.5), axis.text = element_text(size = 13), axis.title = element_text(size = 13, face = "bold"))
```
## Joined plot:
```{r}
library(dplyr)
library(ggpubr)
figure = ggarrange(bacteria_plot, archaea_plot, fungi_plot,
# labels = c('Fusobacterium', 'Actinobacillus', 'Actinomyces', 'Granulicatella', 'Corynebacterium', 'Bergeyella', 'Lautropia', 'Abiotrophia'),
labels = c("A", "B", "C"),
ncol = 3, nrow = 1, common.legend = TRUE,legend="bottom", font.label = list(size = 24)) + theme(plot.margin=unit(c(0.2,0.2,0.2,0.2),"cm"))
```