Skip to content

Commit

Permalink
Merge pull request #763 from nqgurevich/master
Browse files Browse the repository at this point in the history
Violin plotting for multiple modules
  • Loading branch information
joshua-d-campbell authored Aug 24, 2024
2 parents 17c9f6e + d6c4f29 commit 728406e
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 26 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ Imports:
scuttle,
utils,
stats,
zellkonverter
zellkonverter,
tidyr
RoxygenNote: 7.3.1
Suggests:
testthat,
Expand Down
2 changes: 1 addition & 1 deletion R/dropletUtils_emptyDrops.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#' @title Identify empty droplets using \link[DropletUtils]{emptyDrops}.
#' @description Run \link[DropletUtils]{emptyDrops} on the count matrix in the
#' provided \\linkS4class{SingleCellExperiment} object.
#' provided \linkS4class{SingleCellExperiment} object.
#' Distinguish between droplets containing cells and ambient RNA in a
#' droplet-based single-cell RNA sequencing experiment.
#' @param inSCE A \linkS4class{SingleCellExperiment} object. Must contain a raw
Expand Down
28 changes: 22 additions & 6 deletions R/ggPlotting.R
Original file line number Diff line number Diff line change
Expand Up @@ -852,11 +852,19 @@ plotSCEScatter <- function(inSCE,
vcolor = "red",
vsize = 1,
vlinetype = 1) {

mult_modules <- FALSE

if (is.null(groupBy)) {
groupBy <- rep("Sample", length(y))
if (length(colnames(y)) > 1){
mult_modules <- TRUE
groupBy <- rep(colnames(y), each = dim(y)[1])
y <- tidyr::pivot_longer(as.data.frame(y), cols = 1:dim(y)[2], cols_vary = "slowest")$value#
}else{
groupBy <- rep("Sample", length(y))
}
}


if(!is.factor(groupBy)){
if(is.null(plotOrder)){
plotOrder = unique(groupBy)
Expand Down Expand Up @@ -920,6 +928,10 @@ plotSCEScatter <- function(inSCE,
axis.title.x = ggplot2::element_blank())
}

if (mult_modules){
p <- p + xlab("Modules")
}

if (gridLine == TRUE){
p <- p + ggplot2::theme(panel.grid.major.y = ggplot2::element_line("grey"))
}
Expand Down Expand Up @@ -1417,9 +1429,9 @@ plotSCEViolinAssayData <- function(inSCE,
#' @param feature Desired name of feature stored in assay of SingleCellExperiment
#' object. Only used when "assays" slotName is selected. Default NULL.
#' @param sample Character vector. Indicates which sample each cell belongs to.
#' @param dimension Desired dimension stored in the specified reducedDims.
#' Either an integer which indicates the column or a character vector specifies
#' column name. By default, the 1st dimension/column will be used.
#' @param dimension Desired dimension(s) stored in the specified reducedDims.
#' Either an integer which indicates the column(s) or a character vector specifies
#' column name(s). By default, the 1st dimension/column will be used.
#' Only used when "reducedDims" slotName is selected. Default NULL.
#' @param groupBy Groupings for each numeric value. A user may input a vector
#' equal length to the number of the samples in the SingleCellExperiment
Expand Down Expand Up @@ -1568,7 +1580,11 @@ plotSCEViolin <- function(inSCE,
samples <- unique(sample)
plotlist <- lapply(samples, function(x) {
sampleInd <- which(sample == x)
countSub <- counts[sampleInd]
if (length(colnames(counts)) > 1){
countSub <- counts[sampleInd,]
}else{
countSub <- counts[sampleInd]
}
if(!is.null(groupBy)){
groupbySub <- groupBy[sampleInd]
}else{
Expand Down
8 changes: 4 additions & 4 deletions R/miscFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,18 @@ discreteColorPalette <- function(n, palette = c("random", "ggplot", "celda"),
#' Adds '-1', '-2', ... '-i' to multiple duplicated rownames, and in place
#' replace the unique rownames, store unique rownames in \code{rowData}, or
#' return the unique rownames as character vecetor.
#' @param x A matrix like or /linkS4class{SingleCellExperiment} object, on which
#' @param x A matrix like or \linkS4class{SingleCellExperiment} object, on which
#' we can apply \code{rownames()} to and has duplicated rownames.
#' @param as.rowData Only applicable when \code{x} is a
#' /linkS4class{SingleCellExperiment} object. When set to \code{TRUE}, will
#' \linkS4class{SingleCellExperiment} object. When set to \code{TRUE}, will
#' insert a new column called \code{"rownames.uniq"} to \code{rowData(x)}, with
#' the deduplicated rownames.
#' @param return.list When set to \code{TRUE}, will return a character vector
#' of the deduplicated rownames.
#' @export
#' @return By default, a matrix or /linkS4class{SingleCellExperiment} object
#' @return By default, a matrix or \linkS4class{SingleCellExperiment} object
#' with rownames deduplicated.
#' When \code{x} is a /linkS4class{SingleCellExperiment} and \code{as.rowData}
#' When \code{x} is a \linkS4class{SingleCellExperiment} and \code{as.rowData}
#' is set to \code{TRUE}, will return \code{x} with \code{rowData} updated.
#' When \code{return.list} is set to \code{TRUE}, will return a character vector
#' with the deduplicated rownames.
Expand Down
2 changes: 1 addition & 1 deletion R/plotBubble.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' @param ylab The y-axis label
#' @param colorLow The color to be used for lowest value of mean expression
#' @param colorHigh The color to be used for highest value of mean expression
#' @param scale Option to scale the data. Default: /code{FALSE}. Selected assay will not be scaled.
#' @param scale Option to scale the data. Default: \code{FALSE}. Selected assay will not be scaled.
#' @return A ggplot of the bubble plot.
#' @importFrom rlang .data
#' @importFrom reshape2 melt
Expand Down
2 changes: 1 addition & 1 deletion R/runBatchCorrection.R
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ integrated = integrated[:, orderIdx]
#' variable genes identification. Default \code{"counts"}.
#' @param kmeansK An integer vector. Indicating the kmeans' K-value for each
#' batch (i.e. how many subclusters in each batch should exist), in order to
#' construct pseudo-replicates. The length of code{kmeansK} needs to be the same
#' construct pseudo-replicates. The length of \code{kmeansK} needs to be the same
#' as the number of batches. Default \code{NULL}, and this value will be
#' auto-detected by default, depending on \code{cellType}.
#' @param cellType A single character. A string indicating a field in
Expand Down
2 changes: 1 addition & 1 deletion R/runClusterSummaryMetrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @param featureNames A string or vector of strings with each gene to aggregate.
#' @param displayName A string that is the name of the column used for genes.
#' @param groupNames The name of a colData entry that can be used as groupNames.
#' @param scale Option to scale the data. Default: /code{FALSE}. Selected assay will not be scaled.
#' @param scale Option to scale the data. Default: \code{FALSE}. Selected assay will not be scaled.
#' @return A dataframe with mean expression and percent of cells in cluster that
#' express for each cluster.
#' @examples
Expand Down
8 changes: 4 additions & 4 deletions man/dedupRowNames.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/plotBubble.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/plotSCEViolin.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/runClusterSummaryMetrics.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/runEmptyDrops.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/runSCMerge.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 728406e

Please sign in to comment.