-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermanova_bacteria.R
73 lines (60 loc) · 1.34 KB
/
permanova_bacteria.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
#### Setup ####
# random seed
seed <- 2202
source("scripts/00_helperfunctions/alx_OutOfSight.R")
inputfolder <- "../data/processed"
tabfolder <- "../results/output_tables/bacteria"
dir.create(tabfolder, showWarnings = FALSE)
if ( !require("phyloseq", quietly = TRUE) )
BiocManager::install("phyloseq")
if ( !require("gt", quietly = TRUE) )
BiocManager::install("gt")
#### Read data ####
bacter <- readRDS(
paste0(inputfolder,
"/bacter_rar_genus.rds")
)
#### Convert to relative abundance ####
bacter <- transform_sample_counts(
bacter,
function(x) x / sum(x) * 100
)
#### Permanova ####
permanova <- permanova2(
bacter,
distm = "bray",
var = "Country",
permutations = 999,
rngseed = seed,
hellinger = TRUE
)
# Save
gtsave(
permanova %>% gt,
filename = "permanova_country_bacter.html",
path = tabfolder
)
#### Dispersion Test ####
dispersion <- hdisp(
bacter,
distm = "bray",
vars = "Country"
)
saveRDS(
dispersion,
file = paste0(tabfolder, "/dispersion_country_bacter.rds")
)
#### Pairwise permanova ####
pairwise_permanova <- pairwise.permanovas2(
bacter,
variable = "Country",
p.adjust.m = "BH",
rngseed = seed,
hellinger = TRUE
)
# Save
gtsave(
pairwise_permanova %>% arrange(desc(R2)) %>% gt,
filename = "pairwise_permanova_country_bacter.html",
path = tabfolder
)