|
a |
|
b/6-Figure scripts/Fig E4.r |
|
|
1 |
library(data.table) |
|
|
2 |
library(dplyr) |
|
|
3 |
library(reshape2) |
|
|
4 |
library(ggplot2) |
|
|
5 |
library(ggdendro) |
|
|
6 |
library(readxl) |
|
|
7 |
library(ggpubr) |
|
|
8 |
|
|
|
9 |
|
|
|
10 |
# Figure E4b ---------------------------------- |
|
|
11 |
dat <- read_excel("Fig E4 Source Data.xlsx", sheet = "E4b Prop of Mediation All") |
|
|
12 |
|
|
|
13 |
# normalize |
|
|
14 |
dat.dt <- dat |
|
|
15 |
|
|
|
16 |
|
|
|
17 |
dat.dt$InflammationType <- sapply(strsplit(dat.dt$Group,"_",fixed = T),"[[",1 ) |
|
|
18 |
dat.dt$Path <- sapply(dat.dt$Group, |
|
|
19 |
function(x){ |
|
|
20 |
parts <- strsplit(x, "_", fixed = T)[[1]] |
|
|
21 |
paste(parts[2:length(parts)], collapse = "-") |
|
|
22 |
}) |
|
|
23 |
|
|
|
24 |
dat.dt$Path <- factor(dat.dt$Path, levels = c("MetaG-MetaB","MetaB-Trans","Trans-Spuprot","Trans-Serprot")) |
|
|
25 |
|
|
|
26 |
dat.dt$InflammationType <- factor(dat.dt$InflammationType,levels = c("NEU","EOS")) |
|
|
27 |
dat.dt <- dat.dt %>% arrange(Path) %>% arrange(InflammationType) |
|
|
28 |
|
|
|
29 |
dat.dt$Group <- factor(dat.dt$Group, levels = rev(unique(dat.dt$Group))) |
|
|
30 |
|
|
|
31 |
FigE4b <- ggplot(dat.dt , |
|
|
32 |
aes(x=Group, y=Mediation_Proportion))+ |
|
|
33 |
geom_violin(aes(fill=Path),trim = T, scale = "width", alpha=0.5)+ |
|
|
34 |
geom_boxplot(width=0.1, outlier.shape = NA) + |
|
|
35 |
scale_fill_manual(values = c("#F8766D","#CD9600","#7CAE00","#00BE67")) + |
|
|
36 |
theme_bw()+ theme(panel.grid = element_blank(), |
|
|
37 |
axis.text.x = element_blank())+ |
|
|
38 |
coord_flip() |
|
|
39 |
FigE4b |
|
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
# Figure E4c ---------------------------------- |
|
|
44 |
|
|
|
45 |
dat <- read_excel("Fig E4 Source Data.xlsx", sheet = "E4c Reverse Mediation") |
|
|
46 |
|
|
|
47 |
plotDat <- dat %>% |
|
|
48 |
mutate(Forward = ABC_Prop, Reverse = ACB_Prop) %>% |
|
|
49 |
reshape2::melt(id.vars=c("Comparison","Type")) %>% |
|
|
50 |
dplyr::filter(variable %in% c("Forward", "Reverse")) |
|
|
51 |
|
|
|
52 |
plotDat$Type <- factor(plotDat$Type, |
|
|
53 |
levels = c("MetaG-MetaB-NEU","MetaB-HostT-NEU","MetaG-MetaB-EOS","MetaB-HostT-EOS")) |
|
|
54 |
|
|
|
55 |
FigE4c <- ggpaired(plotDat, x = "variable", y = "value", |
|
|
56 |
color = "variable", line.color = "gray", line.size = 0.4)+ |
|
|
57 |
stat_compare_means(paired = TRUE) + |
|
|
58 |
facet_wrap(vars(Type), scales = "free", ncol = 4)+ |
|
|
59 |
theme_bw()+theme(panel.grid = element_blank()) |
|
|
60 |
FigE4c |
|
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
# Figure E4e ---------------------------------- |
|
|
65 |
# Fig E4e. LOSO density plot ####### |
|
|
66 |
rm(list = ls()) |
|
|
67 |
dat.hist <- read_excel("Fig E4 Source Data.xlsx4", sheet = "E4e LOSO") |
|
|
68 |
colnames(dat.hist) <- c("Figs_map", "Figs_color","species","X1") |
|
|
69 |
dat.hist <- dat.hist %>% mutate(X2=X1, Y1=-0.002, Y2=-0.009) |
|
|
70 |
|
|
|
71 |
taxonomy_df <- read_excel("Fig E4 Source Data.xlsx4", sheet = "E4e taxonomy") |
|
|
72 |
|
|
|
73 |
genus <- sapply(strsplit(dat.hist$species,"_", fixed = T),"[[", 1) |
|
|
74 |
genus[!genus %in% taxonomy_df$Genus] |
|
|
75 |
|
|
|
76 |
phylum <- sapply(genus, |
|
|
77 |
function(x){ |
|
|
78 |
if(x %in% taxonomy_df$Genus) { |
|
|
79 |
taxonomy_df$Phylum[which(taxonomy_df$Genus == x)[1]] |
|
|
80 |
}else "Unclassified" |
|
|
81 |
}) |
|
|
82 |
phylum_color_df <- cbind.data.frame(phylum=c("Bacteroidetes","Actinobacteria","TM7","Proteobacteria","Firmicutes","other"), |
|
|
83 |
colors=c("#EF5656","#47B3DA","#9A8FC3","#F7A415","#2BB065","#BABABA"), |
|
|
84 |
stringsAsFactors=F) |
|
|
85 |
dat.hist$phylum <- phylum |
|
|
86 |
dat.hist$phylum_other <- sapply(dat.hist$phylum, function(x)if(x %in% phylum_color_df$phylum) x else "other") |
|
|
87 |
|
|
|
88 |
Fig.map_ymax_df <- cbind.data.frame(Fig.map = unique(dat.hist$Figs_map), |
|
|
89 |
# ymax=c(0.04,0.16,0.03,0.015,0.035,0.038), |
|
|
90 |
ymax = c(0.06,0.19, 0.06, 0.05), |
|
|
91 |
stringsAsFactors=F) |
|
|
92 |
|
|
|
93 |
|
|
|
94 |
for(Fig in unique(dat.hist$Figs_map)){ |
|
|
95 |
|
|
|
96 |
#Fig=unique(dat.hist$Figs_map)[1] |
|
|
97 |
|
|
|
98 |
ymax = Fig.map_ymax_df$ymax[which(Fig.map_ymax_df$Fig.map == Fig)] |
|
|
99 |
|
|
|
100 |
dat_sub <- dat.hist %>% filter(Figs_map %in% Fig) |
|
|
101 |
|
|
|
102 |
phylum_ABC <- unique(dat_sub$phylum_other)[order(unique(dat_sub$phylum_other))] |
|
|
103 |
phylum_rank <- c(phylum_ABC[phylum_ABC != "other"],"other") |
|
|
104 |
|
|
|
105 |
dat_sub$phylum_other <- factor(dat_sub$phylum_other, |
|
|
106 |
levels = phylum_rank) |
|
|
107 |
Colors <- sapply(phylum_rank, function(x) phylum_color_df$colors[which(phylum_color_df$phylum ==x)]) |
|
|
108 |
|
|
|
109 |
histP <- ggplot(dat_sub) + |
|
|
110 |
geom_density(aes(x=X1,y=(..count..)/sum(..count..)),fill = "gray") + ylab("Density") + |
|
|
111 |
xlab("") + |
|
|
112 |
theme_bw()+theme(panel.grid = element_blank()) + |
|
|
113 |
ylim(-0.01,ymax) + |
|
|
114 |
geom_segment(aes(x = X1, y = Y1, xend = X2, yend = Y2, color=phylum_other )) + |
|
|
115 |
scale_color_manual(values = Colors) + |
|
|
116 |
theme(legend.position = "none") + ggtitle(Fig) |
|
|
117 |
|
|
|
118 |
|
|
|
119 |
histP |
|
|
120 |
|
|
|
121 |
assign(paste("histP_", Fig, sep = ""), histP, envir = .GlobalEnv) |
|
|
122 |
} |
|
|
123 |
|
|
|
124 |
histP_MetaG_M00044 |
|
|
125 |
histP_MetaG_P00250 |
|
|
126 |
histP_MetaG_P00380 |
|
|
127 |
histP_MetaG_P00564 |
|
|
128 |
|
|
|
129 |
|
|
|
130 |
library(ggpubr) |
|
|
131 |
FigE4e.LOSO <- ggarrange(histP_MetaG_P00380, histP_MetaG_M00044, histP_MetaG_P00250, histP_MetaG_P00564, ncol = 1) |
|
|
132 |
#ggsave(FigE4e.LOSO,device = "pdf", filename = "FigE4e.KOcontri.pdf", width = 3, height = 10) |
|
|
133 |
|
|
|
134 |
|
|
|
135 |
# Fig E4e. KO contribution ####### |
|
|
136 |
|
|
|
137 |
zscore_df <- read_excel("Fig E4 Source Data.xlsx", sheet = "E4e KO contrib" ) |
|
|
138 |
colnames(zscore_df) <- c("K","sp","score") |
|
|
139 |
|
|
|
140 |
tmp <- zscore.top3_df <- zscore_df %>% |
|
|
141 |
group_by(K) %>% |
|
|
142 |
top_n(n = 3, wt = score) %>% as.data.frame() |
|
|
143 |
tmp <- tmp %>% arrange(desc(score)) %>% arrange(K) |
|
|
144 |
|
|
|
145 |
zscore.top3_df <- tmp %>% #keep the top 3 with highest score |
|
|
146 |
mutate(X = rep(c("X1","X2","X3"), length(unique(zscore_df$K)))) %>% |
|
|
147 |
mutate(genus = sapply(strsplit(sp," ", fixed = T),"[[", 1)) %>% |
|
|
148 |
mutate(phylum = sapply(genus, |
|
|
149 |
function(x){ |
|
|
150 |
if(x %in% taxonomy_df$Genus){ |
|
|
151 |
taxonomy_df$Phylum[which(taxonomy_df$Genus == x)[1]] |
|
|
152 |
}else "Unclassified" |
|
|
153 |
} ) ) %>% |
|
|
154 |
mutate(phylum_other = sapply(phylum, function(x) if(x %in% phylum_color_df$phylum) x else "other")) |
|
|
155 |
|
|
|
156 |
zscore.top3_df$phylum_other <- factor(zscore.top3_df$phylum_other, levels = phylum_rank) |
|
|
157 |
|
|
|
158 |
|
|
|
159 |
FigE4e.KOcontri <- ggplot(zscore.top3_df) + |
|
|
160 |
geom_point(aes(x=X, y=K, size=score, fill=phylum_other), shape=21) + |
|
|
161 |
scale_fill_manual(values = Colors) + |
|
|
162 |
scale_size (range = c (3, 6)) + |
|
|
163 |
theme(panel.grid = element_blank(), axis.title = element_blank(), panel.background = element_blank(), |
|
|
164 |
axis.text.x = element_blank(), legend.position = "none", axis.ticks = element_blank()) |
|
|
165 |
|
|
|
166 |
FigE4e.KOcontri |