Skip to content

Commit

Permalink
Merge pull request #756 from AlexsLemonade/allyhawkins/define-umap-po…
Browse files Browse the repository at this point in the history
…int-sizes

Define umap point size when creating cell type umaps
  • Loading branch information
allyhawkins authored Apr 29, 2024
2 parents d5ff33b + 0e3b01c commit 65738c9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
30 changes: 22 additions & 8 deletions templates/qc_report/celltypes_qc.rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Cell type Annotation Summary

<!--
This file is meant to be run as a child report within either `main_qc_report.rmd` or `celltypes_supplemental_report.rmd`.
-->


```{r}
## function definitions ##
Expand Down Expand Up @@ -86,14 +91,14 @@ lump_wrap_celltypes <- function(df, n_celltypes = 7, wrap = 35) {
#' @param color_variable Column in data frame to color by, not a string.
#' @param legend_title Title for legend.
#' @param legend_nrow Number of rows in legend. Default is 2.
#' @param point_size Point size
#' @param point_size Point size. Default is 1
#'
#' @return UMAP plot as a ggplot2 object
plot_umap <- function(
umap_df,
color_variable,
legend_title,
point_size = point_size,
point_size = 1,
legend_nrow = 2) {
ggplot(umap_df) +
aes(
Expand Down Expand Up @@ -131,14 +136,14 @@ plot_umap <- function(
#' @param umap_df Data frame with UMAP1 and UMAP2 columns
#' @param n_celltypes The number of cell types (facets) displayed in the plot
#' @param annotation_column Column containing cell type annotations
#' @param point_size Point size
#' @param point_size Point size. Default is 1
#'
#' @return ggplot object containing a faceted UMAP where each cell type is a facet.
#' In each panel, the cell type of interest is colored and all other cells are grey.
faceted_umap <- function(umap_df,
n_celltypes,
annotation_column,
point_size = umap_facet_point_size) {
point_size = 1) {
# Determine legend y-coordinate based on n_celltypes
if (n_celltypes %in% 7:8) {
legend_y <- 0.33
Expand Down Expand Up @@ -283,6 +288,11 @@ glue::glue("
```{r, warning = FALSE}
# Create data frame of cell types
celltype_df <- create_celltype_df(processed_sce)
# determine UMAP point sizing
umap_points_sizes <- determine_umap_point_size(ncol(processed_sce))
umap_point_size <- umap_points_sizes[1]
umap_facet_point_size <- umap_points_sizes[2]
```


Expand Down Expand Up @@ -402,7 +412,8 @@ glue::glue("
clusters_plot <- plot_umap(
umap_df,
cluster,
"Cluster"
"Cluster",
point_size = umap_point_size
) +
ggtitle("UMAP colored by cluster identity")
Expand Down Expand Up @@ -447,7 +458,8 @@ if (has_submitter & has_umap) {
faceted_umap(
umap_df,
submitter_n_celltypes,
submitter_celltype_annotation_lumped
submitter_celltype_annotation_lumped,
point_size = umap_facet_point_size
) +
ggtitle("UMAP colored by submitter-provided annotations")
```
Expand All @@ -469,7 +481,8 @@ if (has_singler & has_umap) {
faceted_umap(
umap_df,
singler_n_celltypes,
singler_celltype_annotation_lumped
singler_celltype_annotation_lumped,
point_size = umap_facet_point_size
) +
ggtitle("UMAP colored by SingleR annotations")
```
Expand All @@ -490,7 +503,8 @@ if (has_cellassign & has_umap) {
faceted_umap(
umap_df,
cellassign_n_celltypes,
cellassign_celltype_annotation_lumped
cellassign_celltype_annotation_lumped,
point_size = umap_facet_point_size
) +
ggtitle("UMAP colored by CellAssign annotations")
```
5 changes: 0 additions & 5 deletions templates/qc_report/celltypes_supplemental_report.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,6 @@ plot_height <- 1
# sample_id should be defined with length > 1
sample_id <- metadata(processed_sce)$sample_id
has_multiplex <- length(sample_id) > 1
# determine UMAP point sizing
umap_points_sizes <- determine_umap_point_size(ncol(processed_sce))
umap_point_size <- umap_points_sizes[1]
umap_facet_point_size <- umap_points_sizes[2]
```

<!-- If multiplexed, open with warning -->
Expand Down
5 changes: 0 additions & 5 deletions templates/qc_report/main_qc_report.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ if ((has_singler | has_cellassign) & is.null(params$celltype_report)) {
# check if we have multiplex
has_multiplex <- length(sample_id) > 1
sample_types <- metadata(unfiltered_sce)$sample_type
# determine UMAP point sizing
umap_points_sizes <- determine_umap_point_size(ncol(processed_sce))
umap_point_size <- umap_points_sizes[1]
umap_facet_point_size <- umap_points_sizes[2]
```


Expand Down
8 changes: 8 additions & 0 deletions templates/qc_report/umap_qc.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

The below plot shows the UMAP (Uniform Manifold Approximation and Projection) embeddings for each cell, coloring each cell by the total number of genes detected per cell.

```{r}
# determine UMAP point sizing
umap_points_sizes <- determine_umap_point_size(ncol(processed_sce))
umap_point_size <- umap_points_sizes[1]
umap_facet_point_size <- umap_points_sizes[2]
```


```{r message=FALSE}
# create UMAP colored by number of genes detected
scater::plotUMAP(
Expand Down

0 comments on commit 65738c9

Please sign in to comment.