[16eabd]: / 6-Figure scripts / Fig 2.r

Download this file

346 lines (287 with data), 13.3 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
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
list.files()
library(readxl)
excel_sheets("Fig 2 Source Data.xlsx")
library(dplyr)
# Figure 2a ------------------------------------------
# Figure 2a. metabolome #######
rm(list = ls())
dat.metab <- read_excel("Fig 2 Source Data.xlsx", sheet = "Fig 2a metabolome PCA")
library(ggplot2)
pca <- dat.metab
Fig2a.metab.pca <- ggplot(pca,aes(PC1,PC2))+
geom_point(size=2,aes(col=Group,shape=Cohort))+
scale_color_manual(values=c("#f0999f","#46bbc0"))+
scale_shape_manual(values=c(16,15)) +
theme_bw()+theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank())
Fig2a.metab.pca
pca$GROUP = paste(pca$Group,"|", pca$Cohort,sep = "")
Fig2a.metab.pc1.density <-
ggplot(pca) +
geom_density(aes(x=PC1, group=GROUP, fill=Group, linetype=Cohort),
color="black", alpha=0.6, position = 'identity') +
scale_fill_manual(values=c("#f0999f","#46bbc0")) +
theme_bw() +
scale_linetype_manual(values = c("solid","dashed"))+
labs(fill="")
Fig2a.metab.pc1.density
Fig2a.metab.pc2.density <-
ggplot(pca) +
geom_density(aes(x=PC2, group=GROUP, fill=Group, linetype=Cohort),
color="black", alpha=0.6, position = 'identity') +
scale_fill_manual(values=c("#f0999f","#46bbc0")) +
theme_bw() +
scale_linetype_manual(values = c("solid","dashed"))+
labs(fill="") +
coord_flip()
Fig2a.metab.pc2.density
# Figure 2a. metabolome #######
excel_sheets("Fig 2 Source Data.xlsx")
rm(list = ls())
dat.trans <- read_excel("Fig 2 Source Data.xlsx", sheet = "Fig 2a transcriptome PCA")
#library(ggplot2)
pca <- dat.trans
Fig2a.trans.pca <- ggplot(pca,aes(PC1,PC2))+
geom_point(size=2,aes(col=Group,shape=Cohort))+
scale_color_manual(values=c("#f0999f","#46bbc0"))+
scale_shape_manual(values=c(16,15)) +
theme_bw()+theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank())
Fig2a.trans.pca
pca$GROUP = paste(pca$Group,"|", pca$Cohort,sep = "")
Fig2a.trans.pc1.density <-
ggplot(pca) +
geom_density(aes(x=PC1, group=GROUP, fill=Group, linetype=Cohort),
color="black", alpha=0.6, position = 'identity') +
scale_fill_manual(values=c("#f0999f","#46bbc0")) +
theme_bw() +
scale_linetype_manual(values = c("solid","dashed"))+
labs(fill="")
Fig2a.trans.pc1.density
Fig2a.trans.pc2.density <-
ggplot(pca) +
geom_density(aes(x=PC2, group=GROUP, fill=Group, linetype=Cohort),
color="black", alpha=0.6, position = 'identity') +
scale_fill_manual(values=c("#f0999f","#46bbc0")) +
theme_bw() +
scale_linetype_manual(values = c("solid","dashed"))+
labs(fill="") +
coord_flip()
Fig2a.trans.pc2.density
# Figure 2a. sputum proteome #######
excel_sheets("Fig 2 Source Data.xlsx")
rm(list = ls())
dat.sputum <- read_excel("Fig 2 Source Data.xlsx", sheet = "Fig 2a sputum proteome PCA")
#library(ggplot2)
pca <- dat.sputum
Fig2a.sputum.pca <- ggplot(pca,aes(PC1,PC2))+
geom_point(size=2,aes(col=Group))+
scale_color_manual(values=c("#f0999f","#46bbc0"))+
scale_shape_manual(values=c(16,15)) +
theme_bw()+theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank())
Fig2a.sputum.pca
Fig2a.sputum.pc1.density <-
ggplot(pca) +
geom_density(aes(x=PC1, group=Group, fill=Group),
color="black", alpha=0.6, position = 'identity') +
scale_fill_manual(values=c("#f0999f","#46bbc0")) +
theme_bw() +
scale_linetype_manual(values = c("solid","dashed"))+
labs(fill="")
Fig2a.sputum.pc1.density
Fig2a.sputum.pc2.density <-
ggplot(pca) +
geom_density(aes(x=PC2, group=Group, fill=Group),
color="black", alpha=0.6, position = 'identity') +
scale_fill_manual(values=c("#f0999f","#46bbc0")) +
theme_bw() +
scale_linetype_manual(values = c("solid","dashed"))+
labs(fill="") +
coord_flip()
Fig2a.sputum.pc2.density
# Figure 2a. serum proteome #######
excel_sheets("Fig 2 Source Data.xlsx")
rm(list = ls())
dat.serum <- read_excel("Fig 2 Source Data.xlsx", sheet = "Fig 2a serum proteome PCA")
#library(ggplot2)
pca <- dat.serum
Fig2a.serum.pca <- ggplot(pca,aes(PC1,PC2))+
geom_point(size=2,aes(col=Group))+
scale_color_manual(values=c("#f0999f","#46bbc0"))+
scale_shape_manual(values=c(16,15)) +
theme_bw()+theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank())
Fig2a.serum.pca
Fig2a.serum.pc1.density <-
ggplot(pca) +
geom_density(aes(x=PC1, group=Group, fill=Group),
color="black", alpha=0.6, position = 'identity') +
scale_fill_manual(values=c("#f0999f","#46bbc0")) +
theme_bw() +
scale_linetype_manual(values = c("solid","dashed"))+
labs(fill="")
Fig2a.serum.pc1.density
Fig2a.serum.pc2.density <-
ggplot(pca) +
geom_density(aes(x=PC2, group=Group, fill=Group),
color="black", alpha=0.6, position = 'identity') +
scale_fill_manual(values=c("#f0999f","#46bbc0")) +
theme_bw() +
scale_linetype_manual(values = c("solid","dashed"))+
labs(fill="") +
coord_flip()
Fig2a.serum.pc2.density
# Figure 2b ------------------------------------------
excel_sheets("Fig 2 Source Data.xlsx")
rm(list = ls())
metab.modules <- read_excel("Fig 2 Source Data.xlsx", sheet = "Fig 2b metab modules")
metab.features <- read_excel("Fig 2 Source Data.xlsx", sheet = "Fig 2b metab features")
# Figure 2b.density of modules ####
data <- metab.modules
library(reshape2)
data2<-melt(data,id.vals=c("NAME","CLASS","GROUP") )
md.levels <- c("MEbrown4","MEmediumpurple1","MEskyblue3","MElavenderblush3","MEslateblue",
"MEsalmon2","MEbisque4","MEplum","MEmidnightblue","MEindianred4")
data2$variable=factor(data2$variable,levels=md.levels)
data2$GROUP4 <- paste(data2$GROUP,data2$CLASS, sep = "|")
Fig2b.density <- ggplot(data2,aes(data2$value))+
geom_density(aes(group=data2$GROUP4,fill=data2$CLASS,alpha=0.4,linetype=data2$GROUP))+
scale_color_manual(values=c("#f0999f","#46bbc0"))+
facet_wrap(~data2$variable,scale="free",ncol=1)+
scale_linetype_manual(values=c("solid","dashed"))+
scale_x_continuous(limits=c(-0.2,0.2)) +
theme_bw()+theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank())
Fig2b.density
ggsave(Fig2b.density, filename = "Fig2b.density.pdf",device = "pdf", width = 4, height = 10)
# Figure 2b.heatmap ####
data <- metab.features
data.Sz <- metab.features %>% select(starts_with("Z"))
data.Gz <- metab.features %>% select(!starts_with("Z")) %>% select(-Metabolite, -Group)
colors<-c(seq(-4,0,length=51),seq(0.1,4,length=50))
my_palette<- colorRampPalette(c("#EE9494","#F6E572","#94EE9D","#94E1EE","#94B3EE","white","white","white","white","white","white","white"))(n=100)
library(gplots)
pdf( "Fig2b.metab.hm.Sz.pdf") #save figure2b.metab.heamap.Shenzhen in pdf
heatmap.2(as.matrix(data.Sz),
breaks=colors, scale="row", trace="none",
Rowv=FALSE, dendrogram='column',hclustfun = function(x) hclust(x, method="ward.D2"),
col=rev(my_palette))
dev.off()
pdf( "Fig2b.metab.hm.Gz.pdf") #save figure2b.metab.heamap.Guangzhou in pdf
heatmap.2(as.matrix(data.Gz),
breaks=colors, scale="row", trace="none",
Rowv=FALSE, dendrogram='column',hclustfun = function(x) hclust(x, method="ward.D2"),
col=rev(my_palette))
dev.off()
## Figure 2c ------------------------------------------
excel_sheets("Fig 2 Source Data.xlsx")
rm(list = ls())
trans.modules <- read_excel("Fig 2 Source Data.xlsx", sheet = "Fig 2c trans modules")
trans.features <- read_excel("Fig 2 Source Data.xlsx", sheet = "Fig 2c trans features")
# Figure 2c.density of modules ####
data <- trans.modules
#library(reshape2)
data2<-melt(data,id.vals=c("NAME","CLASS","GROUP") )
md.levels <- c("MEcyan","MEdarkmagenta.1",
"MEorangered4","MEskyblue2",
"MEblueviolet","MEthistle4",
"MElightyellow","MEchocolate4",
"MEbisque4.1","MEsnow4")
data2$variable=factor(data2$variable,levels=md.levels)
data2$GROUP4 <- paste(data2$GROUP,data2$CLASS, sep = "|")
Fig2c.density <- ggplot(data2,aes(value))+
geom_density(aes(group=GROUP4,fill=CLASS,alpha=0.4,linetype=GROUP))+
scale_color_manual(values=c("#f0999f","#46bbc0"))+
facet_wrap(~variable,scale="free",ncol=1)+
scale_linetype_manual(values=c("solid","dashed"))+
scale_x_continuous(limits=c(-0.2,0.2)) +
theme_bw()+theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank())
Fig2c.density
ggsave(Fig2c.density, filename = "Fig2c.density.pdf",device = "pdf", width = 4, height = 10)
# Figure 2c.heatmap ####
data <- trans.features
data.Sz <- trans.features %>% select(starts_with("Z"))
data.Gz <- trans.features %>% select(!starts_with("Z")) %>% select(-Gene, -Module)
colors <- c(seq(-4, 0, length=51), seq(0.1, 4, length=50))
my_palette<- colorRampPalette(c("#EE9494","#F6E572","#94EE9D","#94E1EE","#94B3EE","white","white","white","white","white","white","white"))(n=100)
#library(gplots)
#pdf( "Fig2c.trans.hm.Sz.pdf") #save figure2c.trans.heamap.Shenzhen in pdf
heatmap.2(as.matrix(data.Sz),
breaks=colors, scale="row", trace="none",
Rowv=FALSE, dendrogram='column',hclustfun = function(x) hclust(x, method="ward.D2"),
col=rev(my_palette))
#dev.off()
pdf( "Fig2c.trans.hm.Gz.pdf") #save figure2c.trans.heamap.Guangzhou in pdf
heatmap.2(as.matrix(data.Gz),
breaks=colors, scale="row", trace="none", hclustfun = function(x) hclust(x, method="ward.D2"),
Rowv=FALSE, dendrogram='column',
col=rev(my_palette))
dev.off()
## Figure 2d ------------------------------------------
excel_sheets("Fig 2 data.xlsx")
rm(list = ls())
prot.features <- read_excel("Fig 2 Source Data.xlsx", sheet = "Fig 2d proteome features")
sputum.p <- prot.features %>% select(SampleID, Group, starts_with("Sputum"))
serum.p <- prot.features %>% select(SampleID, Group, starts_with("serum"))
# Figure2d. sputum proteome ####
data <- sputum.p
data.l <- reshape2::melt(data, id.vars=c("SampleID", "Group"))
sapply(data.l,class)
data.l_positive <- data.l %>% filter(value > 0)
H_median_df <- data.l_positive %>% filter(Group == "H") %>%
group_by(variable) %>% summarise(H_median =median(value)) %>%
as.data.frame(stringsAsFactors=F)
plotDat <-
merge(data.l_positive,H_median_df,by="variable") %>%
mutate(normalized_value = value/H_median) %>%
mutate(normalized.log = log10(normalized_value))
Fig2d.sputum <- ggplot(plotDat,aes(normalized.log))+
geom_density(aes(group=Group,fill=Group,alpha=0.4))+
scale_color_manual(values=c("#f0999f","#46bbc0"))+
facet_wrap(~variable,scale="free",ncol = 1) +
# scale_linetype_manual(values=c("solid","dashed"))+
#scale_x_continuous(limits=c(-0.2,0.2))+
theme_bw()+theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank())
Fig2d.sputum
ggsave(Fig2d.sputum, filename = 'Fig2d.sputum.pdf', device = "pdf",width = 4,height = 10)
# Figure2d. serum proteome ####
data <- serum.p
data.l <- reshape2::melt(data, id.vars=c("SampleID", "Group"))
sapply(data.l,class)
data.l_positive <- data.l %>% filter(value > 0)
H_median_df <- data.l_positive %>% filter(Group == "H") %>%
group_by(variable) %>% summarise(H_median =median(value)) %>%
as.data.frame(stringsAsFactors=F)
plotDat <-
merge(data.l_positive,H_median_df,by="variable") %>%
mutate(normalized_value = value/H_median) %>%
mutate(normalized.log = log10(normalized_value))
Fig2d.serum <- ggplot(plotDat,aes(normalized.log))+
geom_density(aes(group=Group,fill=Group,alpha=0.4))+
scale_color_manual(values=c("#f0999f","#46bbc0"))+
facet_wrap(~variable,scale="free",ncol = 1) +
# scale_linetype_manual(values=c("solid","dashed"))+
scale_x_continuous(limits=c(-0.2,0.2))+
theme_bw()+theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank())
Fig2d.serum
ggsave(Fig2d.serum, filename = 'Fig2d.serum.pdf', device = "pdf",width = 4,height = 4)