library(DT)
library(ggpubr)
library(kableExtra)
library(phyloseq)
library(phyloseq.extended)
library(tidyverse)
library(plotly)
library(tidyverse)
library(ggVennDiagram)
library(ggplot2)
source("curation.R")
https://forgemia.inra.fr/migale/metabarfood/
. The
code used is available in the code chunks.
This report shows the analyses performed on real samples of the METABARFOOD project with de DADA2_FROGS approach.
raw_data <- read.csv2("data/metadata_real_reads.tsv" , sep = "\t", stringsAsFactors = F) %>% as_tibble()
Diversity of real samples before and after a manual and expert curation are represented in the following figures.
ecos <- c("MEAT","CHEESE","WINE","BREAD")
markers <- c("ITS1","ITS2","D1D2","RPB2")
for(eco in ecos){
dir <- paste("REAL",eco, sep="_")
cat("\n## ",eco," {.tabset}\n\n")
for(marker in markers){
if(marker=="D1D2"){
cat("\n### ", "D1/D2", "\n\n")
}else{
cat("\n### ", marker, "\n\n")
}
physeq <- readRDS(file.path(dir,paste0(marker,".rds")))
physeq_final <- readRDS(file.path(dir,paste0(marker,"_final.rds")))
taxa_names(physeq) <- paste(taxa_names(physeq), "2", sep = "_")
physeq_all <- merge_phyloseq(physeq_final, physeq)
cat("\n**Abundances** \n")
p <- plot_bar(physeq_all, x="Type") + facet_grid(~SampleID)
p$data$Type <- factor(p$data$Type, levels = c("Raw","Curated"))
print(p)
cat(" \n")
cat("\n**Compositions** \n")
p <- plot_composition(physeq_all, "Kingdom", "Fungi", "Family", x = "Type") +
scale_y_continuous(expand = expansion(0, 0)) +
scale_x_discrete(expand = expansion(0, 0)) +
facet_grid(~ SampleID)
p$data$Type <- factor(p$data$Type, levels = c("Raw","Curated"))
print(p)
cat("\n")
p <- plot_composition(physeq_all, "Kingdom", "Fungi", "Genus", x = "Type") +
scale_y_continuous(expand = expansion(0, 0)) +
scale_x_discrete(expand = expansion(0, 0)) +
facet_grid(~ SampleID)
p$data$Type <- factor(p$data$Type, levels = c("Raw","Curated"))
print(p)
cat("\n")
cat("\n**Alpha-diversity** \n")
p <- plot_richness(physeq = physeq_all, x="SampleID", color = "Type", shape = NULL, title = "Alpha diversity graphics", measures = c("Observed", "Chao1", "ACE", "Shannon", "Simpson", "InvSimpson"))
p$data$Type <- factor(p$data$Type, levels = c("Raw","Curated"))
p <- p + geom_boxplot() + NULL
print(p)
cat("\n")
#cat("\n#### beta-diversity \n")
#beta.dist <- distance(physeq_all, method = "bray")
#ord <- ordinate(physeq_all, method = "MDS", distance = beta.dist)
#p <- plot_ordination(physeq = physeq_all, ordination = ord, type = "samples", axes = c(1, 2), color = "SampleID", shape = NULL, label = NULL, title = "Samples ordination graphic, bray-curtis distance")
#p <- p + theme_bw()
#print(p)
#cat("\n")
}
cat("\n")
}
Abundances
Compositions
Alpha-diversity
Abundances
Compositions
Alpha-diversity
Abundances
Compositions
Alpha-diversity
Abundances
Compositions
Alpha-diversity
Abundances
Compositions
Alpha-diversity
Abundances
Compositions
Alpha-diversity
Abundances
Compositions
Alpha-diversity
Abundances
Compositions
Alpha-diversity
Abundances
Compositions
Alpha-diversity
Abundances
Compositions
Alpha-diversity
Abundances
Compositions
Alpha-diversity
Abundances
Compositions
Alpha-diversity
Abundances
Compositions
Alpha-diversity
Abundances
Compositions
Alpha-diversity
Abundances
Compositions
Alpha-diversity
Abundances
Compositions
Alpha-diversity
eco <- "MEAT"
rank <- "Genus"
dir <- paste("REAL",eco, sep="_")
its1 <- readRDS(file.path(dir,paste0("ITS1_final",".rds")))
its2 <- readRDS(file.path(dir,paste0("ITS2_final",".rds")))
d1d2 <- readRDS(file.path(dir,paste0("D1D2_final",".rds")))
sample_data(d1d2)$Marker <- "D1/D2"
rpb2 <- readRDS(file.path(dir,paste0("RPB2_final",".rds")))
# Remove low-abundant ASVs
its1 <- filter_low_abundant(its1,0.001)
its2 <- filter_low_abundant(its2,0.001)
d1d2 <- filter_low_abundant(d1d2,0.001)
rpb2 <- filter_low_abundant(rpb2,0.001)
all <- merge_phyloseq(its1, its2, d1d2, rpb2)
all_rel = transform_sample_counts(all, function(x) x / sum(x) )
#all_rel <- prune_samples(sample_sums(all_rel) > 0, all_rel)
all_glom <- tax_glom(all_rel, taxrank=rank)
#cat("\n")
#print(tax_table(all_glom) %>% as("matrix") %>% datatable())
#cat("\n")
tax_table(all_glom)[, ] <- tax_table(all_glom)[ , ] %>% as("matrix") %>% stringr::str_replace_all('_', ' ') %>% stringr::str_wrap(50, exdent = 3)
## Qui est bien compatible avec le heatmap
taxa.order <- tax_table(all_glom)[ , rank] %>% sort() %>% rev() %>% rownames()
p <- plot_heatmap(all_glom, distance="bray", sample.label="SampleID", taxa.label=rank, taxa.order = taxa.order, high="#000033", low="#66CCFF", na.value = "white")
p <- p + facet_grid(~Marker, scales = "free_x", space = "free_x")
p <- p+ theme(axis.text.y=element_text(size = 11))
#p <- p + scale_y_discrete(label = function(x) stringr::str_trunc(x, 12))
print(p)
cat("\n")
rank <- "Species"
dir <- paste("REAL",eco, sep="_")
its1 <- readRDS(file.path(dir,paste0("ITS1_final",".rds")))
its2 <- readRDS(file.path(dir,paste0("ITS2_final",".rds")))
d1d2 <- readRDS(file.path(dir,paste0("D1D2_final",".rds")))
sample_data(d1d2)$Marker <- "D1/D2"
rpb2 <- readRDS(file.path(dir,paste0("RPB2_final",".rds")))
# Remove low-abundant ASVs
its1 <- filter_low_abundant(its1,0.001)
its2 <- filter_low_abundant(its2,0.001)
d1d2 <- filter_low_abundant(d1d2,0.001)
rpb2 <- filter_low_abundant(rpb2,0.001)
all <- merge_phyloseq(its1, its2, d1d2, rpb2)
all_rel = transform_sample_counts(all, function(x) x / sum(x) )
#all_rel <- prune_samples(sample_sums(all_rel) > 0, all_rel)
all_glom <- tax_glom(all_rel, taxrank=rank)
tax_table(all_glom)[, ] <- tax_table(all_glom)[ , ] %>% as("matrix") %>% stringr::str_replace_all('_', ' ') %>% stringr::str_wrap(50, exdent = 3)
## Qui est bien compatible avec le heatmap
taxa.order <- tax_table(all_glom)[ , rank] %>% sort() %>% rev() %>% rownames()
p <- plot_heatmap(all_glom, distance="bray", sample.label="SampleID", taxa.label=rank, taxa.order = taxa.order, high="#000033", low="#66CCFF", na.value = "white")
p <- p + facet_grid(~Marker, scales = "free_x", space = "free_x")
p <- p+ theme(axis.text.y=element_text(size = 10))
#p <- p + scale_y_discrete(label = function(x) stringr::str_trunc(x, 12))
print(p)
cat("\n")
eco <- "CHEESE"
rank <- "Genus"
dir <- paste("REAL",eco, sep="_")
its1 <- readRDS(file.path(dir,paste0("ITS1_final",".rds")))
its2 <- readRDS(file.path(dir,paste0("ITS2_final",".rds")))
d1d2 <- readRDS(file.path(dir,paste0("D1D2_final",".rds")))
sample_data(d1d2)$Marker <- "D1/D2"
rpb2 <- readRDS(file.path(dir,paste0("RPB2_final",".rds")))
# Remove low-abundant ASVs
its1 <- filter_low_abundant(its1,0.001)
its2 <- filter_low_abundant(its2,0.001)
d1d2 <- filter_low_abundant(d1d2,0.001)
rpb2 <- filter_low_abundant(rpb2,0.001)
all <- merge_phyloseq(its1, its2, d1d2, rpb2)
all_rel = transform_sample_counts(all, function(x) x / sum(x) )
#all_rel <- prune_samples(sample_sums(all_rel) > 0, all_rel)
all_glom <- tax_glom(all_rel, taxrank=rank)
tax_table(all_glom)[, ] <- tax_table(all_glom)[ , ] %>% as("matrix") %>% stringr::str_replace_all('_', ' ') %>% stringr::str_wrap(50, exdent = 3)
## Qui est bien compatible avec le heatmap
taxa.order <- tax_table(all_glom)[ , rank] %>% sort() %>% rev() %>% rownames()
p <- plot_heatmap(all_glom, distance="bray", sample.label="SampleID", taxa.label=rank, taxa.order = taxa.order, high="#000033", low="#66CCFF", na.value = "white")
p <- p + facet_grid(~Marker, scales = "free_x", space = "free_x")
p <- p+ theme(axis.text.y=element_text(size = 11))
#p <- p + scale_y_discrete(label = function(x) stringr::str_trunc(x, 12))
print(p)
cat("\n")
rank <- "Species"
dir <- paste("REAL",eco, sep="_")
its1 <- readRDS(file.path(dir,paste0("ITS1_final",".rds")))
its2 <- readRDS(file.path(dir,paste0("ITS2_final",".rds")))
d1d2 <- readRDS(file.path(dir,paste0("D1D2_final",".rds")))
sample_data(d1d2)$Marker <- "D1/D2"
rpb2 <- readRDS(file.path(dir,paste0("RPB2_final",".rds")))
# Remove low-abundant ASVs
its1 <- filter_low_abundant(its1,0.001)
its2 <- filter_low_abundant(its2,0.001)
d1d2 <- filter_low_abundant(d1d2,0.001)
rpb2 <- filter_low_abundant(rpb2,0.001)
all <- merge_phyloseq(its1, its2, d1d2, rpb2)
all_rel = transform_sample_counts(all, function(x) x / sum(x) )
#all_rel <- prune_samples(sample_sums(all_rel) > 0, all_rel)
all_glom <- tax_glom(all_rel, taxrank=rank)
tax_table(all_glom)[, ] <- tax_table(all_glom)[ , ] %>% as("matrix") %>% stringr::str_replace_all('_', ' ') %>% stringr::str_wrap(50, exdent = 3)
## Qui est bien compatible avec le heatmap
taxa.order <- tax_table(all_glom)[ , rank] %>% sort() %>% rev() %>% rownames()
p <- plot_heatmap(all_glom, distance="bray", sample.label="SampleID", taxa.label=rank, taxa.order = taxa.order, high="#000033", low="#66CCFF", na.value = "white")
p <- p + facet_grid(~Marker, scales = "free_x", space = "free_x")
p <- p+ theme(axis.text.y=element_text(size = 10))
#p <- p + scale_y_discrete(label = function(x) stringr::str_trunc(x, 12))
print(p)
cat("\n")
eco <- "WINE"
rank <- "Genus"
dir <- paste("REAL",eco, sep="_")
its1 <- readRDS(file.path(dir,paste0("ITS1_final",".rds")))
its2 <- readRDS(file.path(dir,paste0("ITS2_final",".rds")))
d1d2 <- readRDS(file.path(dir,paste0("D1D2_final",".rds")))
sample_data(d1d2)$Marker <- "D1/D2"
rpb2 <- readRDS(file.path(dir,paste0("RPB2_final",".rds")))
# Remove low-abundant ASVs
its1 <- filter_low_abundant(its1,0.001)
its2 <- filter_low_abundant(its2,0.001)
d1d2 <- filter_low_abundant(d1d2,0.001)
rpb2 <- filter_low_abundant(rpb2,0.001)
all <- merge_phyloseq(its1, its2, d1d2, rpb2)
all_rel = transform_sample_counts(all, function(x) x / sum(x) )
#all_rel <- prune_samples(sample_sums(all_rel) > 0, all_rel)
all_glom <- tax_glom(all_rel, taxrank=rank)
all_glom <- manual_changes_taxonomy(all_glom)
tax_table(all_glom)[, ] <- tax_table(all_glom)[ , ] %>% as("matrix") %>% stringr::str_replace_all('_', ' ') %>% stringr::str_wrap(50, exdent = 3)
## Qui est bien compatible avec le heatmap
taxa.order <- tax_table(all_glom)[ , rank] %>% sort() %>% rev() %>% rownames()
p <- plot_heatmap(all_glom, distance="bray", sample.label="SampleID", taxa.label=rank, taxa.order = taxa.order, high="#000033", low="#66CCFF", na.value = "white")
p <- p + facet_grid(~Marker, scales = "free_x", space = "free_x")
p <- p+ theme(axis.text.y=element_text(size = 11))
#p <- p + scale_y_discrete(label = function(x) stringr::str_trunc(x, 12))
print(p)
cat("\n")
rank <- "Species"
dir <- paste("REAL",eco, sep="_")
its1 <- readRDS(file.path(dir,paste0("ITS1_final",".rds")))
its2 <- readRDS(file.path(dir,paste0("ITS2_final",".rds")))
d1d2 <- readRDS(file.path(dir,paste0("D1D2_final",".rds")))
sample_data(d1d2)$Marker <- "D1/D2"
rpb2 <- readRDS(file.path(dir,paste0("RPB2_final",".rds")))
# Remove low-abundant ASVs
its1 <- filter_low_abundant(its1,0.001)
its2 <- filter_low_abundant(its2,0.001)
d1d2 <- filter_low_abundant(d1d2,0.001)
rpb2 <- filter_low_abundant(rpb2,0.001)
all <- merge_phyloseq(its1, its2, d1d2, rpb2)
all_rel = transform_sample_counts(all, function(x) x / sum(x) )
#all_rel <- prune_samples(sample_sums(all_rel) > 0, all_rel)
all_glom <- tax_glom(all_rel, taxrank=rank)
tax_table(all_glom)[, ] <- tax_table(all_glom)[ , ] %>% as("matrix") %>% stringr::str_replace_all('_', ' ') %>% stringr::str_wrap(50, exdent = 3)
## Qui est bien compatible avec le heatmap
taxa.order <- tax_table(all_glom)[ , rank] %>% sort() %>% rev() %>% rownames()
p <- plot_heatmap(all_glom, distance="bray", sample.label="SampleID", taxa.label=rank, taxa.order = taxa.order, high="#000033", low="#66CCFF", na.value = "white")
p <- p + facet_grid(~Marker, scales = "free_x", space = "free_x")
p <- p+ theme(axis.text.y=element_text(size = 10))
#p <- p + scale_y_discrete(label = function(x) stringr::str_trunc(x, 12))
print(p)
cat("\n")
eco <- "BREAD"
rank <- "Species"
dir <- paste("REAL",eco, sep="_")
its1 <- readRDS(file.path(dir,paste0("ITS1_final",".rds")))
its2 <- readRDS(file.path(dir,paste0("ITS2_final",".rds")))
d1d2 <- readRDS(file.path(dir,paste0("D1D2_final",".rds")))
sample_data(d1d2)$Marker <- "D1/D2"
#rpb2 <- readRDS(file.path(dir,paste0("RPB2_final",".rds")))
# Remove low-abundant ASVs
its1 <- filter_low_abundant(its1,0.001)
its2 <- filter_low_abundant(its2,0.001)
d1d2 <- filter_low_abundant(d1d2,0.001)
#rpb2 <- filter_low_abundant(rpb2,0.001)
all <- merge_phyloseq(its1, its2, d1d2)
all_rel = transform_sample_counts(all, function(x) x / sum(x) )
#all_rel <- prune_samples(sample_sums(all_rel) > 0, all_rel)
all_glom <- tax_glom(all_rel, taxrank=rank)
tax_table(all_glom)[, ] <- tax_table(all_glom)[ , ] %>% as("matrix") %>% stringr::str_replace_all('_', ' ') %>% stringr::str_wrap(50, exdent = 3)
## Qui est bien compatible avec le heatmap
taxa.order <- tax_table(all_glom)[ , rank] %>% sort() %>% rev() %>% rownames()
p <- plot_heatmap(all_glom, distance="bray", sample.label="SampleID", taxa.label=rank, taxa.order = taxa.order, high="#000033", low="#66CCFF", na.value = "white")
p <- p + facet_grid(~Marker, scales = "free_x", space = "free_x")
p <- p+ theme(axis.text.y=element_text(size = 10))
#p <- p + scale_y_discrete(label = function(x) stringr::str_trunc(x, 12))
print(p)
cat("\n")
rank <- "Genus"
dir <- paste("REAL",eco, sep="_")
its1 <- readRDS(file.path(dir,paste0("ITS1_final",".rds")))
its2 <- readRDS(file.path(dir,paste0("ITS2_final",".rds")))
d1d2 <- readRDS(file.path(dir,paste0("D1D2_final",".rds")))
sample_data(d1d2)$Marker <- "D1/D2"
#rpb2 <- readRDS(file.path(dir,paste0("RPB2_final",".rds")))
# Remove low-abundant ASVs
its1 <- filter_low_abundant(its1,0.001)
its2 <- filter_low_abundant(its2,0.001)
d1d2 <- filter_low_abundant(d1d2,0.001)
#rpb2 <- filter_low_abundant(rpb2,0.001)
all <- merge_phyloseq(its1, its2, d1d2)
all_rel = transform_sample_counts(all, function(x) x / sum(x) )
#all_rel <- prune_samples(sample_sums(all_rel) > 0, all_rel)
all_glom <- tax_glom(all_rel, taxrank=rank)
#cat("\n")
#print(tax_table(all_glom) %>% as("matrix") %>% datatable())
#cat("\n")
tax_table(all_glom)[, ] <- tax_table(all_glom)[ , ] %>% as("matrix") %>% stringr::str_replace_all('_', ' ') %>% stringr::str_wrap(50, exdent = 3)
## Qui est bien compatible avec le heatmap
taxa.order <- tax_table(all_glom)[ , rank] %>% sort() %>% rev() %>% rownames()
p <- plot_heatmap(all_glom, distance="bray", sample.label="SampleID", taxa.label=rank, taxa.order = taxa.order, high="#000033", low="#66CCFF", na.value = "white")
p <- p + facet_grid(~Marker, scales = "free_x", space = "free_x")
p <- p+ theme(axis.text.y=element_text(size = 11))
#p <- p + scale_y_discrete(label = function(x) stringr::str_trunc(x, 12))
print(p)
cat("\n")
all <- readRDS("data/all_samples.rds")
meat_its1 <- readRDS("REAL_MEAT/ITS1_final.rds")
meat_its1 <- transform_sample_counts(meat_its1, function(x) {x/sum(x)})
sample_names(meat_its1) <- glue::glue(paste("{sample_data(meat_its1)$SampleID}","{sample_data(meat_its1)$Eco}","{sample_data(meat_its1)$Marker}",sep="_"))
taxa_names(meat_its1) <- glue::glue(paste("{taxa_names(meat_its1)}","MEAT","ITS1",sep="_"))
meat_its2 <- readRDS("REAL_MEAT/ITS2_final.rds")
meat_its2 <- transform_sample_counts(meat_its2, function(x) {x/sum(x)})
sample_names(meat_its2) <- glue::glue(paste("{sample_data(meat_its2)$SampleID}","{sample_data(meat_its2)$Eco}","{sample_data(meat_its2)$Marker}",sep="_"))
taxa_names(meat_its2) <- glue::glue(paste("{taxa_names(meat_its2)}","MEAT","ITS2",sep="_"))
meat_rpb2 <- readRDS("REAL_MEAT/RPB2_final.rds")
meat_rpb2 <- transform_sample_counts(meat_rpb2, function(x) {x/sum(x)})
sample_names(meat_rpb2) <- glue::glue(paste("{sample_data(meat_rpb2)$SampleID}","{sample_data(meat_rpb2)$Eco}","{sample_data(meat_rpb2)$Marker}",sep="_"))
taxa_names(meat_rpb2) <- glue::glue(paste("{taxa_names(meat_rpb2)}","MEAT","RPB2",sep="_"))
meat_d1d2 <- readRDS("REAL_MEAT/D1D2_final.rds")
meat_d1d2 <- transform_sample_counts(meat_d1d2, function(x) {x/sum(x)})
sample_names(meat_d1d2) <- glue::glue(paste("{sample_data(meat_d1d2)$SampleID}","{sample_data(meat_d1d2)$Eco}","{sample_data(meat_d1d2)$Marker}",sep="_"))
taxa_names(meat_d1d2) <- glue::glue(paste("{taxa_names(meat_d1d2)}","MEAT","D1D2",sep="_"))
cheese_its1 <- readRDS("REAL_CHEESE/ITS1_final.rds")
cheese_its1 <- transform_sample_counts(cheese_its1, function(x) {x/sum(x)})
sample_names(cheese_its1) <- glue::glue(paste("{sample_data(cheese_its1)$SampleID}","{sample_data(cheese_its1)$Eco}","{sample_data(cheese_its1)$Marker}",sep="_"))
taxa_names(cheese_its1) <- glue::glue(paste("{taxa_names(cheese_its1)}","CHEESE","ITS1",sep="_"))
cheese_its2 <- readRDS("REAL_CHEESE/ITS2_final.rds")
cheese_its2 <- transform_sample_counts(cheese_its2, function(x) {x/sum(x)})
sample_names(cheese_its2) <- glue::glue(paste("{sample_data(cheese_its2)$SampleID}","{sample_data(cheese_its2)$Eco}","{sample_data(cheese_its2)$Marker}",sep="_"))
taxa_names(cheese_its2) <- glue::glue(paste("{taxa_names(cheese_its2)}","CHEESE","ITS2",sep="_"))
cheese_rpb2 <- readRDS("REAL_CHEESE/RPB2_final.rds")
cheese_rpb2 <- transform_sample_counts(cheese_rpb2, function(x) {x/sum(x)})
sample_names(cheese_rpb2) <- glue::glue(paste("{sample_data(cheese_rpb2)$SampleID}","{sample_data(cheese_rpb2)$Eco}","{sample_data(cheese_rpb2)$Marker}",sep="_"))
taxa_names(cheese_rpb2) <- glue::glue(paste("{taxa_names(cheese_rpb2)}","CHEESE","RPB2",sep="_"))
cheese_d1d2 <- readRDS("REAL_CHEESE/D1D2_final.rds")
cheese_d1d2 <- transform_sample_counts(cheese_d1d2, function(x) {x/sum(x)})
sample_names(cheese_d1d2) <- glue::glue(paste("{sample_data(cheese_d1d2)$SampleID}","{sample_data(cheese_d1d2)$Eco}","{sample_data(cheese_d1d2)$Marker}",sep="_"))
taxa_names(cheese_d1d2) <- glue::glue(paste("{taxa_names(cheese_d1d2)}","CHEESE","D1D2",sep="_"))
wine_its1 <- readRDS("REAL_WINE/ITS1_final.rds")
wine_its1 <- transform_sample_counts(wine_its1, function(x) {x/sum(x)})
sample_names(wine_its1) <- glue::glue(paste("{sample_data(wine_its1)$SampleID}","{sample_data(wine_its1)$Eco}","{sample_data(wine_its1)$Marker}",sep="_"))
taxa_names(wine_its1) <- glue::glue(paste("{taxa_names(wine_its1)}","WINE","ITS1",sep="_"))
wine_its2 <- readRDS("REAL_WINE/ITS2_final.rds")
wine_its2 <- transform_sample_counts(wine_its2, function(x) {x/sum(x)})
sample_names(wine_its2) <- glue::glue(paste("{sample_data(wine_its2)$SampleID}","{sample_data(wine_its2)$Eco}","{sample_data(wine_its2)$Marker}",sep="_"))
taxa_names(wine_its2) <- glue::glue(paste("{taxa_names(wine_its2)}","WINE","ITS2",sep="_"))
wine_rpb2 <- readRDS("REAL_WINE/RPB2_final.rds")
wine_rpb2 <- transform_sample_counts(wine_rpb2, function(x) {x/sum(x)})
sample_names(wine_rpb2) <- glue::glue(paste("{sample_data(wine_rpb2)$SampleID}","{sample_data(wine_rpb2)$Eco}","{sample_data(wine_rpb2)$Marker}",sep="_"))
taxa_names(wine_rpb2) <- glue::glue(paste("{taxa_names(wine_rpb2)}","WINE","RPB2",sep="_"))
wine_d1d2 <- readRDS("REAL_WINE/D1D2_final.rds")
wine_d1d2 <- transform_sample_counts(wine_d1d2, function(x) {x/sum(x)})
sample_names(wine_d1d2) <- glue::glue(paste("{sample_data(wine_d1d2)$SampleID}","{sample_data(wine_d1d2)$Eco}","{sample_data(wine_d1d2)$Marker}",sep="_"))
taxa_names(wine_d1d2) <- glue::glue(paste("{taxa_names(wine_d1d2)}","WINE","D1D2",sep="_"))
bread_its1 <- readRDS("REAL_BREAD/ITS1_final.rds")
bread_its1 <- transform_sample_counts(bread_its1, function(x) {x/sum(x)})
sample_names(bread_its1) <- glue::glue(paste("{sample_data(bread_its1)$SampleID}","{sample_data(bread_its1)$Eco}","{sample_data(bread_its1)$Marker}",sep="_"))
taxa_names(bread_its1) <- glue::glue(paste("{taxa_names(bread_its1)}","BREAD","ITS1",sep="_"))
bread_its2 <- readRDS("REAL_BREAD/ITS2_final.rds")
bread_its2 <- transform_sample_counts(bread_its2, function(x) {x/sum(x)})
sample_names(bread_its2) <- glue::glue(paste("{sample_data(bread_its2)$SampleID}","{sample_data(bread_its2)$Eco}","{sample_data(bread_its2)$Marker}",sep="_"))
taxa_names(bread_its2) <- glue::glue(paste("{taxa_names(bread_its2)}","BREAD","ITS2",sep="_"))
bread_d1d2 <- readRDS("REAL_BREAD/D1D2_final.rds")
bread_d1d2 <- transform_sample_counts(bread_d1d2, function(x) {x/sum(x)})
sample_names(bread_d1d2) <- glue::glue(paste("{sample_data(bread_d1d2)$SampleID}","{sample_data(bread_d1d2)$Eco}","{sample_data(bread_d1d2)$Marker}",sep="_"))
taxa_names(bread_d1d2) <- glue::glue(paste("{taxa_names(bread_d1d2)}","BREAD","D1D2",sep="_"))
all <- merge_phyloseq(meat_its1, cheese_its1, wine_its1, bread_its1, meat_its2, cheese_its2, wine_its2, bread_its2, meat_d1d2, cheese_d1d2, wine_d1d2, bread_d1d2, meat_rpb2, cheese_rpb2, wine_rpb2)
saveRDS(all, "data/all_samples_relative.rds")
tib <- psmelt(all) %>% as_tibble()
tib <- tib %>% mutate(Taxo = paste(Kingdom,Phylum,Class,Order,Family,Genus,Species,sep=";")) %>% mutate(ASV = stringr::str_split(OTU, "_") %>% map_chr(., 1)) %>% distinct(ASV, Taxo, .keep_all = T) %>% select(ASV, Taxo, Marker, Sample, Eco) %>% mutate(Marker=replace(Marker, Marker=="D1D2", "D1/D2"))
datatable(tib, extensions='Buttons', options= list(dom='Bfrtip',buttons = c('excel','csv')))
#write.table(tib %>% select(ASV, Taxo, Marker, Sample, Eco) ,"data/real_samples_ASVs.tsv",sep="\t",row.names=FALSE,col.names=TRUE)