-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFig1_F,H.R
More file actions
166 lines (135 loc) · 5.75 KB
/
Copy pathFig1_F,H.R
File metadata and controls
166 lines (135 loc) · 5.75 KB
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
library(phyloseq)
packageVersion("phyloseq")
library(ggplot2)
packageVersion("ggplot2")
library(reshape2)
packageVersion("reshape2")
library(dplyr)
packageVersion("dplyr")
library(ComplexHeatmap)
packageVersion("ComplexHeatmap")
library(colorRamp2)
packageVersion("colorRamp2")
setwd("your_path")
#This R file contains all the scripts used to create the heatmaps for Figure 1F and 1G
#depicting the top 40 bacterial core members and all the fungal core members, respectively
#################16S core#################
core_genus <- read.csv(file = "16S_core.txt", sep = "\t")
core_genus <- core_genus %>%
arrange(desc(sum))
core_genus$Genus <- gsub("Burkholderia-Caballeronia-Paraburkholderia", "B-C-P",
core_genus$Genus)
core_genus$Genus <- gsub("Allorhizobium-Neorhizobium-Pararhizobium-Rhizobium", "Allo-Neo-Para-Rhizobium",
core_genus$Genus)
vector_phylum <- core_genus$Phylum
core_genus <- core_genus[,c(1:13,16,20)]
core_genus[,c(2:13)] * 100
vector_phylum_color <- c(Acidobacteriota = "#B69340",
Actinobacteriota = "darkseagreen",
Firmicutes = "gold2",
Myxococcota = "gold4",
Planctomycetota = "brown2",
Proteobacteria = "dodgerblue3",
Verrucomicrobiota = "deeppink3")
core_genus$Genus_ID <- NULL
rownames(core_genus) <- core_genus$Genus
core_genus$Genus <- NULL
core_genus$Phylum <- NULL
core_genus <- as.matrix(core_genus)
core_genus <- core_genus*100
min(core_genus)
mean(core_genus)
median(core_genus)
max(core_genus)
row_annot <- rowAnnotation(
Phylum = vector_phylum,
col = list(Phylum = vector_phylum_color),
show_legend = FALSE)
col_fun <- colorRamp2(c(0, 0.01, 1, 1.67, 10, 40), c(
"navyblue", "#638CC0",
"lightblue",
"#FDFBBB", "gold",
"#DC4F4D"))
heatmap_obj <- Heatmap(core_genus,
name = "Relative Abundance",
col = col_fun,
show_row_names = TRUE,
show_column_names = TRUE,
show_heatmap_legend = FALSE,
row_names_gp = gpar(fontsize = 13),
column_names_gp = gpar(fontsize = 13),
cluster_rows = FALSE,
cluster_columns = TRUE,
left_annotation = row_annot,
rect_gp = gpar(col = "black"))
lgd = Legend(col_fun = col_fun, title = "Relative abundance",
title_gp = gpar(fontsize = 12, fontface = "bold"),
labels_gp = gpar(fontsize = 12))
lgd_ann_phylum = Legend(
labels = unique(vector_phylum),
title = "Phylum",
legend_gp = gpar(fill=c("dodgerblue3","brown2","#B69340","gold2", "darkseagreen","deeppink3", "gold4")), # I colori dei quadratini
direction = "horizontal",
title_gp = gpar(fontsize = 12, fontface = "bold"),
labels_gp = gpar(fontsize = 12))
draw(heatmap_obj,
annotation_legend_list = list(lgd, lgd_ann_phylum),
heatmap_legend_side = "bottom",
annotation_legend_side = "bottom",
legend_grouping = "adjusted"
)
#################ITS core#################
setwd("your_path")
core_genus_ITS <- read.csv(file = "ITS_core.txt", sep = "\t")
vector_phylum_ITS <- core_genus_ITS$Phylum
core_genus_ITS$somma <- rowSums(core_genus_ITS[2:13])
core_genus_ITS <- core_genus_ITS %>%
arrange(desc(somma))
rownames(core_genus_ITS) <- core_genus_ITS$Genus
#core_genus_ITS <- core_genus_ITS[,c(1:13,16,20)]
core_genus_ITS <- core_genus_ITS[,c(2:13)] * 100
core_genus_ITS$somma <- NULL
core_genus_ITS <- as.matrix(core_genus_ITS)
min(core_genus_ITS)
mean(core_genus_ITS)
median(core_genus_ITS)
max(core_genus_ITS)
col_fun <- colorRamp2(c(0, 0.01, 2.50, 10, 40), c(
"navyblue", "#638CC0",
"lightblue",
"#FDFBBB", #"gold",
"#DC4F4D"))
vector_phylum_color_ITS <- c(Ascomycota = "dodgerblue3",
Basidiomycota = "brown2",
Mucoromycota = "purple",
Rozellomycota = "gold2",
Glomeromycota = "forestgreen")
row_annot <- rowAnnotation(
Phylum = vector_phylum_ITS,
col = list(Phylum = vector_phylum_color_ITS),
show_legend = FALSE)
heatmap_obj_ITS <- Heatmap(core_genus_ITS,
name = "Relative Abundance",
col = col_fun,
show_row_names = TRUE,
show_column_names = TRUE,
show_heatmap_legend = FALSE,
row_names_gp = gpar(fontsize = 13),
column_names_gp = gpar(fontsize = 13),
cluster_rows = FALSE,
cluster_columns = TRUE,
left_annotation = row_annot,
rect_gp = gpar(col = "black"))
lgd = Legend(col_fun = col_fun, title = "Relative abundance",
labels_gp = gpar(fontsize = 12))
lgd_ann_phylum = Legend(
labels = unique(vector_phylum_ITS),
title = "Phylum",
legend_gp = gpar(fill=c("dodgerblue3","gold2", "purple", "brown2", "forestgreen")),
direction = "horizontal",
title_gp = gpar(fontsize = 12, fontface = "bold"),
labels_gp = gpar(fontsize = 12))
draw(heatmap_obj_ITS, annotation_legend_list = list(lgd, lgd_ann_phylum),
heatmap_legend_side = "bottom",
annotation_legend_side = "bottom",
legend_grouping = "adjusted")