Plot the phenotype severity scores (generated by GPT-4) aggregated by the cell types each phenotype is significantly associated with.

plot_celltype_severity(
  results,
  cl = get_cl(),
  q_threshold = 0.05,
  run_enrichment = TRUE,
  top_n = 3,
  types = c("dot", "bar")[1],
  run_prune_ancestors = FALSE,
  nonsig_fill = ggplot2::alpha("grey90", 0.001),
  force_new = FALSE,
  base_size = 8,
  save_path = tempfile(fileext = ".rds"),
  workers = 1
)

Arguments

results

The cell type-phenotype enrichment results generated by gen_results and merged together with merge_results

cl

Cell Ontology (CL) object from KGExplorer::get_ontology("cl").

q_threshold

The q value threshold to subset the results by.

run_enrichment

Instead of simply taking the top N results, run a series of one-sided Wilcoxan rank-sum tests to determine whether the distribution of ordinal severity values (never=0, rarely=1, often=2, always=3) are significantly different between a given cell type and all other cell types. Tests are repeated across each GPT annotation separately using group_by and wilcox_test.

top_n

Top and bottom number of cell types to show per annotation (used in dot plot only).

types

Which types of plots of create.

run_prune_ancestors

Prune redundant ancestral terms if any of their descendants are present. Passes to prune_ancestors.

nonsig_fill

Fill colour for non-significant results.

force_new

Run a new set of enrichment tests even when cached results are found. Only used when run_enrichment=FALSE.

base_size

base font size, given in pts.

save_path

Path to save results to.

workers

Number (>1) or proportion (<1) of worker cores to use.

Value

Named list of ggplot and data.table objects.

Examples

set.seed(2025)
results <- load_example_results()
results <- results[sample(seq(nrow(results)), 5000),]
out <- plot_celltype_severity(results, types=c("bar","dot"))
#> Mapping cell types to cell ontology terms.
#> Adding stage information.
#> Translating ontology terms to ids.
#> Reading cached RDS file: phenotype_to_genes.txt
#> + Version: v2025-05-06
#> 151 phenotypes do not have matching HPO IDs.
#> Reading in GPT annotations for 16,982 phenotypes.
#> Creating bar plot.
#> Creating dot plot.
#> 1 core(s) assigned as workers (3 reserved).
#> Running Wilcoxon rank-sum tests:
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |=                                                                     |   2%
  |                                                                            
  |==                                                                    |   4%
  |                                                                            
  |====                                                                  |   5%
  |                                                                            
  |=====                                                                 |   7%
  |                                                                            
  |======                                                                |   9%
  |                                                                            
  |========                                                              |  11%
  |                                                                            
  |=========                                                             |  12%
  |                                                                            
  |==========                                                            |  14%
  |                                                                            
  |===========                                                           |  16%
  |                                                                            
  |============                                                          |  18%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |===============                                                       |  21%
  |                                                                            
  |================                                                      |  23%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |===================                                                   |  27%
  |                                                                            
  |====================                                                  |  29%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |======================                                                |  32%
  |                                                                            
  |========================                                              |  34%
  |                                                                            
  |=========================                                             |  36%
  |                                                                            
  |==========================                                            |  38%
  |                                                                            
  |============================                                          |  39%
  |                                                                            
  |=============================                                         |  41%
  |                                                                            
  |==============================                                        |  43%
  |                                                                            
  |===============================                                       |  45%
  |                                                                            
  |================================                                      |  46%
  |                                                                            
  |==================================                                    |  48%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |====================================                                  |  52%
  |                                                                            
  |======================================                                |  54%
  |                                                                            
  |=======================================                               |  55%
  |                                                                            
  |========================================                              |  57%
  |                                                                            
  |=========================================                             |  59%
  |                                                                            
  |==========================================                            |  61%
  |                                                                            
  |============================================                          |  62%
  |                                                                            
  |=============================================                         |  64%
  |                                                                            
  |==============================================                        |  66%
  |                                                                            
  |================================================                      |  68%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |==================================================                    |  71%
  |                                                                            
  |===================================================                   |  73%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |======================================================                |  77%
  |                                                                            
  |=======================================================               |  79%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |==========================================================            |  82%
  |                                                                            
  |===========================================================           |  84%
  |                                                                            
  |============================================================          |  86%
  |                                                                            
  |=============================================================         |  88%
  |                                                                            
  |==============================================================        |  89%
  |                                                                            
  |================================================================      |  91%
  |                                                                            
  |=================================================================     |  93%
  |                                                                            
  |==================================================================    |  95%
  |                                                                            
  |====================================================================  |  96%
  |                                                                            
  |===================================================================== |  98%
  |                                                                            
  |======================================================================| 100%
#> 
#> Caching Wilcoxon rank-sum test results: /tmp/RtmpsW0tFt/file100e527c6380.rds