Commit c87b5f22 authored by magali's avatar magali
Browse files

fichiers corrigés

parent 92c682d4
Pipeline #44663 passed with stage
in 3 minutes and 50 seconds
...@@ -10,8 +10,6 @@ date: "2021-06-23 (Last updated: `r Sys.Date()`)" ...@@ -10,8 +10,6 @@ date: "2021-06-23 (Last updated: `r Sys.Date()`)"
bibliography: resources/biblio.bib # don't change bibliography: resources/biblio.bib # don't change
csl: resources/biomed-central.csl # don't change csl: resources/biomed-central.csl # don't change
output: output:
pdf_document:
toc: yes
html_document: html_document:
lib_dir: site_libs lib_dir: site_libs
self_contained: false self_contained: false
...@@ -22,6 +20,8 @@ output: ...@@ -22,6 +20,8 @@ output:
toc_float: true toc_float: true
df_print: paged df_print: paged
css: ['css/styles.css', 'https://use.fontawesome.com/releases/v5.0.9/css/all.css'] css: ['css/styles.css', 'https://use.fontawesome.com/releases/v5.0.9/css/all.css']
pdf_document:
toc: yes
word_document: word_document:
toc: yes toc: yes
always_allow_html: yes always_allow_html: yes
...@@ -675,8 +675,18 @@ Principe courbes de rarefaction : Compter le nombre d'OTU pour un ensemble de so ...@@ -675,8 +675,18 @@ Principe courbes de rarefaction : Compter le nombre d'OTU pour un ensemble de so
```{r ggrare, message=FALSE, eval = TRUE} ```{r ggrare, message=FALSE, eval = TRUE}
p <- ggrare(frogs.data, step = 100, color = "Group", plot = FALSE)
if(file.exists("frogs.data.courbes.rare_F.rds")){
p <- readRDS("frogs.data.courbes.rare_F.rds")
}else{
p <- ggrare(frogs.data, step = 100, color = "Group", plot = FALSE)
saveRDS(p, file = "frogs.data.courbes.rare_F.rds")
}
rare.level <- min(sample_sums(frogs.data)) rare.level <- min(sample_sums(frogs.data))
p <- p + facet_wrap(~Group) + geom_vline(xintercept = rare.level, color = "Gray60")+ p <- p + facet_wrap(~Group) + geom_vline(xintercept = rare.level, color = "Gray60")+
xlab("Sample Size (nb de séquences)") + ylab("Species Richness (nb d'OTU)") xlab("Sample Size (nb de séquences)") + ylab("Species Richness (nb d'OTU)")
plot(p) plot(p)
...@@ -687,7 +697,7 @@ plot(p) ...@@ -687,7 +697,7 @@ plot(p)
```{r 30-plot-richness, eval = TRUE} ```{r 30-plot-richness, eval = TRUE}
p <- plot_richness(frogs.data.rare, color = "Group",measures = c("Observed", "Chao1", "Shannon", "InvSimpson", "Fisher"),x = "Group", title = "Alpha diversity Comparaison microbiote") +theme_bw() + geom_boxplot(aes(fill = Group)) + geom_point() + theme(axis.text.x = element_blank()) p <- plot_richness(frogs.data, color = "Group",measures = c("Observed", "Chao1", "Shannon", "InvSimpson", "Fisher"),x = "Group", title = "Alpha diversity Comparaison microbiote") +theme_bw() + geom_boxplot(aes(fill = Group)) + geom_point() + theme(axis.text.x = element_blank())
plot(p) plot(p)
...@@ -696,9 +706,9 @@ plot(p) ...@@ -696,9 +706,9 @@ plot(p)
#### Richness Table #### Richness Table
```{r 12-create-richness-table, message = FALSE, eval = TRUE} ```{r 12-create-richness-table, message = FALSE, eval = TRUE}
richness.table <- estimate_richness(frogs.data.rare, measures = c("Observed", "Chao1", "Shannon", "Simpson", "InvSimpson", "Fisher")) richness.table <- estimate_richness(frogs.data, measures = c("Observed", "Chao1", "Shannon", "Simpson", "InvSimpson", "Fisher"))
richness.table <- cbind(richness.table, sample_data(frogs.data.rare)) richness.table <- cbind(richness.table, sample_data(frogs.data))
richness.table$Depth <- sample_sums(frogs.data.rare) richness.table$Depth <- sample_sums(frogs.data)
richness.table %>% DT::datatable(extensions = 'Buttons', richness.table %>% DT::datatable(extensions = 'Buttons',
options = list(dom = 'Bfrtip', options = list(dom = 'Bfrtip',
pageLength = 20, pageLength = 20,
...@@ -716,8 +726,8 @@ richness.table %>% DT::datatable(extensions = 'Buttons', ...@@ -716,8 +726,8 @@ richness.table %>% DT::datatable(extensions = 'Buttons',
Analyse de la variance, compare les moyennes d'échantillons. Analyse de la variance, compare les moyennes d'échantillons.
```{r 33-anova, message = FALSE, eval=TRUE} ```{r 33-anova, message = FALSE, eval=TRUE}
div_data <- cbind(estimate_richness(frogs.data.rare, measures = "Observed"), div_data <- cbind(estimate_richness(frogs.data, measures = "Observed"),
sample_data(frogs.data.rare)) sample_data(frogs.data))
model <- aov(Observed ~ 0 + Group, data = div_data) model <- aov(Observed ~ 0 + Group, data = div_data)
anova(model) anova(model)
...@@ -769,8 +779,8 @@ comparison_data ...@@ -769,8 +779,8 @@ comparison_data
```{r 39-create-richness-table, eval=TRUE} ```{r 39-create-richness-table, eval=TRUE}
div_data <- cbind(estimate_richness(frogs.data.rare, measures = "Chao1"), div_data <- cbind(estimate_richness(frogs.data, measures = "Chao1"),
sample_data(frogs.data.rare)) sample_data(frogs.data))
model <- aov(Chao1 ~ 0 + Group, data = div_data) model <- aov(Chao1 ~ 0 + Group, data = div_data)
anova(model) anova(model)
...@@ -803,8 +813,8 @@ TukeyHSD(model) ...@@ -803,8 +813,8 @@ TukeyHSD(model)
```{r 43-create-richness-table, eval=TRUE} ```{r 43-create-richness-table, eval=TRUE}
div_data <- cbind(estimate_richness(frogs.data.rare, measures = "Shannon"), div_data <- cbind(estimate_richness(frogs.data, measures = "Shannon"),
sample_data(frogs.data.rare)) sample_data(frogs.data))
model <- aov(Shannon ~ 0 + Group, data = div_data) model <- aov(Shannon ~ 0 + Group, data = div_data)
anova(model) anova(model)
...@@ -838,8 +848,8 @@ TukeyHSD(model) ...@@ -838,8 +848,8 @@ TukeyHSD(model)
```{r 49-create-richness-table, eval=TRUE} ```{r 49-create-richness-table, eval=TRUE}
div_data <- cbind(estimate_richness(frogs.data.rare, measures = "InvSimpson"), div_data <- cbind(estimate_richness(frogs.data, measures = "InvSimpson"),
sample_data(frogs.data.rare)) sample_data(frogs.data))
model <- aov(InvSimpson ~ 0 + Group, data = div_data) model <- aov(InvSimpson ~ 0 + Group, data = div_data)
anova(model) anova(model)
...@@ -872,8 +882,8 @@ TukeyHSD(model) ...@@ -872,8 +882,8 @@ TukeyHSD(model)
```{r 55-create-richness-table, eval=TRUE} ```{r 55-create-richness-table, eval=TRUE}
div_data <- cbind(estimate_richness(frogs.data.rare, measures = "Fisher"), div_data <- cbind(estimate_richness(frogs.data, measures = "Fisher"),
sample_data(frogs.data.rare)) sample_data(frogs.data))
model <- aov(Fisher ~ 0 + Group, data = div_data) model <- aov(Fisher ~ 0 + Group, data = div_data)
anova(model) anova(model)
...@@ -1328,11 +1338,11 @@ plot_da_composite <- function(da.otus, physeq, labvec = NULL, lfc.threshold = 2, ...@@ -1328,11 +1338,11 @@ plot_da_composite <- function(da.otus, physeq, labvec = NULL, lfc.threshold = 2,
) )
## Plots ## Plots
p.lfc <- ggplot(plotdata, aes(y = OTU, x = log2FoldChange, color = Family)) + p.lfc <- ggplot(plotdata, aes(y = OTU, x = log2FoldChange, color = Family)) +
geom_point(size=3) + geom_point() +
geom_vline(xintercept = 0, linetype = 2) + geom_vline(xintercept = 0, linetype = 2) +
facet_grid(Family~., space = "free_y", scale = "free_y", switch = "both") + facet_grid(Family~., space = "free_y", scale = "free_y", switch = "both") +
geom_text(data = annotate.data, aes(label = label), hjust = 0, vjust = 1) + #vjust=1 c'est le point au dessus du nom family geom_text(data = annotate.data, aes(label = label), hjust = 0, vjust = 1) + #vjust=1 c'est le point au dessus du nom family
geom_text(aes(label = OTU.label, hjust="inward", vjust=1),size=5) #size=3 taille nom family de couleur geom_text(aes(label = OTU.label, hjust="inward", vjust=1),size=3.5) #size=3 taille nom family de couleur
#vjust=0.5 Noms family à coté point #vjust=0.5 Noms family à coté point
p.evidence <- ggplot(plotdata, aes(x = OTU, y = -log10(padj), fill = Family)) + geom_bar(stat = "identity") + p.evidence <- ggplot(plotdata, aes(x = OTU, y = -log10(padj), fill = Family)) + geom_bar(stat = "identity") +
...@@ -1342,10 +1352,10 @@ plot_da_composite <- function(da.otus, physeq, labvec = NULL, lfc.threshold = 2, ...@@ -1342,10 +1352,10 @@ plot_da_composite <- function(da.otus, physeq, labvec = NULL, lfc.threshold = 2,
if (is.null(labvec)) { if (is.null(labvec)) {
labvec <- setNames(nm = unique(plotdata$Group)) labvec <- setNames(nm = unique(plotdata$Group))
} }
hm.data <- plotdata %>% group_by_at(vars(-Sample, -Name, -Abundance)) %>% hm.data <- plotdata %>% group_by(OTU, Group, Family) %>%
summarize(Abundance = mean(Abundance)) %>% summarize(Abundance = mean(Abundance)) %>%
ungroup() %>% ungroup() %>%
mutate(OTU = factor(OTU, levels = otu.order), mutate(OTU = factor(OTU, levels = otu.order),
Family = factor(Family, levels =fam.order), Family = factor(Family, levels =fam.order),
Group = factor(Group, levels = names(labvec), labels = labvec)) Group = factor(Group, levels = names(labvec), labels = labvec))
...@@ -1360,12 +1370,12 @@ plot_da_composite <- function(da.otus, physeq, labvec = NULL, lfc.threshold = 2, ...@@ -1360,12 +1370,12 @@ plot_da_composite <- function(da.otus, physeq, labvec = NULL, lfc.threshold = 2,
p1 <- arrangeGrob(p.lfc.2 + custom.theme + p1 <- arrangeGrob(p.lfc.2 + custom.theme +
theme(legend.position = "none", theme(legend.position = "none",
strip.text.y = element_text( angle = 0,hjust = 0, size = 14), #Noms Family sur la gauche strip.text.y = element_text( angle = 0,hjust = 0, size = 10), #Noms Family sur la gauche
strip.background = element_blank()), strip.background = element_blank()),
p.evidence + custom.theme + p.evidence + custom.theme +
scale_x_discrete(position = "top") + scale_x_discrete(position = "top") +
theme(legend.position = "none", theme(legend.position = "none",
axis.text.y = element_text(size = 10)), axis.text.y = element_text(size = 8)),
p.hm + custom.theme, p.hm + custom.theme,
widths = c(0.47, 0.35, 0.18), #taille largeur des 3 cadres doit être =1 widths = c(0.47, 0.35, 0.18), #taille largeur des 3 cadres doit être =1
nrow = 1, nrow = 1,
...@@ -1393,26 +1403,25 @@ format_names <- function(physeq, min.rank = 0) { ...@@ -1393,26 +1403,25 @@ format_names <- function(physeq, min.rank = 0) {
} }
## Function pour le graphique composite ## Function pour le graphique composite
plot_da_compositebis <- function(da.otus, physeq, labvec = NULL, lfc.threshold = 2, min.abundance = 30) { plot_da_compositebis <- function(da.otus, physeq, labvec = NULL, lfc.threshold = 2, min.abundance = 30) {
## Custome theme #on peut mettre 3 ou 2 ## Custome theme #on peut mettre 3 ou 2
custom.theme <- theme_bw() + custom.theme <- theme_bw() +
theme(panel.spacing = unit(0.2, "lines"), theme(panel.spacing = unit(0.2, "lines"),
axis.title.y = element_blank(), axis.title.y = element_blank(),
axis.ticks.y = element_blank(), axis.ticks.y = element_blank(),
axis.text.y = element_blank(), axis.text.y = element_blank(),
strip.text.y = element_blank(), strip.text.y = element_blank(),
axis.text.x = element_text(size = 10)) #taille noms groupes heatmap axis.text.x = element_text(size = 10)) #taille noms groupes heatmap
## Plotdata ## Plotdata
plotdata <- build_plotdata_daotus(da.otus, physeq, min.abundance = min.abundance) %>% plotdata <- build_plotdata_daotus(da.otus, physeq, min.abundance = min.abundance) %>%
inner_join(tax_table(data) %>% as("matrix") %>% as.data.frame() %>% inner_join(tax_table(data) %>% as("matrix") %>% as.data.frame() %>%
mutate(OTU = taxa_names(data), mutate(OTU = taxa_names(data),
OTU.label = format_names(data)), OTU.label = format_names(data))) %>%
by = "OTU") %>% filter(abs(log2FoldChange) >= 2) %>% #On peut changer la valeur du log2FoldChange =3 ou 2
filter(abs(log2FoldChange) >= 2) %>% #On peut changer la valeur du log2FoldChange =3 ou 2
arrange(log2FoldChange) arrange(log2FoldChange)
##### Correct OTU and Family Order Ajout Mahendra ##### Correct OTU and Family Order Ajout Mahendra
otu.order <- da.otus %>% pull(OTU) otu.order <- da.otus %>% pull(OTU)
...@@ -1422,17 +1431,17 @@ plotdata <- plotdata %>% ...@@ -1422,17 +1431,17 @@ plotdata <- plotdata %>%
inner_join(tax_table(data) %>% as("matrix") %>% as.data.frame() %>% inner_join(tax_table(data) %>% as("matrix") %>% as.data.frame() %>%
mutate(OTU = taxa_names(data), mutate(OTU = taxa_names(data),
OTU.label = format_names(data), OTU.label = format_names(data),
OTU.label.2 = format_names(data, min.rank = 5)), OTU.label.2 = format_names(data, min.rank = 5))) %>%
by = "OTU") %>%
## Tri des OTUs par log fold change décroissant et des familles par ordre alphabétique au sein des phylums ## Tri des OTUs par log fold change décroissant et des familles par ordre alphabétique au sein des phylums
mutate(OTU = factor(OTU, levels = otu.order), mutate(OTU = factor(OTU, levels = otu.order),
Family = factor(Family, levels = fam.order)) Family = factor(Family, levels = fam.order))
#library(paletteer) #library(paletteer)
p.lfc <- ggplot(plotdata, aes(y = OTU, x = log2FoldChange, color = Family)) + p.lfc <- ggplot(plotdata %>% distinct(OTU, log2FoldChange, Family, OTU.label.2),
geom_point(size=4) + geom_vline(xintercept = 0, linetype = 2) + #size=1 taille point et noms family aes(y = OTU, x = log2FoldChange, color = Family)) +
geom_point(size=3) + geom_vline(xintercept = 0, linetype = 2) + #size=1 taille point et noms family
geom_text(aes(x = log2FoldChange - .25*sign(log2FoldChange), geom_text(aes(x = log2FoldChange - .25*sign(log2FoldChange),
label = OTU.label.2, vjust=0.5, #Taille et position noms family à côté des points label = OTU.label.2, vjust=0.5, #Taille et position noms family à côté des points
hjust = if_else(log2FoldChange > 0, 1, 0)))+ hjust = if_else(log2FoldChange > 0, 1, 0)))+
...@@ -1443,37 +1452,38 @@ p.lfc <- ggplot(plotdata, aes(y = OTU, x = log2FoldChange, color = Family)) + ...@@ -1443,37 +1452,38 @@ p.lfc <- ggplot(plotdata, aes(y = OTU, x = log2FoldChange, color = Family)) +
# + scale_x_continuous(limits = c(-15, 35)) ######## pour changer echelle axe des x (log2foldchange) # + scale_x_continuous(limits = c(-15, 35)) ######## pour changer echelle axe des x (log2foldchange)
#Heatmap #Heatmap
hm.data <- plotdata %>% group_by_at(vars(-Sample, -Name, -Abundance)) %>% hm.data <- plotdata %>% group_by(OTU, Group, Family) %>%
summarize(Abundance = mean(Abundance)) %>% summarize(Abundance = mean(Abundance)) %>%
ungroup() %>% ungroup() %>%
mutate(OTU = factor(OTU, levels = otu.order), mutate(OTU = factor(OTU, levels = otu.order),
Family = factor(Family, levels =fam.order), Family = factor(Family, levels =fam.order),
Group = factor(Group, levels = names(labvec), labels = labvec)) Group = factor(Group, levels = names(labvec), labels = labvec))
p.hm <- ggplot(hm.data, aes(y = OTU, x = Group, fill = Abundance)) + geom_tile() + p.hm <- ggplot(hm.data, aes(y = OTU, x = Group, fill = Abundance)) + geom_tile() +
scale_fill_gradient(trans = log_trans(base = 2), na.value = "white", scale_fill_gradient(trans = log_trans(base = 2), na.value = "white",
low = "white", high = "black") low = "white", high = "black")
# #
p2 <- arrangeGrob(p.lfc + custom.theme + guides(colour = guide_legend(override.aes = list(size=5)))+ #taille points de la legende p2 <- arrangeGrob(p.lfc + custom.theme + guides(colour = guide_legend(override.aes = list(size=5)))+ #taille points de la legende
theme(legend.position = c(0.025, 0.975), ########### OU theme(legend.position = c(0.575, 0.425) ################## theme(legend.position = c(0.025, 0.975), ########### OU theme(legend.position = c(0.575, 0.425) ##################
legend.justification = c(0, 1), legend.justification = c(0, 1),
legend.text = element_text(size = 16), #taille noms legende legend.text = element_text(size = 16), #taille noms legende
legend.background = element_rect(fill = "transparent"), legend.background = element_rect(fill = "transparent"),
axis.text.y = element_text(size = 9, hjust = 0.5), #Affichage noms des clusters axis.text.y = element_text(size = 9, hjust = 0.5), #Affichage noms des clusters
axis.text.x = element_text(size = 10)), #taille noms legende axe des x axis.text.x = element_text(size = 10)), #taille noms legende axe des x
p.hm + custom.theme, #p.hm défini la heatmap p.hm + custom.theme, #p.hm défini la heatmap
widths = c(0.78, 0.22), #largeur heatmap widths = c(0.78, 0.22), #largeur heatmap
nrow = 1, nrow = 1,
ncol = 2) ncol = 2)
grid::grid.newpage() grid::grid.newpage()
grid::grid.draw(p2) grid::grid.draw(p2)
invisible(p2) invisible(p2)
} }
############################################################## ##############################################################
############## Function pour le graphique composite TER ##### ############## Function pour le graphique composite TER #####
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment