Skip to content

Commit

Permalink
scDotPlot v0.99.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Laufer committed Sep 17, 2024
1 parent b8606e8 commit bd4ad10
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 17 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: scDotPlot
Title: Cluster a Single-cell RNA-seq Dot Plot
Version: 0.99.3
Version: 0.99.4
Authors@R: c(
person(given = c("Benjamin", "I"),
family = "Laufer",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# scDotPlot 0.99.4

* Addition of seperate clusterRows and clusterColumns arguments

# scDotPlot 0.99.3

* Bug fix for flipPlot argument as well as addition of font customization arguments and graphical unit tests
Expand Down
19 changes: 17 additions & 2 deletions R/scDotPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
#' @param NumDetectedThreshold Numeric specifying threshold for fraction of cells,
#' where values below AverageThreshold and NumDetectedThreshold are transparent
#' @param cluster Logical specifying whether to perform hierarchical clustering
#' analysis
#' analysis on both the rows and columns
#' @param clusterRows Logical specifying whether to perform hierarchical clustering
#' analysis on the rows
#' @param clusterColumns Logical specifying whether to perform hierarchical clustering
#' analysis on the columns
#' @param groupAnno Cell annotations that are stored as names of columns
#' in colData of sce with annotations
#' @param featureAnno Feature annotations that are stored as names of rows
Expand Down Expand Up @@ -93,6 +97,8 @@ scDotPlot.SingleCellExperiment <- function(object,
swap_rownames = NULL,
scale = FALSE,
cluster = TRUE,
clusterRows = cluster,
clusterColumns = cluster,
AverageThreshold = ifelse(scale == FALSE, 0, -Inf),
NumDetectedThreshold = 0.01,
groupAnno = FALSE,
Expand Down Expand Up @@ -168,6 +174,8 @@ scDotPlot.SingleCellExperiment <- function(object,
features = features,
scale = scale,
cluster = cluster,
clusterRows = clusterRows,
clusterColumns = clusterColumns,
AverageThreshold = AverageThreshold,
NumDetectedThreshold = NumDetectedThreshold,
groupAnno = groupAnno,
Expand Down Expand Up @@ -204,6 +212,8 @@ scDotPlot.Seurat <- function(object,
swap_rownames = NULL,
scale = FALSE,
cluster = TRUE,
clusterRows = cluster,
clusterColumns = cluster,
AverageThreshold = ifelse(scale == FALSE, 0, -Inf),
NumDetectedThreshold = 0.01,
groupAnno = FALSE,
Expand Down Expand Up @@ -271,6 +281,8 @@ scDotPlot.Seurat <- function(object,
features = features,
scale = scale,
cluster = cluster,
clusterRows = clusterRows,
clusterColumns = clusterColumns,
AverageThreshold = AverageThreshold,
NumDetectedThreshold = NumDetectedThreshold,
groupAnno = groupAnno,
Expand Down Expand Up @@ -301,6 +313,8 @@ scDotPlot.default <- function(object,
swap_rownames = NULL,
scale = FALSE,
cluster = TRUE,
clusterRows = cluster,
clusterColumns = cluster,
AverageThreshold = ifelse(scale == FALSE, 0, -Inf),
NumDetectedThreshold = 0.01,
groupAnno = FALSE,
Expand Down Expand Up @@ -334,7 +348,8 @@ scDotPlot.default <- function(object,

if(any(cluster == TRUE, !is.null(groupAnno), !is.null(featureAnno))){
dotPlot %>%
.annotateDotPlot(cluster = cluster,
.annotateDotPlot(clusterRows = clusterRows,
clusterColumns = clusterColumns,
groupAnno = groupAnno,
featureAnno = featureAnno,
treeWidth = treeWidth,
Expand Down
15 changes: 10 additions & 5 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#' @keywords internal
#'
.annotateDotPlot <- function(dotPlot,
cluster = TRUE,
clusterRows = TRUE,
clusterColumns = TRUE,
groupAnno = FALSE,
featureAnno = FALSE,
treeWidth = 0.1,
Expand Down Expand Up @@ -95,9 +96,13 @@
purrr::reduce(if(flipPlot == FALSE){rowLabels}else{colLabels},
~ aplot::insert_left(.x, .y, width = annoWidth),
.init = .) %>%
{if(cluster == TRUE){
aplot::insert_left(., treeRow, width = treeWidth) %>%
aplot::insert_top(treeCol, height = treeHeight)
{if(clusterRows == TRUE){
aplot::insert_left(., treeRow, width = treeWidth)
}else{
.
}} %>%
{if(clusterColumns == TRUE){
aplot::insert_top(., treeCol, height = treeHeight)
}else{
.
}}
Expand Down Expand Up @@ -140,7 +145,7 @@

(plotData %>%
dplyr::mutate(alpha = dplyr::case_when(Average > !!AverageThreshold &
NumDetected > NumDetectedThreshold ~ 1,
NumDetected > !!NumDetectedThreshold ~ 1,
.default = 0.1)) %>%
{if(flipPlot == FALSE){
ggplot2::ggplot(., ggplot2::aes(x = !!rlang::sym(group),
Expand Down
10 changes: 7 additions & 3 deletions man/dot-annotateDotPlot.Rd

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

14 changes: 13 additions & 1 deletion man/scDotPlot.Rd

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

10 changes: 5 additions & 5 deletions vignettes/scDotPlot.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ rowData(sce)$Marker <- features[match(rownames(sce), features)] |>

Finally, we create the plot. The `group` arguments utilize the colData, while the `features` arguments use the rowData. The `paletteList` argument can be used to manually specify the colors for the annotations specified through `groupAnno` and `featureAnno`. The clustering of the columns shows that cell the cell sub-types cluster by cell-type, while the clustering of the rows shows that most of the markers clusters by their cell type.

```{r Plot SingleCellExperiment logcounts, fig.width=12, fig.height=12, dpi=50}
```{r scePlot1, fig.cap = "scDotPlot of SingleCellExperiment logcounts", fig.width=12, fig.height=12, dpi=50}
library(scDotPlot)
library(ggsci)
Expand All @@ -107,7 +107,7 @@ sce |>

Plotting by Z-score through `scale = TRUE` improves the clustering result for the rows.

```{r Plot SingleCellExperiment Z, fig.width=12, fig.height=12, dpi=50}
```{r scePlot2, fig.cap = "scDotPlot of SingleCellExperiment Z-scores", fig.width=12, fig.height=12, dpi=50}
sce |>
scDotPlot(scale = TRUE,
features = features,
Expand Down Expand Up @@ -150,9 +150,9 @@ features <- features |>

## Plot logcounts

Plotting a Seurat object is similair to plotting a SingleCellExperiment object.
Plotting a Seurat object is similar to plotting a SingleCellExperiment object.

```{r Plot Seurat logcounts, fig.width=4, fig.height=5, out.width="50%", out.height="50%", dpi=50}
```{r SeuratPlot1, fig.cap = "scDotPlot of Seurat logcounts", fig.width=4, fig.height=5, out.width="75%", out.height="75%", dpi=50}
pbmc_small |>
scDotPlot(features = features,
group = "RNA_snn_res.1",
Expand All @@ -168,7 +168,7 @@ pbmc_small |>

Again, we see that plotting by Z-score improves the clustering result for the rows.

```{r Plot Seurat Z, fig.width=4, fig.height=5, out.width="50%", out.height="50%", dpi=50}
```{r SeuratPlot2, fig.cap = "scDotPlot of Seurat Z-scores", fig.width=4, fig.height=5, out.width="75%", out.height="75%", dpi=50}
pbmc_small |>
scDotPlot(scale = TRUE,
features = features,
Expand Down

0 comments on commit bd4ad10

Please sign in to comment.