From 7b99606d406168a75f7f8cbacf82fed1fed8d6bd Mon Sep 17 00:00:00 2001 From: Ally Hawkins <54039191+allyhawkins@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:44:04 -0500 Subject: [PATCH 1/7] add boolean for if clusters exist --- templates/qc_report/celltypes_qc.rmd | 10 +++++----- templates/qc_report/celltypes_supplemental_report.rmd | 4 ++-- templates/qc_report/main_qc_report.rmd | 2 ++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/templates/qc_report/celltypes_qc.rmd b/templates/qc_report/celltypes_qc.rmd index 5da08030..93288aa4 100644 --- a/templates/qc_report/celltypes_qc.rmd +++ b/templates/qc_report/celltypes_qc.rmd @@ -93,7 +93,7 @@ plot_umap <- function( umap_df, color_variable, legend_title, - point_size = umap_point_size, + point_size = point_size, legend_nrow = 2) { ggplot(umap_df) + aes( @@ -370,7 +370,7 @@ create_celltype_n_table(celltype_df, cellassign_celltype_annotation) |> ``` -```{r, eval = has_umap} +```{r, eval = has_umap & has_clusters} knitr::asis_output(glue::glue(" ## UMAPs @@ -388,7 +388,7 @@ umap_df <- lump_wrap_celltypes(celltype_df) -```{r, eval = has_umap && has_multiplex, results='asis'} +```{r, eval = has_umap && has_multiplex && has_clusters, results='asis'} glue::glue("
This library contains multiple samples that have not been batch-corrected, which may confound clustering assignments. @@ -398,7 +398,7 @@ glue::glue(" ``` -```{r eval = has_umap, message=FALSE, warning=FALSE} +```{r eval = has_umap & has_clusters, message=FALSE, warning=FALSE} clusters_plot <- plot_umap( umap_df, cluster, @@ -418,7 +418,7 @@ if (length(levels(umap_df$cluster)) <= 8) { ``` -```{r, eval = has_umap} +```{r, eval = has_umap & has_celltypes} knitr::asis_output( 'Next, we show UMAPs colored by cell types. For each cell typing method, we show a separate faceted UMAP. diff --git a/templates/qc_report/celltypes_supplemental_report.rmd b/templates/qc_report/celltypes_supplemental_report.rmd index 652d6748..022ad473 100644 --- a/templates/qc_report/celltypes_supplemental_report.rmd +++ b/templates/qc_report/celltypes_supplemental_report.rmd @@ -416,7 +416,7 @@ glue::glue(" ``` -```{r, eval = !has_multiplex, results='asis'} +```{r, eval = !has_multiplex & has_clusters, results='asis'} glue::glue(" ## Unsupervised clustering @@ -448,7 +448,7 @@ plot_height <- calculate_plot_height( ``` -```{r, eval = !has_multiplex, fig.height = plot_height, fig.width = 8.5, warning = FALSE} +```{r, eval = !has_multiplex & has_clusters, fig.height = plot_height, fig.width = 8.5, warning = FALSE} jaccard_cluster_matrices |> create_heatmap_list( column_title = "Clusters", diff --git a/templates/qc_report/main_qc_report.rmd b/templates/qc_report/main_qc_report.rmd index f64c3536..039de0f7 100644 --- a/templates/qc_report/main_qc_report.rmd +++ b/templates/qc_report/main_qc_report.rmd @@ -117,6 +117,7 @@ if (has_cellhash) { # check for umap and celltypes, but need to be sure that processed_sce exists first if (has_processed) { has_umap <- "UMAP" %in% reducedDimNames(processed_sce) + has_clusters <- "cluster" %in% names(colData(processed_sce)) has_singler <- "singler" %in% metadata(processed_sce)$celltype_methods has_cellassign <- "cellassign" %in% metadata(processed_sce)$celltype_methods @@ -129,6 +130,7 @@ if (has_processed) { is_supplemental <- FALSE # this is not the celltype supp report } else { has_umap <- FALSE + has_clusters <- FALSE has_singler <- FALSE has_cellassign <- FALSE has_submitter <- FALSE From 1a7a28261574e7a9e66271ebeae1a713f2d8c209 Mon Sep 17 00:00:00 2001 From: Ally Hawkins <54039191+allyhawkins@users.noreply.github.com> Date: Wed, 24 Apr 2024 16:31:09 -0500 Subject: [PATCH 2/7] account for missing predictions --- bin/add_celltypes_to_sce.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/add_celltypes_to_sce.R b/bin/add_celltypes_to_sce.R index 53d4a667..ac32d200 100755 --- a/bin/add_celltypes_to_sce.R +++ b/bin/add_celltypes_to_sce.R @@ -191,13 +191,13 @@ if (!is.null(opt$cellassign_predictions)) { if (file.size(opt$cellassign_predictions) > 0) { predictions <- readr::read_tsv(opt$cellassign_predictions) } else { - # if it's empty, then sce could not be converted to anndata and cell assign was not run - sce$cellassign_celltype_annotation <- "Not run" + predictions <- NULL } - # if the only column is the barcode column then CellAssign didn't complete successfully + # if the only column is the barcode column or if the predictions file was empty + # then CellAssign didn't complete successfully # otherwise add in cell type annotations and metadata to SCE - if (all(colnames(predictions) == "barcode")) { + if (is.null(predictions) | all(colnames(predictions) == "barcode")) { # if failed then note that in the cell type column sce$cellassign_celltype_annotation <- "Not run" } else { From 8d5799f5ec286954c7dcb63d04035d73db0e4ff0 Mon Sep 17 00:00:00 2001 From: Ally Hawkins <54039191+allyhawkins@users.noreply.github.com> Date: Thu, 25 Apr 2024 08:38:36 -0500 Subject: [PATCH 3/7] move addition of has_clusters to correct report --- templates/qc_report/celltypes_supplemental_report.rmd | 1 + templates/qc_report/main_qc_report.rmd | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/templates/qc_report/celltypes_supplemental_report.rmd b/templates/qc_report/celltypes_supplemental_report.rmd index 022ad473..f0962c66 100644 --- a/templates/qc_report/celltypes_supplemental_report.rmd +++ b/templates/qc_report/celltypes_supplemental_report.rmd @@ -266,6 +266,7 @@ has_submitter <- "submitter" %in% metadata(processed_sce)$celltype_methods && # check for umap has_umap <- "UMAP" %in% reducedDimNames(processed_sce) +has_clusters <- "cluster" %in% names(colData(processed_sce)) # what celltypes are available? available_celltypes <- c( diff --git a/templates/qc_report/main_qc_report.rmd b/templates/qc_report/main_qc_report.rmd index 039de0f7..f64c3536 100644 --- a/templates/qc_report/main_qc_report.rmd +++ b/templates/qc_report/main_qc_report.rmd @@ -117,7 +117,6 @@ if (has_cellhash) { # check for umap and celltypes, but need to be sure that processed_sce exists first if (has_processed) { has_umap <- "UMAP" %in% reducedDimNames(processed_sce) - has_clusters <- "cluster" %in% names(colData(processed_sce)) has_singler <- "singler" %in% metadata(processed_sce)$celltype_methods has_cellassign <- "cellassign" %in% metadata(processed_sce)$celltype_methods @@ -130,7 +129,6 @@ if (has_processed) { is_supplemental <- FALSE # this is not the celltype supp report } else { has_umap <- FALSE - has_clusters <- FALSE has_singler <- FALSE has_cellassign <- FALSE has_submitter <- FALSE From 1ff240c7f1192256247f1fb69a94b6c6bf55df01 Mon Sep 17 00:00:00 2001 From: Ally Hawkins <54039191+allyhawkins@users.noreply.github.com> Date: Thu, 25 Apr 2024 09:28:40 -0500 Subject: [PATCH 4/7] put clusters definition into main report --- templates/qc_report/celltypes_supplemental_report.rmd | 2 +- templates/qc_report/main_qc_report.rmd | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/templates/qc_report/celltypes_supplemental_report.rmd b/templates/qc_report/celltypes_supplemental_report.rmd index f0962c66..4b1dc159 100644 --- a/templates/qc_report/celltypes_supplemental_report.rmd +++ b/templates/qc_report/celltypes_supplemental_report.rmd @@ -264,7 +264,7 @@ has_cellassign <- "cellassign" %in% metadata(processed_sce)$celltype_methods has_submitter <- "submitter" %in% metadata(processed_sce)$celltype_methods && !all(is.na(processed_sce$submitter_celltype_annotation)) # make sure they aren't all NA -# check for umap +# check for umap and clusters has_umap <- "UMAP" %in% reducedDimNames(processed_sce) has_clusters <- "cluster" %in% names(colData(processed_sce)) diff --git a/templates/qc_report/main_qc_report.rmd b/templates/qc_report/main_qc_report.rmd index f64c3536..aac47d8a 100644 --- a/templates/qc_report/main_qc_report.rmd +++ b/templates/qc_report/main_qc_report.rmd @@ -117,7 +117,7 @@ if (has_cellhash) { # check for umap and celltypes, but need to be sure that processed_sce exists first if (has_processed) { has_umap <- "UMAP" %in% reducedDimNames(processed_sce) - + has_clusters <- "cluster" %in% names(colData(processed_sce)) has_singler <- "singler" %in% metadata(processed_sce)$celltype_methods has_cellassign <- "cellassign" %in% metadata(processed_sce)$celltype_methods has_submitter <- "submitter" %in% metadata(processed_sce)$celltype_methods && @@ -129,6 +129,7 @@ if (has_processed) { is_supplemental <- FALSE # this is not the celltype supp report } else { has_umap <- FALSE + has_clusters <- FALSE has_singler <- FALSE has_cellassign <- FALSE has_submitter <- FALSE From 2d3d30fda0752d2aa998dbfa9e8365e97ab065e9 Mon Sep 17 00:00:00 2001 From: Ally Hawkins <54039191+allyhawkins@users.noreply.github.com> Date: Thu, 25 Apr 2024 10:03:35 -0500 Subject: [PATCH 5/7] make sure has_celltypes is in supplemental --- templates/qc_report/celltypes_supplemental_report.rmd | 3 +++ 1 file changed, 3 insertions(+) diff --git a/templates/qc_report/celltypes_supplemental_report.rmd b/templates/qc_report/celltypes_supplemental_report.rmd index 4b1dc159..03e3b3c0 100644 --- a/templates/qc_report/celltypes_supplemental_report.rmd +++ b/templates/qc_report/celltypes_supplemental_report.rmd @@ -264,6 +264,9 @@ has_cellassign <- "cellassign" %in% metadata(processed_sce)$celltype_methods has_submitter <- "submitter" %in% metadata(processed_sce)$celltype_methods && !all(is.na(processed_sce$submitter_celltype_annotation)) # make sure they aren't all NA +# If at least 1 is present, we have cell type annotations. +has_celltypes <- any(has_singler, has_cellassign, has_submitter) + # check for umap and clusters has_umap <- "UMAP" %in% reducedDimNames(processed_sce) has_clusters <- "cluster" %in% names(colData(processed_sce)) From c74328a41eba2b19fdb3992f374ba42424d48acf Mon Sep 17 00:00:00 2001 From: Ally Hawkins <54039191+allyhawkins@users.noreply.github.com> Date: Thu, 25 Apr 2024 10:38:15 -0500 Subject: [PATCH 6/7] only create supplemental if > 1 cell in object --- bin/sce_qc_report.R | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/bin/sce_qc_report.R b/bin/sce_qc_report.R index 3833c6fe..d7f4728c 100755 --- a/bin/sce_qc_report.R +++ b/bin/sce_qc_report.R @@ -285,17 +285,20 @@ if (opt$celltype_report_file != "") { stop("Supplemental cell types report template not found.") } - # render report - rmarkdown::render( - input = opt$celltype_report_template, - output_file = basename(opt$celltype_report_file), - output_dir = dirname(opt$celltype_report_file), - intermediates_dir = tempdir(), - knit_root_dir = tempdir(), - envir = new.env(), - params = list( - library = metadata_list$library_id, - processed_sce = processed_sce + # only render supplemental report if there's more than one cell + if (ncol(processed_sce) > 1) { + # render report + rmarkdown::render( + input = opt$celltype_report_template, + output_file = basename(opt$celltype_report_file), + output_dir = dirname(opt$celltype_report_file), + intermediates_dir = tempdir(), + knit_root_dir = tempdir(), + envir = new.env(), + params = list( + library = metadata_list$library_id, + processed_sce = processed_sce + ) ) - ) + } } From ca62f473e98c59d090c155979b624d9b6d01e1e9 Mon Sep 17 00:00:00 2001 From: Ally Hawkins <54039191+allyhawkins@users.noreply.github.com> Date: Thu, 25 Apr 2024 12:15:53 -0500 Subject: [PATCH 7/7] Apply suggestions from code review Co-authored-by: Joshua Shapiro --- bin/add_celltypes_to_sce.R | 2 +- templates/qc_report/celltypes_qc.rmd | 6 +++--- templates/qc_report/celltypes_supplemental_report.rmd | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/add_celltypes_to_sce.R b/bin/add_celltypes_to_sce.R index ac32d200..b837255c 100755 --- a/bin/add_celltypes_to_sce.R +++ b/bin/add_celltypes_to_sce.R @@ -197,7 +197,7 @@ if (!is.null(opt$cellassign_predictions)) { # if the only column is the barcode column or if the predictions file was empty # then CellAssign didn't complete successfully # otherwise add in cell type annotations and metadata to SCE - if (is.null(predictions) | all(colnames(predictions) == "barcode")) { + if (is.null(predictions) || all(colnames(predictions) == "barcode")) { # if failed then note that in the cell type column sce$cellassign_celltype_annotation <- "Not run" } else { diff --git a/templates/qc_report/celltypes_qc.rmd b/templates/qc_report/celltypes_qc.rmd index 93288aa4..07a4e1da 100644 --- a/templates/qc_report/celltypes_qc.rmd +++ b/templates/qc_report/celltypes_qc.rmd @@ -370,7 +370,7 @@ create_celltype_n_table(celltype_df, cellassign_celltype_annotation) |> ``` -```{r, eval = has_umap & has_clusters} +```{r, eval = has_umap && has_clusters} knitr::asis_output(glue::glue(" ## UMAPs @@ -398,7 +398,7 @@ glue::glue(" ``` -```{r eval = has_umap & has_clusters, message=FALSE, warning=FALSE} +```{r eval = has_umap && has_clusters, message=FALSE, warning=FALSE} clusters_plot <- plot_umap( umap_df, cluster, @@ -418,7 +418,7 @@ if (length(levels(umap_df$cluster)) <= 8) { ``` -```{r, eval = has_umap & has_celltypes} +```{r, eval = has_umap && has_celltypes} knitr::asis_output( 'Next, we show UMAPs colored by cell types. For each cell typing method, we show a separate faceted UMAP. diff --git a/templates/qc_report/celltypes_supplemental_report.rmd b/templates/qc_report/celltypes_supplemental_report.rmd index 03e3b3c0..c5b5ea9d 100644 --- a/templates/qc_report/celltypes_supplemental_report.rmd +++ b/templates/qc_report/celltypes_supplemental_report.rmd @@ -420,7 +420,7 @@ glue::glue(" ``` -```{r, eval = !has_multiplex & has_clusters, results='asis'} +```{r, eval = !has_multiplex && has_clusters, results='asis'} glue::glue(" ## Unsupervised clustering @@ -452,7 +452,7 @@ plot_height <- calculate_plot_height( ``` -```{r, eval = !has_multiplex & has_clusters, fig.height = plot_height, fig.width = 8.5, warning = FALSE} +```{r, eval = !has_multiplex && has_clusters, fig.height = plot_height, fig.width = 8.5, warning = FALSE} jaccard_cluster_matrices |> create_heatmap_list( column_title = "Clusters",