-
Notifications
You must be signed in to change notification settings - Fork 15
/
04R-Prepare-TCGA-data-for-Qiime-and-plot-alpha-diversity.R
executable file
·464 lines (421 loc) · 29.1 KB
/
04R-Prepare-TCGA-data-for-Qiime-and-plot-alpha-diversity.R
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
#-----------------------------------------------------------------------------
# 04-Prepare-TCGA-data-for-Qiime-and-plot-alpha-diversity.R
# Copyright (c) 2021--, Greg Poore
# Purposes:
# - Prepare TCGA data for Qiime analyses to calculate alpha and beta diversities
# - Plot Qiime alpha diversity results (beta diversities to be shown using Emperor)
# - Prepare TCGA data for MMvec analyses to examine co-occurring fungi and bacteria
#-----------------------------------------------------------------------------
#----------------------------------------------------------#
# Load environments
#----------------------------------------------------------#
# Load dependencies
require(devtools)
require(doMC)
require(plyr)
require(dplyr)
require(reshape2)
require(ggpubr)
require(ggsci)
require(tibble)
require(EnvStats) # to show sample sizes
require(biomformat)
require(Rhdf5lib)
numCores <- detectCores()
registerDoMC(cores=numCores)
#----------------------------------------------------------#
# Import data
#----------------------------------------------------------#
load("Interim_data/snmDataFungi_DecontamV2_25Mar22.RData", verbose = TRUE) # To load the metadata and raw data objects
rep200TaxSplit <- read.csv("Supporting_data/rep200_lineage_map_split.csv", stringsAsFactors = FALSE, row.names = 1)
#--------------------------------------------------------------------------------------------------------------------#
# Separate raw data into seq center-experimental strategy groups (to preclude needing batch correction)
#--------------------------------------------------------------------------------------------------------------------#
metaQiitaCombined_Nonzero_DecontamV2 %>% count(data_submitting_center_label, experimental_strategy)
#--------------------Subset metadata--------------------#
# WGS (note that Broad has both WGS and RNA, so separate objects are made for both)
metaQiitaCombined_Nonzero_DecontamV2_HMS <- metaQiitaCombined_Nonzero_DecontamV2 %>% filter(data_submitting_center_label == "Harvard Medical School") %>% droplevels()
metaQiitaCombined_Nonzero_DecontamV2_BCM <- metaQiitaCombined_Nonzero_DecontamV2 %>% filter(data_submitting_center_label == "Baylor College of Medicine") %>% droplevels()
metaQiitaCombined_Nonzero_DecontamV2_MDA <- metaQiitaCombined_Nonzero_DecontamV2 %>% filter(data_submitting_center_label == "MD Anderson - Institute for Applied Cancer Science") %>% droplevels()
metaQiitaCombined_Nonzero_DecontamV2_WashU <- metaQiitaCombined_Nonzero_DecontamV2 %>% filter(data_submitting_center_label == "Washington University School of Medicine") %>% droplevels()
metaQiitaCombined_Nonzero_DecontamV2_Broad_WGS <- metaQiitaCombined_Nonzero_DecontamV2 %>%
filter(data_submitting_center_label == "Broad Institute of MIT and Harvard") %>%
filter(experimental_strategy == "WGS") %>% droplevels()
# RNA-Seq (note that Broad has both WGS and RNA-Seq, so separate objects are made for both)
metaQiitaCombined_Nonzero_DecontamV2_UNC <- metaQiitaCombined_Nonzero_DecontamV2 %>% filter(data_submitting_center_label == "University of North Carolina") %>% droplevels()
metaQiitaCombined_Nonzero_DecontamV2_CMS <- metaQiitaCombined_Nonzero_DecontamV2 %>% filter(data_submitting_center_label == "Canada's Michael Smith Genome Sciences Centre") %>% droplevels()
metaQiitaCombined_Nonzero_DecontamV2_Broad_RNA <- metaQiitaCombined_Nonzero_DecontamV2 %>%
filter(data_submitting_center_label == "Broad Institute of MIT and Harvard") %>%
filter(experimental_strategy == "RNA-Seq") %>% droplevels()
#--------------------Subset count data--------------------#
# WGS (note that Broad has both WGS and RNA, so separate objects are made for both)
rep200_HiSeq_Fungi_DecontamV2_HMS <- rep200Data_WGS_RNA_HiSeq_Fungi_DecontamV2_Nonzero[rownames(metaQiitaCombined_Nonzero_DecontamV2_HMS),]
rep200_HiSeq_Fungi_DecontamV2_BCM <- rep200Data_WGS_RNA_HiSeq_Fungi_DecontamV2_Nonzero[rownames(metaQiitaCombined_Nonzero_DecontamV2_BCM),]
rep200_HiSeq_Fungi_DecontamV2_MDA <- rep200Data_WGS_RNA_HiSeq_Fungi_DecontamV2_Nonzero[rownames(metaQiitaCombined_Nonzero_DecontamV2_MDA),]
rep200_HiSeq_Fungi_DecontamV2_WashU <- rep200Data_WGS_RNA_HiSeq_Fungi_DecontamV2_Nonzero[rownames(metaQiitaCombined_Nonzero_DecontamV2_WashU),]
rep200_HiSeq_Fungi_DecontamV2_Broad_WGS <- rep200Data_WGS_RNA_HiSeq_Fungi_DecontamV2_Nonzero[rownames(metaQiitaCombined_Nonzero_DecontamV2_Broad_WGS),]
# RNA-Seq (note that Broad has both WGS and RNA-Seq, so separate objects are made for both)
rep200_HiSeq_Fungi_DecontamV2_UNC <- rep200Data_WGS_RNA_HiSeq_Fungi_DecontamV2_Nonzero[rownames(metaQiitaCombined_Nonzero_DecontamV2_UNC),]
rep200_HiSeq_Fungi_DecontamV2_CMS <- rep200Data_WGS_RNA_HiSeq_Fungi_DecontamV2_Nonzero[rownames(metaQiitaCombined_Nonzero_DecontamV2_CMS),]
rep200_HiSeq_Fungi_DecontamV2_Broad_RNA <- rep200Data_WGS_RNA_HiSeq_Fungi_DecontamV2_Nonzero[rownames(metaQiitaCombined_Nonzero_DecontamV2_Broad_RNA),]
#--------------------Intersect with fungi with >1% aggregate genome coverage--------------------#
load("Interim_data/metaQiitaWGS_RNA_AllSeqPlatforms_Joined_WithBamcounts_and_Data_25Mar22.RData", verbose = TRUE)
coverageFungiAllSamples <- read.csv("Input_data/fungi_filt_updated_29Sep21_coverage_all_wgs_and_rna_output.csv", stringsAsFactors = FALSE)
coverageFungiAllSamples_1Percent <- coverageFungiAllSamples %>% filter(coverage_ratio >= 0.01)
coverageFungiAllSamples_1Percent_OGUs <- coverageFungiAllSamples_1Percent$gotu
# WGS
rep200_HiSeq_Fungi_HMS_Cov <- rep200Data_WGS_RNA_Matched_Fungi[rownames(metaQiitaCombined_Nonzero_DecontamV2_HMS),colnames(rep200Data_WGS_RNA_Matched_Fungi) %in% coverageFungiAllSamples_1Percent_OGUs]
rep200_HiSeq_Fungi_BCM_Cov <- rep200Data_WGS_RNA_Matched_Fungi[rownames(metaQiitaCombined_Nonzero_DecontamV2_BCM),colnames(rep200Data_WGS_RNA_Matched_Fungi) %in% coverageFungiAllSamples_1Percent_OGUs]
rep200_HiSeq_Fungi_MDA_Cov <- rep200Data_WGS_RNA_Matched_Fungi[rownames(metaQiitaCombined_Nonzero_DecontamV2_MDA),colnames(rep200Data_WGS_RNA_Matched_Fungi) %in% coverageFungiAllSamples_1Percent_OGUs]
rep200_HiSeq_Fungi_WashU_Cov <- rep200Data_WGS_RNA_Matched_Fungi[rownames(metaQiitaCombined_Nonzero_DecontamV2_WashU),colnames(rep200Data_WGS_RNA_Matched_Fungi) %in% coverageFungiAllSamples_1Percent_OGUs]
rep200_HiSeq_Fungi_Broad_WGS_Cov <- rep200Data_WGS_RNA_Matched_Fungi[rownames(metaQiitaCombined_Nonzero_DecontamV2_Broad_WGS),colnames(rep200Data_WGS_RNA_Matched_Fungi) %in% coverageFungiAllSamples_1Percent_OGUs]
# RNA
rep200_HiSeq_Fungi_UNC_Cov <- rep200Data_WGS_RNA_Matched_Fungi[rownames(metaQiitaCombined_Nonzero_DecontamV2_UNC),colnames(rep200Data_WGS_RNA_Matched_Fungi) %in% coverageFungiAllSamples_1Percent_OGUs]
rep200_HiSeq_Fungi_CMS_Cov <- rep200Data_WGS_RNA_Matched_Fungi[rownames(metaQiitaCombined_Nonzero_DecontamV2_CMS),colnames(rep200Data_WGS_RNA_Matched_Fungi) %in% coverageFungiAllSamples_1Percent_OGUs]
rep200_HiSeq_Fungi_Broad_RNA_Cov <- rep200Data_WGS_RNA_Matched_Fungi[rownames(metaQiitaCombined_Nonzero_DecontamV2_Broad_RNA),colnames(rep200Data_WGS_RNA_Matched_Fungi) %in% coverageFungiAllSamples_1Percent_OGUs]
## Remove zero sum samples -- Broad_WGS and UNC have zero sum samples; for naming convention, all will be processed
# e.g. summary(rowSums(rep200_HiSeq_Fungi_Broad_WGS_Cov)==0)
rep200_HiSeq_Fungi_HMS_Cov_Nonzero <- rep200_HiSeq_Fungi_HMS_Cov[!rowSums(rep200_HiSeq_Fungi_HMS_Cov)==0,]
rep200_HiSeq_Fungi_BCM_Cov_Nonzero <- rep200_HiSeq_Fungi_BCM_Cov[!rowSums(rep200_HiSeq_Fungi_BCM_Cov)==0,]
rep200_HiSeq_Fungi_MDA_Cov_Nonzero <- rep200_HiSeq_Fungi_MDA_Cov[!rowSums(rep200_HiSeq_Fungi_MDA_Cov)==0,]
rep200_HiSeq_Fungi_WashU_Cov_Nonzero <- rep200_HiSeq_Fungi_WashU_Cov[!rowSums(rep200_HiSeq_Fungi_WashU_Cov)==0,]
rep200_HiSeq_Fungi_Broad_WGS_Cov_Nonzero <- rep200_HiSeq_Fungi_Broad_WGS_Cov[!rowSums(rep200_HiSeq_Fungi_Broad_WGS_Cov)==0,]
rep200_HiSeq_Fungi_UNC_Cov_Nonzero <- rep200_HiSeq_Fungi_UNC_Cov[!rowSums(rep200_HiSeq_Fungi_UNC_Cov)==0,]
rep200_HiSeq_Fungi_CMS_Cov_Nonzero <- rep200_HiSeq_Fungi_CMS_Cov[!rowSums(rep200_HiSeq_Fungi_CMS_Cov)==0,]
rep200_HiSeq_Fungi_Broad_RNA_Cov_Nonzero <- rep200_HiSeq_Fungi_Broad_RNA_Cov[!rowSums(rep200_HiSeq_Fungi_Broad_RNA_Cov)==0,]
# Match metadata
metaQiitaCombined_Nonzero_DecontamV2_HMS_Cov_Nonzero <- droplevels(metaQiitaCombined_Nonzero_DecontamV2_HMS[rownames(rep200_HiSeq_Fungi_HMS_Cov_Nonzero),])
metaQiitaCombined_Nonzero_DecontamV2_BCM_Cov_Nonzero <- droplevels(metaQiitaCombined_Nonzero_DecontamV2_BCM[rownames(rep200_HiSeq_Fungi_BCM_Cov_Nonzero),])
metaQiitaCombined_Nonzero_DecontamV2_MDA_Cov_Nonzero <- droplevels(metaQiitaCombined_Nonzero_DecontamV2_MDA[rownames(rep200_HiSeq_Fungi_MDA_Cov_Nonzero),])
metaQiitaCombined_Nonzero_DecontamV2_WashU_Cov_Nonzero <- droplevels(metaQiitaCombined_Nonzero_DecontamV2_WashU[rownames(rep200_HiSeq_Fungi_WashU_Cov_Nonzero),])
metaQiitaCombined_Nonzero_DecontamV2_Broad_WGS_Cov_Nonzero <- droplevels(metaQiitaCombined_Nonzero_DecontamV2_Broad_WGS[rownames(rep200_HiSeq_Fungi_Broad_WGS_Cov_Nonzero),])
metaQiitaCombined_Nonzero_DecontamV2_UNC_Cov_Nonzero <- droplevels(metaQiitaCombined_Nonzero_DecontamV2_UNC[rownames(rep200_HiSeq_Fungi_UNC_Cov_Nonzero),])
metaQiitaCombined_Nonzero_DecontamV2_CMS_Cov_Nonzero <- droplevels(metaQiitaCombined_Nonzero_DecontamV2_CMS[rownames(rep200_HiSeq_Fungi_CMS_Cov_Nonzero),])
metaQiitaCombined_Nonzero_DecontamV2_Broad_RNA_Cov_Nonzero <- droplevels(metaQiitaCombined_Nonzero_DecontamV2_Broad_RNA[rownames(rep200_HiSeq_Fungi_Broad_RNA_Cov_Nonzero),])
#--------------------Save data for ML--------------------#
save(rep200_HiSeq_Fungi_DecontamV2_HMS,
rep200_HiSeq_Fungi_DecontamV2_BCM,
rep200_HiSeq_Fungi_DecontamV2_MDA,
rep200_HiSeq_Fungi_DecontamV2_WashU,
rep200_HiSeq_Fungi_DecontamV2_Broad_WGS,
rep200_HiSeq_Fungi_DecontamV2_UNC,
rep200_HiSeq_Fungi_DecontamV2_CMS,
rep200_HiSeq_Fungi_DecontamV2_Broad_RNA,
metaQiitaCombined_Nonzero_DecontamV2_HMS,
metaQiitaCombined_Nonzero_DecontamV2_BCM,
metaQiitaCombined_Nonzero_DecontamV2_MDA,
metaQiitaCombined_Nonzero_DecontamV2_WashU,
metaQiitaCombined_Nonzero_DecontamV2_Broad_WGS,
metaQiitaCombined_Nonzero_DecontamV2_UNC,
metaQiitaCombined_Nonzero_DecontamV2_CMS,
metaQiitaCombined_Nonzero_DecontamV2_Broad_RNA,
rep200_HiSeq_Fungi_HMS_Cov_Nonzero,
rep200_HiSeq_Fungi_BCM_Cov_Nonzero,
rep200_HiSeq_Fungi_MDA_Cov_Nonzero,
rep200_HiSeq_Fungi_WashU_Cov_Nonzero,
rep200_HiSeq_Fungi_Broad_WGS_Cov_Nonzero,
rep200_HiSeq_Fungi_UNC_Cov_Nonzero,
rep200_HiSeq_Fungi_CMS_Cov_Nonzero,
rep200_HiSeq_Fungi_Broad_RNA_Cov_Nonzero,
metaQiitaCombined_Nonzero_DecontamV2_HMS_Cov_Nonzero,
metaQiitaCombined_Nonzero_DecontamV2_BCM_Cov_Nonzero,
metaQiitaCombined_Nonzero_DecontamV2_MDA_Cov_Nonzero,
metaQiitaCombined_Nonzero_DecontamV2_WashU_Cov_Nonzero,
metaQiitaCombined_Nonzero_DecontamV2_Broad_WGS_Cov_Nonzero,
metaQiitaCombined_Nonzero_DecontamV2_UNC_Cov_Nonzero,
metaQiitaCombined_Nonzero_DecontamV2_CMS_Cov_Nonzero,
metaQiitaCombined_Nonzero_DecontamV2_Broad_RNA_Cov_Nonzero,
file = "Interim_data/data_for_ml_tcga_by_seq_center_and_experimental_strategy_with_coverage_filter_decontamV2_29Mar22.RData")
# Scripts: S12B
# load("Interim_data/data_for_ml_tcga_by_seq_center_and_experimental_strategy_16Sep21.RData")
#----------------------------------------------------------#
# Prepare TCGA data for Qiime
# Formerly without decontamination but now with (Mar 29 2022)
#----------------------------------------------------------#
# Subset to primary tumor data
metaQiitaCombined_Nonzero_HMS_PT <- metaQiitaCombined_Nonzero_DecontamV2_HMS %>%
filter(sample_type == "Primary Tumor") %>%
rename("submitted_name" = "sample_name") %>%
select(investigation, disease_type, experimental_strategy,data_submitting_center_label) %>%
rownames_to_column("sampleid") %>% droplevels()
metaQiitaCombined_Nonzero_BCM_PT <- metaQiitaCombined_Nonzero_DecontamV2_BCM %>%
filter(sample_type == "Primary Tumor") %>%
rename("submitted_name" = "sample_name") %>%
select(investigation, disease_type, experimental_strategy,data_submitting_center_label) %>%
rownames_to_column("sampleid") %>% droplevels()
metaQiitaCombined_Nonzero_MDA_PT <- metaQiitaCombined_Nonzero_DecontamV2_MDA %>%
filter(sample_type == "Primary Tumor") %>%
rename("submitted_name" = "sample_name") %>%
select(investigation, disease_type, experimental_strategy,data_submitting_center_label) %>%
rownames_to_column("sampleid") %>% droplevels()
metaQiitaCombined_Nonzero_WashU_PT <- metaQiitaCombined_Nonzero_DecontamV2_WashU %>%
filter(sample_type == "Primary Tumor") %>%
rename("submitted_name" = "sample_name") %>%
select(investigation, disease_type, experimental_strategy,data_submitting_center_label) %>%
rownames_to_column("sampleid") %>% droplevels()
metaQiitaCombined_Nonzero_Broad_WGS_PT <- metaQiitaCombined_Nonzero_DecontamV2_Broad_WGS %>%
filter(sample_type == "Primary Tumor") %>%
rename("submitted_name" = "sample_name") %>%
select(investigation, disease_type, experimental_strategy,data_submitting_center_label) %>%
rownames_to_column("sampleid") %>% droplevels()
# Write metadata to text files
write.table(metaQiitaCombined_Nonzero_HMS_PT, file = "Qiime_data_and_scripts/Qiime_input_data/metaQiitaCombined_Nonzero_HMS_PT.txt",
quote = FALSE, sep = "\t", row.names = FALSE,col.names = TRUE)
write.table(metaQiitaCombined_Nonzero_BCM_PT, file = "Qiime_data_and_scripts/Qiime_input_data/metaQiitaCombined_Nonzero_BCM_PT.txt",
quote = FALSE, sep = "\t", row.names = FALSE,col.names = TRUE)
write.table(metaQiitaCombined_Nonzero_MDA_PT, file = "Qiime_data_and_scripts/Qiime_input_data/metaQiitaCombined_Nonzero_MDA_PT.txt",
quote = FALSE, sep = "\t", row.names = FALSE,col.names = TRUE)
write.table(metaQiitaCombined_Nonzero_WashU_PT, file = "Qiime_data_and_scripts/Qiime_input_data/metaQiitaCombined_Nonzero_WashU_PT.txt",
quote = FALSE, sep = "\t", row.names = FALSE,col.names = TRUE)
write.table(metaQiitaCombined_Nonzero_Broad_WGS_PT, file = "Qiime_data_and_scripts/Qiime_input_data/metaQiitaCombined_Nonzero_Broad_WGS_PT.txt",
quote = FALSE, sep = "\t", row.names = FALSE,col.names = TRUE)
## Subset count data
rep200_HiSeq_Fungi_Decontam_HMS_PT <- rep200_HiSeq_Fungi_DecontamV2_HMS[metaQiitaCombined_Nonzero_HMS_PT$sampleid,]
rep200_HiSeq_Fungi_Decontam_BCM_PT <- rep200_HiSeq_Fungi_DecontamV2_BCM[metaQiitaCombined_Nonzero_BCM_PT$sampleid,]
rep200_HiSeq_Fungi_Decontam_MDA_PT <- rep200_HiSeq_Fungi_DecontamV2_MDA[metaQiitaCombined_Nonzero_MDA_PT$sampleid,]
rep200_HiSeq_Fungi_Decontam_WashU_PT <- rep200_HiSeq_Fungi_DecontamV2_WashU[metaQiitaCombined_Nonzero_WashU_PT$sampleid,]
rep200_HiSeq_Fungi_Decontam_Broad_WGS_PT <- rep200_HiSeq_Fungi_DecontamV2_Broad_WGS[metaQiitaCombined_Nonzero_Broad_WGS_PT$sampleid,]
## Save count data as biom tables
rep200_HiSeq_Fungi_Decontam_HMS_PT_BIOM <- make_biom(t(rep200_HiSeq_Fungi_Decontam_HMS_PT))
write_biom(rep200_HiSeq_Fungi_Decontam_HMS_PT_BIOM, biom_file = "Qiime_data_and_scripts/Qiime_input_data/rep200_HiSeq_Fungi_Decontam_HMS_PT.biom")
rep200_HiSeq_Fungi_Decontam_BCM_PT_BIOM <- make_biom(t(rep200_HiSeq_Fungi_Decontam_BCM_PT))
write_biom(rep200_HiSeq_Fungi_Decontam_BCM_PT_BIOM, biom_file = "Qiime_data_and_scripts/Qiime_input_data/rep200_HiSeq_Fungi_Decontam_BCM_PT.biom")
rep200_HiSeq_Fungi_Decontam_MDA_PT_BIOM <- make_biom(t(rep200_HiSeq_Fungi_Decontam_MDA_PT))
write_biom(rep200_HiSeq_Fungi_Decontam_MDA_PT_BIOM, biom_file = "Qiime_data_and_scripts/Qiime_input_data/rep200_HiSeq_Fungi_Decontam_MDA_PT.biom")
rep200_HiSeq_Fungi_Decontam_WashU_PT_BIOM <- make_biom(t(rep200_HiSeq_Fungi_Decontam_WashU_PT))
write_biom(rep200_HiSeq_Fungi_Decontam_WashU_PT_BIOM, biom_file = "Qiime_data_and_scripts/Qiime_input_data/rep200_HiSeq_Fungi_Decontam_WashU_PT.biom")
rep200_HiSeq_Fungi_Decontam_Broad_WGS_PT_BIOM <- make_biom(t(rep200_HiSeq_Fungi_Decontam_Broad_WGS_PT))
write_biom(rep200_HiSeq_Fungi_Decontam_Broad_WGS_PT_BIOM, biom_file = "Qiime_data_and_scripts/Qiime_input_data/rep200_HiSeq_Fungi_Decontam_Broad_WGS_PT.biom")
#----------------------------------------------------------#
# Use Qiime to derive alpha and beta diversity results
#----------------------------------------------------------#
# Scripts for doing these steps are outlined in the
# "Qiime_data_and_scripts" folder and some of their outputs
# will be used to create plots below for alpha diversity.
#----------------------------------------------------------#
# Import alpha diversity results from Qiime
#----------------------------------------------------------#
# NOTE: The loaded csv files were acquired by uploading the corresponding .qzv file
# to https://view.qiime2.org/ and then clicking "Download raw data as TSV" followed by
# (i) deleting the 2nd row (contains unnecessary column type info) and (ii) saving as a CSV file.
# HMS
alphaDivOtus_HMS <- read.csv("Qiime_data_and_scripts_resubmission_version/core_metrics_hms_5k/alpha_div_observed_features_hms_5k.csv", stringsAsFactors = FALSE)
alphaDivShannon_HMS <- read.csv("Qiime_data_and_scripts_resubmission_version/core_metrics_hms_5k/alpha_div_shannon_hms_5k.csv", stringsAsFactors = FALSE)
alphaDivOtus_HMS$investigation <- gsub("^TCGA\\-","",alphaDivOtus_HMS$investigation)
alphaDivShannon_HMS$investigation <- gsub("^TCGA\\-","",alphaDivShannon_HMS$investigation)
# BCM
alphaDivOtus_BCM <- read.csv("Qiime_data_and_scripts_resubmission_version/core_metrics_bcm_5k/alpha_div_observed_features_bcm_5k.csv", stringsAsFactors = FALSE)
alphaDivShannon_BCM <- read.csv("Qiime_data_and_scripts_resubmission_version/core_metrics_bcm_5k/alpha_div_shannon_bcm_5k.csv", stringsAsFactors = FALSE)
alphaDivOtus_BCM$investigation <- gsub("^TCGA\\-","",alphaDivOtus_BCM$investigation)
alphaDivShannon_BCM$investigation <- gsub("^TCGA\\-","",alphaDivShannon_BCM$investigation)
# MDA
alphaDivOtus_MDA <- read.csv("Qiime_data_and_scripts_resubmission_version/core_metrics_mda_5k/alpha_div_observed_features_mda_5k.csv", stringsAsFactors = FALSE)
alphaDivShannon_MDA <- read.csv("Qiime_data_and_scripts_resubmission_version/core_metrics_mda_5k/alpha_div_shannon_mda_5k.csv", stringsAsFactors = FALSE)
alphaDivOtus_MDA$investigation <- gsub("^TCGA\\-","",alphaDivOtus_MDA$investigation)
alphaDivShannon_MDA$investigation <- gsub("^TCGA\\-","",alphaDivShannon_MDA$investigation)
# WashU
alphaDivOtus_WashU <- read.csv("Qiime_data_and_scripts_resubmission_version/core_metrics_washU_5k/alpha_div_observed_features_washU_5k.csv", stringsAsFactors = FALSE)
alphaDivShannon_WashU <- read.csv("Qiime_data_and_scripts_resubmission_version/core_metrics_washU_5k/alpha_div_shannon_washU_5k.csv", stringsAsFactors = FALSE)
alphaDivOtus_WashU$investigation <- gsub("^TCGA\\-","",alphaDivOtus_WashU$investigation)
alphaDivShannon_WashU$investigation <- gsub("^TCGA\\-","",alphaDivShannon_WashU$investigation)
# Broad WGS
alphaDivOtus_Broad_WGS <- read.csv("Qiime_data_and_scripts_resubmission_version/core_metrics_broad_WGS_2k/alpha_div_observed_features_broad_WGS_2k.csv", stringsAsFactors = FALSE)
alphaDivShannon_Broad_WGS <- read.csv("Qiime_data_and_scripts_resubmission_version/core_metrics_broad_WGS_2k/alpha_div_shannon_broad_WGS_2k.csv", stringsAsFactors = FALSE)
alphaDivOtus_Broad_WGS$investigation <- gsub("^TCGA\\-","",alphaDivOtus_Broad_WGS$investigation)
alphaDivShannon_Broad_WGS$investigation <- gsub("^TCGA\\-","",alphaDivShannon_Broad_WGS$investigation)
#----------------------------------------------------------#
# Plot Qiime alpha diversity data for HMS and MDA with matching cancer type colors
#----------------------------------------------------------#
colors <- pal_d3("category20")(15)
table(alphaDivOtus_HMS$investigation)
# HMS observed features
alphaDivOtus_HMS %>%
mutate(palColors = case_when(
investigation == "BLCA" ~ colors[1],
investigation == "BRCA" ~ colors[2],
investigation == "CESC" ~ colors[3],
investigation == "COAD" ~ colors[4],
investigation == "HNSC" ~ colors[5],
investigation == "LGG" ~ colors[6],
investigation == "LUAD" ~ colors[7],
investigation == "PRAD" ~ colors[8],
investigation == "READ" ~ colors[9],
investigation == "SKCM" ~ colors[10],
investigation == "STAD" ~ colors[11],
investigation == "THCA" ~ colors[12],
investigation == "UCEC" ~ colors[13]
)) -> alphaDivOtus_HMS_colored
# HMS shannon
alphaDivShannon_HMS %>%
mutate(palColors = case_when(
investigation == "BLCA" ~ colors[1],
investigation == "BRCA" ~ colors[2],
investigation == "CESC" ~ colors[3],
investigation == "COAD" ~ colors[4],
investigation == "HNSC" ~ colors[5],
investigation == "LGG" ~ colors[6],
investigation == "LUAD" ~ colors[7],
investigation == "PRAD" ~ colors[8],
investigation == "READ" ~ colors[9],
investigation == "SKCM" ~ colors[10],
investigation == "STAD" ~ colors[11],
investigation == "THCA" ~ colors[12],
investigation == "UCEC" ~ colors[13]
)) -> alphaDivShannon_HMS_colored
table(alphaDivOtus_MDA$investigation)
# MDA observed features
alphaDivOtus_MDA %>%
mutate(
palColors = case_when(
investigation == "BLCA" ~ colors[1],
investigation == "BRCA" ~ colors[2],
investigation == "CESC" ~ colors[3],
# investigation == "COAD" ~ colors[4],
investigation == "HNSC" ~ colors[5],
# investigation == "LGG" ~ colors[6],
# investigation == "LUAD" ~ colors[7],
# investigation == "PRAD" ~ colors[8],
# investigation == "READ" ~ colors[9],
# investigation == "SKCM" ~ colors[10],
investigation == "STAD" ~ colors[11],
investigation == "THCA" ~ colors[12],
# investigation == "UCEC" ~ colors[13]
investigation == "ESCA" ~ colors[14],
investigation == "UVM" ~ colors[15]
)) -> alphaDivOtus_MDA_colored
# MDA shannon
alphaDivShannon_MDA %>%
mutate(
palColors = case_when(
investigation == "BLCA" ~ colors[1],
investigation == "BRCA" ~ colors[2],
investigation == "CESC" ~ colors[3],
# investigation == "COAD" ~ colors[4],
investigation == "HNSC" ~ colors[5],
# investigation == "LGG" ~ colors[6],
# investigation == "LUAD" ~ colors[7],
# investigation == "PRAD" ~ colors[8],
# investigation == "READ" ~ colors[9],
# investigation == "SKCM" ~ colors[10],
investigation == "STAD" ~ colors[11],
investigation == "THCA" ~ colors[12],
# investigation == "UCEC" ~ colors[13]
investigation == "ESCA" ~ colors[14],
investigation == "UVM" ~ colors[15]
)) -> alphaDivShannon_MDA_colored
# HMS observed features
alphaDivOtus_HMS_colored %>%
ggplot(aes(reorder(investigation, observed_otus, FUN=median), observed_otus, fill=palColors)) +
geom_boxplot() + xlab("TCGA cancer type (Harvard Med School)") + ylab("Observed features") + theme_pubr(legend = "none") +
rotate_x_text(30) +
scale_fill_manual(values = levels(factor(alphaDivOtus_HMS_colored$palColors))) +
stat_compare_means(label.x.npc = 0.1, label.y.npc = 0.5) +
stat_n_text()
ggsave(filename = "Figures/Supplementary_Figures/alphaDivOtusPlot_HMS.pdf",
dpi = "retina", units = "in", height = 4, width = 7)
alphaDivOtus_HMS_colored %>% write.csv("Figures_data/Supplementary_Figures/alphaDivOtusPlot_HMS.csv")
# HMS shannon
alphaDivShannon_HMS_colored %>%
ggplot(aes(reorder(investigation, shannon, FUN=median), shannon, fill=palColors)) +
geom_boxplot() + xlab("TCGA cancer type (Harvard Med School)") + ylab("Shannon diversity") + theme_pubr(legend = "none") +
rotate_x_text(30) +
scale_fill_manual(values = levels(factor(alphaDivShannon_HMS_colored$palColors))) +
stat_compare_means(label.x.npc = 0.1, label.y.npc = 0.5) +
stat_n_text()
ggsave(filename = "Figures/Supplementary_Figures/alphaDivShannonPlot_HMS.pdf",
dpi = "retina", units = "in", height = 4, width = 7)
alphaDivShannon_HMS_colored %>% write.csv("Figures_data/Supplementary_Figures/alphaDivOtusPlot_HMS.csv")
# MDA observed features
alphaDivOtus_MDA_colored %>%
ggplot(aes(reorder(investigation, observed_otus, FUN=median), observed_otus, fill=palColors)) +
geom_boxplot() + xlab("TCGA cancer type (MD Anderson)") + ylab("Observed features") + theme_pubr(legend = "none") +
rotate_x_text(30) +
scale_fill_manual(values = levels(factor(alphaDivOtus_MDA_colored$palColors))) +
stat_compare_means(label.x.npc = 0.1, label.y.npc = 0.5) +
stat_n_text()
ggsave(filename = "Figures/Supplementary_Figures/alphaDivOtusPlot_MDA.pdf",
dpi = "retina", units = "in", height = 4, width = 7)
alphaDivOtus_MDA_colored %>% write.csv("Figures_data/Supplementary_Figures/alphaDivOtusPlot_MDA.csv")
# MDA shannon
alphaDivShannon_MDA_colored %>%
ggplot(aes(reorder(investigation, shannon, FUN=median), shannon, fill=palColors)) +
geom_boxplot() + xlab("TCGA cancer type (MD Anderson)") + ylab("Shannon diversity") + theme_pubr(legend = "none") +
rotate_x_text(30) +
scale_fill_manual(values = levels(factor(alphaDivShannon_MDA_colored$palColors))) +
stat_compare_means(label.x.npc = 0.1, label.y.npc = 0.5) +
stat_n_text()
ggsave(filename = "Figures/Supplementary_Figures/alphaDivShannonPlot_MDA.pdf",
dpi = "retina", units = "in", height = 4, width = 7)
alphaDivShannon_MDA_colored %>% write.csv("Figures_data/Supplementary_Figures/alphaDivShannonPlot_MDA.csv")
# BCM observed features
alphaDivOtus_BCM %>%
ggplot(aes(reorder(investigation, observed_otus, FUN=median), observed_otus, fill=investigation)) +
geom_boxplot() + xlab("TCGA cancer type (BCM)") + ylab("Observed features") + theme_pubr(legend = "none") +
rotate_x_text(30) +
scale_fill_igv() +
# scale_fill_manual(values = levels(factor(alphaDivOtus_BCM$palColors))) +
stat_compare_means(label.x.npc = 0.1, label.y.npc = 0.5) +
stat_n_text()
ggsave(filename = "Figures/Supplementary_Figures/alphaDivOtusPlot_BCM.pdf",
dpi = "retina", units = "in", height = 4, width = 7)
alphaDivOtus_BCM %>% write.csv("Figures_data/Supplementary_Figures/alphaDivOtusPlot_BCM.csv")
# BCM shannon
alphaDivShannon_BCM %>%
ggplot(aes(reorder(investigation, shannon, FUN=median), shannon, fill=investigation)) +
geom_boxplot() + xlab("TCGA cancer type (BCM)") + ylab("Shannon diversity") + theme_pubr(legend = "none") +
rotate_x_text(30) +
scale_fill_igv() +
# scale_fill_manual(values = levels(factor(alphaDivShannon_BCM_colored$palColors))) +
stat_compare_means(label.x.npc = 0.1, label.y.npc = 0.5) +
stat_n_text()
ggsave(filename = "Figures/Supplementary_Figures/alphaDivShannonPlot_BCM.pdf",
dpi = "retina", units = "in", height = 4, width = 7)
alphaDivShannon_BCM %>% write.csv("Figures_data/Supplementary_Figures/alphaDivShannonPlot_BCM.csv")
# WashU observed features
alphaDivOtus_WashU %>%
ggplot(aes(reorder(investigation, observed_otus, FUN=median), observed_otus, fill=investigation)) +
geom_boxplot() + xlab("TCGA cancer type (WashU)") + ylab("Observed features") + theme_pubr(legend = "none") +
rotate_x_text(30) +
scale_fill_igv() +
# scale_fill_manual(values = levels(factor(alphaDivOtus_WashU$palColors))) +
stat_compare_means(label.x.npc = 0.1, label.y.npc = 0.5) +
stat_n_text()
ggsave(filename = "Figures/Supplementary_Figures/alphaDivOtusPlot_WashU.pdf",
dpi = "retina", units = "in", height = 4, width = 7)
alphaDivOtus_WashU %>% write.csv("Figures_data/Supplementary_Figures/alphaDivOtusPlot_WashU.csv")
# WashU shannon
alphaDivShannon_WashU %>%
ggplot(aes(reorder(investigation, shannon, FUN=median), shannon, fill=investigation)) +
geom_boxplot() + xlab("TCGA cancer type (WashU)") + ylab("Shannon diversity") + theme_pubr(legend = "none") +
rotate_x_text(30) +
scale_fill_igv() +
# scale_fill_manual(values = levels(factor(alphaDivShannon_WashU_colored$palColors))) +
stat_compare_means(label.x.npc = 0.1, label.y.npc = 0.5) +
stat_n_text()
ggsave(filename = "Figures/Supplementary_Figures/alphaDivShannonPlot_WashU.pdf",
dpi = "retina", units = "in", height = 4, width = 7)
alphaDivShannon_WashU %>% write.csv("Figures_data/Supplementary_Figures/alphaDivShannonPlot_WashU.csv")
# Broad WGS observed features
alphaDivOtus_Broad_WGS %>%
ggplot(aes(reorder(investigation, observed_otus, FUN=median), observed_otus, fill=investigation)) +
geom_boxplot() + xlab("TCGA cancer type (Broad WGS)") + ylab("Observed features") + theme_pubr(legend = "none") +
rotate_x_text(30) +
scale_fill_igv() +
# scale_fill_manual(values = levels(factor(alphaDivOtus_Broad_WGS$palColors))) +
stat_compare_means(label.x.npc = 0.1, label.y.npc = 0.8) +
stat_n_text()
ggsave(filename = "Figures/Supplementary_Figures/alphaDivOtusPlot_Broad_WGS.pdf",
dpi = "retina", units = "in", height = 4, width = 7)
alphaDivOtus_Broad_WGS %>% write.csv("Figures_data/Supplementary_Figures/alphaDivOtusPlot_Broad_WGS.csv")
# Broad WGS shannon
alphaDivShannon_Broad_WGS %>%
ggplot(aes(reorder(investigation, shannon, FUN=median), shannon, fill=investigation)) +
geom_boxplot() + xlab("TCGA cancer type (Broad WGS)") + ylab("Shannon diversity") + theme_pubr(legend = "none") +
rotate_x_text(30) +
scale_fill_igv() +
# scale_fill_manual(values = levels(factor(alphaDivShannon_Broad_WGS_colored$palColors))) +
stat_compare_means(label.x.npc = 0.1, label.y.npc = 0.8) +
stat_n_text()
ggsave(filename = "Figures/Supplementary_Figures/alphaDivShannonPlot_Broad_WGS.pdf",
dpi = "retina", units = "in", height = 4, width = 7)
alphaDivShannon_Broad_WGS %>% write.csv("Figures_data/Supplementary_Figures/alphaDivShannonPlot_Broad_WGS.csv")