From 9dd94755b9e1213b80825b00aeb15e3777305409 Mon Sep 17 00:00:00 2001 From: Ally Hawkins Date: Thu, 12 Dec 2024 14:46:37 -0600 Subject: [PATCH 1/2] fix join error with cluster column --- analyses/cell-type-ewings/scripts/utils/clustering-functions.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analyses/cell-type-ewings/scripts/utils/clustering-functions.R b/analyses/cell-type-ewings/scripts/utils/clustering-functions.R index 5c0f01bfb..3df5dd415 100644 --- a/analyses/cell-type-ewings/scripts/utils/clustering-functions.R +++ b/analyses/cell-type-ewings/scripts/utils/clustering-functions.R @@ -56,7 +56,7 @@ get_cluster_stats <- function(sce, return(stats_df) }) |> dplyr::bind_rows(.id = "cluster_params") |> - dplyr::left_join(all_cluster_results, by = c("cell_id", "cluster_params")) + dplyr::left_join(all_cluster_results, by = c("cell_id", "cluster_params", "cluster")) return(all_stats_df) } From 5e7f4ccd82277444cc1aaa56725a61115b3879f2 Mon Sep 17 00:00:00 2001 From: Ally Hawkins Date: Thu, 12 Dec 2024 14:46:47 -0600 Subject: [PATCH 2/2] add table with number of clusters --- .../01-clustering-metrics.Rmd | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/analyses/cell-type-ewings/template_notebooks/clustering-workflow/01-clustering-metrics.Rmd b/analyses/cell-type-ewings/template_notebooks/clustering-workflow/01-clustering-metrics.Rmd index 49be4bf2c..84d4c1447 100644 --- a/analyses/cell-type-ewings/template_notebooks/clustering-workflow/01-clustering-metrics.Rmd +++ b/analyses/cell-type-ewings/template_notebooks/clustering-workflow/01-clustering-metrics.Rmd @@ -149,6 +149,21 @@ all_stats <- split_umap_df |> purrr::map(\(df) {get_cluster_stats(sce,df)}) ``` +Before we show any statistics, we will first show the number of clusters for each set of parameters. +For any cases where we only see 1 cluster, no distributions will be shown in the plots. + +```{r} +all_stats |> + purrr::imap(\(df, method){ + df |> + dplyr::select(resolution, nn, cluster) |> + dplyr::group_by(resolution, nn) |> + dplyr::summarise(num_of_clusters = length(unique(cluster))) |> + knitr::kable() + }) +``` + + ### Silhouette width ```{r} @@ -169,17 +184,17 @@ all_stats |> ```{r, warning=FALSE, message=FALSE} # calculate cluster stability -stability_stats <- split_umap_df |> +stability_stats <- split_umap_df |> purrr::map(\(df){ get_cluster_stability(sce, df, params$threads)}) ``` ```{r, warning=FALSE, message=FALSE} # plot stability across all parameters -stability_stats |> +stability_stats |> purrr::imap(\(df, cluster_method){ - - + + # plot stability across all values of k ggplot(df, aes(x = nn, y = ari)) + geom_jitter(width = 0.1) + @@ -198,8 +213,8 @@ stability_stats |> quantile(x, 0.75) } ) - - + + }) ```