Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ Imports:
scuttle,
utils,
stats,
zellkonverter
zellkonverter,
lifecycle
RoxygenNote: 7.3.2
Suggests:
testthat,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ importFrom(dplyr,select)
importFrom(dplyr,summarize)
importFrom(dplyr,ungroup)
importFrom(grid,gpar)
importFrom(lifecycle,deprecate_warn)
importFrom(lifecycle,deprecated)
importFrom(magrittr,"%>%")
importFrom(methods,slot)
importFrom(reshape2,melt)
Expand Down
110 changes: 84 additions & 26 deletions R/ggPlotting.R
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,9 @@ plotSCEDimReduceColData <- function(inSCE,
#' @param reducedDimName saved dimension reduction name in the
#' \linkS4class{SingleCellExperiment} object. Required.
#' @param sample Character vector. Indicates which sample each cell belongs to.
#' @param feature Name of feature stored in assay of SingleCellExperiment
#' @param features Name of feature stored in assay of SingleCellExperiment
#' object.
#' @param feature Deprecated, use `features` instead.
#' @param featureLocation Indicates which column name of rowData to query gene.
#' @param featureDisplay Indicates which column name of rowData to use
#' to display feature for visualization.
Expand Down Expand Up @@ -498,23 +499,26 @@ plotSCEDimReduceColData <- function(inSCE,
#' @param legendTitle title of legend. Default NULL.
#' @param legendTitleSize size of legend title. Default 12.
#' @param legendSize size of legend. Default 10.
#' @param ncols number of columns for multiple feature plotting. Default NULL.
#' @param groupBy Facet wrap the scatterplot based on value.
#' Default \code{NULL}.
#' @param combinePlot Must be either "all", "sample", or "none". "all" will combine all plots into a single
#' .ggplot object, while "sample" will output a list of plots separated by sample. Default "none".
#' @param plotLabels labels to each plot. If set to "default", will use the name of the samples
#' as the labels. If set to "none", no label will be plotted.
#' @return a ggplot of the reduced dimension plot of feature data.
#' @importFrom lifecycle deprecated deprecate_warn
#' @examples
#' data("mouseBrainSubsetSCE")
#' plotSCEDimReduceFeatures(
#' inSCE = mouseBrainSubsetSCE, feature = "Apoe",
#' inSCE = mouseBrainSubsetSCE, features = "Apoe",
#' shape = NULL, reducedDimName = "TSNE_counts",
#' useAssay = "counts", xlab = "tSNE1", ylab = "tSNE2"
#' )
#' @export
plotSCEDimReduceFeatures <- function(inSCE,
feature,
features,
feature = deprecated(),
reducedDimName,
sample = NULL,
featureLocation = NULL,
Expand All @@ -540,37 +544,40 @@ plotSCEDimReduceFeatures <- function(inSCE,
legendTitle = NULL,
legendSize = 10,
legendTitleSize = 12,
ncols = NULL,
groupBy = NULL,
combinePlot = "none",
plotLabels = NULL) {
combinePlot <- match.arg(combinePlot,c("all", "sample", "none"))
if (lifecycle::is_present(feature)) {
deprecate_warn("2.19.1", "singleCellTK::plotSCEDimReduceFeatures(feature = )",
"singleCellTK::plotSCEDimReduceFeatures(features = )")
features <- feature
}
combinePlot <- match.arg(combinePlot,c("all", "sample", "none"))

if(!is.null(featureDisplay)){
featureDisplay <- match.arg(featureDisplay,
c("rownames",
colnames(SummarizedExperiment::rowData(inSCE)))
)
}else{
if(exists(x = "featureDisplay", inSCE@metadata)){
featureDisplay <- inSCE@metadata$featureDisplay
}
if(!is.null(featureDisplay)){
featureDisplay <- match.arg(featureDisplay,
c("rownames",
colnames(SummarizedExperiment::rowData(inSCE))))
}else{
if(exists(x = "featureDisplay", inSCE@metadata)){
featureDisplay <- inSCE@metadata$featureDisplay
}
}

mat <- getBiomarker(
if (length(features) > 1) {
plotlist <- lapply(features, function(f) {
mat <- getBiomarker(
inSCE = inSCE,
useAssay = useAssay,
gene = feature,
gene = f,
binary = "Continuous",
featureLocation = featureLocation,
featureDisplay = featureDisplay
)
counts <- mat[, 2]

if(!is.null(featureDisplay)){
title = utils::tail(colnames(mat),1)
}

g <- .ggScatter(
)
counts <- mat[, 2]
plot_title <- if(!is.null(featureDisplay)) utils::tail(colnames(mat),1) else f
.ggScatter(
inSCE = inSCE,
sample = sample,
conditionClass = "numeric",
Expand All @@ -591,17 +598,68 @@ plotSCEDimReduceFeatures <- function(inSCE,
binLabel = binLabel,
defaultTheme = defaultTheme,
dotSize = dotSize,
title = title,
title = plot_title,
titleSize = titleSize,
legendTitle = legendTitle,
legendTitleSize = legendTitleSize,
legendSize = legendSize,
groupBy = groupBy,
combinePlot = combinePlot,
combinePlot = "none",
plotLabels = plotLabels
)
})
if (combinePlot != "none") {
plotlist <- .ggSCTKCombinePlots(plotlist,
combinePlot = combinePlot,
ncols = ncols,
labels = plotLabels)
}
return(plotlist)
} else {
mat <- getBiomarker(
inSCE = inSCE,
useAssay = useAssay,
gene = features,
binary = "Continuous",
featureLocation = featureLocation,
featureDisplay = featureDisplay
)
counts <- mat[, 2]
if(!is.null(featureDisplay)){
title = utils::tail(colnames(mat),1)
}
g <- .ggScatter(
inSCE = inSCE,
sample = sample,
conditionClass = "numeric",
colorBy = counts,
shape = shape,
transparency = 1,
colorLow = colorLow,
colorMid = colorMid,
colorHigh = colorHigh,
reducedDimName = reducedDimName,
xlab = xlab,
ylab = ylab,
axisSize = axisSize,
axisLabelSize = axisLabelSize,
dim1 = dim1,
dim2 = dim2,
bin = bin,
binLabel = binLabel,
defaultTheme = defaultTheme,
dotSize = dotSize,
title = title,
titleSize = titleSize,
legendTitle = legendTitle,
legendTitleSize = legendTitleSize,
legendSize = legendSize,
groupBy = groupBy,
combinePlot = combinePlot,
plotLabels = plotLabels
)

return(g)
}
}

#' @title Dimension reduction plot tool for all types of data
Expand Down
2 changes: 1 addition & 1 deletion R/runTSCAN.R
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ plotTSCANDimReduceFeatures <- function(
features <- stats::na.omit(features)
for (f in features) {
# Should not enter the loop if features is length zero after NA omit
g <- plotSCEDimReduceFeatures(inSCE, feature = f,
g <- plotSCEDimReduceFeatures(inSCE, features = f,
useAssay = useAssay,
featureLocation = by,dim1 = 1, dim2 = 2,
featureDisplay = featureDisplay,
Expand Down
11 changes: 7 additions & 4 deletions R/seuratFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -2134,11 +2134,14 @@ plotSeuratGenes <- function(inSCE,
seurat.version <- .getSeuratObjectMajorVersion(seuratObject)

if(plotType %in% c("dot", "heatmap")){
if (length(features) < 2) {
stop("At least 2 features are required for this plotType.")
if (length(features) == 1) {
dummyfeature <- rownames(inSCE)[which(!rownames(inSCE) == features)][1]
seuratObject <-
Seurat::ScaleData(seuratObject, features = c(features,dummyfeature))
}else{
seuratObject <-
Seurat::ScaleData(seuratObject, features = features)
}
seuratObject <-
Seurat::ScaleData(seuratObject, features = features)
}

indices <- list()
Expand Down
2 changes: 1 addition & 1 deletion inst/shiny/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -4883,7 +4883,7 @@ shinyServer(function(input, output, session) {
legendSize = input$adjustlegendsize, legendTitleSize = input$adjustlegendtitlesize,
conditionClass = pltVars$class, defaultTheme = as.logical(pltVars$defTheme))
}else if(input$TypeSelect_Colorby == "Expression Assays"){
a <- plotSCEDimReduceFeatures(vals$counts, feature = input$GeneSelect_Assays_Colorby,
a <- plotSCEDimReduceFeatures(vals$counts, features = input$GeneSelect_Assays_Colorby,
reducedDimName = input$QuickAccess, useAssay = input$AdvancedMethodSelect_Colorby,
xlab = xname, ylab = yname, legendTitle = legendname, title = input$adjusttitle,
groupBy = pltVars$groupby, bin = pltVars$bin, transparency = input$adjustalpha,
Expand Down
12 changes: 9 additions & 3 deletions man/plotSCEDimReduceFeatures.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-qc.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test_that(desc = "Testing plotSCEScatter functions", {
reducedDimName = "UMAP", labelClusters = FALSE,
sample = sampleVector, combinePlot = "all")
expect_is(p1, c("gg","ggplot"))
p2 <- plotSCEDimReduceFeatures(inSCE = sceres, feature = "ENSG00000251562",
p2 <- plotSCEDimReduceFeatures(inSCE = sceres, features = "ENSG00000251562",
shape = NULL, reducedDimName = "UMAP",
useAssay = "counts", xlab = "UMAP1", ylab = "UMAP2",
sample = sampleVector, combinePlot = "all")
Expand Down
2 changes: 1 addition & 1 deletion vignettes/articles/2d_embedding.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ plotUMAP(sce)
# Customizing scatter plot with more information from cell metadata (colData)
plotSCEDimReduceColData(sce, colorBy = "cluster", reducedDimName = "UMAP")
# Color scatter plot with feature expression
plotSCEDimReduceFeatures(sce, feature = "CD8A", reducedDimName = "UMAP")
plotSCEDimReduceFeatures(sce, features = "CD8A", reducedDimName = "UMAP")
```

````{=html}
Expand Down
2 changes: 1 addition & 1 deletion vignettes/articles/dimensionality_reduction.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ plotPCA(sce)
# Customizing scatter plot with more information from cell metadata (colData)
plotSCEDimReduceColData(sce, colorBy = "cluster", reducedDimName = "PCA")
# Color scatter plot with feature expression
plotSCEDimReduceFeatures(sce, feature = "CD8A", reducedDimName = "PCA")
plotSCEDimReduceFeatures(sce, features = "CD8A", reducedDimName = "PCA")
```

Besides, SCTK also wraps elbow plot, Jackstraw plot and DimHeatmap methods from *Seurat*. For usage of these visualization methods, please refer to [Seurat Curated Workflow](seurat_curated_workflow.html)
Expand Down
Loading