Skip to content

Commit

Permalink
Release v0.2.2
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
FabbriniMarco committed May 30, 2024
1 parent f5a3f81 commit 093af20
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 13 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>, Gabriele Conti
Maintainer: Marco Fabbrini <[email protected]>
Description: An ensemble of functions for easier and quicker preliminary microbiome analyses
Expand Down
23 changes: 16 additions & 7 deletions R/microbAIDeR_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ microbAIDeR_install_dependancies <- function(){
if(!require(ggrepel)){
install.packages("ggrepel")
}
if(!require(scales)){
install.packages("scales")
}
}


Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand All @@ -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=", ")
))
Expand Down Expand Up @@ -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="") )
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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=", ")
))
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion man/compute_beta_diversity.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 1 addition & 4 deletions man/compute_volcano_plots.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
42 changes: 42 additions & 0 deletions man/mkdir.Rd
Original file line number Diff line number Diff line change
@@ -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 - [email protected]
}
\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.

0 comments on commit 093af20

Please sign in to comment.