-
Notifications
You must be signed in to change notification settings - Fork 0
/
orp16S.R
1730 lines (1581 loc) · 75.8 KB
/
orp16S.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
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
# JMDplots/orp16S.R
# Plots for paper on Zc-ORP correlations 20210827
# Group studies by environment types 20210828
envirotype <- list(
"River & Seawater" = c("MLL+18", "HXZ+20", "GSBT20_Prefilter", "GSBT20_Postfilter", "WHL+21", "ZLH+22", "ZZL+21", "LWJ+21", "GZL21", "RARG22"),
"Lake & Pond" = c("SAR+13", "LLC+19", "BCA+21", "HLZ+18", "BWD+19", "IBK+22", "NLE+21", "MTC21", "SPA+21"),
"Groundwater" = c("KLM+16", "WLJ+16", "ZDW+19", "DJK+18", "SRM+19", "APV+20", "YHK+20", "ZCZ+21", "MGW+22", "MCR+22"),
# NOTE: Keep Geothermal in 4th location to get red color 20210904
"Geothermal" = c("PCL+18_Acidic", "PCL+18_Alkaline", "GWS+20", "PBU+20", "MWY+21"),
"Hyperalkaline" = c("SBP+20", "RMB+17", "CTS+17", "KSR+21", "PSB+21", "NTB+21"),
"Sediment" = c("ZML+17", "BSPD17", "RKN+17", "HDZ+19", "OHL+18_DNA", "WHLH21a", "RSS+18", "CLS+19", "HSF+19", "ZHZ+19",
"LMBA21_2017", "HSF+22", "ZZLL21", "WFB+21", "HCW+22", "WKG+22"),
"Soil" = c("MLL+19", "BMOB18", "WHLH21", "CWC+20", "PSG+20", "LJC+20", "DTJ+20", "RKSK22", "DLS21_Bulk", "WKP+22",
"CKB+22", "CLZ+22")
)
# Turn the list into a data frame for easier lookup 20210904
envirodat <- do.call(rbind, lapply(seq_along(envirotype), function(i) data.frame(study = envirotype[[i]], groupnum = i)))
envirodat <- cbind(envirodat, group = names(envirotype)[envirodat$groupnum])
# Select color palette 20210914
orp16Scol <- palette.colors(n = length(envirotype), palette = "Classic Tableau", alpha = 0.75)
# Read Eh7 - Zc data
EZdat <- read.csv(system.file("extdata/orp16S/EZdat.csv", package = "JMDplots"))
# Read linear fit coefficients
EZlm <- read.csv(system.file("extdata/orp16S/EZlm.csv", package = "JMDplots"))
##################################
### Functions for main figures ###
##################################
# Figure 1: Thermodynamic model for the relationship between carbon oxidation state of reference proteomes and redox potential 20221213
orp16S_1 <- function(pdf = FALSE) {
# Setup plot
if(pdf) pdf("Figure_1.pdf", width = 7, height = 6, bg = "white")
mat <- matrix(c(1,1,1,2,2,2, 1,1,1,3,3,3, 4,4,5,5,6,6), nrow = 3, byrow = TRUE)
layout(mat)
# Species with optimal growth temperatures from 30-40 °C
species <- c(
# Class I
"Methanococcus vannielii", "Methanococcus maripaludis", "Methanococcus voltae", "Methanobrevibacter_A smithii",
# Class II
#"Methanosarcina barkeri", "Methanoplanus limicola", "Methanofollis liminatans"
"Methanofollis liminatans"
)
# Get reference proteomes
gtdb <- read.csv(system.file("RefDB/GTDB_220/genome_AA.csv.xz", package = "JMDplots"))
igtdb <- match(species, gtdb$ref)
aa <- gtdb[igtdb, ]
ip <- add.protein(aa, as.residue = TRUE)
# Plot theoretical (equilibrium) Eh-pH diagram
basis(c("glutamine", "glutamic acid", "cysteine", "H2O", "H+", "e-"), c(-3.2, -4.5, -3.6, 0, 0, 0))
res <- 385
a <- affinity(pH = c(3, 11, res), Eh = c(-0.5, 0.1, res), iprotein = ip)
# Use abbreviations for species
names <- paste0("M", substr(sapply(strsplit(species, " "), "[", 2), 1, 2))
srt <- c(0, -40, -40, -40, 0)
d <- diagram(a, names = names, ylab = "Eh (V)", srt = srt, mar = c(3.1, 3.1, 3, 1))
abline(v = 5, lty = 2, col = 2)
abline(v = 7, lty = 2, col = 1)
abline(v = 9, lty = 2, col = 4)
title("Metastable equilibrium (Met. Equil.)\namong selected reference proteomes", font.main = 1)
label.figure("a", cex = 1.7, font = 2)
# Plot theoretical Zc as a function of Eh and Eh7
par(mar = c(3.1, 4.1, 2, 1))
par(yaxs = "r")
# Calculate Zc
Zc <- Zc(aa)
# Get Zc values at discrete pHs
pHs <- c(5, 7, 9)
adjs <- c(0.6, 0.8, 1.1)
Zcvals <- lapply(pHs, function(pH) {
ipH <- d$vals$pH == pH
ispecies_pH <- d$predominant[ipH, ]
Zc[ispecies_pH]
})
names(Zcvals) <- pHs
col <- c(2, 1, 4)
# Loop over Eh and Eh7
for(xvar in c("Eh", "Eh7")) {
plot(c(-0.5, 0.1), extendrange(unlist(Zcvals)), xlab = paste(xvar, "(V)"), ylab = "", type = "n")
mtext(axis.label("Zc"), side = 2, line = 2.5, cex = par("cex"), las = 0)
# Apply offset to distinguish same Zc values at different pH
dy <- c(-0.0005, 0, 0.0005)
for(i in 1:length(pHs)) {
xvals <- d$vals$Eh
# Calculate Eh7
if(xvar == "Eh7") xvals <- xvals + -0.05916 * (7 - pHs[i])
# Dashed lines between Zc
lines(xvals, Zcvals[[i]] + dy[i], col = col[i], lty = 2)
# Solid lines at single Zc
uZc <- unique(Zcvals[[i]])
lapply(unique(Zcvals[[i]]), function(uZc) {
iuZc <- Zcvals[[i]] == uZc
lines(xvals[iuZc], Zcvals[[i]][iuZc] + dy[i], col = col[i], lwd = 2)
})
if(xvar == "Eh") {
# Plot pH labels
iEh <- which(Zcvals[[i]] == Zc[3])[1]
text(xvals[iEh], -0.19, paste("pH =", pHs[i]), adj = adjs[i])
}
}
if(xvar == "Eh") title("Met. Equil. at three pH values", font.main = 1)
if(xvar == "Eh7") title("Met. Equil. with Eh7 correction", font.main = 1)
if(xvar == "Eh") label.figure("b", cex = 1.7, font = 2)
}
# Plot theoretical Zc as a function of Eh7 with simulated noise added 20221220
par(xaxs = "r")
# Use second pH value defined above (i.e. pH = 7)
i <- 2
pH <- pHs[i]
# Calculate Eh7 (xvals)
xvals <- round(d$vals$Eh, 8)
xvals <- xvals + -0.05916 * (7 - pH)
# Use coarser resolution for scatterplot
ipoint <- seq(1, 385, length.out = 97)
# Use values in the range [-0.3, -0.1]
iEh7 <- which(xvals >= -0.3 & xvals <= -0.1)
iuse <- intersect(ipoint, iEh7)
xvals <- xvals[iuse]
# Get Zc values
Zc <- Zcvals[[i]][iuse]
# Plot 1: Theoretical Zc vs Eh7
plot(xvals, Zc, xlab = "Eh7 (V)", ylab = "", pch = 19, cex = 0.5, col = "#00000080")
mtext(axis.label("Zc"), side = 2, line = 2.5, cex = par("cex"), las = 0)
add.linear.local(xvals, Zc, legend = "topleft", cex = 1, inset = c(-0.08, -0.05), with.N = FALSE, scale = 1)
title("Met. Equil. sampled at pH = 7", font.main = 1)
label.figure("c", cex = 1.7, font = 2)
# Use GTDB amino acid compositions and taxon names
species_aa <- gtdb
taxa <- read.csv(system.file("RefDB/GTDB_220/taxonomy.csv.xz", package = "JMDplots"), as.is = TRUE)
if(FALSE) {
# Old code for RefSeq
# Make sure the data tables have consistent taxids
stopifnot(all(species_aa$organism == taxa$taxid))
# Keep only Bacteria and Archaea classified at species level 20220104
isspecies <- !is.na(taxa$species)
ivirus <- taxa$superkingdom == "Viruses"
ivirus[is.na(ivirus)] <- FALSE
species_aa <- species_aa[isspecies & !ivirus, ]
taxa <- taxa[isspecies & !ivirus, ]
} else {
# New code for GTDB 20240709
# Make sure the data tables have consistent genome names
stopifnot(all(species_aa$organism == taxa$genome))
}
# Keep only species with at least 500 sequences
ilow <- species_aa$chains < 500
species_aa <- species_aa[!ilow, ]
taxa <- taxa[!ilow, ]
# Plot 2: Random Zc vs Eh7
set.seed(42)
# Randomly sample rows from GTDB data frame
ispecies <- sample(1:nrow(species_aa), length(Zc))
randvals <- Zc(species_aa[ispecies, ])
ylim <- range(c(randvals, -0.08))
plot(xvals, randvals, xlab = "Eh7 (V)", ylab = "", ylim = ylim, pch = 19, cex = 0.5, col = "#00000080")
mtext(axis.label("Zc"), side = 2, line = 2.5, cex = par("cex"), las = 0)
add.linear.local(xvals, randvals, legend = "topleft", cex = 1, inset = c(-0.08, -0.05), with.N = FALSE, scale = 1)
title("Random species from GTDB", font.main = 1)
# Plot 3: Theoretical + random Zc vs Eh7
Zc_shaped <- (Zc + 4*randvals) / 5
ylim <- range(c(Zc_shaped, -0.08))
plot(xvals, Zc_shaped, xlab = "Eh7 (V)", ylab = "", ylim = ylim, pch = 19, cex = 0.5, col = "#00000080")
mtext(axis.label("Zc"), side = 2, line = 2.5, cex = par("cex"), las = 0)
add.linear.local(xvals, Zc_shaped, legend = "topleft", cex = 1, inset = c(-0.08, -0.05), with.N = FALSE, scale = 1)
title("20% Met. Equil. + 80% Random ", font.main = 1)
if(pdf) dev.off()
}
# Zc of reference proteomes compared with oxygen tolerance and with metaproteomes 20221228
orp16S_2 <- function(pdf = FALSE) {
# Setup plot
if(pdf) pdf("Figure_2.pdf", width = 8, height = 3.5, bg = "white")
mat <- matrix(1:3, nrow = 1)
layout(mat, widths = c(0.9, 1.4, 0.9))
par(mgp = c(2.5, 1, 0))
# Panel A: Zc in obligate anaerobic and aerotolerant genera 20221017
par(mar = c(4, 4, 2.5, 1))
# Read table from Million and Raoult, 2018
dat <- read.csv(system.file("extdata/orp16S/MR18_Table_S1.csv", package = "JMDplots"))
# Clean up names
dat$Genus.name <- gsub(" ", "", dat$Genus.name)
# Get amino acid compositions for genera
aa <- taxon_AA$GTDB_220
# Calculate Zc
values <- Zc(aa)
ylim <- c(-0.24, -0.095)
# Remove suffixes used in GTDB (_A, _B, etc.)
genome <- sapply(strsplit(aa$organism, "_"), "[", 1)
# Match genus names to GTDB
iref <- match(dat$Genus.name, genome)
# Print coverage information
nna <- sum(is.na(iref))
print(paste(nna, "genera not matched to GTDB"))
# Report archaeal genera 20230107
genera <- aa[na.omit(iref), ]$organism
taxonomy <- read.csv(system.file("RefDB/GTDB_220/taxonomy.csv.xz", package = "JMDplots"), as.is = TRUE)
itax <- match(genera, taxonomy$genus)
taxonomy <- taxonomy[itax, ]
archaeal_genera <- taxonomy$genus[taxonomy$domain == "Archaea"]
print(paste("Archaeal genera:", paste(archaeal_genera, collapse = " ")))
# Get values for obligate anaerobes and aerotolerant genera
values <- values[iref]
values <- list(
Anaerobe = values[dat$Obligate.anerobic.prokaryote == 1],
Aerotolerant = values[dat$Obligate.anerobic.prokaryote == 0]
)
boxplot(values, ylab = quote(italic(Z)[C]~"of genus reference proteome"), ylim = ylim, names = NA)
axis(1, 1, labels = "Strictly\nAnaerobic", tick = FALSE, line = 0.7)
axis(1, 2, labels = "Aerotolerant", tick = FALSE, line = 0.3)
# Add p-values
ptext <- bquote(italic(P) == .(signif(t.test(values$Anaerobe, values$Aerotolerant)$p.value, 3)))
legend("bottomright", legend = ptext, bty = "n")
# Show number of genera below names
n <- c(
sum(dat$Obligate.anerobic.prokaryote == 1 & !is.na(iref)),
sum(dat$Obligate.anerobic.prokaryote == 0 & !is.na(iref))
)
l1 <- bquote(italic(N)==.(n[1]))
l2 <- bquote(italic(N)==.(n[2]))
axis(1, 1, labels = l1, tick = FALSE, line = 1.8)
axis(1, 2, labels = l2, tick = FALSE, line = 1.8)
# Add mean difference to title
md <- round(diff(sapply(values, mean, na.rm = TRUE)), 4)
main <- paste("Mean difference =", md)
title(main, font.main = 1, cex.main = 1, line = -0.9)
title("Oxygen tolerance", font.main = 1)
label.figure("a", font = 2, cex = 1.5, xfrac = 0.04)
# Panel B: Zc of community reference proteomes vs metaproteomes 20221222
par(mar = c(4, 4, 2.5, 1))
# Calculate chemical metrics
dat <- getMP_orp16S()
Zclim <- c(-0.20, -0.10)
plot(Zclim, Zclim, xlab = quote(italic(Z)[C]~"of metaproteome"), ylab = quote(italic(Z)[C]~"of community reference proteome"), type = "n")
lines(Zclim, Zclim, lty = 2, col = 8)
points(dat$Zc_MP, dat$Zc_16S, pch = dat$pch, bg = dat$bg, col = dat$col)
add.linear.local(dat$Zc_MP, dat$Zc_16S, legend = "topleft", with.N = FALSE, scale = 1, nounits = TRUE)
title(hyphen.in.pdf("Metaproteome - Reference proteome comparison"), font.main = 1)
label.figure("b", font = 2, cex = 1.5, xfrac = 0.03)
# Make legend for datasets
idup <- duplicated(dat$Name)
# Get dataset names and number of samples
names <- dat$Name[!idup]
nsamp <- sapply(lapply(names, `==`, dat$Name), sum)
names <- paste0(names, " (", nsamp, ")")
dat <- dat[!idup, ]
opar <- par(mar = c(4, 0, 4, 0))
plot.new()
legend("left", sapply(names, hyphen.in.pdf), pch = dat$pch, col = dat$col, pt.bg = dat$bg, bty = "n")
par(opar)
if(pdf) dev.off()
}
# Figure 3: Methods overview and Winogradsky columns 20221110
orp16S_3 <- function(pdf = FALSE) {
if(pdf) pdf("Figure_3.pdf", width = 6/(8/15), height = 4, bg = "white")
# Figure 1a: Schematic of data and methods 20210830
layout(matrix(1:3, nrow = 1), widths = c(8, 3.5, 3.5))
par(cex = 1)
# Define colors; adapted from
# https://cdn.elifesciences.org/author-guide/tables-colour.pdf
Purple <- "#9E86C9"
Purple80 <- "#9E86C980"
PurpleText <- "#9C27B0"
Blue80 <- "#90CAF980"
BlueText <- "#366BFB"
Red80 <- "#E5737380"
RedText <- "#D50000"
Orange80 <- "#FFB74D80"
OrangeText <- "#f7831c"
Gray <- "#E6E6E6"
# Setup plot
par(mar = c(0, 0, 0, 0))
plot(c(5, 95), c(1, 80), type = "n", axes = FALSE, xlab = "", ylab = "")
# Uncomment this as a guide for making the 'grid' one 20210927
#box(lwd = 2)
grid.roundrect(0.5*(8/15), 0.5, 0.49, 0.99, gp = gpar(fill = "azure"))
dy <- -2.5
# Plot lines to go behind shapes
lines(c(20, 50), c(20, 60)+dy)
lines(c(20, 50), c(60, 60)+dy)
lines(c(50, 80), c(60, 60)+dy)
# Add arrows along lines 20210927
arrows(20, 20+dy, 20*0.35 + 50*0.65, (20*0.35 + 60*0.65)+dy, length = 0.1)
arrows(20, 60+dy, 37, 60+dy, length = 0.1)
arrows(50, 60+dy, 66, 60+dy, length = 0.1)
# Plot shapes and text for biological methods
text(20, 79+dy, "Biological Methods", col = RedText, font = 2)
for(bg in c("white", Red80)) points(20, 60+dy, pch = 21, cex = 17, bg = bg)
text(20, 66+dy, "GTDB", font = 2, col = RedText)
text(20, 57+dy, "Reference\nproteomes\nof taxa")
for(bg in c("white", Red80)) points(20, 20+dy, pch = 21, cex = 17, bg = bg)
text(20, 25+dy, "16S + RDP", font = 2, col = RedText)
text(20, 18+dy, "Taxonomic\nabundances")
# Plot shapes and text for chemical methods
text(80, 79+dy, "Chemical Methods", col = BlueText, font = 2)
for(bg in c("white", Blue80)) points(80, 60+dy, pch = 22, cex = 16, bg = bg)
text(80, 67+dy, quote(bolditalic(Z)[bold(C)]), col = BlueText, cex = 1.2)
text(80, 57.5+dy, "Carbon\noxidation\nstate")
# Show multiple physicochemical variables 20210927
# Function to draw rectangle at x,y with width and height w,h
myrect <- function(x, y, w, h, ...) rect(x - w/2, y - h/2, x + w/2, y + h/2, ...)
# T, Eh, pH, O2
for(col in c("white", Blue80)) myrect(73, 16+dy, 5, 6, col = col)
text(73, 17.3+dy, "pH", col = BlueText, adj = c(0.5, 1))
for(col in c("white", Blue80)) myrect(80, 16+dy, 7, 7, col = col)
text(80, 17.3+dy, "Eh", col = BlueText, adj = c(0.5, 1))
for(col in c("white", Blue80)) myrect(87.5, 16+dy, 6, 6, col = col)
text(87.5, 17.3+dy, "T", font = 3, col = BlueText, adj = c(0.5, 1))
for(col in c("white", Blue80)) myrect(80, 8+dy, 5, 6, col = col)
text(80, 8+dy, quote(O[2]), col = BlueText)
# Add Eh7 and lines to source data 20221008
for(col in c("white", Blue80)) myrect(80, 25.5+dy, 7, 7, col = col)
text(80, 25.5+dy, "Eh7", font = 2, col = BlueText)
lines(c(73, 87.5), c(19.5, 19.5))
lines(c(73, 73), c(16.5, 19.5))
lines(c(80, 80), c(17, 19.5))
lines(c(87.5, 87.5), c(16.5, 19.5))
# Plot inner rectangle and text
third <- 100/3
# Uncomment this to make the original rectangle (as a guide for the 'grid' one)
#for(bg in c("white", Orange80)) rect(1.2*third, 50+dy, 1.8*third, 70+dy, col = bg)
# Use this to get rounded corners 20210927
for(fill in c("white", Orange80)) grid.roundrect(0.5*(8/15), 0.7, 0.11, 0.23, gp = gpar(fill = fill))
text(50, 67+dy, quote(bold(C[bolditalic(c)]*H[bolditalic(h)]*N[bolditalic(n)]*O[bolditalic(o)]*S[bolditalic(s)])), col = OrangeText)
text(50, 58+dy, "Community\nreference\nproteomes")
# Plot arrows and text labels
arrows(1*third - 1, 20+dy, 1*third + 6, 20+dy, code = 1, lty = 1, length = 0.1)
arrows(2*third - 4, 16+dy, 2*third + 2.5, 16+dy, code = 2, lty = 1, length = 0.1)
text(50, 18+dy, "Community and\nenvironmental data")
arrows(80, 31+dy, 80, 46.5+dy, code = 3, lwd = 1.5, length = 0.1, col = BlueText)
text(78, 46+dy, "Thermodynamic prediction", font = 2, cex = 0.9, adj = c(1, 1))
text(78, 46+dy, "\nPositive correlation between\ncarbon oxidation state\nand redox potential", font = 3, cex = 0.9, adj = c(1, 1))
label.figure("a", font = 2, cex = 1.5, xfrac = 0.015, yfrac = 0.97)
## Figure 1b: Chemical depth profiles in Winogradsky columns 20210829
par(mar = c(4, 4, 1, 1), mgp = c(2.5, 1, 0))
# ORP measurements from Diez-Ercilla et al. (2019)
depth <- c(25, 22, 18, 14, 12, 9, 5)
ORP <- c(-229, -241, -229, -201, 302, 501, 641) / 1000 # Units: V
pH <- c(5.5, 5.5, 5.5, 4.7, 3.0, 2.7, 2.6)
SWIdepth <- 11.3
# Shift depth values so SWI is at zero
MODdepth <- depth - SWIdepth
plot(ORP, MODdepth, ylim = c(14.7, -6.3), type = "b", lty = 2, xlab = "Eh or Eh7 (V)", ylab = "Depth (cm)", xlim = c(-0.4, 0.8), las = 1)
abline(h = 0, lty = 2, col = "darkgray", lwd = 1.5)
# Calculate and plot Eh7 20210926
Eh7 <- ORP + -0.05916 * (7 - pH)
lines(Eh7, MODdepth, type = "b", pch = 19)
text(0.08, -3.5, "Eh7")
text(0.72, -3.5, "Eh")
label.figure("b", font = 2, cex = 1.5, yfrac = 0.97)
# Get 16S metadata and chemical metrics for Rundell et al. (2014) experiments
metrics.in <- getmetrics_orp16S("RBW+14")
mdat <- getmdat_orp16S("RBW+14", metrics.in)
metrics <- mdat$metrics
# Get Zc values for each layer
layers <- c("12 cm", "8 cm", "4 cm", "SWI", "Top")
Zc <- lapply(layers, function(layer) metrics$Zc[mdat$metadata$layer == layer])
# Make boxplots
boxplot(Zc, horizontal = TRUE, show.names = FALSE, xlab = axis.label("Zc"), ylim = c(-0.18, -0.145), yaxs = "i", col = "azure3")
axis(2, 1:5, labels = layers, las = 1)
# Add sample sizes
par(xpd = NA)
for(i in 1:5) {
label <- bquote(italic(N) == .(length(Zc[[i]])))
text(-0.1835, i - 0.3, label, adj = 1, cex = 0.9)
}
par(xpd = FALSE)
label.figure("c", font = 2, cex = 1.5, yfrac = 0.97)
# Reset layout to make orp16S_2 in the examples run nicely 20211011
if(pdf) dev.off() else layout(1)
}
# Figure 4: Sample locations and Eh-pH diagram 20221110
orp16S_4 <- function(pdf = FALSE) {
## Panel A: Sample locations on world map
if(pdf) pdf("Figure_4.pdf", width = 26, height = 15+9-1, bg = "white")
mat <- matrix(c(1,1,1,1, 1,2,3,1, 0,2,3,0), nrow = 3, byrow = TRUE)
layout(mat, heights = c(14, 1, 8), widths = c(7, 9, 3, 7))
par(cex = 1)
# Coordinates for orp16S datasets
file <- tempfile()
# Write spaces here (but don't save them in the file) to make this easier to read
writeLines(con = file, text = gsub(" ", "", c(
# Column names
"study, latitude, longitude",
## River & Seawater (comments indicate source of coordinates from paper or SRA metadata)
"MLL+18, 22.20, 113.09", # Fig. 1
"HXZ+20, 16.52, 111.77", # Table 1
# GSBT20 see below
"WHL+21, 30.76, 115.36", # SAMN13242327
"ZLH+22, 24.179, 98.902", # SAMN16122993
"ZZL+21, 22.77, 113.79", # SAMN16964962
"LWJ+21, 36.569, 120.976", # SAMN18558469
# GZL21 see below
"RARG22, 18.5, -99.5", # Materials and methods
## Lake & Pond
"SAR+13, 1.96, -157.33", # Materials and methods
"LLC+19, 24.82, 118.15", # SAMN04549101
"BCA+21, 46.3615, 25.0509", # SAMN07409474
"HLZ+18, 24.795, 118.138", # SAMN07638080
"BWD+19, 47.120571, -88.545425", # SAMN09980099
"IBK+22, 53.1516, 13.0262", # SAMN15366194
"NLE+21, 32.833, 35.583", # SAMEA7280991
"MTC21, 41.396, -0.058", # SAMN10716683
"SPA+21, 45.8126, 8.7401", # SAMN17524543
## Geothermal (Hot Spring)
"PCL+18_Acidic, -38.5, 176.0", # Fig. 1
"GWS+20, 30.12, 101.94", # SAMN13430433
"PBU+20, 54.4395, 160.144194", # SAMN14538724
# MWY+21 see below
## Hyperalkaline
"SBP+20, 38.862, -122.414", # SAMN03850954
"RMB+17, 22.9052, 58.6606", # SAMN05981641
"CTS+17, 10.94323, -85.63485", # SAMN06226041
"KSR+21, 44.264340, 8.46442", # SAMN17101425
"PSB+21, 38.8621, -122.4304", # SAMN17252996
"NTB+21, 22.881, 58.701", # SAMN19998441
## Soil - put this group before Groundwater and Sediment for clearer visualization in GBA 20210927
"MLL+19, 26.1, 112.5", # Materials and methods
"BMOB18, 40.60842, -74.19258", # SAMN07828017 ### Laboratory
"WHLH21, 37.53, 105.03", # Materials and methods
"CWC+20, 28.226, 116.898", # Materials and methods ### Laboratory
"PSG+20, 36.61, -119.53", # Web search for Parlier, CA ### Mesocosm
# LJC+20 see below
"DTJ+20, 26.45, 111.52", # SAMN14332759 ### Laboratory
"RKSK22, 31.97283, -81.0304", # SAMN16678415
"DLS21_Bulk, 39.39, -75.44", # SAMN17245435 ### Mesocosm
"WKP+22, 53.29, 17.79", # SAMN23457780
"CKB+22, 37.8635, 138.9426", # Wikipedia Niigata University ### Laboratory
"CLZ+22, 25.1, 113.63", # Materials and Methods ### Laboratory
## Groundwater
"KLM+16, 42.99, -82.30", # SAMN04423023
"WLJ+16, 41, 107", # SAMN05938707
"ZDW+19, 30.18, 113.61", # SAMN07528610
"DJK+18, 39.44, -82.22", # Materials and methods
"SRM+19, 12.67417, 101.3889", # Materials and methods
"APV+20, 20.12, -99.23", # Materials and methods
"YHK+20, 51.209467, 10.791968", # SAMEA5714424
"ZCZ+21, 45.21, 9.57", # Table 1
"MGW+22, -36.849, 174.769", # Wikipedia University of Auckland
"MCR+22, -38.386099, 144.865068", # SAMN29926991
## Sediment
"ZML+17, 22.494, 114.029", # Table 1
"BSPD17, 57.89297, 16.5855", # SAMN05163191 ### Laboratory
"RKN+17, 62.03, 29.98", # SAMN05933570 ### Laboratory
"HDZ+19, 29.901, 113.52435", # SAMN05990289
"OHL+18_DNA, 56.02, 10.26", # Experimental procedures
"WHLH21a, 23.52, 113.495", # Materials and methods
"RSS+18, 82, -71", # Introduction
"CLS+19, 32.22, 118.83", # SAMN08683376
"HSF+19, 47.803, 16.709", # methods
"ZHZ+19, 23.130, 113.671", # Materials and methods ### Laboratory
"LMBA21_2017, 43.42, -2.7", # Fig. 1
"HSF+22, -9.42979, 46.49524", # SAMN14343437
"ZZLL21, 22.68, 113.97", # SAMN16964887
"WFB+21, 56.440893, -2.863194", # methods ### Mesocosm
"HCW+22, 31.3, 119.98", # Materials and methods ### Laboratory
"WKG+22, 53.164, 17.704" # Materials and methods
)))
# This reads the data
coords <- read.csv(file, as.is = TRUE)
# Make sure the study keys are correct 20220522
stopifnot(all(coords$study %in% unlist(envirotype)))
# Start map
# https://cran.r-project.org/web/packages/oce/vignettes/map_projections.html
par(mar = c(2, 0.5, 0, 0.5))
# We don't need data(coastlineWorld) ... it's the default map 20211003
# A color between azure2 and azure3 20220516
azure23 <- rgb(t((col2rgb("azure2") + col2rgb("azure3")) / 2), maxColorValue = 255)
mapPlot(col = azure23, projection = "+proj=wintri", border = "white", drawBox = FALSE)
# Add Great Lakes
# https://www.sciencebase.gov/catalog/item/530f8a0ee4b0e7e46bd300dd
# https://gis.stackexchange.com/questions/296170/r-shapefile-transform-longitude-latitude-coordinates
hydro_pdir <- system.file("extdata/orp16S/hydro_p", package = "JMDplots")
for(lake in c("Erie", "Huron", "Michigan", "Ontario", "Superior", "StClair")) {
file <- file.path(hydro_pdir, paste0("hydro_p_Lake", lake, ".shp"))
tx <- st_read(file, quiet = TRUE)
# https://mhweber.github.io/AWRA_2020_R_Spatial/coordinate-reference-systems.html
## library(sf) (version 1.0.8) gave:
## Linking to GEOS 3.10.2, GDAL 3.4.2, PROJ 9.0.0; sf_use_s2() is TRUE
## This was working with those versions
#tx_ll <- st_transform(tx, "+proj=longlat +ellps=GRS80 +datum=NAD83")
# library(sf) (version 1.0.9) gave:
# Linking to GEOS 3.11.1, GDAL 3.6.1, PROJ 9.1.1; sf_use_s2() is TRUE
# Drop datum setting to workaround "GDAL Error 6: Cannot find coordinate operations ..."
tx_ll <- st_transform(tx, "+proj=longlat +ellps=GRS80")
gl.coords <- st_coordinates(tx_ll)
mapPolygon(gl.coords[, "X"], gl.coords[, "Y"], col = "white", border = NA)
}
# Get colors for studies
icol <- envirodat$groupnum[match(coords$study, envirodat$study)]
# Identify studies that use samples from laboratory or mesocosm experiments
lab <- c(
# Sediment
"BSPD17", "RKN+17", "ZHZ+19", "WFB+21", "HCW+22",
# Soil
"BMOB18", "CWC+20", "PSG+20", "DTJ+20",
"DLS21_Bulk", "CKB+22", "CLZ+22"
)
pch <- ifelse(coords$study %in% lab, 15, 19)
# Use smaller points for high-density regions 20210915
cex <- ifelse(coords$study %in% c(
"ZZL+21", "MLL+18", "ZML+17", "ZZLL21", "ZHZ+19", "WHLH21a", # GD-HK-MO GBA
"HDZ+19", # Hubei
"WKG+22" # Poland
), 1.5, 2.5)
# Plot sample locations
mapPoints(coords$longitude, coords$latitude, pch = pch, col = orp16Scol[icol], cex = cex)
# Plot transects 20210929
# Coordinates for East Asia Paddy Soil dataset are from
# Sourcedata.xlsx from https://doi.org/10.6084/m9.figshare.12622829
dat <- getmdat_orp16S("LJC+20")
mapPoints(dat$longitude, dat$latitude, col = orp16Scol[7], lwd = 2)
# Coordinates for Southern Tibetan Plateau dataset are from Table 1 of MWY+21
dat <- getmdat_orp16S("MWY+21")
latlon <- paste(dat$latitude, dat$longitude)
isuniq <- !duplicated(latlon)
dat <- dat[isuniq, ]
mapPoints(dat$longitude, dat$latitude, col = orp16Scol[4], lwd = 2)
# Coordinates for Three Gorges Reservoir are from Table S1 of GZL21
dat <- getmdat_orp16S("GZL21")
dat <- dat[!is.na(dat$"ORP (mV)"), ]
latlon <- paste(dat$Latitude, dat$Longitude)
isuniq <- !duplicated(latlon)
dat <- dat[isuniq, ]
mapPoints(dat$Longitude, dat$Latitude, col = orp16Scol[1], lwd = 1)
# Coordinates for Port Microbes are from https://github.com/rghannam/portmicrobes/data/metadata/pm_metadata.csv
dat <- getmdat_orp16S("GSBT20")
# Use first sample for each port
dat <- dat[!duplicated(dat$Port), ]
mapPoints(dat$Longitude, dat$Latitude, col = orp16Scol[1], pch = 17)
# Add legend
ienv = c(1, 2, 4, 5, 3, 6, 7)
par(xpd = NA)
legend("bottomleft", names(envirotype)[ienv], pch = 19, col = orp16Scol[ienv], bty = "n", cex = 2, pt.cex = 3, inset = c(0, -0.03))
ltext <- c("Field sites", "Laboratory or mesocosm", "Smaller symbols for", "densely sampled areas", "Port sites", "Open symbols for transects")
legend("bottomright", ltext, pch = c(19, 15, 20, NA, 17, 1), col = c(1, 1, 1, NA, orp16Scol[1], 1),
bty = "n", cex = 2, pt.cex = c(3, 3, 3, 3, 2, 2), inset = c(0, -0.03))
par(xpd = FALSE)
label.figure("a", font = 2, cex = 3.8)
## Panel B: Eh-pH diagram for all environment types 20220516
par(cex = 2)
# Get data for unique samples
ssr <- paste(EZdat$study, EZdat$sample, EZdat$Run, sep = "_")
idup <- duplicated(ssr)
thisdat <- EZdat[!idup, ]
# Remove NA pH
thisdat <- thisdat[!is.na(thisdat$pH), ]
# Get colors
ienv <- match(thisdat$envirotype, names(envirotype))
col <- orp16Scol[ienv]
# Make plot
par(mar = c(4, 4, 1, 1))
plot(thisdat$pH, thisdat$Eh / 1000, col = col, pch = 19, cex = 0.5, xlab = "pH", ylab = "Eh (V)",
xlim = c(-2, 14), ylim = c(-0.6, 1), xaxs = "i", yaxs = "i", axes = FALSE)
box()
axis(1, at = seq(-2, 14, 2))
axis(2, at = round(seq(-0.6, 1, 0.2), 1), gap.axis = 0)
# Add outline from Bass Becking et al. (1960)
BKM60 <- read.csv(system.file("extdata/orp16S/BKM60.csv", package = "JMDplots"))
BKM60$Eh <- BKM60$Eh / 1000 # Units: V
segment <- NULL
top <- subset(BKM60, segment == "top")
lines(top$pH, top$Eh)
bottom <- subset(BKM60, segment == "bottom")
lines(bottom$pH, bottom$Eh)
left <- subset(BKM60, segment == "left")
for(i in 1:(nrow(left)/2)) {
ii <- c(i*2-1, i*2)
lines(left$pH[ii], left$Eh[ii])
}
right <- subset(BKM60, segment == "right")
for(i in 1:(nrow(right)/2)) {
ii <- c(i*2-1, i*2)
lines(right$pH[ii], right$Eh[ii])
}
O2 <- subset(BKM60, segment == "O2")
lines(O2$pH, O2$Eh, lwd = 2)
H2 <- subset(BKM60, segment == "H2")
lines(H2$pH, H2$Eh, lwd = 2)
text(0, 0.055, quote(H^"+"), cex = 1.2, srt = -30)
text(-0.5, -0.035, quote(H[2]), cex = 1.2, srt = -30)
text(5.5, 0.84, quote(H[2]*O), cex = 1.2, srt = -30)
text(6, 0.93, quote(O[2]), cex = 1.2, srt = -30)
label.figure("b", font = 2, cex = 1.9)
# Add legend
par(mar = c(4, 1, 1, 1))
plot.new()
ienv = c(1, 2, 4, 5, 3, 6, 7)
ltext <- names(envirotype)[ienv]
legend("left", ltext, pch = 19, col = orp16Scol[ienv], bty = "n", xpd = NA)
if(pdf) dev.off()
}
# Figure 5: Associations between Eh7 and Zc at local scales 20220517
orp16S_5 <- function(pdf = FALSE) {
if(pdf) pdf("Figure_5.pdf", width = 8, height = 6, bg = "white")
mat <- matrix(c(1,1,1,1, 2,2,2,2, 3,3,3,3,
0,0,0,0,0,0,0,0,0,0,0,0,
4,4,4,4,4, 0, 6,6,6, 7,7,7,
5,5,5,5,5, 0, 6,6,6, 7,7,7),
nrow = 4, byrow = TRUE)
layout(mat, heights = c(3, 0.75, 3, 3))
par(mar = c(3, 4, 3, 1))
par(mgp = c(2.5, 1, 0))
## Panel A: Analysis of selected datasets 20211003
# Daya Bay (Sediment)
plotEZ("WHLH21a", "Bacteria", groupby = "Position", groups = c("Surface", "Middle", "Bottom"),
legend.x = "bottomleft", title.line = NULL, dxlim = c(-20, 0), slope.legend = "right")
title("Daya Bay\n(Sediment bacteria)", font.main = 1)
label.figure("a", font = 2, cex = 2.3, yfrac = 0.9)
# Bay of Biscay (Sediment)
plotEZ("LMBA21_2017", "Bacteria", groupby = "Season", groups = c("Summer", "Winter"),
legend.x = "bottomright", title.line = NULL, dxlim = c(0, 170), dylim = c(-0.01, 0), slope.legend = "bottom")
title("Bay of Biscay\n(Sediment bacteria)", font.main = 1)
# Hunan Soil (Soil)
plotEZ("MLL+19", "Bacteria", groupby = "Type", groups = c("Upland", "Paddy", "Sediment"),
title.line = NULL, dylim = c(0, 0.01), slope.legend = "top")
title("Hunan Province\n(Soil and sediment bacteria)", font.main = 1)
## Panel B: Slope vs log10(number of samples) for all datasets
par(mar = c(3.6, 4, 1, 1))
# Use Bacteria only 20210913
lmbac <- EZlm[EZlm$lineage == "Bacteria", ]
# Get color according to environment group
env <- envirodat[match(lmbac$study, envirodat$study), ]
# Get range for included samples 20210905
i1 <- c(1, 2, 4, 5)
j1 <- env$groupnum %in% i1
i2 <- c(3, 6, 7)
j2 <- env$groupnum %in% i2
xlim <- range(log10(lmbac$nsamp[j1 | j2]))
# Get range of slopes (absolute value)
ymaxabs <- max(abs(lmbac$slope[j1 | j2]))
ylim <- c(-ymaxabs*1.2, ymaxabs)
# River & seawater, lake & pond, geothermal, hyperalkaline
plot(xlim, ylim, type = "n", xlab = quote(log[10]~"(Number of samples)"), ylab = quote("Slope of linear fit"~(1/V)))
abline(h = 0, lty = 2, lwd = 1.5, col = "gray50")
abline(h = c(-0.1, 0.1), lty = 3, lwd = 1.5, col = "gray50")
x1 <- log10(lmbac$nsamp[j1])
y1 <- lmbac$slope[j1]
col1 <- orp16Scol[env$groupnum[j1]]
# Make bigger points for larger slopes 20221230
cex1 <- ifelse(abs(y1) > 0.1, 1.5, 1)
points(x1, y1, pch = 19, col = col1, cex = cex1)
# Add legend
ltext <- names(envirotype)[i1[1:2]]
legend("bottomleft", ltext, pch = 19, col = orp16Scol[i1[1:2]])
ltext <- names(envirotype)[i1[3:4]]
legend("bottomright", ltext, pch = 19, col = orp16Scol[i1[3:4]])
title("Linear regressions for bacterial communities\nin each dataset", font.main = 1, xpd = NA, line = 0.7)
label.figure("b", font = 2, cex = 2.3, yfrac = 1.05)
# Groundwater, sediment, soil
plot(xlim, ylim, type = "n", xlab = quote(log[10]~"(Number of samples)"), ylab = quote("Slope of linear fit"~(1/V)))
abline(h = 0, lty = 2, lwd = 1.5, col = "gray50")
abline(h = c(-0.1, 0.1), lty = 3, lwd = 1.5, col = "gray50")
x2 <- log10(lmbac$nsamp[j2])
y2 <- lmbac$slope[j2]
col2 <- orp16Scol[env$groupnum[j2]]
cex2 <- ifelse(abs(y2) > 0.1, 1.5, 1)
points(x2, y2, pch = 19, col = col2, cex = cex2)
ltext <- names(envirotype)[i2]
legend("bottomright", ltext, pch = 19, col = orp16Scol[i2], bg = "white")
## Panel C: Distinctions in carbon oxidation state estimated for different geothermal areas 20210930
# Use Geothermal datasets
i <- 4
studies <- envirotype[[i]]
# Assign colors
# Use blue for neutral/alkaline
col <- rep(orp16Scol[1], length(studies))
# Use red for acidic
iacid <- studies %in% c("PCL+18_Acidic", "LMG+20")
col[iacid] <- orp16Scol[4]
# Use gray for sediments
ised <- studies %in% c("PBU+20", "MWY+21")
col[ised] <- "gray"
# Offset for labels 20211012
dx <- list(
c(0.04, 0.04, -0.22, 0.04, -0.19),
c(0.04, 0.04, 0.04, 0, -0.21)
)
dy <- list(
c(0, 0, -0.03, 0, -0.008),
c(0, 0, 0, 0, 0.014)
)
# Loop over Bacteria and Archaea
lineages <- c("Bacteria", "Archaea")
for(k in 1:2) {
dat <- EZlm[EZlm$lineage == lineages[k], ]
plot(c(-0.45, 0.40), c(-0.24, -0.12), type = "n", xlab = "Eh7 (V)", ylab = cplab$Zc)
for(j in seq_along(studies)) {
with(dat[dat$study == studies[j], ], {
# Divide by 1000 to convert slope from V-1 to mV-1 (used by lm fit) 20220520
y <- function(x) intercept + slope * x / 1000
Eh7 <- c(Eh7min, Eh7max)
Zc <- y(Eh7)
if(length(Eh7) > 0) {
lines(Eh7 / 1000, Zc, col = col[j], lwd = 2)
# Add number to identify dataset
text(tail(Eh7 / 1000, 1) + dx[[k]][j], tail(Zc, 1) + dy[[k]][j], j)
}
})
}
title(paste0("Geothermal\n", tolower(lineages[k])), font.main = 1, xpd = NA, line = 0.7)
if(k==1) {
label.figure("c", font = 2, cex = 2.3, yfrac = 1.025)
# Add legend
lacid <- paste0("Acidic (", paste(which(iacid), collapse = ", "), ")")
lneut <- "Circumneutral to"
lalk <- paste0("alkaline (", paste(which(col == orp16Scol[1]), collapse = ", "), ")")
lsed <- paste0("Sediment (", paste(which(ised), collapse = ", "), ")")
legend("topleft", c(lacid, lneut, lalk, lsed), col = c(orp16Scol[4], orp16Scol[1], NA, "gray"), lwd = 2, bty = "n")
}
}
if(pdf) dev.off()
}
# Figure 6: Associations between Eh7 and Zc at a global scale 20210828
orp16S_6 <- function(pdf = FALSE, EMP_primers = FALSE) {
if(pdf) {
if(EMP_primers) pdf("Figure_S3.pdf", width = 10, height = 7, bg = "white")
else pdf("Figure_6.pdf", width = 10, height = 7, bg = "white")
}
mat <- matrix(c(
16, 16, rep(1:7, each = 6), 17, 17,
16, 16, rep(8:14, each = 6), 18, 18,
rep(15, 46),
rep(0, 46),
rep(0, 5), rep(19, 16), rep(20, 16), rep(21, 9)
), nrow = 5, byrow = TRUE)
layout(mat, heights = c(2, 2, 0.5, 0.5, 4))
par(mar = c(4, 4, 1, 1))
par(mgp = c(2.5, 1, 0))
## Take only datasets that use EMP primers 20221004
if(EMP_primers) {
uses_EMP_primers <- c(
"MLL+18", "LWJ+21", "RARG22", # River & Seawater
"MTC21", # Lake & Pond
"PCL+18_Acidic", "PCL+18_Alkaline", "GWS+20", "MWY+21", # Geothermal
"SBP+20", "RMB+17", "PSB+21", # Hyperalkaline
"WLJ+16", "ZDW+19", "DJK+18", "APV+20", "MGW+22", # Groundwater
"OHL+18_DNA", "ZHZ+19", # Sediment
"MLL+19", "PSG+20", "RKSK22", "CKB+22" # Soil
)
EZdat <- EZdat[EZdat$study %in% uses_EMP_primers, ]
# Make sure we didn't miss any studies (check for typos ...)
stopifnot(all(uses_EMP_primers %in% EZdat$study))
}
## Panel A: Scatterplots and fits for Bacteria and Archaea in each environment
par(mar = c(0, 0, 1, 0))
xlim <- range(EZdat$Eh7)
ylim <- range(EZdat$Zc, -0.1)
eedat <- EZdat[EZdat$lineage == "Bacteria", ]
global.slopes <- list()
global.slopes$Bacteria <- eachenv(eedat, xlim = xlim, ylim = ylim, lineage = "Bacteria")
par(mar = c(1, 0, 0, 0))
eedat <- EZdat[EZdat$lineage == "Archaea", ]
global.slopes$Archaea <- eachenv(eedat, xlim = xlim, ylim = ylim, lineage = "Archaea")
# Add labels
plot.new()
text(0.5, -0.5, "Eh7 (V)", cex = 1.2, xpd = NA)
plot.new()
text(0.2, 0.5, cplab$Zc, cex = 1.2, srt = 90, xpd = NA)
label.figure("a", font = 2, cex = 2, xfrac = 0.2, yfrac = 0.97)
plot.new()
text(0.3, 0.5, "Bacteria", srt = 90, xpd = NA)
plot.new()
text(0.3, 0.5, "Archaea", srt = 90, xpd = NA)
## Panel B: Scatterplots and fits for Bacteria and Archaea in all environments 20210914
# Start plot for Bacteria
par(mar = c(4, 4, 1, 1))
plot(c(-0.50, 0.65), range(EZdat$Zc), type = "n", xlab = "Eh7 (V)", ylab = cplab$Zc)
# Use Bacteria only
thisdat <- EZdat[EZdat$lineage == "Bacteria", ]
# Add linear fit; include number of studies in legend 20210925
nstudy <- length(unique(thisdat$study))
add.linear.global(thisdat$Eh7, thisdat$Zc, nstudy)
# Add points
eachenv(thisdat, add = TRUE, do.linear = FALSE)
title("Bacteria", font.main = 1, line = 0.5, xpd = NA)
label.figure("b", font = 2, cex = 2, xfrac = 0.05, yfrac = 1)
# Now do Archaea
plot(c(-0.50, 0.65), range(EZdat$Zc), type = "n", xlab = "Eh7 (V)", ylab = cplab$Zc)
thisdat <- EZdat[EZdat$lineage == "Archaea", ]
nstudy <- length(unique(thisdat$study))
add.linear.global(thisdat$Eh7, thisdat$Zc, nstudy, inset = c(0, 0.05))
eachenv(thisdat, add = TRUE, do.linear = FALSE)
title("Archaea", font.main = 1, line = 0.5, xpd = NA)
# Add legend
par(mar = c(4, 1, 1, 1))
plot.new()
ienv = c(1, 2, 4, 5, 3, 6, 7)
ltext <- names(envirotype)[ienv]
legend("left", ltext, pch = 19, col = orp16Scol[ienv], bty = "n")
if(pdf) dev.off()
# Return slopes 20220611
invisible(global.slopes)
}
###########################################
### Functions for supplementary figures ###
###########################################
# Figure S1: Zc-Eh scatterplots for all studies 20210827
# This also creates files EZdat (Eh and Zc values) and
# EZlm (linear fits) for use by other plotting functions
orp16S_S1 <- function(pdf = FALSE) {
# Setup figure
if(pdf) pdf("Figure_S1.pdf", width = 9, height = 12, bg = "white")
par(mfrow = c(4, 3))
results <- c(
message("\nRiver & Seawater"),
plotEZ("MLL+18", "Bacteria", groupby = "Season", groups = c("Summer", "Winter"), legend.x = "bottomright"),
plotEZ("HXZ+20", "Bacteria", groupby = "Station", groups = c("SYBL", "C4")),
plotEZ("GSBT20_Prefilter", "two", groupby = "Region", groups = c("West Coast U.S.", "Great Lakes", "East Coast U.S.", "Europe", "Asia"),
legend.x = "bottomright", dylim = c(-0.015, 0)),
plotEZ("GSBT20_Postfilter", "two", groupby = "Region", groups = c("West Coast U.S.", "Great Lakes", "East Coast U.S.", "Europe", "Asia"),
legend.x = "bottomright", dylim = c(-0.007, 0), dxlim = c(0, 75)),
plotEZ("WHL+21", "Bacteria", groupby = "Season", groups = c("Spring", "Summer", "Autumn", "Winter"), legend.x = "bottomleft"),
plotEZ("ZLH+22", "Bacteria"),
plotEZ("ZZL+21", "Bacteria", groupby = "Location", groups = c("Main Stream", "Animal Farm", "Hospital", "WWTP", "Tributary"),
legend.x = "bottomright", dxlim = c(0, 100)),
plotEZ("LWJ+21", "two", groupby = "Type", groups = c("Freshwater", "Freshwater Plastic", "Seawater", "Seawater Plastic"), dylim = c(0, 0.01)),
plotEZ("GZL21", "Bacteria", groupby = "Type", groups = c("Surface water", "Middle water", "Bottom water"), legend.x = "bottomleft"),
plotEZ("RARG22", "two", groupby = "Group", groups = c("AMD", "Abiotic Treatment", "Biotic Treatment", "Stream"), dylim = c(0, 0.007)),
message("\nLake & Pond"),
plotEZ("SAR+13", "two", groupby = "Zone", groups = c("Photic-oxic", "Transition", "Anoxic")),
plotEZ("LLC+19", "Bacteria", groupby = "Size", groups = c("Free-living", "Particle-associated")),
plotEZ("BCA+21", "Bacteria", groupby = "Month", groups = c("Jul", "Nov", "Feb", "Apr")),
plotEZ("HLZ+18", "Bacteria", groupby = "Type", groups = c("Reservoir", "Pond"), legend.x = "bottomright"),
plotEZ("BWD+19", "Bacteria", groupby = "Cover", groups = c("Ice", "Ice Free"), legend.x = "bottomright"),
plotEZ("IBK+22", "two", groupby = "Land Use", groups = c("Arable", "Forest", "Grassland")),
plotEZ("NLE+21", "Bacteria", groupby = "Year", groups = c("2017", "2018"), legend.x = "bottomleft"),
plotEZ("MTC21", "two", groupby = "Year", groups = c(2012, 2013, 2014)),
plotEZ("SPA+21", "Bacteria", groupby = "Depth", groups = c("Epi", "Secchi", "Meso"), legend.x = "bottomleft"),
message("\nGeothermal"),
plotEZ("PCL+18_Acidic", "two", legend.x = "bottomright"),
plotEZ("PCL+18_Alkaline", "two"),
plotEZ("GWS+20", "two", groupby = "Hydrothermal Field", groups = c("Batang", "Litang", "Kangding")),
plotEZ("PBU+20", "Bacteria", groupby = "Type", groups = c("Cauldron", "Sampling Pit", "Spring", "Geyser Valley (Control)"), legend.x = "bottomright"),
plotEZ("MWY+21", "two", groupby = "Location", groups = c("Quseyongba", "Moluojiang", "Daggyai", "Quzhuomu"), legend.x = "bottomright"),
message("\nHyperalkaline"),
plotEZ("SBP+20", "Bacteria", groupby = "pH Group", groups = c("< 10", "> 10")),
plotEZ("RMB+17", "two", groupby = "pH Group", groups = c("< 10", "> 10")),
plotEZ("CTS+17", "two", groupby = "Type", groups = c("River", "Well", "Spring"), legend.x = "bottomleft"),
plotEZ("KSR+21", "Bacteria", groupby = "Location", groups = c("Lerone", "Branega", "Branega Creek Water")),
plotEZ("PSB+21", "Bacteria", groupby = "O2 range", groups = c("> 0.5 mg/L", "0.2-0.5 mg/L", "< 0.2 mg/L"), dxlim = c(-100, 0), dylim = c(0, 0.01)),
plotEZ("NTB+21", "two", groupby = "Well", groups = c("BA1A", "BA1D")),
message("\nGroundwater"),
plotEZ("KLM+16", "Bacteria", groupby = "Day", groups = c(-1, 246, 448, 671)),
plotEZ("WLJ+16", "two", groupby = "Arsenic", groups = c("As < 100 \u03BCg/L", "As > 100 \u03BCg/L")),
plotEZ("ZDW+19", "two", groupby = "Season", groups = c("Non-monsoon", "Spring", "Monsoon", "Autumn"), legend.x = "bottomright"),
plotEZ("DJK+18", "two", groupby = "Aquifer", groups = c("Athens", "Greene", "Licking"), legend.x = "bottomleft"),
plotEZ("SRM+19", "Bacteria", groupby = "Land Use", groups = c("Agriculture", "Community", "Landfill", "Mine")),
plotEZ("APV+20", "two", groupby = "Type", groups = c("Canal", "Piezometer", "Well", "Spring")),
plotEZ("YHK+20", "Bacteria", groupby = "Location", groups = c("Upper Hillslope", "Middle Slope", "Lower Footslope"), dylim = c(0, 0.005)),
plotEZ("ZCZ+21", "Bacteria", groupby = "Location", groups = c("LO", "CR1", "MN", "VA", "BS", "CR2"), legend.x = "topright"),
plotEZ("MGW+22", "two", groupby = "Region", groups = c("Auckland", "Canterbury", "Taupo", "Wellington"), legend.x = "bottomleft", dylim = c(-0.006, 0)),
plotEZ("MCR+22", "two", groupby = "Location", groups = c("Upstream", "WWTP", "Farm", "Swamp"), legend.x = "bottomleft"),
message("\nSediment"),
plotEZ("ZML+17", "two", groupby = "Depth", groups = c("\u2264 5 cm", "\u2265 10 cm", "\u2265 20 cm"), legend.x = "bottomleft", dylim = c(-0.003, 0)),
plotEZ("BSPD17", "Bacteria", groupby = "Type", groups = c("Water", "Sediment")),
plotEZ("RKN+17", "two", groupby = "Treatment", groups = c("CH4", "CH4+Fe", "CH4+Mn"), legend.x = "bottomleft"),
plotEZ("HDZ+19", "Bacteria", groupby = "Type", groups = c("Water", "Sediment")),
plotEZ("OHL+18_DNA", "two", groupby = "Location", groups = c("Kal\u00f8 Vig", "Lake Constance", "Norsminde Fjord")),
plotEZ("WHLH21a", "Bacteria", groupby = "Position", groups = c("Surface", "Middle", "Bottom"), legend.x = "bottomleft"),
plotEZ("RSS+18", "Bacteria", groupby = "Site", groups = c("Deep Hole", "Snowgoose Bay", "John's Island", "Skeleton Lake"), dylim = c(0, 0.005)),
plotEZ("CLS+19", "two", groupby = "Type", groups = c("Water", "Sediment"), legend.x = "bottomright", dylim = c(-0.002, 0)),
plotEZ("HSF+19", "Bacteria", groupby = "Type", groups = c("Water", "Sediment-Water Interface", "Sediment"), legend.x = "topright"),
plotEZ("ZHZ+19", "two", groupby = "Treatment", groups = c("Original", "Nitrate-reducing", "Ferric-reducing", "Sulfate-reducing", "Methanogenic"),
dylim = c(0, 0.005)),
plotEZ("LMBA21_2017", "two", groupby = "Season", groups = c("Summer", "Winter"), legend.x = "bottomright", dylim = c(-0.005, 0)),
plotEZ("HSF+22", "Bacteria", groupby = "Location", groups = c("West Lagoon", "North Lagoon", "South Lagoon", "Cinq Cases"),
legend.x = "bottomright", dxlim = c(0, 100)),
plotEZ("ZZLL21", "Bacteria", groupby = "Type", groups = c("Main stream", "Animal farm", "Hospital", "WWTP", "Tributary"),
legend.x = "bottomleft", dylim = c(-0.005, 0)),
plotEZ("WFB+21", "Bacteria", groupby = "Treatment", groups = c("C. volutator", "H. diversicolor", "Cv & Hd", "MPB", "Manual turbation"),
dylim = c(0, 0.002)),
plotEZ("HCW+22", "Bacteria", groupby = "Condition", groups = c("Static", "Weak", "Strong"), dylim = c(0, 0.007)),
plotEZ("WKG+22", "Bacteria", groupby = "Season", groups = c("Spring", "Summer", "Autumn", "Winter"), dylim = c(0, 0.002)),
message("\nSoil"),
plotEZ("MLL+19", "two", groupby = "Type", groups = c("Upland", "Paddy", "Sediment")),
plotEZ("BMOB18", "two", groupby = "Treatment", groups = c("Acetate", "No amendment", "Pre-incubation"), dxlim = c(-50, 0)),
plotEZ("WHLH21", "Bacteria", groupby = "Stage", groups = c("Cyanobacteria", "Cyanolichen", "Chlorolichen", "Moss"), legend.x = "bottomright"),
plotEZ("CWC+20", "Bacteria", groupby = "Management", groups = c("Flooding", "Draining"), legend.x = "bottomright"),
plotEZ("PSG+20", "two", groupby = "Treatment", groups = c("Initial", "NCC", "RB", "RGP", "TP"), legend.x = "bottomright"),
plotEZ("LJC+20", "Bacteria", groupby = "MAT", groups = c(">= 21.5 \u00b0C", "< 21.5 \u00b0C"), dylim = c(0, 0.005)),
plotEZ("DTJ+20", "Bacteria", groupby = "Zone", groups = c("Bulk Soil", "Mature", "Elongation", "Tip")),
plotEZ("RKSK22", "two", groupby = "Compartment", groups = c("Bulk sediment", "Rhizosphere", "Root"), legend.x = "bottomright"),
plotEZ("DLS21_Bulk", "Bacteria", groupby = "Treatment", groups = c("Control", "Char", "Silicate", "Husk")),
plotEZ("WKP+22", "Bacteria", groupby = "Type", groups = c("Intercropping", "Monoculture"), legend.x = "bottomleft"),
plotEZ("CKB+22", "two", groupby = "Treatment", groups = c("FM 5 Mg/ha", "FM 10 Mg/ha", "RS 5 Mg/ha", "RS 10 Mg/ha"), legend.x = "bottomright"),
plotEZ("CLZ+22", "Bacteria")
)
# Done plotting!
if(pdf) dev.off()
# Assemble all data
EZdat <- do.call(rbind, results[names(results) == "EZdat"])
# Assemble all linear model results
coefficients <- sapply(results[names(results) == "EZlm"], "[", "coefficients")
intercept <- sapply(coefficients, "[[", "(Intercept)")
slope <- sapply(coefficients, "[[", "Eh7")
model <- lapply(results[names(results) == "EZlm"], "[[", "model")
Eh7lim <- sapply(lapply(model, "[", "Eh7"), "range")
Eh7min <- Eh7lim[1, ]
Eh7max <- Eh7lim[2, ]
# Get MOE95 (95% CI) 20221008
CI95 <- lapply(results[names(results) == "EZlm"], "confint", parm = "Eh7", level = 0.95)
MOE95 <- sapply(lapply(CI95, range), diff) / 2
# Get study name etc.
study <- sapply(results[names(results) == "study"], "[")
name <- sapply(results[names(results) == "name"], "[")
envirotype <- sapply(results[names(results) == "envirotype"], "[")
lineage <- sapply(results[names(results) == "lineage"], "[")
nsamp <- sapply(model, nrow)
pearson.r <- unlist(lapply(results[names(results) == "pearson"], "[[", "estimate"))
# Note: slope and MOE95 are mutiplied by 1000 to convert from mV-1 to V-1
EZlm <- data.frame(study, name, envirotype, lineage, nsamp, Eh7min, Eh7max,
slope = signif(slope * 1000, 6), MOE95 = signif(MOE95 * 1000, 6), intercept = signif(intercept, 6), pearson.r = signif(pearson.r, 6))
# Save data and results to files