From 093af206699499f4ff9be5d0286a1ec9a3fdac04 Mon Sep 17 00:00:00 2001 From: Marco Date: Thu, 30 May 2024 16:15:49 +0200 Subject: [PATCH] Release v0.2.2 Fixed minor bugs, added details to adonis exported table, added mkdir function and the possibility of adding transparency to PCoA points through the alpha.points parameter. --- DESCRIPTION | 2 +- R/microbAIDeR_functions.R | 23 +++++++++++++------ man/compute_beta_diversity.Rd | 5 ++++- man/compute_volcano_plots.Rd | 5 +---- man/mkdir.Rd | 42 +++++++++++++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 man/mkdir.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 300a0ff..65d57ae 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: microbAIDeR Type: Package Title: An ensemble of functions for easier and quicker preliminary microbiome analysis -Version: 0.2.1 +Version: 0.2.2 Author: Marco Fabbrini , Gabriele Conti Maintainer: Marco Fabbrini Description: An ensemble of functions for easier and quicker preliminary microbiome analyses diff --git a/R/microbAIDeR_functions.R b/R/microbAIDeR_functions.R index 7e2edb4..b166f93 100644 --- a/R/microbAIDeR_functions.R +++ b/R/microbAIDeR_functions.R @@ -53,6 +53,9 @@ microbAIDeR_install_dependancies <- function(){ if(!require(ggrepel)){ install.packages("ggrepel") } + if(!require(scales)){ + install.packages("scales") + } } @@ -288,6 +291,9 @@ align_legend <- function(p, hjust = 0.5) } +mkdir <- function (path){ + if(!dir.exists(path)){dir.create(path)} +} compute_wilcoxon_and_plot <- function(data, group, taxlevel, save.path = getwd(), color.grouping, comparison.list = NULL, p.adjust.method = "fdr", trends = TRUE, plot.not.sig = FALSE, @@ -566,7 +572,7 @@ compute_wilcoxon_and_plot <- function(data, group, taxlevel, save.path = getwd() compute_beta_diversity <- function(beta_metrics = c("braycurtis", "jaccard", "unweighted_unifrac", "weighted_unifrac"), save.path = getwd(), adonis_n_perm = 9999, beta.folder.path = paste(getwd(), "RESULTS/beta_diversity", sep="/"), manual.beta.path = NULL, sample.list, mds = c(1,2), group, color.grouping , - spiders = FALSE, spiders.lwd = 1.5, ellipses = FALSE, ellipse.focus = FALSE,ellipse.fill = FALSE, ellipse.conf = 0.95, ellipse.alpha = 0.75 , ellipse.lwd = 2.5, manual.bordercol = NULL, + alpha.points = 1, spiders = FALSE, spiders.lwd = 1.5, ellipses = FALSE, ellipse.focus = FALSE,ellipse.fill = FALSE, ellipse.conf = 0.95, ellipse.alpha = 0.75 , ellipse.lwd = 2.5, manual.bordercol = NULL, svg.width = 7, svg.height = 5, cex.points = 1.2, adonis.p.adjust = "fdr", wilcoxon.p.adjust = "fdr", nrow.graph = 2, ncol.graph = 2, width.graph = 6, height.graph = 4, ggplot.margins = c(0.15, 0.15, 0.15, 0.6), @@ -591,7 +597,7 @@ compute_beta_diversity <- function(beta_metrics = c("braycurtis", "jaccard", "un call.print = as.data.frame(rbind( paste(beta_metrics, collapse=", "), color.grouping = paste(color.grouping, collapse = ", "), save.path, adonis_n_perm , beta.folder.path , mds = paste(mds, collapse=", ") , - spiders, ellipses , ellipse.focus , ellipse.conf , ellipse.alpha , + alpha.points, spiders, ellipses , ellipse.focus , ellipse.conf , ellipse.alpha , svg.width , svg.height , cex.points , adonis.p.adjust, wilcoxon.p.adjust, additional.params=paste(additional.params, collapse=", ") )) @@ -630,6 +636,9 @@ compute_beta_diversity <- function(beta_metrics = c("braycurtis", "jaccard", "un color_beta[is.na(color_beta)] = "black" } colnames(coord_beta) = c("AX1", "AX2") + if( !is.numeric(alpha.points) ){alpha.points = 1} + if( alpha.points > 1 ){ alpha.points = 1} + if(alpha.points < 1){color_beta = scales::alpha(color_beta, alpha.points)} # Base plot svg( paste(save.path,"/", metrics, ".svg", sep=""), width=svg.width, height = svg.height) plot(metric_beta, type="n", main=metrics, choices=mds, xlab=paste("MDS", mds[1]," - [" ,sig1, "%]", sep="") , ylab=paste("MDS", mds[2]," - [" ,sig2, "%]", sep="") ) @@ -692,7 +701,7 @@ compute_beta_diversity <- function(beta_metrics = c("braycurtis", "jaccard", "un adone[,adonis.p.adjust] <- sapply(adone$p.adjusted, sigFunction, trends = trends) addSheet( path=paste(save.path, "/beta_adonis.xlsx", sep=""), sheet.name = metrics, - addition = adone[,c(1,6,9, 7,10)], col.save=TRUE, row.save=FALSE) + addition = adone, col.save=TRUE, row.save=FALSE) # Calculate and plot the intra-group variances print(paste("Computing intra-group variance")) @@ -1024,7 +1033,7 @@ scaling.manual <- function(x, range.min, range.max) { compute_volcano_plots <- function(data, group, taxlevel, save.path = getwd(), p.adjust.method = "fdr", trends=TRUE, sigcolors=c("ivory3", "orange3", "darkred"), - paired = FALSE, nrow.graph = 1, ncol.graph = 2, width.graph = 20, height.graph = 8, ggplot.margins = c(1,1,1,.5), + nrow.graph = 1, ncol.graph = 2, width.graph = 20, height.graph = 8, ggplot.margins = c(1,1,1,.5), label.text.size = 2.8, label.padding=4, arrows=TRUE, arrow.length=1.5,arrow.lwd=1.8,arrow.origin.offset=0.5, arrow.text.cex=.7,arrow.text.color="grey22", @@ -1057,7 +1066,7 @@ compute_volcano_plots <- function(data, group, taxlevel, save.path = getwd(), p. wt <- rep(NA, nrow(data)) for( i in 1:nrow(data)) { - wt[i] = suppressWarnings(wilcox.test( as.numeric(data[i,]) ~ group, paired = paired )$p.value) + wt[i] = suppressWarnings(wilcox.test( as.numeric(data[i,]) ~ group )$p.value) } wt[is.nan(wt)] = 1 wt[is.na(wt)] = 1 @@ -1084,7 +1093,7 @@ compute_volcano_plots <- function(data, group, taxlevel, save.path = getwd(), p. call.print = as.data.frame(rbind(p.adjust.method, taxlevel, save.path, sigcolors = paste(sigcolors, collapse = ", "), nrow.graph , ncol.graph , width.graph , height.graph , ggplot2.margins = paste(ggplot.margins, collapse = ", ") , - paired, label.text.size, label.padding,arrow.length,arrow.lwd,arrow.origin.offset, + label.text.size, label.padding,arrow.length,arrow.lwd,arrow.origin.offset, arrow.text.cex,arrow.text.color, text.x.size , text.y.size , text.y.title.size, additional.params=paste(additional.params, collapse=", ") )) @@ -1188,7 +1197,7 @@ compute_volcano_plots <- function(data, group, taxlevel, save.path = getwd(), p. labs(x="Log-Fold change", size="Rel. Ab.", y=paste("-log2(", p.adjust.method, ")", sep=""))+ scale_y_continuous(limits = c(0, max(-log2(tidata$corr))+.5 ) )+ scale_x_continuous(limits = c( min(tidata$LFC)-.5, max(tidata$LFC)+.5 ))+ - geom_text_repel(show_guide=F, size = label.text.size, point.padding = label.padding, aes(fontface = "italic"))+ + geom_text_repel(show.legend=F, size = label.text.size, point.padding = label.padding, aes(fontface = "italic"))+ theme( legend.key = element_rect(fill = NA), plot.margin = unit(ggplot.margins, "cm"), axis.text.x = element_text(size = text.x.size), axis.text.y = element_text(size = text.y.size), axis.title.y = element_text(size = text.y.title.size) diff --git a/man/compute_beta_diversity.Rd b/man/compute_beta_diversity.Rd index 213a843..95749dd 100644 --- a/man/compute_beta_diversity.Rd +++ b/man/compute_beta_diversity.Rd @@ -14,7 +14,7 @@ compute_beta_diversity(beta.folder.path = paste(getwd(), "RESULTS/beta_diversity beta_metrics = c("braycurtis", "jaccard", "unweighted_unifrac", "weighted_unifrac"), \cr mds = c(1, 2), adonis_n_perm = 9999, \cr adonis.p.adjust = "fdr", wilcoxon.p.adjust = "fdr" \cr - plot.not.sig = FALSE, \cr + plot.not.sig = FALSE, alpha.points=1 \cr spiders = FALSE, spiders.lwd = 1.5, ellipses = FALSE, ellipse.focus = FALSE, ellipse.fill = FALSE, \cr ellipse.lwd = 2.5, ellipse.conf = 0.95, ellipse.alpha = 0.75, manual.bordercol = NULL,\cr svg.width = 7, svg.height = 5, \cr @@ -68,6 +68,9 @@ Please note that in case of a two-group beta diversity analysis, the reported co } \item{wilcoxon.p.adjust}{ A \bold{character} value pointing to the P-value correction method for the pairwise Wilcoxon testing for the intra-group variance (Default = "fdr"). Can be any value from p.adjust.methods.\cr +} + \item{alpha.points}{ +A \bold{numeric} value handling points fill transparency in plots (Default = 1 - fully opaque) \cr } \item{spiders}{ A \bold{logical} (Default = FALSE), specifying whether to produce an additional PCoA plot with spiders. diff --git a/man/compute_volcano_plots.Rd b/man/compute_volcano_plots.Rd index a24f307..0ed7052 100644 --- a/man/compute_volcano_plots.Rd +++ b/man/compute_volcano_plots.Rd @@ -10,7 +10,7 @@ This function handles non-tidy data.frames (e.g. OTU tables) and produces a scat \usage{ compute_volcano_plots(data, group, taxlevel, save.path = getwd(), p.adjust.method = "fdr", \cr trends=TRUE, sigcolors=c("ivory3", "orange3", "darkred"),\cr - paired = FALSE, nrow.graph = 1, ncol.graph = 2, width.graph = 20, height.graph = 8, \cr + nrow.graph = 1, ncol.graph = 2, width.graph = 20, height.graph = 8, \cr ggplot.margins = c(1, 1, 1, .5), label.text.size = 2.8, label.padding=4,\cr arrows=TRUE, arrow.length=1.5,arrow.lwd=1.8,arrow.origin.offset=0.5,\cr arrow.text.cex=.7,arrow.text.color="grey22",\cr @@ -41,9 +41,6 @@ A \bold{logical} (Default = TRUE), specifying whether to consider also trends (P } \item{sigcolors}{ A three element \emph{character} vector containing the colors for the non significant, trends and significant points (Default = c("ivory3", "orange3", "darkred")). If trends is set to FALSE, only the first and third colors will be used, however the vector must always contain three colors. -} - \item{paired}{ -A \bold{logical} (Default = FALSE), specifying whether to perform paired Wilcoxon tests (signed-rank tests) in case of paired observations (e.g. matched pairs or before/after samples, or repeated measures). } \item{nrow.graph}{ Number of rows of the output .pdf file (Default = 1). Used to group the volcano plots in the same sheet. diff --git a/man/mkdir.Rd b/man/mkdir.Rd new file mode 100644 index 0000000..742045b --- /dev/null +++ b/man/mkdir.Rd @@ -0,0 +1,42 @@ +\name{mkdir} +\alias{mkdir} +%- Also NEED an '\alias' for EACH other topic documented here. +\title{ +Create a folder if it doesn't already exists +%% ~~function to do ... ~~ +} +\description{ +%% ~~ A concise (1-5 lines) description of what the function does. ~~ +This script takes a PATH as input and checks if the given folder already exists. If not, it creates it. +} +\usage{ +mkdir(path) +} +%- maybe also 'usage' for other objects documented here. +\arguments{ + \item{path}{ +Full or local \bold{PATH} to the folder that we want to create +} +} +\details{ + +} + +\author{ +Marco Fabbrini - m.fabbrini@unibo.it +} + +\examples{ +mkdir("Plots") +mkdir("Plots/Subfolder of Plots") +mkdir("Plots/Subfolder of Plots/Additional subfolder") + } +% Add one or more standard keywords, see file 'KEYWORDS' in the +% R documentation directory (show via RShowDoc("KEYWORDS")): +% \keyword{ ~kwd1 } +% \keyword{ ~kwd2 } +% Use only one keyword per line. +% For non-standard keywords, use \concept instead of \keyword: +% \concept{ ~cpt1 } +% \concept{ ~cpt2 } +% Use only one concept per line.