-
Notifications
You must be signed in to change notification settings - Fork 0
/
20230419_Halden_analysis.Rmd
3292 lines (2604 loc) · 110 KB
/
20230419_Halden_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: "Halden 2021"
author: "Juliette Ohan"
date: "7/28/2022"
output:
word_document: default
html_document: default
editor_options:
markdown:
wrap: 72
---
This is an R document to analyze the chemical values and biological
sequences from Biocrusts on Salt Heaps in Germany aka the "Halden."
Measurements: Abiotics - EC, Chl a, pH, DOC, TDN (site + stage + type,
3x rep) output:
Biotics - DNA sequencing of 16S rRNA gene (only site + stage, 3x rep)
output: ASV table with taxonomy
qPCR of 16S rRNA bacterial and archaeal genes (site + stage) output:
Co-variates: 2 sites = OD, WT 3 stages = heap, initial, biocrust (3x
replicates) 2 soil types (paired) = bulk, gradient
ALPHA DIVERSITY, RICHNESS, EVENNESS, RAREFY - edited Sept/5/22
```{r}
#install.packages("tidyverse")
library(tidyverse)
library(ggplot2)
library(dplyr)
#getwd()
#setwd
#import data from present working directory, if it is a file on your work computer.. THIS IS ALREADY SCALED TO 14347 READS
#Get ASV file
asv.data <- read.csv("D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/20220404_with_archaea/abundance_with_archea.csv",
header = TRUE,
sep = ",",
dec = ".")
#remove singletons!!!! This might affect a lot ~~~ +++ ~~~ +++ ~~~
#change first column to row names
asv.data <- data.frame(asv.data, row.names =1)
#get mapping file
salt_map <- read.csv("D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/all/salt_map.csv",
header = TRUE,
sep = ",",
dec = ".")
#reorder levels
salt_map$type <- factor(salt_map$type, levels = c("heap","initial", "biocrust"))
salt_map$label <- factor(salt_map$label, levels = c ("OD_heap", "OD_initial", "OD_biocrust",
"WT_heap", "WT_initial", "WT_biocrust"))
#subset by type
salt_map_OD <- subset(salt_map, site == "OD", select = c("NAME", "label", "Sample_num", "seqID", "site", "type"))
salt_map_WT <- subset(salt_map, site == "WT", select = c("NAME", "label","Sample_num", "seqID", "site", "type"))
#match and replace seqID with Names
asv.data2 <- asv.data %>%
rename_at(as.vector(na.omit(salt_map$seqID[match(names(asv.data), salt_map$seqID)])),
~as.vector(na.omit(salt_map$NAME[match(names(asv.data), salt_map$seqID)])))
#------------------------------------------------------------------------------------------------------
#diversity indices using vegan
#https://peat-clark.github.io/BIO381/veganTutorial.html
#https://grunwaldlab.github.io/analysis_of_microbiome_community_data_in_r/07--diversity_stats.html
library("vegan")
#?vegan
#I need to transpose the dataset for OTU/species as columns and samples as rows
asv.data.t2 <- t(asv.data2)
#reorder sites
asv.data.t2 <- asv.data.t2[order(factor(row.names(asv.data.t2), levels=c(
"OD_heap_1", "OD_heap_2", "OD_heap_3",
"OD_initial_1", "OD_initial_2", "OD_initial_3",
"OD_biocrust_1", "OD_biocrust_2", "OD_biocrust_3",
"WT_heap_2", "WT_heap_3",
"WT_initial_1", "WT_initial_2", "WT_initial_3",
"WT_biocrust_1", "WT_biocrust_2", "WT_biocrust_3"))),]
#get the different alpha diversity metrics
simpson <- diversity(asv.data.t2, index = "simpson")
invsimp <- diversity(asv.data.t2, "inv")
shannon <- diversity(asv.data.t2, index = "shannon")
## Fisher alpha
alpha <- fisher.alpha(asv.data.t2)
# ## Species richness (S) and Pielou's evenness (J): THIS IS AFTER SCALING!
S <- specnumber(asv.data.t2) ## rowSums(BCI > 0) does the same...
even <- shannon/log(S)
even
# #compare simpson and shannon
#par(mfrow = c(1, 2)) # use par to generate panels with 1 row of 2 graphs
hist(simpson)
hist(shannon)
#par(mfrow = c(1, 2))
bray = vegdist(asv.data.t2, "bray")
gower = vegdist(asv.data.t2, "gower")
hist(bray, xlim = range(0.0,1.0))
hist(gower, xlim = range(0.0,1.0))
#rarefy
spAbund <- rowSums(asv.data.t2) #gives the number of individuals found in each plot
spAbund # view observations per plot
#rarefaction curve
#rare <- rarecurve(asv.data.t2, col = "blue")
# Plot all (NOT SURE HOW TO INTERPRET THIS)
#pairs(cbind(shannon, simpson, invsimp, alpha), pch="+", col="blue")
#remove sample from mapping file to allow for boxplots
salt_map2 <- salt_map[!(salt_map$NAME=="WT_heap_1"),]
#Plot values
ggplot(salt_map2, aes(x = label, y = alpha, fill = type)) +
geom_boxplot()+
#ADD TITLE
ggtitle("Fisher (Alpha Diversity)") +
#ASSIGN COLORS
scale_fill_manual(values = c("heap" = "#5cc6de",
"initial" = "#ffcd0c",
"biocrust" = "#048861")) +
#REMOVE AXIS LABELS
theme(
axis.title.x = element_blank(),
axis.title.y = element_blank(),
)
ggplot(salt_map2, aes(x = label, y = simpson, fill = type)) + #this seems correct
geom_boxplot() +
ggtitle("Simpson (Dominance)") +
scale_fill_manual(values = c("heap" = "#5cc6de",
"initial" = "#ffcd0c",
"biocrust" = "#048861")) +
theme(
axis.title.x = element_blank(),
axis.title.y = element_blank(),
)
ggplot(salt_map2, aes(x = label, y = shannon, fill = type)) +
geom_boxplot()+
ggtitle("Shannon (Diversity)") +
scale_fill_manual(values = c("heap" = "#5cc6de",
"initial" = "#ffcd0c",
"biocrust" = "#048861")) +
theme(
axis.title.x = element_blank(),
axis.title.y = element_blank(),
)
ggplot(salt_map2, aes(x = label, y = even, fill = type)) +
geom_boxplot()+
ggtitle("Pielou (Evenness)") +
scale_fill_manual(values = c("heap" = "#5cc6de",
"initial" = "#ffcd0c",
"biocrust" = "#048861")) +
theme(
axis.title.x = element_blank(),
axis.title.y = element_blank(),
)
ggplot(salt_map2, aes(x = label, y = S, fill = type)) +
geom_boxplot()+
ggtitle(" Species Richness (S)") +
scale_fill_manual(values = c("heap" = "#5cc6de",
"initial" = "#ffcd0c",
"biocrust" = "#048861")) +
theme(
axis.title.x = element_blank(),
axis.title.y = element_blank(),
)
#SOMETHING IS WRONG HERE?, THERE SHOULD NOT BE A HEAP SAMPLE WITH HIGH DIVERSITY...MAYBE I MISLABELLED A SAMPLE...rob did this analysis for me anyway and it came out ok, here the numbers in simpson seem OK also
```
PREP DATA - edited Apr/5/22
```{r}
#merge biological replicates and remove asvs that are not present in all replicates, so you only have six treatments
#make separate df for each treatment
OD_crust <- asv.data[, c("Juliette11", "Juliette12", "Juliette13")]
OD_inter <- asv.data[, c("Juliette22", "Juliette15", "Juliette16")]
OD_heap <- asv.data[, c("Juliette17", "Juliette18", "Juliette19")]
WT_crust <- asv.data[, c("Juliette1", "Juliette2", "Juliette3")]
WT_inter <- asv.data[, c("Juliette4", "Juliette5", "Juliette6")]
WT_heap <- asv.data[, c("Juliette10", "Juliette8")]
#removing all rows with ALL zeros
#(See https://stackoverflow.com/questions/18055788/how-to-remove-rows-with-0-values-using-r)
WT_crust <- WT_crust[apply(WT_crust[,-1], 1, function(x) !all(x==0)),]
WT_inter <- WT_inter[apply(WT_inter[,-1], 1, function(x) !all(x==0)),]
OD_crust <- OD_crust[apply(OD_crust[,-1], 1, function(x) !all(x==0)),]
OD_inter <- OD_inter[apply(OD_inter[,-1], 1, function(x) !all(x==0)),]
OD_heap <- OD_heap [apply(OD_heap [,-1], 1, function(x) !all(x==0)),]
#different function for WT_heap since it only has two replicates
WT_heap <- WT_heap[rowSums(WT_heap[])>0,]
#
# #write the asvs to text files, this output in downloads folder (on mac)
# write.table(WT_crust[0], file = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/20220404_with_archaea/WT_crust.txt", quote = FALSE, row.names = TRUE, col.names = FALSE,)
#
# write.table(WT_heap[0], file = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/20220404_with_archaea/WT_heap.txt", quote = FALSE, row.names = TRUE, col.names = FALSE,)
#
# write.table(WT_inter[0], file = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/20220404_with_archaea/WT_inter.txt", quote = FALSE, row.names = TRUE, col.names = FALSE,)
#
# write.table(OD_crust[0], file = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/20220404_with_archaea/OD_crust.txt", quote = FALSE, row.names = TRUE, col.names = FALSE,)
#
# write.table(OD_inter[0], file = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/20220404_with_archaea/OD_inter.txt", quote = FALSE, row.names = TRUE, col.names = FALSE,)
#
# write.table(OD_heap[0], file = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/20220404_with_archaea/OD_heap.txt", quote = FALSE, row.names = TRUE, col.names = FALSE,)
```
AMPVIS2 HEATMAP - edited May/3/22
```{r dev = c("png", "jpg", "pdf")}
#install.packages("ampvis2")
library(ampvis2)
#some colors for the heatmaps
library(scales)
library(viridis)
#show_col(viridis(10))
#load in tables
data <- amp_load(
otutable = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/20220404_with_archaea/abundance_with_archea_ampvis.csv ",
metadata = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/all/OUT_300721/halden_mapping_ampvis.txt",
taxonomy = NULL,
fasta = NULL,
tree = NULL,
pruneSingletons = TRUE
)
#reorder
data$metadata$type <- factor(data$metadata$type, levels = c("Heap","Initial", "Biocrust"))
#remotes::install_github("kasperskytte/ggnet")
#install.packages('sna')
#make a heatmap (http://albertsenlab.org/ampvis2-heatmap/)
#Domain, Phylum, Class, Order, Family, Genus, Species
order_by_y_vec = paste(data$tax$Phylum, data$tax$Family, sep = "; ")
amp_heatmap(
data = data,
tax_aggregate = "Family",
tax_add = "Phylum",
tax_show = 50,
showRemainingTaxa = TRUE,
plot_values = TRUE, #this shows the numerical value of reads
group_by = "site",
facet_by = "type",
plot_colorscale = "sqrt",
order_y_by = rev(sort(unique(order_by_y_vec))), #call previous variable made
)
amp_heatmap(
data = data,
tax_aggregate = "Phylum",
# tax_add = "Phylum",
tax_show = 20,
showRemainingTaxa = TRUE,
plot_values = TRUE, #this shows the numerical value of reads
group_by = "site",
facet_by = "type",
plot_colorscale = "sqrt",
#color_vector = c( "whitesmoke", "royalblue4")
#color_vector = c( "#440154FF", "#481567FF", "#482677FF", "#453781FF","#404788FF","#39568CFF","#33638DFF","#2D708EFF","#287D8EFF","#238A8DFF","#1F968BFF","#20A387FF","#29AF7FFF","#3CBB75FF", "#55C667FF", "#73D055FF", "#95D840FF", "#B8DE29FF", "#DCE319FF", "#FDE725FF")
)
order_by_y_vec = paste(data$tax$Phylum, data$tax$Genus, sep = "; ")
#Genus <-
amp_heatmap(
data = data,
tax_aggregate = "Genus",
tax_add = "Phylum",
tax_show = 40,
showRemainingTaxa = TRUE,
tax_class = TRUE,
plot_values = TRUE, #this shows the numerical value of reads
group_by = "site",
facet_by = "type",
order_y_by = rev(unique(order_by_y_vec)), #call previous variable made
plot_colorscale = "sqrt",
#color_vector = c("royalblue4", "whitesmoke", "darkred")
)
#make charactervector x to order y axis - cannot have extra appended tax_add if you want to manually reorder
# x <- c("Phormidesmiales", "Nostocales","Thermomicrobiales", "Cytophagales", "Balneolales")
order_by_y_vec = paste(data$tax$Phylum, data$tax$Order, sep = "; ")
#this didnt work here..
amp_heatmap(
data = data,
tax_aggregate = "Order",
tax_add = "Phylum",
tax_show = 30,
showRemainingTaxa = TRUE,
#order_y_by = x,
order_y_by = rev(unique(order_by_y_vec)), #call previous variable made
tax_class = TRUE,
plot_values = TRUE, #this shows the numerical value of reads
group_by = "site",
facet_by = "type",
plot_colorscale = "sqrt"
)
order_by_y_vec = paste(data$tax$Phylum, data$tax$Class, sep = "; ")
sort(order_by_y_vec)
amp_heatmap(
data = data,
tax_aggregate = "Class",
tax_add = "Phylum",
tax_show = 25,
showRemainingTaxa = TRUE,
order_y_by = rev(sort(unique(order_by_y_vec))), #call previous variable made
tax_class = TRUE,
plot_values = TRUE, #this shows the numerical value of reads
group_by = "site",
facet_by = "type",
plot_colorscale = "sqrt"
)
#subset Cyanobacteria from existing SILVA assigned taxonomy------------------------------------------
library(ampvis2)
data
#sample_variables(data)
cyano <- amp_subset_taxa(data, tax_vector = "Cyanobacteria", normalise = FALSE, remove = FALSE )
cyano
cyano$metadata$type <- factor(cyano$metadata$type, levels = c("Heap","Initial", "Biocrust"))
order_by_y_vec = paste(cyano$tax$Class, cyano$tax$Genus, sep = "; ")
sort(order_by_y_vec)
amp_heatmap(
data = cyano,
tax_aggregate = "Genus",
tax_add = "Class",
tax_show = 60,
showRemainingTaxa = TRUE,
order_y_by = rev(sort(unique(order_by_y_vec))), #call previous variable made
tax_class = TRUE,
plot_values = FALSE, #this shows the numerical value of reads
group_by = "site",
facet_by = "type",
#(logical) Transform the OTU read counts to be in percent per sample. (default: TRUE)
normalise = FALSE,
plot_colorscale = "sqrt"
)
#load in Cyanobacteria from Cydrasil assigned taxonomy------------------------------------------
#load in tables
cyano_cyd <- amp_load(
otutable = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/amp_vis/cyano_cydrasil_otu.csv",
metadata = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/all/OUT_300721/halden_mapping_ampvis.txt",
taxonomy = NULL,
fasta = NULL,
tree = NULL,
pruneSingletons = FALSE
)
#reorder
cyano_cyd$metadata$type <- factor(cyano_cyd$metadata$type, levels = c("Heap","Initial", "Biocrust"))
#sample_variables(cyano_cyd)
cyano_cyd <- amp_subset_taxa(cyano_cyd, tax_vector = "Cyanobacteria", normalise = FALSE, remove = FALSE )
cyano_cyd
order_by_y_vec = paste(cyano_cyd$tax$Genus, cyano_cyd$tax$Species, sep = "; ")
sort(order_by_y_vec)
cyano_cyd_plot <-
amp_heatmap(
data = cyano_cyd,
tax_aggregate = "Species",
tax_add = "Genus",
tax_show = 40,
showRemainingTaxa = TRUE,
order_y_by = rev(sort(unique(order_by_y_vec))), #call previous variable made
tax_class = TRUE,
plot_values = FALSE, #this shows the numerical value of reads
group_by = "site",
facet_by = "type",
plot_colorscale = "sqrt",
normalise = FALSE
)
cyano_cyd_plot +
#change text size
theme(plot.title = element_text(size = 20)) +
theme(axis.title = element_text(size = 20)) +
#change axis labels
theme(axis.text.y = element_text(size = 15)) +
theme(axis.text.x = element_text(size = 20)) +
#only change legend title
theme(legend.title = element_text(size = 15)) +
#only change legend text
theme(legend.text = element_text(size = 15)) +
#change facet title size
theme(strip.text = element_text(size = 20))
order_by_y_vec = paste(cyano_cyd$tax$Family, cyano_cyd$tax$Genus, sep = "; ")
sort(order_by_y_vec)
amp_heatmap(
data = cyano_cyd,
tax_aggregate = "Genus",
tax_add = "Family",
tax_show = 40,
showRemainingTaxa = TRUE,
order_y_by = rev(sort(unique(order_by_y_vec))), #call previous variable made
tax_class = TRUE,
plot_values = FALSE, #this shows the numerical value of reads
group_by = "site",
facet_by = "type",
plot_colorscale = "sqrt",
normalise = FALSE
)
```
AMPVIS2 - CORE VENN DIAGRAMS - edited Apr/5/22
```{r dev = c("png", "jpg", "pdf")}
library(ampvis2)
#venn diagram of core otus (https://madsalbertsen.github.io/ampvis2/reference/amp_venn.html)
#"cut_a and cut_f are thresholds for defining when a OTU should be considered a "core" OTU.
#cut_a is the minimum abundance for being considered, Abundance cutoff in percent. OTU's below this abundance are excluded from the analysis. default 80%. We set this for 65% to account for presence in at least 2 samples (2/3 is 66.7% of biological replicates)
#cut_f is the minimum frequency above the cut_a threshold for being considered a "core" OTU." Frequency cutoff in percent. OTU's within the top \code{cut_f} of the reads are considered a "core" OTU. default 0.1%. We set this for 0.001% as they did in this study: https://www.nature.com/articles/s42003-021-01690-5 so that any ASV must be above 0.001% read abundance to be counted.
#' Calculates the number of "core" OTUs shared by groups given thresholds for how frequent the OTUs should be above a certain abundance. Also returns the average abundance of the OTUs in a particular group.
#detailed_output (logical) Return additional details or not. If TRUE, it is r
#Recommended to save to an object and then access the additional data by View(object$data). (default: FALSE)
venn_all <- amp_venn(
data,
group_by = "type",
cut_a = 0.001,
cut_f = 65,
text_size = 5,
normalise = TRUE,
detailed_output = TRUE
)
#between sites
venn_site <- amp_venn(
data,
group_by = "site",
cut_a = .001,
cut_f = 65,
text_size = 5,
normalise = TRUE,
detailed_output = TRUE
)
#subset only OD
data_OD <- amp_subset_samples(data, site %in% c("OD"))
venn_OD <- amp_venn(
data_OD,
group_by = "type",
cut_a = 0.001,
cut_f = 65,
text_size = 5,
normalise = TRUE,
detailed_output = TRUE
)
#subset only WT
data_WT <- amp_subset_samples(data, site %in% c("WT"))
venn_WT <- amp_venn(
data_WT,
group_by = "type",
cut_a = 0.001,
cut_f = 65,
text_size = 5,
normalise = TRUE,
detailed_output = TRUE
)
#subset crust
data_biocrust <- amp_subset_samples(data, type %in% c("Biocrust"))
venn_biocrust <- amp_venn(
data_biocrust,
group_by = "site",
cut_a = 0.001,
cut_f = 65,
text_size = 5,
normalise = TRUE,
detailed_output = TRUE
)
#save ASVs to an object
df_biocrust = venn_biocrust$Otutable
# #save df to .csv on local
# write.csv(x = df_biocrust, file = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/20220404_with_archaea/df_biocrust.csv", row.names = FALSE)
#View(venn_biocrust$data)
data_inter <- amp_subset_samples(data, type %in% c("Initial"))
venn_inter <- amp_venn(
data_inter,
group_by = "site",
cut_a = 0.001,
cut_f = 65,
text_size = 5,
normalise = TRUE,
detailed_output = TRUE
)
#save ASVs to an object
df_inter = venn_inter$Otutable
#save df to .csv on local
# write.csv(x = df_inter, file = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/20220404_with_archaea/df_inter.csv", row.names = FALSE)
#subset heap
data_heap <- amp_subset_samples(data, type %in% c("Heap"))
venn_heap <- amp_venn(
data_heap,
group_by = "site",
cut_a = 0.001,
cut_f = 65,
text_size = 5,
normalise = TRUE,
detailed_output = TRUE
)
#save ASVs to an object
df_heap = venn_heap$Otutable
#venn_heap$plot
# #save df to .csv on local
# write.csv(x = df_heap, file = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/20220404_with_archaea/df_heap.csv", row.names = FALSE)
```
AMPVIS - CORE HEATMAPS - edited MAr/13/22
```{r dev = c("png", "jpg", "pdf")}
#----------------------------------------------
library(ampvis2)
library(dplyr)
#install.packages("readr")
library(readr)
#Make venn diagrams with only CORE ASVs
#load in tables
#try to do them all at once
#HEAP CORE HEATMAP
#keep only rows that are "Core"
df_heap2 <- df_heap[df_heap$Shared == "Core", ]
#remove last column (using dplyr)
df_heap2 <- select(df_heap2, -Shared)
#rename row headers (using dplyr)
df_heap2 <- df_heap2 %>%
rename(
OTU2 = OTU,
)
asv.data <- read_csv("D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/20220404_with_archaea/asv.table.csv", col_names = TRUE)
#rename row headers (using dplyr)
asv.data <- asv.data %>%
rename(
OTU = ...1,
)
#SOLUTION FROM ROB Match up values from asv.data to df_heap2
df_heap3 =
asv.data %>%
filter(`OTU` %in% df_heap2$OTU2) %>%
select(c(`OTU`, names(df_heap2) %>% grep("Juliette", ., value = T))) %>%
right_join(df_heap2[,1:8], by = c("OTU" = "OTU2"))
data_heap <- amp_load(
otutable = df_heap3,
metadata = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/all/OUT_300721/halden_mapping_ampvis.txt",
taxonomy = NULL,
fasta = NULL,
tree = NULL,
pruneSingletons = TRUE
)
#this is from roberto, to order by phylum, THIS DOES NOT WORK FOR HEAPS
order_by_y_vec = paste(data_heap$tax$Phylum, data_heap$tax$Class, sep = "; ")
plot_heap <- amp_heatmap(
data = data_heap,
tax_aggregate = "Class",
tax_add = "Phylum",
tax_show = 20,
showRemainingTaxa = TRUE,
order_y_by = rev(unique(order_by_y_vec)), #call previous variable made
tax_class = TRUE,
plot_values = TRUE, #this shows the numerical value of reads
group_by = "site",
facet_by = "type",
plot_colorscale = "sqrt",
color_vector = c( "whitesmoke", "royalblue4")
)
# #save plot as pdf on windows device
# ggsave(
# "core_heap.jpeg",
# plot = last_plot(),
# device = NULL,
# path = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/20220404_with_archaea/core_venn",
# scale = 1,
# width = 5,
# height = 3,
# #units = c("in"),
# dpi = 500,
# limitsize = TRUE,
# bg = NULL
# )
#------------------------------------------------------------------------------------------------------------------------------------------
#INTERSTAGE CORE HEATMAP
#keep only rows that are "Core"
df_inter2 <- df_inter[df_inter$Shared == "Core", ]
# write.csv(x = df_heap2, file = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/20220404_with_archaea/df_inter2.csv", row.names = TRUE)
#remove last column (using dplyr)
df_inter2 <- select(df_inter2, -Shared)
#rename row headers (using dplyr)
df_inter2 <- df_inter2 %>%
rename(
OTU2 = OTU,
)
# Match up values from asv.data to df_inter2
df_inter3 =
asv.data %>%
filter(`OTU` %in% df_inter2$OTU2) %>%
select(c(`OTU`, names(df_inter2) %>% grep("Juliette", ., value = T))) %>%
right_join(df_inter2[,1:8], by = c("OTU" = "OTU2"))
data_inter <- amp_load(
otutable = df_inter3,
metadata = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/all/OUT_300721/halden_mapping_ampvis.txt",
taxonomy = NULL,
fasta = NULL,
tree = NULL,
pruneSingletons = TRUE
)
#order by phylum
order_by_y_vec = paste(data_inter$tax$Phylum, data_inter$tax$Class, sep = "; ")
plot_inter <- amp_heatmap(
data = data_inter,
tax_aggregate = "Class",
tax_add = "Phylum",
tax_show = 20,
showRemainingTaxa = TRUE,
order_y_by = rev(sort(unique(order_by_y_vec))),
tax_class = TRUE,
plot_values = TRUE, #this shows the numerical value of reads
group_by = "site",
facet_by = "type",
plot_colorscale = "sqrt",
color_vector = c( "whitesmoke", "royalblue4")
)
#
# #save plot as pdf on windows device
# ggsave(
# "core_inter.jpeg",
# plot = last_plot(),
# device = NULL,
# path = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/20220404_with_archaea/core_venn/",
# scale = 1,
# width = 5,
# height = 5,
# #units = c("in"),
# dpi = 500,
# limitsize = TRUE,
# bg = NULL
# )
#------------------------------------------------------------------------------------------------------------------------------------------
#BIOCRUST CORE HEATMAP
#keep only rows that are "Core"
df_biocrust2 <- df_biocrust[df_biocrust$Shared == "Core", ]
#remove last column (using dplyr)
df_biocrust2 <- select(df_biocrust2, -Shared)
#rename row headers (using dplyr)
df_biocrust2 <- df_biocrust2 %>%
rename(
OTU2 = OTU,
)
# Match up values from asv.data to df_biocrust2
df_biocrust3 =
asv.data %>%
filter(`OTU` %in% df_biocrust2$OTU2) %>%
select(c(`OTU`, names(df_biocrust2) %>% grep("Juliette", ., value = T))) %>%
right_join(df_biocrust2[,1:8], by = c("OTU" = "OTU2"))
data_biocrust <- amp_load(
otutable = df_biocrust3,
metadata = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/all/OUT_300721/halden_mapping_ampvis.txt",
taxonomy = NULL,
fasta = NULL,
tree = NULL,
pruneSingletons = TRUE
)
order_by_y_vec = paste(data_biocrust$tax$Phylum, data_biocrust$tax$Class, sep = "; ")
plot_biocrust <- amp_heatmap(
data = data_biocrust,
tax_aggregate = "Class",
tax_add = "Phylum",
tax_show = 20,
showRemainingTaxa = TRUE,
order_y_by = rev(sort(unique(order_by_y_vec))),
tax_class = TRUE,
plot_values = TRUE, #this shows the numerical value of reads
group_by = "site",
facet_by = "type",
plot_colorscale = "sqrt",
color_vector = c( "whitesmoke", "royalblue4")
)
#
# #save plot as pdf on windows device
# ggsave(
# "core_biocrust.jpeg",
# plot = last_plot(),
# device = NULL,
# path = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/20220404_with_archaea/core_venn/",
# scale = 1,
# width = 5,
# height = 7,
# #units = c("in"),
# dpi = 500,
# limitsize = TRUE,
# bg = NULL
# )
#add them all up into one figure - This is weirdddd
library(ggpubr)
core_all <- ggarrange(plot_heap, plot_inter, plot_biocrust,
labels = c("A.", "B.", "C."),
label.y = 0.05,
label.x = 0.05,
font.label = list(size = 18),
nrow = 1,
ncol = 3,
#widths = c(1,0.05,1,0.05,1, 0.05,1,0.05,1 ),
common.legend = TRUE, legend = "right"
)
core_all
#------------------------------------------------------------------------------------------------------------------------------------------
# HEAP CORE HEATMAP - GENUS LEVEL CLASSIFICATION
#order by phylum THIS IS NOT WORKING
order_by_y_vec = paste(data_heap$tax$Phylum, data_heap$tax$Genus, sep = "; ")
g1 <- amp_heatmap(
data = data_heap,
tax_aggregate = "Genus",
tax_add = "Phylum",
tax_show = 20,
showRemainingTaxa = TRUE,
#order_y_by = rev(unique(order_by_y_vec)), #call previous variable made
tax_class = TRUE,
plot_values = TRUE, #this shows the numerical value of reads
group_by = "site",
facet_by = "type",
plot_colorscale = "sqrt",
color_vector = c( "whitesmoke", "royalblue4")
)
# ggsave(
# "core_heap_genus.pdf",
# plot = last_plot(),
# device = NULL,
# path = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/20220404_with_archaea/core_venn/",
# scale = 1,
# width = 5,
# height = 5,
# #units = c("in"),
# dpi = 300,
# limitsize = TRUE,
# bg = NULL
# )
#------------------------------------------------------------------------------------------------------------------------------------------
# INTER CORE HEATMAP - GENUS LEVEL CLASSIFICATION
#order by phylum THIS IS WORKING
order_by_y_vec = paste(data_inter$tax$Phylum, data_inter$tax$Genus, sep = "; ")
g2 <- amp_heatmap(
data = data_inter,
tax_aggregate = "Genus",
tax_add = "Phylum",
tax_show = 20,
showRemainingTaxa = TRUE,
order_y_by = rev(sort(unique(order_by_y_vec))),
tax_class = TRUE,
plot_values = TRUE, #this shows the numerical value of reads
group_by = "site",
facet_by = "type",
plot_colorscale = "sqrt",
color_vector = c( "whitesmoke", "royalblue4")
)
#
# ggsave(
# "core_inter_genus_all.pdf",
# plot = last_plot(),
# device = NULL,
# path = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/20220404_with_archaea/core_venn/",
# scale = 1,
# width = 5,
# height = 20,
# #units = c("in"),
# dpi = 300,
# limitsize = TRUE,
# bg = NULL
# )
#------------------------------------------------------------------------------------------------------------------------------------------
# BIOCRUST CORE HEATMAP - GENUS LEVEL CLASSIFICATION
#order by phylum THIS IS WORKING
order_by_y_vec = paste(data_biocrust$tax$Phylum, data_biocrust$tax$Genus, sep = "; ")
g3 <-amp_heatmap(
data = data_biocrust,
tax_aggregate = "Genus",
tax_add = "Phylum",
tax_show = 20,
showRemainingTaxa = TRUE,
order_y_by = rev(sort(unique(order_by_y_vec))),
tax_class = TRUE,
plot_values = TRUE, #this shows the numerical value of reads
group_by = "site",
facet_by = "type",
plot_colorscale = "sqrt",
color_vector = c( "whitesmoke", "royalblue4")
)
# #save plot as pdf on windows device
# ggsave(
# "core_biocrust_genus_all.pdf",
# plot = last_plot(),
# device = NULL,
# path = "D:/Users/juliette.ohan/Desktop/2_Saltheaps_(Ohan)/Experiments/Scripts_(R_and_Bioinformatics)/20220404_with_archaea/core_venn/",
# scale = 1,
# width = 5,
# height = 20,
# #units = c("in"),
# dpi = 300,
# limitsize = TRUE,
# bg = NULL
# )
core_all_genus <- ggarrange(g1, g2, g3,
labels = c("A.", "B.", "C."),
label.y = 0.05,
label.x = 0.05,
font.label = list(size = 18),
nrow = 1,
ncol = 3,
#widths = c(1,0.05,1,0.05,1, 0.05,1,0.05,1 ),
common.legend = TRUE, legend = "right"
)
core_all_genus
```
AMP VIS MISC - OK on 2-18-22
```{r dev = c("png", "jpg", "pdf")}
#THIS IS JUST TESTING OTHER FUNCTIONS OF THE AMPVIS2 PACKAGE
#MEAN READ ABUNDANCE (from https://madsalbertsen.github.io/ampvis2/articles/ampvis2.html)
amp_boxplot(data_WT,
group_by = "type",
tax_show = 10,
tax_add = "Phylum")
amp_boxplot(data_OD,
group_by = "type",
tax_show = 10,
tax_add = "Phylum")
#ORDINATION PLOT - CCA
ordinationresult <- amp_ordinate(data,
type = "CCA",
constrain = "type",
transform = "Hellinger",
sample_color_by = "type",
sample_shape_by = "site",
#sample_colorframe = TRUE,
sample_colorframe_label = "type",
detailed_output = TRUE)
ordinationresult$plot
#add environmental variables with env fit
#another CCA plot
amp_ordinate(data,
type = "CCA",
constrain = "type",
transform = "Hellinger",
sample_color_by = "type",
sample_shape_by = "site",
#sample_colorframe = TRUE,
sample_colorframe_label = "type",
#species_plot = TRUE,
species_label_taxonomy = "Genus",
detailed_output = TRUE)
#PCOA
amp_ordinate(data,
type = "pcoa",
distmeasure = "bray",
sample_color_by = "type",
sample_shape_by = "site",