1414# ' a given cell type and all other cell types.
1515# ' Tests are repeated across each GPT annotation separately using
1616# ' \link[dplyr]{group_by} and \link[rstatix]{wilcox_test}.
17+ # ' @param nonsig_fill Fill colour for non-significant results.
1718# ' @inheritParams prioritise_targets
1819# ' @inheritParams plot_bar_dendro
1920# ' @inheritParams ggplot2::theme_bw
21+ # ' @inheritParams KGExplorer::set_cores
2022# ' @returns Named list of ggplot and data.table objects.
2123# '
2224# ' @export
@@ -35,7 +37,8 @@ plot_celltype_severity <- function(results,
3537 nonsig_fill = ggplot2 :: alpha(" grey90" ,.001 ),
3638 force_new = FALSE ,
3739 base_size = 8 ,
38- save_path = tempfile(fileext = " .rds" )){
40+ save_path = tempfile(fileext = " .rds" ),
41+ workers = 1 ){
3942
4043 requireNamespace(" ggplot2" )
4144 severity_score_gpt <- cl_name <- cl_id <- value <- variable <- p <- FDR <-
@@ -111,14 +114,23 @@ plot_celltype_severity <- function(results,
111114 wt_res <- readRDS(save_path )
112115 } else {
113116 # # Run new tests
114- BPPARAM <- KGExplorer :: set_cores()
117+ BPPARAM <- KGExplorer :: set_cores(workers = workers )
115118 messager(" Running Wilcoxon rank-sum tests:" )
116119 wt_res <- BiocParallel :: bplapply(
117120 unique(agg_gpt $ cl_id ),
118121 function (ct ){
119122 # messager("Running Wilcoxon rank-sum test:",ct)
120123 tmp <- agg_gpt [,group : = cl_id == ct ][,value : = as.numeric(value )]
121- tmp [! is.na(value )]| >
124+ tmp <- tmp [! is.na(value )]
125+ # Remove groups there's not enough samples to run tests on
126+ tmp [,n_samples : = data.table :: uniqueN(value ), by = variable ]
127+ tmp [,n_groups : = data.table :: uniqueN(group ), by = variable ]
128+ tmp <- tmp [n_samples > = 2 & n_groups > = 2 ]
129+ if (nrow(tmp ) == 0 ) {
130+ return (NULL )
131+ }
132+
133+ tmp | >
122134 dplyr :: group_by(variable )| >
123135 rstatix :: wilcox_test(value ~ group ,
124136 ref.group = " FALSE" ,
0 commit comments