Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs for dealing with processed objects with only 1 cell #755

Merged
merged 7 commits into from
Apr 25, 2024
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
8 changes: 4 additions & 4 deletions bin/add_celltypes_to_sce.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 15 additions & 12 deletions bin/sce_qc_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
)
}
}
10 changes: 5 additions & 5 deletions templates/qc_report/celltypes_qc.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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

Expand All @@ -388,7 +388,7 @@ umap_df <- lump_wrap_celltypes(celltype_df)

<!-- First UMAP: clusters -->

```{r, eval = has_umap && has_multiplex, results='asis'}
```{r, eval = has_umap && has_multiplex && has_clusters, results='asis'}
glue::glue("
<div class=\"alert alert-info\">
This library contains multiple samples that have not been batch-corrected, which may confound clustering assignments.
Expand All @@ -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,
Expand All @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions templates/qc_report/celltypes_supplemental_report.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,12 @@ 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
# 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))

# what celltypes are available?
available_celltypes <- c(
Expand Down Expand Up @@ -416,7 +420,7 @@ glue::glue("
```

<!-- If not multiplexed, show the header, text, and heatmap -->
```{r, eval = !has_multiplex, results='asis'}
```{r, eval = !has_multiplex && has_clusters, results='asis'}
glue::glue("
## Unsupervised clustering

Expand Down Expand Up @@ -448,7 +452,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",
Expand Down
3 changes: 2 additions & 1 deletion templates/qc_report/main_qc_report.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -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
Expand Down
Loading