diff --git a/R/Seurat.Utils.R b/R/Seurat.Utils.R index c7db68b..3d7adb6 100644 --- a/R/Seurat.Utils.R +++ b/R/Seurat.Utils.R @@ -1165,6 +1165,9 @@ getClusterNames <- function(obj = combined.obj, ident = GetClusteringRuns(obj)[2 #' @param obj Seurat object, Default: combined.obj #' @param res Clustering resoluton to use, Default: FALSE #' @param pat Pattern to match, Default: `*snn_res.*[0-9]$` +#' @param v +#' +#' @return Prints and returns the sorted unique cluster names as a character vector. #' @examples #' \dontrun{ #' if (interactive()) { @@ -1172,13 +1175,22 @@ getClusterNames <- function(obj = combined.obj, ident = GetClusteringRuns(obj)[2 #' } #' } #' @export -GetClusteringRuns <- function(obj = combined.obj, res = FALSE, pat = "*snn_res.[0-9].[0-9]+$") { # OLD: '*snn_res.*[0-9]$' +GetClusteringRuns <- function(obj = combined.obj, + res = FALSE, pat = "*snn_res.[0-9].[0-9]+$", + v = TRUE) { + if (!isFALSE(res)) pat <- gsub(x = pat, pattern = "\\[.*\\]", replacement = res) clustering.results <- sort(CodeAndRoll2::grepv(x = colnames(obj@meta.data), pattern = pat)) + if (identical(clustering.results, character(0))) warning("No matching (simple) clustering column found!", immediate. = TRUE) - message("Clustering runs found:") - dput(clustering.results) + + if(v) { + message("Clustering runs found:") + dput(clustering.results) + } + + return(clustering.results) } @@ -1193,6 +1205,8 @@ GetClusteringRuns <- function(obj = combined.obj, res = FALSE, pat = "*snn_res.[ #' @param topgene Match clustering named after top expressed gene (see vertesy/Seurat.pipeline/~Diff gene expr.), Default: FALSE #' @param pat Pattern to match, Default: '^cl.names.Known.*[0,1]\.[0-9]$' #' @param find.alternatives If TRUE, tries to find alternative clustering runs with +#' the same resolution, Default: TRUE +#' @param v Verbose output, Default: TRUE #' simple GetClusteringRuns(), Default: TRUE #' @examples #' \dontrun{ @@ -1205,7 +1219,8 @@ GetNamedClusteringRuns <- function( obj = combined.obj, res = list(FALSE, 0.5)[[1]], topgene = FALSE, pat = c("^cl.names.*[0-9]\\.[0-9]", "Name|name")[2], - find.alternatives = TRUE) { + find.alternatives = TRUE, + v = TRUE) { if (res) pat <- gsub(x = pat, pattern = "\\[.*\\]", replacement = res) if (topgene) pat <- gsub(x = pat, pattern = "Known", replacement = "top") @@ -1215,10 +1230,11 @@ GetNamedClusteringRuns <- function( warning("No matching (named) clustering column found! Trying GetClusteringRuns(..., pat = '*_res.*[0,1]\\.[0-9]$)", immediate. = TRUE ) if (find.alternatives) clustering.results <- - GetClusteringRuns(obj = obj, res = FALSE, pat = "*_res.*[0,1]\\.[0-9]$") + GetClusteringRuns(obj = obj, res = FALSE, pat = "*_res.*[0,1]\\.[0-9]$", v = F) } - dput(clustering.results) + if(v) dput(clustering.results) + return(clustering.results) } diff --git a/R/Seurat.Utils.Visualization.R b/R/Seurat.Utils.Visualization.R index c9ad253..df1d860 100644 --- a/R/Seurat.Utils.Visualization.R +++ b/R/Seurat.Utils.Visualization.R @@ -573,7 +573,7 @@ plotGeneExprHistAcrossCells <- function( PctCellsAboveX <- function(obj = combined.obj, feature = "TOP2A", - ident = GetNamedClusteringRuns(obj)[1], + ident = GetNamedClusteringRuns(obj = obj, v = F)[1], threshold = 2, suffix = ppp(substitute(obj), ncol(obj), "thr", threshold), box = FALSE, @@ -1866,7 +1866,7 @@ qFeatureScatter <- function( qSeuViolin <- function( obj, feature = "nFeature_RNA", - ident = GetNamedClusteringRuns(obj)[1], + ident = GetNamedClusteringRuns(obj = obj, v = F)[1], split.by = NULL, colors = NULL, replace.na = FALSE, @@ -2144,7 +2144,7 @@ clUMAP <- function( # if (is.null(ident)) { - ident <- GetNamedClusteringRuns(obj = obj)[1] + ident <- GetNamedClusteringRuns(obj = obj, v = F)[1] message("Identity not provided. Plotting: ", ident) } @@ -2311,7 +2311,7 @@ umapHiLightSel <- function(obj = combined.obj, #' @export DimPlot.ClusterNames <- function( obj = combined.obj, - ident = GetNamedClusteringRuns(obj)[1], + ident = GetNamedClusteringRuns(obj = obj, v = F)[1], reduction = "umap", title = ident, ...) { @@ -3853,7 +3853,7 @@ ww.check.quantile.cutoff.and.clip.outliers <- function(expr.vec = plotting.data[ plot3D.umap.gene <- function( gene = "TOP2A", obj = combined.obj, - annotate.by = GetNamedClusteringRuns(obj)[1], + annotate.by = GetNamedClusteringRuns(obj = obj, v = F)[1], quantileCutoff = .99, def.assay = c("integrated", "RNA")[2], suffix = NULL, @@ -3951,7 +3951,7 @@ plot3D.umap.gene <- function( plot3D.umap <- function( obj = combined.obj, - category = GetNamedClusteringRuns(obj)[1], + category = GetNamedClusteringRuns(obj = obj, v = F)[1], annotate.by = category, suffix = NULL, dotsize = 1.25, diff --git a/man/DimPlot.ClusterNames.Rd b/man/DimPlot.ClusterNames.Rd index a0724e3..58fd3bf 100644 --- a/man/DimPlot.ClusterNames.Rd +++ b/man/DimPlot.ClusterNames.Rd @@ -6,7 +6,7 @@ \usage{ DimPlot.ClusterNames( obj = combined.obj, - ident = GetNamedClusteringRuns(obj)[1], + ident = GetNamedClusteringRuns(obj = obj, v = F)[1], reduction = "umap", title = ident, ... diff --git a/man/GetClusteringRuns.Rd b/man/GetClusteringRuns.Rd index f18d473..014a084 100644 --- a/man/GetClusteringRuns.Rd +++ b/man/GetClusteringRuns.Rd @@ -7,7 +7,8 @@ GetClusteringRuns( obj = combined.obj, res = FALSE, - pat = "*snn_res.[0-9].[0-9]+$" + pat = "*snn_res.[0-9].[0-9]+$", + v = TRUE ) } \arguments{ @@ -16,6 +17,11 @@ GetClusteringRuns( \item{res}{Clustering resoluton to use, Default: FALSE} \item{pat}{Pattern to match, Default: \verb{*snn_res.*[0-9]$}} + +\item{v}{} +} +\value{ +Prints and returns the sorted unique cluster names as a character vector. } \description{ The \code{GetClusteringRuns} function retrieves metadata column names associated with diff --git a/man/GetNamedClusteringRuns.Rd b/man/GetNamedClusteringRuns.Rd index 467df53..65dff77 100644 --- a/man/GetNamedClusteringRuns.Rd +++ b/man/GetNamedClusteringRuns.Rd @@ -9,7 +9,8 @@ GetNamedClusteringRuns( res = list(FALSE, 0.5)[[1]], topgene = FALSE, pat = c("^cl.names.*[0-9]\\\\.[0-9]", "Name|name")[2], - find.alternatives = TRUE + find.alternatives = TRUE, + v = TRUE ) } \arguments{ @@ -22,6 +23,9 @@ GetNamedClusteringRuns( \item{pat}{Pattern to match, Default: '^cl.names.Known.*\link{0,1}\.\link{0-9}$'} \item{find.alternatives}{If TRUE, tries to find alternative clustering runs with +the same resolution, Default: TRUE} + +\item{v}{Verbose output, Default: TRUE simple GetClusteringRuns(), Default: TRUE} } \description{ diff --git a/man/PctCellsAboveX.Rd b/man/PctCellsAboveX.Rd index 5a59083..4f9558f 100644 --- a/man/PctCellsAboveX.Rd +++ b/man/PctCellsAboveX.Rd @@ -7,7 +7,7 @@ PctCellsAboveX( obj = combined.obj, feature = "TOP2A", - ident = GetNamedClusteringRuns(obj)[1], + ident = GetNamedClusteringRuns(obj = obj, v = F)[1], threshold = 2, suffix = ppp(substitute(obj), ncol(obj), "thr", threshold), box = FALSE, diff --git a/man/clUMAP.Rd b/man/clUMAP.Rd index 9f665b8..1a9c37e 100644 --- a/man/clUMAP.Rd +++ b/man/clUMAP.Rd @@ -20,6 +20,7 @@ clUMAP( plotname = ppp(toupper(reduction), ident), cols = NULL, palette = c("alphabet", "alphabet2", "glasbey", "polychrome", "stepped")[3], + max.cols.for.std.palette = 7, highlight.clusters = NULL, cells.highlight = NULL, label = TRUE, diff --git a/man/plot3D.umap.Rd b/man/plot3D.umap.Rd index 23ca667..5fdec41 100644 --- a/man/plot3D.umap.Rd +++ b/man/plot3D.umap.Rd @@ -6,7 +6,7 @@ \usage{ plot3D.umap( obj = combined.obj, - category = GetNamedClusteringRuns(obj)[1], + category = GetNamedClusteringRuns(obj = obj, v = F)[1], annotate.by = category, suffix = NULL, dotsize = 1.25, diff --git a/man/plot3D.umap.gene.Rd b/man/plot3D.umap.gene.Rd index 198109c..6b90d6a 100644 --- a/man/plot3D.umap.gene.Rd +++ b/man/plot3D.umap.gene.Rd @@ -7,7 +7,7 @@ plot3D.umap.gene( gene = "TOP2A", obj = combined.obj, - annotate.by = GetNamedClusteringRuns(obj)[1], + annotate.by = GetNamedClusteringRuns(obj = obj, v = F)[1], quantileCutoff = 0.99, def.assay = c("integrated", "RNA")[2], suffix = NULL, diff --git a/man/qSeuViolin.Rd b/man/qSeuViolin.Rd index 88efcfa..b13e523 100644 --- a/man/qSeuViolin.Rd +++ b/man/qSeuViolin.Rd @@ -7,7 +7,7 @@ qSeuViolin( obj, feature = "nFeature_RNA", - ident = GetNamedClusteringRuns(obj)[1], + ident = GetNamedClusteringRuns(obj = obj, v = F)[1], split.by = NULL, colors = NULL, replace.na = FALSE,