Diff of /6-Figure scripts/Fig 2.r [000000] .. [16eabd]

Switch to unified view

a b/6-Figure scripts/Fig 2.r
1
list.files()
2
3
library(readxl)
4
excel_sheets("Fig 2 Source Data.xlsx")
5
6
library(dplyr)
7
8
# Figure 2a ------------------------------------------
9
10
# Figure 2a. metabolome #######
11
rm(list = ls())
12
dat.metab <- read_excel("Fig 2 Source Data.xlsx", sheet = "Fig 2a metabolome PCA")
13
14
library(ggplot2)
15
pca <- dat.metab
16
Fig2a.metab.pca <- ggplot(pca,aes(PC1,PC2))+
17
  geom_point(size=2,aes(col=Group,shape=Cohort))+
18
  scale_color_manual(values=c("#f0999f","#46bbc0"))+
19
  scale_shape_manual(values=c(16,15)) +
20
  theme_bw()+theme(axis.line = element_line(colour = "black"),
21
                   panel.grid.major = element_blank(),
22
                   panel.grid.minor = element_blank(),
23
                   panel.background = element_blank())
24
Fig2a.metab.pca
25
26
pca$GROUP = paste(pca$Group,"|", pca$Cohort,sep = "")
27
28
Fig2a.metab.pc1.density <-
29
  ggplot(pca) +
30
  geom_density(aes(x=PC1, group=GROUP, fill=Group, linetype=Cohort),
31
               color="black", alpha=0.6, position = 'identity') +
32
  scale_fill_manual(values=c("#f0999f","#46bbc0")) +
33
  theme_bw() +
34
  scale_linetype_manual(values = c("solid","dashed"))+
35
  labs(fill="")
36
Fig2a.metab.pc1.density
37
38
Fig2a.metab.pc2.density <-
39
  ggplot(pca) +
40
  geom_density(aes(x=PC2, group=GROUP, fill=Group, linetype=Cohort),
41
               color="black", alpha=0.6, position = 'identity') +
42
  scale_fill_manual(values=c("#f0999f","#46bbc0")) +
43
  theme_bw() +
44
  scale_linetype_manual(values = c("solid","dashed"))+
45
  labs(fill="") + 
46
  coord_flip()
47
Fig2a.metab.pc2.density
48
49
50
51
# Figure 2a. metabolome #######
52
excel_sheets("Fig 2 Source Data.xlsx")
53
rm(list = ls())
54
dat.trans <- read_excel("Fig 2 Source Data.xlsx", sheet = "Fig 2a transcriptome PCA")
55
56
#library(ggplot2)
57
pca <- dat.trans
58
Fig2a.trans.pca <- ggplot(pca,aes(PC1,PC2))+
59
  geom_point(size=2,aes(col=Group,shape=Cohort))+ 
60
  scale_color_manual(values=c("#f0999f","#46bbc0"))+
61
  scale_shape_manual(values=c(16,15)) +
62
  theme_bw()+theme(axis.line = element_line(colour = "black"),
63
                   panel.grid.major = element_blank(),
64
                   panel.grid.minor = element_blank(),
65
                   panel.background = element_blank())
66
Fig2a.trans.pca
67
68
pca$GROUP = paste(pca$Group,"|", pca$Cohort,sep = "")
69
70
Fig2a.trans.pc1.density <-
71
  ggplot(pca) +
72
  geom_density(aes(x=PC1, group=GROUP, fill=Group, linetype=Cohort),
73
               color="black", alpha=0.6, position = 'identity') +
74
  scale_fill_manual(values=c("#f0999f","#46bbc0")) +
75
  theme_bw() +
76
  scale_linetype_manual(values = c("solid","dashed"))+
77
  labs(fill="")
78
Fig2a.trans.pc1.density
79
80
Fig2a.trans.pc2.density <-
81
  ggplot(pca) +
82
  geom_density(aes(x=PC2, group=GROUP, fill=Group, linetype=Cohort),
83
               color="black", alpha=0.6, position = 'identity') +
84
  scale_fill_manual(values=c("#f0999f","#46bbc0")) +
85
  theme_bw() +
86
  scale_linetype_manual(values = c("solid","dashed"))+
87
  labs(fill="") + 
88
  coord_flip()
89
Fig2a.trans.pc2.density
90
91
92
# Figure 2a. sputum proteome #######
93
excel_sheets("Fig 2 Source Data.xlsx")
94
rm(list = ls())
95
dat.sputum <- read_excel("Fig 2 Source Data.xlsx", sheet = "Fig 2a sputum proteome PCA")
96
97
#library(ggplot2)
98
pca <- dat.sputum
99
Fig2a.sputum.pca <- ggplot(pca,aes(PC1,PC2))+
100
  geom_point(size=2,aes(col=Group))+
101
  scale_color_manual(values=c("#f0999f","#46bbc0"))+
102
  scale_shape_manual(values=c(16,15)) +
103
  theme_bw()+theme(axis.line = element_line(colour = "black"),
104
                   panel.grid.major = element_blank(),
105
                   panel.grid.minor = element_blank(),
106
                   panel.background = element_blank())
107
Fig2a.sputum.pca
108
109
Fig2a.sputum.pc1.density <-
110
  ggplot(pca) +
111
  geom_density(aes(x=PC1, group=Group, fill=Group),
112
               color="black", alpha=0.6, position = 'identity') +
113
  scale_fill_manual(values=c("#f0999f","#46bbc0")) +
114
  theme_bw() +
115
  scale_linetype_manual(values = c("solid","dashed"))+
116
  labs(fill="")
117
Fig2a.sputum.pc1.density
118
119
Fig2a.sputum.pc2.density <-
120
  ggplot(pca) +
121
  geom_density(aes(x=PC2, group=Group, fill=Group),
122
               color="black", alpha=0.6, position = 'identity') +
123
  scale_fill_manual(values=c("#f0999f","#46bbc0")) +
124
  theme_bw() +
125
  scale_linetype_manual(values = c("solid","dashed"))+
126
  labs(fill="") + 
127
  coord_flip()
128
Fig2a.sputum.pc2.density
129
130
131
# Figure 2a. serum proteome #######
132
excel_sheets("Fig 2 Source Data.xlsx")
133
rm(list = ls())
134
dat.serum <- read_excel("Fig 2 Source Data.xlsx", sheet = "Fig 2a serum proteome PCA")
135
136
#library(ggplot2)
137
pca <- dat.serum
138
Fig2a.serum.pca <- ggplot(pca,aes(PC1,PC2))+
139
  geom_point(size=2,aes(col=Group))+  
140
  scale_color_manual(values=c("#f0999f","#46bbc0"))+
141
  scale_shape_manual(values=c(16,15)) +
142
  theme_bw()+theme(axis.line = element_line(colour = "black"),
143
                   panel.grid.major = element_blank(),
144
                   panel.grid.minor = element_blank(),
145
                   panel.background = element_blank())
146
Fig2a.serum.pca
147
148
Fig2a.serum.pc1.density <-
149
  ggplot(pca) +
150
  geom_density(aes(x=PC1, group=Group, fill=Group),
151
               color="black", alpha=0.6, position = 'identity') +
152
  scale_fill_manual(values=c("#f0999f","#46bbc0")) +
153
  theme_bw() +
154
  scale_linetype_manual(values = c("solid","dashed"))+
155
  labs(fill="")
156
Fig2a.serum.pc1.density
157
158
Fig2a.serum.pc2.density <-
159
  ggplot(pca) +
160
  geom_density(aes(x=PC2, group=Group, fill=Group),
161
               color="black", alpha=0.6, position = 'identity') +
162
  scale_fill_manual(values=c("#f0999f","#46bbc0")) +
163
  theme_bw() +
164
  scale_linetype_manual(values = c("solid","dashed"))+
165
  labs(fill="") + 
166
  coord_flip()
167
Fig2a.serum.pc2.density
168
169
170
# Figure 2b ------------------------------------------
171
excel_sheets("Fig 2 Source Data.xlsx")
172
rm(list = ls())
173
metab.modules <- read_excel("Fig 2 Source Data.xlsx", sheet = "Fig 2b metab modules")
174
metab.features <- read_excel("Fig 2 Source Data.xlsx", sheet = "Fig 2b metab features")
175
176
# Figure 2b.density of modules ####
177
data <- metab.modules
178
library(reshape2)
179
data2<-melt(data,id.vals=c("NAME","CLASS","GROUP") )
180
md.levels <- c("MEbrown4","MEmediumpurple1","MEskyblue3","MElavenderblush3","MEslateblue",
181
               "MEsalmon2","MEbisque4","MEplum","MEmidnightblue","MEindianred4")
182
183
data2$variable=factor(data2$variable,levels=md.levels)
184
data2$GROUP4 <- paste(data2$GROUP,data2$CLASS, sep = "|")
185
Fig2b.density <- ggplot(data2,aes(data2$value))+
186
  geom_density(aes(group=data2$GROUP4,fill=data2$CLASS,alpha=0.4,linetype=data2$GROUP))+
187
  scale_color_manual(values=c("#f0999f","#46bbc0"))+
188
  facet_wrap(~data2$variable,scale="free",ncol=1)+
189
  scale_linetype_manual(values=c("solid","dashed"))+
190
  scale_x_continuous(limits=c(-0.2,0.2)) +
191
  theme_bw()+theme(axis.line = element_line(colour = "black"),
192
                   panel.grid.major = element_blank(),
193
                   panel.grid.minor = element_blank(),
194
                   panel.background = element_blank())
195
Fig2b.density
196
ggsave(Fig2b.density, filename = "Fig2b.density.pdf",device = "pdf", width = 4, height = 10)
197
198
# Figure 2b.heatmap ####
199
data <- metab.features 
200
data.Sz <- metab.features %>% select(starts_with("Z")) 
201
data.Gz <- metab.features %>% select(!starts_with("Z")) %>% select(-Metabolite, -Group)
202
203
colors<-c(seq(-4,0,length=51),seq(0.1,4,length=50))
204
my_palette<- colorRampPalette(c("#EE9494","#F6E572","#94EE9D","#94E1EE","#94B3EE","white","white","white","white","white","white","white"))(n=100)
205
library(gplots)
206
pdf( "Fig2b.metab.hm.Sz.pdf") #save figure2b.metab.heamap.Shenzhen in pdf
207
heatmap.2(as.matrix(data.Sz),
208
          breaks=colors, scale="row", trace="none", 
209
          Rowv=FALSE, dendrogram='column',hclustfun = function(x) hclust(x, method="ward.D2"),
210
          col=rev(my_palette))
211
dev.off()
212
213
pdf( "Fig2b.metab.hm.Gz.pdf") #save figure2b.metab.heamap.Guangzhou in pdf
214
heatmap.2(as.matrix(data.Gz),
215
          breaks=colors, scale="row", trace="none", 
216
          Rowv=FALSE, dendrogram='column',hclustfun = function(x) hclust(x, method="ward.D2"),
217
          col=rev(my_palette))  
218
dev.off()
219
220
221
## Figure 2c ------------------------------------------
222
excel_sheets("Fig 2 Source Data.xlsx")
223
rm(list = ls())
224
trans.modules <- read_excel("Fig 2 Source Data.xlsx", sheet = "Fig 2c trans modules")
225
trans.features <- read_excel("Fig 2 Source Data.xlsx", sheet = "Fig 2c trans features")
226
227
# Figure 2c.density of modules ####
228
data <- trans.modules
229
#library(reshape2)
230
data2<-melt(data,id.vals=c("NAME","CLASS","GROUP") )
231
md.levels <- c("MEcyan","MEdarkmagenta.1",
232
               "MEorangered4","MEskyblue2",
233
               "MEblueviolet","MEthistle4",
234
               "MElightyellow","MEchocolate4",
235
               "MEbisque4.1","MEsnow4")
236
237
data2$variable=factor(data2$variable,levels=md.levels)
238
data2$GROUP4 <- paste(data2$GROUP,data2$CLASS, sep = "|")
239
Fig2c.density <- ggplot(data2,aes(value))+
240
  geom_density(aes(group=GROUP4,fill=CLASS,alpha=0.4,linetype=GROUP))+
241
  scale_color_manual(values=c("#f0999f","#46bbc0"))+
242
  facet_wrap(~variable,scale="free",ncol=1)+
243
  scale_linetype_manual(values=c("solid","dashed"))+
244
  scale_x_continuous(limits=c(-0.2,0.2)) +
245
  theme_bw()+theme(axis.line = element_line(colour = "black"),
246
                   panel.grid.major = element_blank(),
247
                   panel.grid.minor = element_blank(),
248
                   panel.background = element_blank())
249
Fig2c.density
250
ggsave(Fig2c.density, filename = "Fig2c.density.pdf",device = "pdf", width = 4, height = 10)
251
252
253
# Figure 2c.heatmap ####
254
data <- trans.features 
255
data.Sz <- trans.features %>% select(starts_with("Z")) 
256
data.Gz <- trans.features %>% select(!starts_with("Z")) %>% select(-Gene, -Module)
257
258
colors <- c(seq(-4, 0, length=51), seq(0.1, 4, length=50))
259
my_palette<- colorRampPalette(c("#EE9494","#F6E572","#94EE9D","#94E1EE","#94B3EE","white","white","white","white","white","white","white"))(n=100)
260
#library(gplots)
261
#pdf( "Fig2c.trans.hm.Sz.pdf") #save figure2c.trans.heamap.Shenzhen in pdf
262
heatmap.2(as.matrix(data.Sz),
263
          breaks=colors, scale="row", trace="none", 
264
          Rowv=FALSE, dendrogram='column',hclustfun = function(x) hclust(x, method="ward.D2"),
265
          col=rev(my_palette))
266
#dev.off()
267
268
pdf( "Fig2c.trans.hm.Gz.pdf") #save figure2c.trans.heamap.Guangzhou in pdf
269
heatmap.2(as.matrix(data.Gz),
270
          breaks=colors, scale="row", trace="none", hclustfun = function(x) hclust(x, method="ward.D2"),
271
          Rowv=FALSE, dendrogram='column',
272
          col=rev(my_palette))
273
dev.off()
274
275
276
## Figure 2d ------------------------------------------
277
excel_sheets("Fig 2 data.xlsx")
278
rm(list = ls())
279
prot.features <- read_excel("Fig 2 Source Data.xlsx", sheet = "Fig 2d proteome features")
280
sputum.p <- prot.features %>% select(SampleID, Group, starts_with("Sputum"))
281
serum.p <- prot.features %>% select(SampleID, Group, starts_with("serum"))
282
283
# Figure2d. sputum proteome ####
284
data <- sputum.p
285
286
data.l <- reshape2::melt(data, id.vars=c("SampleID", "Group"))
287
sapply(data.l,class)
288
data.l_positive <- data.l %>% filter(value > 0)
289
290
H_median_df <- data.l_positive %>% filter(Group == "H") %>% 
291
  group_by(variable) %>% summarise(H_median =median(value)) %>%
292
  as.data.frame(stringsAsFactors=F)
293
294
plotDat <- 
295
  merge(data.l_positive,H_median_df,by="variable") %>%
296
  mutate(normalized_value = value/H_median) %>% 
297
  mutate(normalized.log = log10(normalized_value))
298
299
300
Fig2d.sputum <- ggplot(plotDat,aes(normalized.log))+
301
  geom_density(aes(group=Group,fill=Group,alpha=0.4))+
302
  scale_color_manual(values=c("#f0999f","#46bbc0"))+
303
  facet_wrap(~variable,scale="free",ncol = 1) +
304
  # scale_linetype_manual(values=c("solid","dashed"))+
305
  #scale_x_continuous(limits=c(-0.2,0.2))+
306
  theme_bw()+theme(axis.line = element_line(colour = "black"),
307
                   panel.grid.major = element_blank(),
308
                   panel.grid.minor = element_blank(),
309
                   panel.background = element_blank())
310
311
Fig2d.sputum 
312
ggsave(Fig2d.sputum, filename = 'Fig2d.sputum.pdf', device = "pdf",width = 4,height = 10)
313
314
315
316
# Figure2d. serum proteome ####
317
data <- serum.p
318
319
data.l <- reshape2::melt(data, id.vars=c("SampleID", "Group"))
320
sapply(data.l,class)
321
data.l_positive <- data.l %>% filter(value > 0)
322
323
H_median_df <- data.l_positive %>% filter(Group == "H") %>% 
324
  group_by(variable) %>% summarise(H_median =median(value)) %>%
325
  as.data.frame(stringsAsFactors=F)
326
327
plotDat <- 
328
  merge(data.l_positive,H_median_df,by="variable") %>%
329
  mutate(normalized_value = value/H_median) %>% 
330
  mutate(normalized.log = log10(normalized_value))
331
332
333
Fig2d.serum <- ggplot(plotDat,aes(normalized.log))+
334
  geom_density(aes(group=Group,fill=Group,alpha=0.4))+
335
  scale_color_manual(values=c("#f0999f","#46bbc0"))+
336
  facet_wrap(~variable,scale="free",ncol = 1) +
337
  # scale_linetype_manual(values=c("solid","dashed"))+
338
  scale_x_continuous(limits=c(-0.2,0.2))+
339
  theme_bw()+theme(axis.line = element_line(colour = "black"),
340
                   panel.grid.major = element_blank(),
341
                   panel.grid.minor = element_blank(),
342
                   panel.background = element_blank())
343
344
Fig2d.serum 
345
ggsave(Fig2d.serum, filename = 'Fig2d.serum.pdf', device = "pdf",width = 4,height = 4)