forked from shandley/human_volunteer_rotabiome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhuman_volunteer_16S_analysis.Rmd
1630 lines (1364 loc) · 66.6 KB
/
human_volunteer_16S_analysis.Rmd
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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Human Volunteer 16S Amplicon Analysis"
author: "Barry Hykes Jr. and Scott A. Handley"
date: '`r format(Sys.Date(), "%B %d, %Y")`'
output: html_document
---
**Project Description:** Analysis of 16S rRNA amplicon data from a cohort of human volunteers (heatlhy men aged 18-35) randomized into three treatment groups: 1) control (no antibiotics), 2) narrow spectrum (oral vancomycin) or 3) broad-spectrum (oral vancomycin, ciprofloxacin, and metronidazole) antibiotics. Antibiotics were taken for 7-days prior to vaccination with Rotarix (RVV), polysaccharide-pneumococcal (Pneumo 23) and tetanus-toxoid vaccine. The primary endpoint was difference in 28 days-post-vaccination anti-RV IgA. Secondary endpoints were proportion of volunteers with day 7 anti-RV IgA boosting (>=2 fold-increase), absolute and proportion of RV-antigen shedding, anti-RV, pneumococcal and anti-tetanus IgG.
**Primary Collaborator:**
Vanessa Harris (v.harris@aighd.org)
**Other relevant files:**
The following Phyloseq objects are available. Each is distinguished based on the 16S reference database used for taxonomic classification. RDP and Silva were processed through the species assignment workflow:
* ps0.human_volunteer.gg.RDS
* ps0.human_volunteer.silva.RDS
* ps0.human_volunteer.rdp.RDS
* Mapping file: mapping_human_volunteer.txt
**Workflow details:** The R commands below represent a full analysis of the following:
1) Sample assessment
2) ASV properties
3) Community composition
4) Alpha diversity
5) Beta diversity
6) Differential abundance testing
```{r initiate-environment}
# Set default knitr option
knitr::opts_chunk$set(fig.width=8,
fig.height=6,
fig.path="./figures/",
dev='png',
warning=FALSE,
message=FALSE)
# Load libraries
library("tidyverse"); packageVersion("tidyverse")
library("reshape2"); packageVersion("reshape2")
library("plyr"); packageVersion("plyr")
library("phyloseq"); packageVersion("phyloseq")
library("RColorBrewer"); packageVersion("RColorBrewer")
library("vegan"); packageVersion("vegan")
library("gridExtra"); packageVersion("gridExtra")
library("knitr"); packageVersion("knitr")
library("plotly"); packageVersion("plotly")
library("microbiome"); packageVersion("microbiome")
library("ggpubr"); packageVersion("ggpubr")
library("data.table"); packageVersion("data.table")
library("pairwiseAdonis"); packageVersion("pairwiseAdonis")
library("DESeq2"); packageVersion("DESeq2")
# ggplot2 settings
# Set global theming
theme_set(theme_bw(base_size = 12))
# Set a seed value so that exact results can be reproduced
set.seed(1000)
```
##Read in data
```{r initiate-data}
# Load Phyloseq Object
# Selected RDP due to it's up-to-date nature and conservative taxonomy. Other files are also valid for anlysis but are not explored here but are available in the ./data/ directory
ps0 <- readRDS("~/Dropbox/Research/human_volunteer/data/ps0.human_volunteer.rdp.RDS")
ps0
# Load mapping file
map <- import_qiime_sample_data("~/Dropbox/Research/human_volunteer/data/mapping_human_volunteer.txt")
ps0 <- merge_phyloseq(ps0, map)
ps0
# View sample variables & generate basic stats
sample_variables(ps0)
sd(sample_sums(ps0))
get_taxa_unique(ps0, "Phylum")
ntaxa(ps0)
```
##Factor reordering and renaming
```{r factor-adjustments}
# Order and update randomization arms factor
sample_data(ps0)$randomization_arm
sample_data(ps0)$randomization_arm <- factor(sample_data(ps0)$randomization_arm, levels = c("No_antibiotics", "Narrow_spectrum_antibiotics", "Broad_spectrum_antibiotics"))
sample_data(ps0)$randomization_arm
sample_data(ps0)$randomization_arm <- factor(sample_data(ps0)$randomization_arm, labels = c("No antibiotics", "Narrow spectrum antibiotics", "Broad spectrum antibiotics"))
sample_data(ps0)$randomization_arm
```
##Sample assessment
```{r sample-removal-identification}
# Format a data table to combine sample summary data with sample variable data
ss <- sample_sums(ps0)
sd <- as.data.frame(sample_data(ps0)) # useful to coerce the phyloseq object into an R data frame
ss.df <- merge(sd, data.frame("ASV" = ss), by ="row.names") # merge ss with sd by row names. Rename ss to ASVs in the new data frame
# Plot the data by the treatment variable
y = 100 # Set a threshold for the minimum number of acceptable reads. Can start as a guess
x = "randomization_arm" # Set the x-axis variable you want to examine
label = "Description" # This is the label you want to overlay on the points that are below threshold y. Should be something sample specific
# Plot
p.ss.boxplot<- ggplot(ss.df, aes_string(x, y = "ASV")) + # x is what you assigned it above
geom_boxplot(outlier.colour="NA", aes(group = randomization_arm)) +
scale_y_log10() +
geom_hline(yintercept = y, lty = 2) + # Draws a dashed line across the threshold you set above as y
geom_jitter(alpha = 0.6, width = 0.15, size = 3) +
labs(y = "ASV (log10)") +
facet_grid(~day) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
theme(legend.position = "NULL") +
theme(axis.title.x = element_blank())
p.ss.boxplot
```
##Outlier sample removal
```{r sample-removal}
# Remove samples with fewer than y ASV
# Save samples that fell below the selected threshold
ps.failed <- prune_samples(sample_sums(ps0) < y, ps0)
nsamples(ps.failed)
# Create a table of failed sample information
failed.samples <- data.frame(sample_names(ps.failed), sample_data(ps.failed)$sample_ID, sample_data(ps.failed)$tube_ID)
write.table(failed.samples, file = "./results/failed_samples.txt", sep = "\t")
# Remove samples with fewer than y ASV
ps0
ps0 <- prune_samples(sample_sums(ps0) >=y, ps0)
ps0
min(sample_sums(ps0))
```
##Taxon cleaning
```{r taxon-cleaning}
# Begin by removing sequences that were not classified as Bacteria or were classified as either mitochondria or chlorplast
ps0 # Check the number of taxa prior to removal
ps1 <- ps0 %>%
subset_taxa(
Kingdom == "Bacteria" &
Family != "mitochondria" &
Class != "Chloroplast" &
Phylum != "Cyanobacteria/Chloroplast"
)
ps1 # Confirm that the taxa were removed
```
##Data transformations
```{r data-transform}
# Some of these are not used in subsequent analysis, but are coded as a chunk here for convenience
# Transform to Realative abundances
ps1.ra <- transform_sample_counts(ps1, function(OTU) OTU/sum(OTU))
```
##Subsetting
```{r subsetting}
# No antibiotics (control)
ps1.con <- subset_samples(ps1, randomization_arm == "No antibiotics")
ps1.con
ps1.con <- prune_samples(sample_sums(ps1.con) > 0, ps1.con)
ps1.con
ps1.con.log <- transform_sample_counts(ps1.con, function(x) log(1 + x))
# Narrow spectrum antibiotics
ps1.narrow <- subset_samples(ps1, randomization_arm == "Narrow spectrum antibiotics")
ps1.narrow
ps1.narrow <- prune_samples(sample_sums(ps1.narrow) > 0, ps1.narrow)
ps1.narrow
ps1.narrow.log <- transform_sample_counts(ps1.narrow, function(x) log(1 + x))
# Broad spectrum antibiotics
ps1.broad <- subset_samples(ps1, randomization_arm == "Broad spectrum antibiotics")
ps1.broad
ps1.broad <- prune_samples(sample_sums(ps1.broad) > 0, ps1.broad)
ps1.broad
ps1.broad.log <- transform_sample_counts(ps1.broad, function(x) log(1 + x))
# Antibiotics
ps1.abx <- subset_samples(ps1, antibiotics == "Antibiotics")
ps1.abx
ps1.abx <- prune_samples(sample_sums(ps1.abx) > 0, ps1.abx)
ps1.abx
ps1.abx.log <- transform_sample_counts(ps1.abx, function(x) log(1 + x))
```
##Community composition plotting
These plots were not included in the final manuscript but remain here as compositional overviews. Interactive plots are also produced.
```{r community-composition-plots}
# Phyla level plots
# Melt to long format (for ggploting)
# Prune out phyla below % in each sample
# Set propotional threshold for taxa to be removed
threshold = 0.03
ps1_phylum <- ps1 %>%
tax_glom(taxrank = "Phylum") %>% # agglomerate at phylum level
transform_sample_counts(function(x) {x/sum(x)} ) %>% # Transform to rel. abundance
psmelt() %>% # Melt to long format
filter(Abundance > threshold) %>% # Filter out low abundance taxa
arrange(Phylum) # Sort data frame alphabetically by phylum
# Convert Sample No to a factor because R is weird sometime
ps1_phylum$patient_ID <- as.factor(ps1_phylum$patient_ID)
p.comm.bar <- ggplot(ps1_phylum, aes(x = patient_ID, y = Abundance, fill = Phylum)) +
geom_bar(stat = "identity", width = 0.9) +
facet_wrap(randomization_arm~day, scales = "free_x") +
ggtitle("Community Composition Over Time and Randomization Arm") +
labs(y = "Relative Abundance") +
theme(legend.position = "bottom") +
theme(axis.text.x = element_blank()) +
theme(axis.title.x = element_blank()) +
scale_fill_brewer(palette = "Dark2")
p.comm.bar
# Draw interactive plot
ggplotly(p.comm.bar)
```
##Phyla-level summary plots
```{r phyla-level-boxplots}
# Agglomerate taxa
glom <- tax_glom(ps1.ra, taxrank = 'Phylum')
# Create dataframe from phyloseq object
dat <- as.tibble(psmelt(glom))
# Set comparisons
my_comparisons.1 <- list( c("No antibiotics", "Narrow spectrum antibiotics"), c("No antibiotics", "Broad spectrum antibiotics"), c("Narrow spectrum antibiotics", "Broad spectrum antibiotics") )
my_comparisons.2 <- list( c("-9", "0"), c("-9", "7"), c("0", "7") )
# Table of mean abundances per Phylum
dat.summary <- dat %>%
group_by(Phylum) %>%
summarise(mean = mean(Abundance)) %>%
arrange(desc(mean))
ggplot(dat.summary, aes(x = fct_reorder(Phylum, mean), y = mean)) +
geom_point() +
coord_flip()
# Reorder
levels(dat$Phylum)
dat.reorder <- dat %>%
mutate(Phylum = reorder(Phylum, Abundance, mean))
levels(dat.reorder$Phylum)
# Determine how mean abundances of Phyla are altered by treatment
p.boxplot.phylum.1 <- ggboxplot(dat.reorder, x = "randomization_arm", y = "Abundance", outlier.shape = NA) +
geom_jitter(width = 0.2) +
labs(title = "Figure S3", y = "Relative Abundance", x = "") +
coord_cartesian(ylim = c(0, 1.5)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
stat_compare_means(comparisons = my_comparisons.1, label = "p.signif", hide.ns = TRUE) +
facet_grid(day~Phylum)
p.boxplot.phylum.1
# Note: For the figure in the manuscript we manually replaced the asterisks and removed the ns for aesthetic purposes
# Subset to phyla with treatment alteration in mean abundnaces
dat.1 <- filter(dat.reorder, Phylum %in% c("Firmicutes",
"Bacteroidetes",
"Proteobacteria",
"Verrucomicrobia",
"Actinobacteria",
"Fusobacteria"))
levels(dat.1$Phylum)
dat.1 <- droplevels(dat.1)
levels(dat.1$Phylum)
# Boxplot with treatment altered phyla
p.boxplot.phylum.2 <- ggboxplot(dat.1, x = "randomization_arm", y = "Abundance", outlier.shape = NA) +
geom_jitter(width = 0.2) +
labs(title = "Figure S3", y = "Relative Abundance", x = "") +
coord_cartesian(ylim = c(0, 1.5)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
stat_compare_means(comparisons = my_comparisons.1, label = "p.format", hide.ns = TRUE) +
facet_grid(day~Phylum)
p.boxplot.phylum.2
# Note: For the figure in the manuscript we manually replaced the asterisks and removed the ns for aesthetic purposes
# Not inlcuded in the final manuscript, but referenced in the text
p.boxplot.phylum.3 <- ggpaired(dat.1, x = "day", y = "Abundance", outlier.shape = NA, id = "patient_ID") +
geom_jitter(width = 0.2) +
labs(y = "Relative Abundance") +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
stat_compare_means(comparisons = my_comparisons.2, hide.ns = FALSE, label = "p.signif") +
facet_grid(randomization_arm~Phylum) +
coord_cartesian(ylim = c(0, 1.5))
p.boxplot.phylum.3
```
```{r phyla-smoother-plots}
# Reorder for legend consistency
# Reorder
levels(dat.1$Phylum)
dat.1.reorder <- dat.1 %>%
mutate(Phylum = reorder(Phylum, Abundance, function(x) -mean(x)))
levels(dat.1.reorder$Phylum)
p.gam.phylum <- ggplot(dat.1.reorder, aes(x = day, y = Abundance, color = Phylum)) +
stat_smooth(method = "gam", formula = y ~ s(x, bs = "cr", k = 3)) +
labs(y = "Relative Abundance", x = "Day") +
scale_x_continuous(breaks = c(-9,0,7)) +
coord_cartesian(ylim = c(0, 1)) +
geom_jitter(size = 3, alpha = 0.4, width = 1.5) +
facet_grid(~randomization_arm)
p.gam.phylum
```
##Alpha diversity
```{r add-sample-data}
# Diversity calculations
diversity <- global(ps1)
head(diversity)
# Bind sample data to diversity data
sd.1 <- as.data.frame(sample_data(ps1)) # useful to coerce the phyloseq object into an R data frame
ps1.rich <- merge(sd.1, diversity, by ="row.names") # merge sd.1 by row names
```
```{r paired-richness}
my.comparisons.paired <- list(c("Pre", "0"), c("Pre", "7"), c("0","7"))
p.paired.rich.1 <- ggpaired(ps1.rich, x = "day", y = "richness_0", outlier.shape = NA, id = "patient_ID") +
geom_jitter(width = 0.2) +
labs(y = "Richness") +
theme(axis.title.x = element_blank()) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
facet_grid(~randomization_arm) +
stat_compare_means(label = "p.signif", method = "t.test", ref.group = "-9", hide.ns = TRUE) +
theme(axis.text.x = element_blank())
p.paired.sd.1 <- ggpaired(ps1.rich, x = "day", y = "diversities_shannon", outlier.shape = NA, id = "patient_ID") +
geom_jitter(width = 0.2) +
labs(y = "Shannon Diversity") +
theme(axis.title.x = element_blank()) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
facet_grid(~randomization_arm) +
stat_compare_means(label = "p.signif", method = "t.test", ref.group = "-9", hide.ns = TRUE)
ggarrange(p.paired.rich.1, p.paired.sd.1, nrow = 2, labels = c("A)", "B)"))
# Alpha diversity comparisons between treatments
p.paired.rich.2 <- ggboxplot(ps1.rich, x = "randomization_arm", y = "richness_0", outlier.shape = NA, id = "patient_ID") +
geom_jitter(width = 0.2) +
labs(y = "Richness") +
theme(axis.title.x = element_blank()) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
facet_grid(~day) +
stat_compare_means(label = "p.format", comparisons = my_comparisons.1, hide.ns = TRUE) +
theme(axis.text.x = element_blank())
p.paired.sd.2 <- ggboxplot(ps1.rich, x = "randomization_arm", y = "diversities_shannon", outlier.shape = NA, id = "patient_ID") +
geom_jitter(width = 0.2) +
labs(y = "Shannon Diversity") +
theme(axis.title.x = element_blank()) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
facet_grid(~day) +
stat_compare_means(label = "p.format", comparisons = my_comparisons.1, hide.ns = TRUE)
ggarrange(p.paired.rich.2, p.paired.sd.2, nrow = 2, labels = c("A)", "B)"))
# Note: This figure was not included in the final manuscript, but the analysis and p-values were referenced in the text
```
```{r alpha-div-day7-roto-boost-alpha-diversity}
# These plots were not inlcuded in the final manuscript, but were discussed in the results
p.rich.rota_boost <- ggboxplot(subset(ps1.rich, randomization_arm == "Narrow spectrum antibiotics"), x = "d7_rota_boost_updated", y = "richness_0", outlier.shape = NA) +
geom_jitter(width = 0.2) +
ylim(0,250) +
labs(y = "Richness", title = "Boost") +
theme(axis.title.x = element_blank()) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
stat_compare_means(label = "p.format", method = "t.test", hide.ns = TRUE) +
facet_grid(~day) +
theme(axis.text.x = element_blank())
p.sd.rota_boost <- ggboxplot(subset(ps1.rich, randomization_arm == "Narrow spectrum antibiotics"), x = "d7_rota_boost_updated", y = "diversities_shannon", outlier.shape = NA) +
geom_jitter(width = 0.2) +
ylim(0,5) +
labs(y = "Shannon diversity") +
theme(axis.title.x = element_blank()) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
stat_compare_means(label = "p.format", method = "t.test", hide.ns = TRUE) +
facet_grid(~day)
ggarrange(p.rich.rota_boost, p.sd.rota_boost, nrow = 2, labels = c("A)", "B)"))
# Note: This figure was not included in the final manuscript, but the analysis and p-values were referenced in the text
```
##Alpha diversity and shedding
Shedding was defined as having one or more stool samples per patient positive for rotavirus shedding.
```{r alpha-div-shedding-alpha-diversity}
p.rich.shedding <- ggboxplot(subset(ps1.rich, randomization_arm == "Narrow spectrum antibiotics"), x = "Shedding", y = "richness_0", outlier.shape = NA) +
geom_jitter(width = 0.2) +
ylim(0,250) +
labs(y = "Richness", title = "Shedding") +
theme(axis.title.x = element_blank()) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
stat_compare_means(label = "p.format", method = "t.test", hide.ns = TRUE) +
facet_grid(~day) +
theme(axis.text.x = element_blank())
p.sd.shedding <- ggboxplot(subset(ps1.rich, randomization_arm == "Narrow spectrum antibiotics"), x = "Shedding", y = "diversities_shannon", outlier.shape = NA) +
geom_jitter(width = 0.2) +
ylim(0,5) +
labs(y = "Shannon diversity") +
theme(axis.title.x = element_blank()) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
stat_compare_means(label = "p.format", method = "t.test", hide.ns = TRUE) +
#facet_grid(~randomization_arm) +
scale_x_discrete(labels = c("No", "Yes"))
ggarrange(p.rich.shedding, p.sd.shedding, nrow = 2, labels = c("A)", "B)"))
# Note: This figure was not included in the final manuscript, but the analysis and p-values were referenced in the text
```
##Beta diversity analysis
```{r beta-div}
# UniFrac
ord.ps1.uni <- ordinate(ps1, method = "PCoA", distance = "unifrac")
# weighted UniFrac
ord.ps1.wuni <- ordinate(ps1, method = "PCoA", distance = "wunifrac")
# PCoA plot - Boost
p.ord.wuni <- plot_ordination(ps1, ord.ps1.wuni, color = "randomization_arm", shape = "d7_rota_boost_updated") +
geom_point(size=3, alpha = 0.7) +
scale_color_brewer(palette = "Dark2") +
geom_point(colour = "grey50", size = 0.5) +
facet_grid(~ day) +
labs(color = "Treatment", shape = "Day 7 Rotavirus Boosted") +
theme(legend.position = "null") +
geom_hline(yintercept = 0, size = 0.1, lty = 2) +
geom_vline(xintercept = 0, size = 0.1, lty = 2) +
theme(panel.grid.major = element_blank()) +
theme(panel.grid.minor = element_blank())
p.ord.uni <- plot_ordination(ps1, ord.ps1.uni, color = "randomization_arm", shape = "d7_rota_boost_updated") +
geom_point(size=3, alpha = 0.7) +
scale_color_brewer(palette = "Dark2") +
geom_point(colour = "grey50", size = 0.5) +
facet_grid(~ day) +
labs(color = "Treatment", shape = "Rotavirus Boosted") +
theme(legend.position = "null")+
geom_hline(yintercept = 0, size = 0.1, lty = 2) +
geom_vline(xintercept = 0, size = 0.1, lty = 2) +
theme(panel.grid.major = element_blank()) +
theme(panel.grid.minor = element_blank())
ggarrange(p.ord.uni, p.ord.wuni, nrow = 2)
# Species ordination for all Phylum
# Note: The final manuscript just showed the top 6 most abundant phylum. Code for this is in the following chunk
plot_ordination(ps1, ord.ps1.wuni, color = "Genus", type = "taxa") +
geom_point(size=2.5) +
geom_point(colour = "grey50", size = 0.25) +
labs(color = "Day 7 Rotavirus Boosted", shape = "Treatment") +
theme(legend.position = "null") +
facet_wrap(~Phylum, ncol = 4) +
geom_hline(yintercept = 0, size = 0.1, lty = 2) +
geom_vline(xintercept = 0, size = 0.1, lty = 2) +
theme(panel.grid.major = element_blank()) +
theme(panel.grid.minor = element_blank())
```
## Beta diversity with top 6 Phyla
```{r beta-div-top-6-phylum}
# Select only top phyla for display purposes
phylum.sum <- tapply(taxa_sums(ps1), tax_table(ps1)[, "Phylum"], sum, na.rm=TRUE)
# Select top 6 most abundant phyla (to correspond with other figrures)
top6phyla <- names(sort(phylum.sum, TRUE))[1:6]
top6phyla
ps1.top6 <- prune_taxa((tax_table(ps1)[, "Phylum"] %in% top6phyla), ps1)
get_taxa_unique(ps1.top6, "Phylum")
# UniFrac
ord.ps1.uni.top6 <- ordinate(ps1.top6, method = "PCoA", distance = "unifrac")
# weighted UniFrac
ord.ps1.wuni.top6 <- ordinate(ps1.top6, method = "PCoA", distance = "wunifrac")
p.ord.species <- plot_ordination(ps1.top6, ord.ps1.wuni, color = "Genus", type = "taxa") +
geom_point(size=2.5) +
geom_point(colour = "grey50", size = 0.25) +
labs(color = "Day 7 Rotavirus Boosted", shape = "Treatment") +
theme(legend.position = "null") +
facet_wrap(~Phylum, ncol = 6) +
geom_hline(yintercept = 0, size = 0.1, lty = 2) +
geom_vline(xintercept = 0, size = 0.1, lty = 2) +
theme(panel.grid.major = element_blank()) +
theme(panel.grid.minor = element_blank())
p.ord.species
```
```{r beta-div-figure-for-manuscript}
ggarrange(p.ord.uni, p.ord.wuni, p.ord.species, nrow = 3, labels = c("A)", "B)", "C)"))
# Note: p.ord.species was re-ordered in Keynote because SH couldn't figure out a simple way to reorder the phyla in PhyloSeq. He is sure there is a more sophisticated way to do this though :)
```
##Premanova significance testing (ADONIS)
```{r pairwise-ADONIS}
# Create relevant subsets
ps1.d_9 <- subset_samples(ps1, day == "-9")
ps1.d0 <- subset_samples(ps1, day == "0")
ps1.d7 <- subset_samples(ps1, day == "7")
# Day -9
ps1_otu_table.d_9 <- as.data.frame(otu_table(ps1.d_9))
sd.df.d_9 <- as.data.frame(sample_data(ps1.d_9))
ps1_otu_table.d_9$randomization_arm <- sd.df.d_9$randomization_arm
kable(pairwise.adonis(ps1_otu_table.d_9[,1:1588], ps1_otu_table.d_9$randomization_arm), format = "pandoc", caption = "Day -9")
# Day 0
ps1_otu_table.d0 <- as.data.frame(otu_table(ps1.d0))
sd.df.d0 <- as.data.frame(sample_data(ps1.d0))
ps1_otu_table.d0$randomization_arm <- sd.df.d0$randomization_arm
kable(pairwise.adonis(ps1_otu_table.d0[,1:1588], ps1_otu_table.d0$randomization_arm), format = "pandoc", caption = "Day 0")
# Day 7
ps1_otu_table.d7 <- as.data.frame(otu_table(ps1.d7))
sd.df.d7 <- as.data.frame(sample_data(ps1.d7))
ps1_otu_table.d7$randomization_arm <- sd.df.d7$randomization_arm
kable(pairwise.adonis(ps1_otu_table.d7[,1:1588], ps1_otu_table.d7$randomization_arm), format = "pandoc", caption = "Day 7")
```
#Differential Abundance Testing
##Pairwise comparisons across treatments at each sampling time
- Control Vs. narrow x's 3 time points (-9, 0, 7)
- Control vs. Broad x's 3 time points (-9, 0, 7)
- Narrow vs. Broad x's 3 time points (-9, 0, 7)
**Total:** 9 Comparisons
# Differential abundance testing preperation
```{r diffab-treatment-pairwise-prep}
# Set alpha
alpha = 0.05
# Calculate geometric means prior to estimate size factors
# This is required for data sets with lots of zeros
gm_mean = function(x, na.rm=TRUE){
exp(sum(log(x[x > 0]), na.rm=na.rm) / length(x))
}
# Generate subsets
# Pairwise treatment groups
ps1.CvN <- subset_samples(ps1, randomization_arm != "Broad spectrum antibiotics")
sample_data(ps1.CvN)$randomization_arm
ps1.CvB <- subset_samples(ps1, randomization_arm != "Narrow spectrum antibiotics")
sample_data(ps1.CvB)$randomization_arm
ps1.NvB <- subset_samples(ps1, randomization_arm != "No antibiotics")
sample_data(ps1.NvB)$randomization_arm
# Day subsets
ps1.CvN
ps1.CvN_9 <- subset_samples(ps1.CvN, day == "-9")
ps1.CvN_9
sample_data(ps1.CvN_9)$day
ps1.CvN.0 <- subset_samples(ps1.CvN, day == "0")
ps1.CvN.0
sample_data(ps1.CvN.0)$day
ps1.CvN.7 <- subset_samples(ps1.CvN, day == "7")
ps1.CvN.7
sample_data(ps1.CvN.7)$day
# Control vs Broad by day
ps1.CvB_9 <- subset_samples(ps1.CvB, day == "-9")
ps1.CvB_9
sample_data(ps1.CvB_9)$day
ps1.CvB.0 <- subset_samples(ps1.CvB, day == "0")
ps1.CvB.0
sample_data(ps1.CvB.0)$day
ps1.CvB.7 <- subset_samples(ps1.CvB, day == "7")
ps1.CvB.7
sample_data(ps1.CvB.7)$day
# Narrow vs Broad by day
ps1.NvB_9 <- subset_samples(ps1.NvB, day == "-9")
ps1.NvB_9
sample_data(ps1.NvB_9)$day
ps1.NvB.0 <- subset_samples(ps1.NvB, day == "0")
ps1.NvB.0
sample_data(ps1.NvB.0)$day
ps1.NvB.7 <- subset_samples(ps1.NvB, day == "7")
ps1.NvB.7
sample_data(ps1.NvB.7)$day
```
##Control vs Narrow Spectrum Day -9
```{r diff-ab-control-v-narrow-d.9}
# Differential Abundance Testing
sample_data(ps1.CvN_9)$randomization_arm
sample_data(ps1.CvN_9)$day
ds.NoAbx.Narrow.d_9 <- phyloseq_to_deseq2(ps1.CvN_9, ~randomization_arm)
geoMeans.ds.NoAbx.Narrow.d_9 <- apply(counts(ds.NoAbx.Narrow.d_9), 1, gm_mean)
ds.NoAbx.Narrow.d_9 <- estimateSizeFactors(ds.NoAbx.Narrow.d_9, geoMeans = geoMeans.ds.NoAbx.Narrow.d_9)
dds.NoAbx.Narrow.d_9 <- DESeq(ds.NoAbx.Narrow.d_9, test="Wald", fitType="local", betaPrior = FALSE)
# Tabulate and write results
res.dds.NoAbx.Narrow.d_9 = results(dds.NoAbx.Narrow.d_9, cooksCutoff = FALSE)
sigtab_dds.dds.NoAbx.Narrow.d_9 = res.dds.NoAbx.Narrow.d_9[which(res.dds.NoAbx.Narrow.d_9$padj < alpha), ]
sigtab_dds.dds.NoAbx.Narrow.d_9 = cbind(as(sigtab_dds.dds.NoAbx.Narrow.d_9, "data.frame"), as(tax_table(ps1.CvN_9)[rownames(sigtab_dds.dds.NoAbx.Narrow.d_9), ], "matrix"))
summary(res.dds.NoAbx.Narrow.d_9)
head(sigtab_dds.dds.NoAbx.Narrow.d_9)
write.table(sigtab_dds.dds.NoAbx.Narrow.d_9, file="./results/deseq_d_9_NoAbx.Narrow.txt", sep = "\t") # Change filename to save results to appropriate file
# Quick check of factor levels
mcols(res.dds.NoAbx.Narrow.d_9, use.names = TRUE)
# Prepare to join results data.table and taxonomy table
resdt.dds.NoAbx.Narrow.d_9 = data.table(as(results(dds.NoAbx.Narrow.d_9, cooksCutoff = FALSE), "data.frame"),
keep.rownames = TRUE)
setnames(resdt.dds.NoAbx.Narrow.d_9, "rn", "OTU")
taxdt.dds.d_9.com = data.table(data.frame(as(tax_table(ps1.CvN_9), "matrix")), keep.rownames = TRUE)
setnames(taxdt.dds.d_9.com, "rn", "OTU")
# Join results data.table and taxonomy table
setkeyv(taxdt.dds.d_9.com, "OTU")
setkeyv(resdt.dds.NoAbx.Narrow.d_9, "OTU")
resdt.dds.NoAbx.Narrow.d_9 <- taxdt.dds.d_9.com[resdt.dds.NoAbx.Narrow.d_9]
resdt.dds.NoAbx.Narrow.d_9
resdt.dds.NoAbx.Narrow.d_9[, Significant := padj < alpha]
resdt.dds.NoAbx.Narrow.d_9[!is.na(Significant)]
resdt.dds.NoAbx.Narrow.d_9
volcano.NoAbx.Narrow.d_9 = ggplot(
data = resdt.dds.NoAbx.Narrow.d_9[!is.na(Significant)][(pvalue < 1)],
mapping = aes(x = log2FoldChange,
y = -log10(pvalue),
color = Phylum,
label = OTU, label1 = Genus)) +
theme_bw() +
geom_point() +
geom_point(data = resdt.dds.NoAbx.Narrow.d_9[(Significant)], size = 7, alpha = 0.7) +
# geom_text(data = resdt[(Significant)], mapping = aes(label = paste("Genus:", Genus)), color = "black", size = 3) +
theme(axis.text.x = element_text(angle = -90, hjust = 0, vjust=0.5)) +
geom_hline(yintercept = -log10(alpha)) +
ggtitle("DESeq2 Negative Binomial Test Volcano Plot\nDay -9 No Antibiotics vs Narrow Spectrum Antibiotics") +
theme(axis.title = element_text(size=12)) +
theme(axis.text = element_text(size=12)) +
theme(legend.text = element_text(size=12)) +
geom_vline(xintercept = 0, lty = 2)
volcano.NoAbx.Narrow.d_9
summary(res.dds.NoAbx.Narrow.d_9)
mcols(res.dds.NoAbx.Narrow.d_9, use.names = TRUE)
ggplotly(volcano.NoAbx.Narrow.d_9)
```
##Control vs Narrow Spectrum Day 0
```{r diff-ab-control-v-narrow-d0}
# Differential Abundance Testing
sample_data(ps1.CvN.0)$randomization_arm
sample_data(ps1.CvN.0)$day
ds.NoAbx.Narrow.d0 <- phyloseq_to_deseq2(ps1.CvN.0, ~randomization_arm)
geoMeans.ds.NoAbx.Narrow.d0 <- apply(counts(ds.NoAbx.Narrow.d0), 1, gm_mean)
ds.NoAbx.Narrow.d0 <- estimateSizeFactors(ds.NoAbx.Narrow.d0, geoMeans = geoMeans.ds.NoAbx.Narrow.d0)
dds.NoAbx.Narrow.d0 <- DESeq(ds.NoAbx.Narrow.d0, test="Wald", fitType="local", betaPrior = FALSE)
# Tabulate and write results
res.dds.NoAbx.Narrow.d0 = results(dds.NoAbx.Narrow.d0, cooksCutoff = FALSE)
sigtab_dds.dds.NoAbx.Narrow.d0 = res.dds.NoAbx.Narrow.d0[which(res.dds.NoAbx.Narrow.d0$padj < alpha), ]
sigtab_dds.dds.NoAbx.Narrow.d0 = cbind(as(sigtab_dds.dds.NoAbx.Narrow.d0, "data.frame"), as(tax_table(ps1.CvN_9)[rownames(sigtab_dds.dds.NoAbx.Narrow.d0), ], "matrix"))
summary(res.dds.NoAbx.Narrow.d0)
head(sigtab_dds.dds.NoAbx.Narrow.d0)
write.table(sigtab_dds.dds.NoAbx.Narrow.d0, file="./results/deseq_d0_NoAbx.Narrow.txt", sep = "\t") # Change filename to save results to appropriate file
# Quick check of factor levels
mcols(res.dds.NoAbx.Narrow.d0, use.names = TRUE)
# Prepare to join results data.table and taxonomy table
resdt.dds.NoAbx.Narrow.d0 = data.table(as(results(dds.NoAbx.Narrow.d0, cooksCutoff = FALSE), "data.frame"),
keep.rownames = TRUE)
setnames(resdt.dds.NoAbx.Narrow.d0, "rn", "OTU")
taxdt.dds.d0.com = data.table(data.frame(as(tax_table(ps1.CvN.0), "matrix")), keep.rownames = TRUE)
setnames(taxdt.dds.d0.com, "rn", "OTU")
# Join results data.table and taxonomy table
setkeyv(taxdt.dds.d0.com, "OTU")
setkeyv(resdt.dds.NoAbx.Narrow.d0, "OTU")
resdt.dds.NoAbx.Narrow.d0 <- taxdt.dds.d0.com[resdt.dds.NoAbx.Narrow.d0]
resdt.dds.NoAbx.Narrow.d0
resdt.dds.NoAbx.Narrow.d0[, Significant := padj < alpha]
resdt.dds.NoAbx.Narrow.d0[!is.na(Significant)]
resdt.dds.NoAbx.Narrow.d0
volcano.NoAbx.Narrow.d0 = ggplot(
data = resdt.dds.NoAbx.Narrow.d0[!is.na(Significant)][(pvalue < 1)],
mapping = aes(x = log2FoldChange,
y = -log10(pvalue),
color = Phylum,
label = OTU, label1 = Genus)) +
theme_bw() +
geom_point() +
geom_point(data = resdt.dds.NoAbx.Narrow.d0[(Significant)], size = 7, alpha = 0.7) +
# geom_text(data = resdt[(Significant)], mapping = aes(label = paste("Genus:", Genus)), color = "black", size = 3) +
theme(axis.text.x = element_text(angle = -90, hjust = 0, vjust=0.5)) +
geom_hline(yintercept = -log10(alpha)) +
ggtitle("DESeq2 Negative Binomial Test Volcano Plot\nDay 0 No Antibiotics vs Narrow Spectrum Antibiotics") +
theme(axis.title = element_text(size=12)) +
theme(axis.text = element_text(size=12)) +
theme(legend.text = element_text(size=12)) +
geom_vline(xintercept = 0, lty = 2)
volcano.NoAbx.Narrow.d0
summary(res.dds.NoAbx.Narrow.d0)
mcols(res.dds.NoAbx.Narrow.d0, use.names = TRUE)
ggplotly(volcano.NoAbx.Narrow.d0)
nrow(res.dds.NoAbx.Narrow.d0)
```
##Control vs Narrow Spectrum Day 7
```{r diff-ab-control-v-narrow-d7}
# Differential Abundance Testing
sample_data(ps1.CvN.7)$randomization_arm
sample_data(ps1.CvN.7)$day
ds.NoAbx.Narrow.d7 <- phyloseq_to_deseq2(ps1.CvN.7, ~randomization_arm)
geoMeans.ds.NoAbx.Narrow.d7 <- apply(counts(ds.NoAbx.Narrow.d7), 1, gm_mean)
ds.NoAbx.Narrow.d7 <- estimateSizeFactors(ds.NoAbx.Narrow.d7, geoMeans = geoMeans.ds.NoAbx.Narrow.d7)
dds.NoAbx.Narrow.d7 <- DESeq(ds.NoAbx.Narrow.d7, test="Wald", fitType="local", betaPrior = FALSE)
# Tabulate and write results
res.dds.NoAbx.Narrow.d7 = results(dds.NoAbx.Narrow.d7, cooksCutoff = FALSE)
sigtab_dds.dds.NoAbx.Narrow.d7 = res.dds.NoAbx.Narrow.d7[which(res.dds.NoAbx.Narrow.d7$padj < alpha), ]
sigtab_dds.dds.NoAbx.Narrow.d7 = cbind(as(sigtab_dds.dds.NoAbx.Narrow.d7, "data.frame"), as(tax_table(ps1.CvN_9)[rownames(sigtab_dds.dds.NoAbx.Narrow.d7), ], "matrix"))
summary(res.dds.NoAbx.Narrow.d7)
head(sigtab_dds.dds.NoAbx.Narrow.d7)
write.table(sigtab_dds.dds.NoAbx.Narrow.d7, file="./results/deseq_d7_NoAbx.Narrow.txt", sep = "\t") # Change filename to save results to appropriate file
# Quick check of factor levels
mcols(res.dds.NoAbx.Narrow.d7, use.names = TRUE)
# Prepare to join results data.table and taxonomy table
resdt.dds.NoAbx.Narrow.d7 = data.table(as(results(dds.NoAbx.Narrow.d7, cooksCutoff = FALSE), "data.frame"),
keep.rownames = TRUE)
setnames(resdt.dds.NoAbx.Narrow.d7, "rn", "OTU")
taxdt.dds.d7.com = data.table(data.frame(as(tax_table(ps1.CvN.7), "matrix")), keep.rownames = TRUE)
setnames(taxdt.dds.d7.com, "rn", "OTU")
# Join results data.table and taxonomy table
setkeyv(taxdt.dds.d7.com, "OTU")
setkeyv(resdt.dds.NoAbx.Narrow.d7, "OTU")
resdt.dds.NoAbx.Narrow.d7 <- taxdt.dds.d7.com[resdt.dds.NoAbx.Narrow.d7]
resdt.dds.NoAbx.Narrow.d7
resdt.dds.NoAbx.Narrow.d7[, Significant := padj < alpha]
resdt.dds.NoAbx.Narrow.d7[!is.na(Significant)]
resdt.dds.NoAbx.Narrow.d7
volcano.NoAbx.Narrow.d7 = ggplot(
data = resdt.dds.NoAbx.Narrow.d7[!is.na(Significant)][(pvalue < 1)],
mapping = aes(x = log2FoldChange,
y = -log10(pvalue),
color = Phylum,
label = OTU, label1 = Genus)) +
theme_bw() +
geom_point() +
geom_point(data = resdt.dds.NoAbx.Narrow.d7[(Significant)], size = 7, alpha = 0.7) +
# geom_text(data = resdt[(Significant)], mapping = aes(label = paste("Genus:", Genus)), color = "black", size = 3) +
theme(axis.text.x = element_text(angle = -90, hjust = 0, vjust=0.5)) +
geom_hline(yintercept = -log10(alpha)) +
ggtitle("DESeq2 Negative Binomial Test Volcano Plot\nDay 7 No Antibiotics vs Narrow Spectrum Antibiotics") +
theme(axis.title = element_text(size=12)) +
theme(axis.text = element_text(size=12)) +
theme(legend.text = element_text(size=12)) +
geom_vline(xintercept = 0, lty = 2)
volcano.NoAbx.Narrow.d7
summary(res.dds.NoAbx.Narrow.d7)
mcols(res.dds.NoAbx.Narrow.d7, use.names = TRUE)
ggplotly(volcano.NoAbx.Narrow.d7)
```
#Control vs. Broad Spectrum Antibiotics
##Control vs. Broad Spectrum Antibiotics Day -9
```{r diffab-control-v-broad-d.9}
# Differential Abundance Testing
sample_data(ps1.CvB_9)$randomization_arm
sample_data(ps1.CvB_9)$day
ds.NoAbx.Broad.d_9 <- phyloseq_to_deseq2(ps1.CvB_9, ~randomization_arm)
geoMeans.ds.NoAbx.Broad.d_9 <- apply(counts(ds.NoAbx.Broad.d_9), 1, gm_mean)
ds.NoAbx.Broad.d_9 <- estimateSizeFactors(ds.NoAbx.Broad.d_9, geoMeans = geoMeans.ds.NoAbx.Broad.d_9)
dds.NoAbx.Broad.d_9 <- DESeq(ds.NoAbx.Broad.d_9, test="Wald", fitType="local", betaPrior = FALSE)
# Tabulate and write results
res.dds.NoAbx.Broad.d_9 = results(dds.NoAbx.Broad.d_9, cooksCutoff = FALSE)
sigtab_dds.dds.NoAbx.Broad.d_9 = res.dds.NoAbx.Broad.d_9[which(res.dds.NoAbx.Broad.d_9$padj < alpha), ]
sigtab_dds.dds.NoAbx.Broad.d_9 = cbind(as(sigtab_dds.dds.NoAbx.Broad.d_9, "data.frame"), as(tax_table(ps1.CvB_9)[rownames(sigtab_dds.dds.NoAbx.Broad.d_9), ], "matrix"))
summary(res.dds.NoAbx.Broad.d_9)
head(sigtab_dds.dds.NoAbx.Broad.d_9)
write.table(sigtab_dds.dds.NoAbx.Broad.d_9, file="./results/deseq_d_9_NoAbx.Broad.txt", sep = "\t") # Change filename to save results to appropriate file
# Quick check of factor levels
mcols(res.dds.NoAbx.Broad.d_9, use.names = TRUE)
# Prepare to join results data.table and taxonomy table
resdt.dds.NoAbx.Broad.d_9 = data.table(as(results(dds.NoAbx.Broad.d_9, cooksCutoff = FALSE), "data.frame"),
keep.rownames = TRUE)
setnames(resdt.dds.NoAbx.Broad.d_9, "rn", "OTU")
taxdt.dds.d_9.com = data.table(data.frame(as(tax_table(ps1.CvB_9), "matrix")), keep.rownames = TRUE)
setnames(taxdt.dds.d_9.com, "rn", "OTU")
# Join results data.table and taxonomy table
setkeyv(taxdt.dds.d_9.com, "OTU")
setkeyv(resdt.dds.NoAbx.Broad.d_9, "OTU")
resdt.dds.NoAbx.Broad.d_9 <- taxdt.dds.d_9.com[resdt.dds.NoAbx.Broad.d_9]
resdt.dds.NoAbx.Broad.d_9
resdt.dds.NoAbx.Broad.d_9[, Significant := padj < alpha]
resdt.dds.NoAbx.Broad.d_9[!is.na(Significant)]
resdt.dds.NoAbx.Broad.d_9
volcano.NoAbx.Broad.d_9 = ggplot(
data = resdt.dds.NoAbx.Broad.d_9[!is.na(Significant)][(pvalue < 1)],
mapping = aes(x = log2FoldChange,
y = -log10(pvalue),
color = Phylum,
label = OTU, label1 = Genus)) +
theme_bw() +
geom_point() +
geom_point(data = resdt.dds.NoAbx.Broad.d_9[(Significant)], size = 7, alpha = 0.7) +
# geom_text(data = resdt[(Significant)], mapping = aes(label = paste("Genus:", Genus)), color = "black", size = 3) +
theme(axis.text.x = element_text(angle = -90, hjust = 0, vjust=0.5)) +
geom_hline(yintercept = -log10(alpha)) +
ggtitle("DESeq2 Negative Binomial Test Volcano Plot\nDay -9 No Antibiotics vs Broad Spectrum Antibiotics") +
theme(axis.title = element_text(size=12)) +
theme(axis.text = element_text(size=12)) +
theme(legend.text = element_text(size=12)) +
geom_vline(xintercept = 0, lty = 2)
volcano.NoAbx.Broad.d_9
summary(res.dds.NoAbx.Broad.d_9)
mcols(res.dds.NoAbx.Broad.d_9, use.names = TRUE)
ggplotly(volcano.NoAbx.Broad.d_9)
```
##Control vs. Broad Spectrum Antibiotics Day 0
```{r diffab-control-vs-broad-d0}
# Differential Abundance Testing
sample_data(ps1.CvB.0)$randomization_arm
sample_data(ps1.CvB.0)$day
ds.NoAbx.Broad.d0 <- phyloseq_to_deseq2(ps1.CvB.0, ~randomization_arm)
geoMeans.ds.NoAbx.Broad.d0 <- apply(counts(ds.NoAbx.Broad.d0), 1, gm_mean)
ds.NoAbx.Broad.d0 <- estimateSizeFactors(ds.NoAbx.Broad.d0, geoMeans = geoMeans.ds.NoAbx.Broad.d0)
dds.NoAbx.Broad.d0 <- DESeq(ds.NoAbx.Broad.d0, test="Wald", fitType="local", betaPrior = FALSE)
# Tabulate and write results
res.dds.NoAbx.Broad.d0 = results(dds.NoAbx.Broad.d0, cooksCutoff = FALSE)
sigtab_dds.dds.NoAbx.Broad.d0 = res.dds.NoAbx.Broad.d0[which(res.dds.NoAbx.Broad.d0$padj < alpha), ]
sigtab_dds.dds.NoAbx.Broad.d0 = cbind(as(sigtab_dds.dds.NoAbx.Broad.d0, "data.frame"), as(tax_table(ps1.CvB_9)[rownames(sigtab_dds.dds.NoAbx.Broad.d0), ], "matrix"))
summary(res.dds.NoAbx.Broad.d0)
head(sigtab_dds.dds.NoAbx.Broad.d0)
write.table(sigtab_dds.dds.NoAbx.Broad.d0, file="./results/deseq_d0_NoAbx.Broad.txt", sep = "\t") # Change filename to save results to appropriate file
# Quick check of factor levels
mcols(res.dds.NoAbx.Broad.d0, use.names = TRUE)
# Prepare to join results data.table and taxonomy table
resdt.dds.NoAbx.Broad.d0 = data.table(as(results(dds.NoAbx.Broad.d0, cooksCutoff = FALSE), "data.frame"),
keep.rownames = TRUE)
setnames(resdt.dds.NoAbx.Broad.d0, "rn", "OTU")
taxdt.dds.d0.com = data.table(data.frame(as(tax_table(ps1.CvB.0), "matrix")), keep.rownames = TRUE)
setnames(taxdt.dds.d0.com, "rn", "OTU")
# Join results data.table and taxonomy table
setkeyv(taxdt.dds.d0.com, "OTU")
setkeyv(resdt.dds.NoAbx.Broad.d0, "OTU")
resdt.dds.NoAbx.Broad.d0 <- taxdt.dds.d0.com[resdt.dds.NoAbx.Broad.d0]
resdt.dds.NoAbx.Broad.d0
resdt.dds.NoAbx.Broad.d0[, Significant := padj < alpha]
resdt.dds.NoAbx.Broad.d0[!is.na(Significant)]
resdt.dds.NoAbx.Broad.d0
volcano.NoAbx.Broad.d0 = ggplot(
data = resdt.dds.NoAbx.Broad.d0[!is.na(Significant)][(pvalue < 1)],
mapping = aes(x = log2FoldChange,
y = -log10(pvalue),
color = Phylum,
label = OTU, label1 = Genus)) +
theme_bw() +
geom_point() +
geom_point(data = resdt.dds.NoAbx.Broad.d0[(Significant)], size = 7, alpha = 0.7) +
# geom_text(data = resdt[(Significant)], mapping = aes(label = paste("Genus:", Genus)), color = "black", size = 3) +
theme(axis.text.x = element_text(angle = -90, hjust = 0, vjust=0.5)) +
geom_hline(yintercept = -log10(alpha)) +
ggtitle("DESeq2 Negative Binomial Test Volcano Plot\nDay 0 No Antibiotics vs Broad Spectrum Antibiotics") +
theme(axis.title = element_text(size=12)) +
theme(axis.text = element_text(size=12)) +
theme(legend.text = element_text(size=12)) +
geom_vline(xintercept = 0, lty = 2)
volcano.NoAbx.Broad.d0
summary(res.dds.NoAbx.Broad.d0)
mcols(res.dds.NoAbx.Broad.d0, use.names = TRUE)
ggplotly(volcano.NoAbx.Broad.d0)
```
##Control vs. Broad Spectrum Antibiotics Day 7
```{r diffab-control-vs-broad-d7}
# Differential Abundance Testing
sample_data(ps1.CvB.7)$randomization_arm
sample_data(ps1.CvB.7)$day
ds.NoAbx.Broad.d7 <- phyloseq_to_deseq2(ps1.CvB.7, ~randomization_arm)
geoMeans.ds.NoAbx.Broad.d7 <- apply(counts(ds.NoAbx.Broad.d7), 1, gm_mean)
ds.NoAbx.Broad.d7 <- estimateSizeFactors(ds.NoAbx.Broad.d7, geoMeans = geoMeans.ds.NoAbx.Broad.d7)
dds.NoAbx.Broad.d7 <- DESeq(ds.NoAbx.Broad.d7, test="Wald", fitType="local", betaPrior = FALSE)
# Tabulate and write results
res.dds.NoAbx.Broad.d7 = results(dds.NoAbx.Broad.d7, cooksCutoff = FALSE)
sigtab_dds.dds.NoAbx.Broad.d7 = res.dds.NoAbx.Broad.d7[which(res.dds.NoAbx.Broad.d7$padj < alpha), ]
sigtab_dds.dds.NoAbx.Broad.d7 = cbind(as(sigtab_dds.dds.NoAbx.Broad.d7, "data.frame"), as(tax_table(ps1.CvB_9)[rownames(sigtab_dds.dds.NoAbx.Broad.d7), ], "matrix"))
summary(res.dds.NoAbx.Broad.d7)
head(sigtab_dds.dds.NoAbx.Broad.d7)
write.table(sigtab_dds.dds.NoAbx.Broad.d7, file="./results/deseq_d7_NoAbx.Broad.txt", sep = "\t") # Change filename to save results to appropriate file
# Quick check of factor levels
mcols(res.dds.NoAbx.Broad.d7, use.names = TRUE)
# Prepare to join results data.table and taxonomy table
resdt.dds.NoAbx.Broad.d7 = data.table(as(results(dds.NoAbx.Broad.d7, cooksCutoff = FALSE), "data.frame"),
keep.rownames = TRUE)
setnames(resdt.dds.NoAbx.Broad.d7, "rn", "OTU")
taxdt.dds.d7.com = data.table(data.frame(as(tax_table(ps1.CvB.7), "matrix")), keep.rownames = TRUE)
setnames(taxdt.dds.d7.com, "rn", "OTU")
# Join results data.table and taxonomy table
setkeyv(taxdt.dds.d7.com, "OTU")
setkeyv(resdt.dds.NoAbx.Broad.d7, "OTU")
resdt.dds.NoAbx.Broad.d7 <- taxdt.dds.d7.com[resdt.dds.NoAbx.Broad.d7]
resdt.dds.NoAbx.Broad.d7
resdt.dds.NoAbx.Broad.d7[, Significant := padj < alpha]
resdt.dds.NoAbx.Broad.d7[!is.na(Significant)]
resdt.dds.NoAbx.Broad.d7
volcano.NoAbx.Broad.d7 = ggplot(
data = resdt.dds.NoAbx.Broad.d7[!is.na(Significant)][(pvalue < 1)],
mapping = aes(x = log2FoldChange,
y = -log10(pvalue),
color = Phylum,
label = OTU, label1 = Genus)) +
theme_bw() +
geom_point() +
geom_point(data = resdt.dds.NoAbx.Broad.d7[(Significant)], size = 7, alpha = 0.7) +
# geom_text(data = resdt[(Significant)], mapping = aes(label = paste("Genus:", Genus)), color = "black", size = 3) +
theme(axis.text.x = element_text(angle = -90, hjust = 0, vjust=0.5)) +
geom_hline(yintercept = -log10(alpha)) +
ggtitle("DESeq2 Negative Binomial Test Volcano Plot\nDay 7 No Antibiotics vs Broad Spectrum Antibiotics") +
theme(axis.title = element_text(size=12)) +
theme(axis.text = element_text(size=12)) +
theme(legend.text = element_text(size=12)) +
geom_vline(xintercept = 0, lty = 2)