From b35fc81acc7d2bcad97297648258b61928812472 Mon Sep 17 00:00:00 2001 From: scottdossantos <136380707+scottdossantos@users.noreply.github.com> Date: Fri, 8 Dec 2023 09:54:49 -0500 Subject: [PATCH 1/2] implemented density plots other than for PC1 & PC2 - Edited codaSeq.PCAplot() so that the density plot data depends on the 'PC' argument. Previously it was hard-coded to only draw plots for PC1 and PC2. Whoops. - Edited codaSeq.PCAplot() documentation accordingly (along with some minor typo corrections) - Also added the 'z.warning' argument to cmultRepl() calls in the codaSeq.PCAplot() documentation, and in the CoDaSeq vignette file to prevent any features from being dropped --- CoDaSeq/R/codaSeq.PCAplot.r | 35 ++++++++++++++------------ CoDaSeq/man/codaSeq.PCAplot.rd | 27 +++++++++++--------- CoDaSeq/vignettes/CoDaSeq_vignette.Rnw | 14 +++++------ 3 files changed, 41 insertions(+), 35 deletions(-) diff --git a/CoDaSeq/R/codaSeq.PCAplot.r b/CoDaSeq/R/codaSeq.PCAplot.r index 4b6914c..4311103 100644 --- a/CoDaSeq/R/codaSeq.PCAplot.r +++ b/CoDaSeq/R/codaSeq.PCAplot.r @@ -23,10 +23,10 @@ #' `load.sym` (default: `TRUE`). #' @param plot.ellipses Character vector indicating whether or not to draw #' confidence ellipses around sample *or* loading groups. Must be one of either -#' `"groups"` or `"loadings"`, or `NULL`. +#' `"groups"` or `"loadings"`, or `NULL` (default: `NULL`). #' @param plot.density Logical value indicating whether or not to draw density #' plots for the specified principal components above and beside the main -#' biplot. +#' biplot (default: `NULL`). #' @param grp A list of groups where each element is a vector containing the #' indices of group members (default: `NULL`). #' @param grp.col A vector of the same length as `grp` containing colours for @@ -40,7 +40,7 @@ #' each element of `grp.sym` paired with the corresponding element of #' `grp`). #' * A character vector equal to `"text"` (plots samples as text, with the -#' label set to `rownames(pcx$x)`). +#' labels set to `rownames(pcx$x)`). #' @param grp.cex A numeric value indicating the relative size of the group #' symbols or text to be plotted (default: `1`). #' @param load.grp A list of loading groups where each element is a vector @@ -57,26 +57,29 @@ #' each element of `load.sym` paired with the corresponding element of #' `load.grp`). #' * A character vector equal to `"text"` (plots variable loadings as text, -#' with the label set to `rownames(pcx$rotation)`). +#' with the labels set to `rownames(pcx$rotation)`). #' @param load.cex A numeric value indicating the relative size of the #' loading symbols or text to be plotted (default: `0.5`). #' @param PC A numeric vector of length = 2 indicating which prinicpal #' components should be plotted (default: `c(1,2)`) #' @param plot.legend A character string equal to either `"groups"` or #' `"loadings"`, or NULL, indicating whether to draw a legend for groups, -#' loadings or neither (default: `NULL`). -#' @param leg.position A character string equal to one of the following: -#' `"topleft"`, `"top"`, `"topright"`, `"right"`, `"bottomright"`, `"bottom"`, -#' `"bottomleft"`, `"left"`, or `"center"`. Cannot be called in conjunction -#' with `leg.xy` (default: `NULL`). +#' loadings or neither (default: `NULL`). If you wish to draw legends for +#' both groups and loadings, you can call `legend()` immediately after +#' `codaSeq.PCAplot()`, adjusting the `x` and `y` arguments manually +#' (start at zero and play around with the numbers). +#' @param leg.position A character vector indicating legend position presets, +#' equal to one of the following: `"topleft"`, `"top"`, `"topright"`, +#' `"right"`, `"bottomright"`, `"bottom"`, `"bottomleft"`, `"left"`, or +#' `"center"`. Cannot be called alongside with `leg.xy` (default: `NULL`). #' @param leg.xy A numeric vector of length = 2, specifying the x and y #' coordinates at which to draw the top-right corner of the legend box. Cannot -#' be called in conjunctionn with `leg.position` (default: `NULL`) +#' be called in conjunction with `leg.position` (default: `NULL`). #' @param leg.cex A numeric value indicating the relative size of the legend #' text (default: `0.55`). #' @param leg.columns A numeric calue indicating the number of columns to split #' legend items into (default: `1`) -#' @param title A character string containing the desired title of the biplot +#' @param title A character vector containing the desired title of the biplot #' (default: `""`). #' #' @return Returns a plot showing samples and/or loadings as specified by the @@ -146,7 +149,7 @@ #' #' # Bayesian-multiplicative replacement of count-zeros #' clr.input<-cmultRepl(t(ak_op),label = "0", -#' method = "CZM",output = "p-counts") +#' method = "CZM",, z.warning = 0.99) #' #' # CLR-transformation using codaSeq.clr #' clr.data<-codaSeq.clr(t(clr.input), IQLR = FALSE, @@ -388,8 +391,8 @@ codaSeq.PCAplot <- function(pcx, plot.groups=FALSE, plot.loadings=TRUE, plot.ell if(plot.density=="groups"){ list.group<-list() for(k in 1:length(grp)){ - points.pc1<-pcx$x[,1][grp[[k]]] - points.pc2<-pcx$x[,2][grp[[k]]] + points.pc1<-pcx$x[,PC[1]][grp[[k]]] + points.pc2<-pcx$x[,PC[2]][grp[[k]]] list.group[[names(grp)[k]]]<-as.data.frame(cbind(points.pc1,points.pc2)) } @@ -433,8 +436,8 @@ codaSeq.PCAplot <- function(pcx, plot.groups=FALSE, plot.loadings=TRUE, plot.ell } else if(plot.density=="loadings"){ list.loadings<-list() for (k in 1:length(load.grp)) { - points.pc1<-pcx$rotation[,1][load.grp[[k]]]*scale.factor.1 - points.pc2<-pcx$rotation[,2][load.grp[[k]]]*scale.factor.2 + points.pc1<-pcx$rotation[,PC[1]][load.grp[[k]]]*scale.factor.1 + points.pc2<-pcx$rotation[,PC[2]][load.grp[[k]]]*scale.factor.2 list.loadings[[names(load.grp)[k]]]<-as.data.frame(cbind(points.pc1,points.pc2)) } diff --git a/CoDaSeq/man/codaSeq.PCAplot.rd b/CoDaSeq/man/codaSeq.PCAplot.rd index a3b2a9d..cae1324 100644 --- a/CoDaSeq/man/codaSeq.PCAplot.rd +++ b/CoDaSeq/man/codaSeq.PCAplot.rd @@ -26,11 +26,11 @@ depending on \code{grp.sym} (default: \code{FALSE}).} \item{plot.ellipses}{Character vector indicating whether or not to draw confidence ellipses around sample \emph{or} loading groups. Must be one of either -\code{"groups"} or \code{"loadings"}, or \code{NULL}.} +\code{"groups"} or \code{"loadings"}, or \code{NULL} (default: \code{NULL}).} \item{plot.density}{Logical value indicating whether or not to draw density plots for the specified principal components above and beside the main -biplot.} +biplot (default: \code{NULL}).} \item{grp}{A list of groups where each element is a vector containing the indices of group members (default: \code{NULL}).} @@ -48,7 +48,7 @@ specified values to set the \code{pch} argument on a per-group basis, with each element of \code{grp.sym} paired with the corresponding element of \code{grp}). \item A character vector equal to \code{"text"} (plots samples as text, with the -label set to \code{rownames(pcx$x)}). +labels set to \code{rownames(pcx$x)}). }} \item{grp.cex}{A numeric value indicating the relative size of the group @@ -71,7 +71,7 @@ specified values to set the \code{pch} argument on a per-group basis, with each element of \code{load.sym} paired with the corresponding element of \code{load.grp}). \item A character vector equal to \code{"text"} (plots variable loadings as text, -with the label set to \code{rownames(pcx$rotation)}). +with the labels set to \code{rownames(pcx$rotation)}). }} \item{load.cex}{A numeric value indicating the relative size of the @@ -82,16 +82,19 @@ components should be plotted (default: \code{c(1,2)})} \item{plot.legend}{A character string equal to either \code{"groups"} or \code{"loadings"}, or NULL, indicating whether to draw a legend for groups, -loadings or neither (default: \code{NULL}).} +loadings or neither (default: \code{NULL}). If you wish to draw legends for +both groups and loadings, you can call \code{legend()} immediately after +\code{codaSeq.PCAplot()}, adjusting the \code{x} and \code{y} arguments manually +(start at zero and play around with the numbers).} -\item{leg.position}{A character string equal to one of the following: -\code{"topleft"}, \code{"top"}, \code{"topright"}, \code{"right"}, \code{"bottomright"}, \code{"bottom"}, -\code{"bottomleft"}, \code{"left"}, or \code{"center"}. Cannot be called in conjunction -with \code{leg.xy} (default: \code{NULL}).} +\item{leg.position}{A character vector indicating legend position presets, +equal to one of the following: \code{"topleft"}, \code{"top"}, \code{"topright"}, +\code{"right"}, \code{"bottomright"}, \code{"bottom"}, \code{"bottomleft"}, \code{"left"}, or +\code{"center"}. Cannot be called alongside with \code{leg.xy} (default: \code{NULL}).} \item{leg.xy}{A numeric vector of length = 2, specifying the x and y coordinates at which to draw the top-right corner of the legend box. Cannot -be called in conjunctionn with \code{leg.position} (default: \code{NULL})} +be called in conjunction with \code{leg.position} (default: \code{NULL}).} \item{leg.cex}{A numeric value indicating the relative size of the legend text (default: \code{0.55}).} @@ -99,7 +102,7 @@ text (default: \code{0.55}).} \item{leg.columns}{A numeric calue indicating the number of columns to split legend items into (default: \code{1})} -\item{title}{A character string containing the desired title of the biplot +\item{title}{A character vector containing the desired title of the biplot (default: \code{""}).} } \value{ @@ -152,7 +155,7 @@ symbols<-c(rep(17,13),rep(16,13),11) # Bayesian-multiplicative replacement of count-zeros clr.input<-cmultRepl(t(ak_op),label = "0", - method = "CZM",output = "p-counts") + method = "CZM",, z.warning = 0.99) # CLR-transformation using codaSeq.clr clr.data<-codaSeq.clr(t(clr.input), IQLR = FALSE, diff --git a/CoDaSeq/vignettes/CoDaSeq_vignette.Rnw b/CoDaSeq/vignettes/CoDaSeq_vignette.Rnw index ab95f3f..99f7929 100644 --- a/CoDaSeq/vignettes/CoDaSeq_vignette.Rnw +++ b/CoDaSeq/vignettes/CoDaSeq_vignette.Rnw @@ -74,7 +74,7 @@ We now replace 0 counts in the dataset with imputed values using the Count Zero # from the zCompositions package # the table is transposed t() to make the samples by row # all further analyses have this orientation -f.n0 <- cmultRepl(t(f), label=0, method="CZM") +f.n0 <- cmultRepl(t(f), label=0, method="CZM", z.warning = 0.99) # perform the centered log-ratio transformation f.clr <- codaSeq.clr(f.n0, samples.by.row=TRUE) @@ -101,7 +101,7 @@ par(mfrow=c(3,4)) label="ALL" f <- codaSeq.filter(ak_op, min.reads=1000, samples.by.row=FALSE, min.count=1) -f.n0 <- cmultRepl(t(f), label=0, method="CZM") +f.n0 <- cmultRepl(t(f), label=0, method="CZM", z.warning = 0.99) # perform the centered log-ratio transformation f.clr <- codaSeq.clr(f.n0, samples.by.row=TRUE) f.pcx <- prcomp(f.clr) @@ -110,7 +110,7 @@ codaSeq.PCAplot(f.pcx, title=label, plot.groups=TRUE, grp.col=rbcol, label="min.count=100" f <- codaSeq.filter(ak_op, min.reads=1000, min.count=10, samples.by.row=FALSE) -f.n0 <- cmultRepl(t(f), label=0, method="CZM") +f.n0 <- cmultRepl(t(f), label=0, method="CZM", z.warning = 0.99) # perform the centered log-ratio transformation f.clr <- codaSeq.clr(f.n0, samples.by.row=TRUE) f.pcx <- prcomp(f.clr) @@ -119,7 +119,7 @@ codaSeq.PCAplot(f.pcx, title=label, plot.groups=TRUE, grp.col=rbcol, label="min.prop=0.01" f <- codaSeq.filter(ak_op, min.reads=1000, min.prop=0.01, samples.by.row=FALSE) -f.n0 <- cmultRepl(t(f), label=0, method="CZM") +f.n0 <- cmultRepl(t(f), label=0, method="CZM", z.warning = 0.99) # perform the centered log-ratio transformation f.clr <- codaSeq.clr(f.n0, samples.by.row=TRUE) f.pcx <- prcomp(f.clr) @@ -128,7 +128,7 @@ codaSeq.PCAplot(f.pcx, title=label, plot.groups=TRUE, grp.col=rbcol, label="max.prop=0.01" f <- codaSeq.filter(ak_op, min.reads=1000, min.prop=0.001, max.prop=0.01, samples.by.row=FALSE) -f.n0 <- cmultRepl(t(f), label=0, method="CZM") +f.n0 <- cmultRepl(t(f), label=0, method="CZM", z.warning = 0.99) # perform the centered log-ratio transformation f.clr <- codaSeq.clr(f.n0, samples.by.row=TRUE) f.pcx <- prcomp(f.clr) @@ -137,7 +137,7 @@ codaSeq.PCAplot(f.pcx, title=label, plot.groups=TRUE, grp.col=rbcol, label="var.filt=TRUE" f <- codaSeq.filter(ak_op, min.reads=1000, var.filt=TRUE, samples.by.row=FALSE) -f.n0 <- cmultRepl(t(f), label=0, method="CZM") +f.n0 <- cmultRepl(t(f), label=0, method="CZM", z.warning = 0.99) # perform the centered log-ratio transformation f.clr <- codaSeq.clr(f.n0, samples.by.row=TRUE) f.pcx <- prcomp(f.clr) @@ -146,7 +146,7 @@ codaSeq.PCAplot(f.pcx, title=label, plot.groups=TRUE, grp.col=rbcol, label="min.occurrence=0.5" f <- codaSeq.filter(ak_op, min.reads=1000, min.occurrence=0.5, samples.by.row=FALSE) -f.n0 <- cmultRepl(t(f), label=0, method="CZM") +f.n0 <- cmultRepl(t(f), label=0, method="CZM", z.warning = 0.99) # perform the centered log-ratio transformation f.clr <- codaSeq.clr(f.n0, samples.by.row=TRUE) f.pcx <- prcomp(f.clr) From c3b98db2ccc15ecc8aa36486b85e2ef13d354a6f Mon Sep 17 00:00:00 2001 From: scottdossantos <136380707+scottdossantos@users.noreply.github.com> Date: Mon, 7 Apr 2025 14:47:03 -0400 Subject: [PATCH 2/2] Added z.warning to example of PCAvalues - Added a missing call to cmultRepl in the example code of codaSeq.PCAvalues() to make sure all values are kept (removes feature only if >99% of values are 0). --- .DS_Store | Bin 10244 -> 10244 bytes CoDaSeq/R/.DS_Store | Bin 0 -> 6148 bytes CoDaSeq/R/codaSeq.PCAvalues.R | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 CoDaSeq/R/.DS_Store diff --git a/.DS_Store b/.DS_Store index 23f4e67bad47283e62534975a88c70c7fe76e01c..d1dd03c5d13a38b1d1ef6b1a961b797888b06766 100644 GIT binary patch delta 429 zcmZn(XbG6$FDSymz`)4BAi$85ZWx@LpIfjwQDPbUW;PC1j(U(B3xgg*IzuKy2}~X+ z#=vls?;^5XZoZ34QcivnP>jRDV*Z^?6OTHg%BSF!FUWw{4b;QHaCZZUWMxR+EF@sa zSdU^agZCPDzQ*o|EUitP*yP}`yUH#-R`GV(*i z1|-G6{j7g;fDkiV46@zX(srpuUSPY~8JrpN8C)0=8G;#7847dr5%%L&h2jQY2Zqg# S5_W8x*%f}VY<@1x%nSg+m}Zv% delta 71 zcmZn(XbG6$FU-Nfz`)4BAi%(oom5_2kd%|3v@vlh`(}0y77j*^%`F1vjGL{66c{(x b3V&eTd|Oh7ZDTH1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0