From 82b46b609698adeee96635b2e5260382c8a29c2e Mon Sep 17 00:00:00 2001 From: "Brian M. Schilder" <34280215+bschilder@users.noreply.github.com> Date: Mon, 6 May 2024 13:57:44 +0100 Subject: [PATCH] Fix plot_bar_dendro_facets --- DESCRIPTION | 2 +- NEWS.md | 8 ++++++++ R/add_logfc.R | 4 ++-- R/plot_bar_dendro.R | 5 ++++- R/plot_bar_dendro_facets.R | 11 ++++++++--- man/plot_bar_dendro.Rd | 3 +++ man/plot_bar_dendro_facets.Rd | 4 ++++ 7 files changed, 30 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1629625..b9931d2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: MSTExplorer Title: Multi-Scale Target Explorer -Version: 1.0.0 +Version: 1.0.1 Authors@R: c( person(given = "Brian", diff --git a/NEWS.md b/NEWS.md index 9cce88d..f9151a6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,11 @@ +# MSTExplorer 1.0.1 + +## Bug fixes + +* `plot_bar_dendro_facets` + - Add `hpo` arg to pass HPO directly. + - Fix `data_summary` so that denominator is the number of on-target cell types only. + # MSTExplorer 1.0.0 ## New features diff --git a/R/add_logfc.R b/R/add_logfc.R index 1b7c860..1d5027a 100644 --- a/R/add_logfc.R +++ b/R/add_logfc.R @@ -16,8 +16,8 @@ add_logfc <- function(results, messager("Adding logFC column.") # results[,logFC:=log10(scales::rescale(estimate,c(.Machine$double.xmin, 1)))] # results[,logFC:=logFC/mean(results$logFC)] - results[,logFC:=get(effect_var)+abs(min(get(effect_var)))] - results[,logFC:=log2(logFC/mean(results$logFC))] + results[,logFC:=(get(effect_var)+abs(min(get(effect_var))))] + results[,logFC:=(log2(logFC/mean(results$logFC)))] # hist(results$logFC) } else { messager("logFC already exists in results.", diff --git a/R/plot_bar_dendro.R b/R/plot_bar_dendro.R index 87fb0e8..87cb184 100644 --- a/R/plot_bar_dendro.R +++ b/R/plot_bar_dendro.R @@ -16,6 +16,8 @@ #' denoted by "*" above its bar. #' @param expand_dendro_x Passed to \link[ggplot2]{scale_x_discrete} #' in the cell type dendrogram. +#' @param cl Cell Ontology (CL) object from +#' \code{KGExplorer::get_ontology("cl")}. #' @inheritParams plot_ #' @inheritParams ggnetwork_plot_full #' @inheritParams HPOExplorer::add_ancestor @@ -133,7 +135,8 @@ plot_bar_dendro <- function(results = load_example_results(), color_vector=color_vector, legend.position=legend.position, q_threshold=q_threshold, - facets=facets) + facets=facets, + hpo=hpo) ggbars <- ggbars_out$plot #### Create dendrogram plot #### ggdend <- diff --git a/R/plot_bar_dendro_facets.R b/R/plot_bar_dendro_facets.R index 96ab696..06eaf9d 100644 --- a/R/plot_bar_dendro_facets.R +++ b/R/plot_bar_dendro_facets.R @@ -49,6 +49,7 @@ #' background_full=FALSE) plot_bar_dendro_facets <- function(results = load_example_results(), results_full = NULL, + hpo=HPOExplorer::get_hpo(), target_branches = get_target_branches(), keep_ancestors = names(target_branches), target_celltypes = get_target_celltypes( @@ -98,18 +99,21 @@ plot_bar_dendro_facets <- function(results = load_example_results(), } results <- HPOExplorer::add_ancestor(results, lvl = lvl, + hpo=hpo, force_new = TRUE) results[, phenotypes_per_ancestor:=data.table::uniqueN(hpo_id), by=c("ancestor","ancestor_name")] } if("hpo_name" %in% c(fill_var,facets)){ - results <- HPOExplorer::add_hpo_name(results) + results <- HPOExplorer::add_hpo_name(results, + hpo=hpo) } #### Create filtered dataset for plotting #### { if(!is.null(keep_ancestors) && "hpo_name" %in% names(results)){ dat <- HPOExplorer::filter_descendants(phenos = results, + hpo = hpo, keep_descendants = keep_ancestors) } else { dat <- data.table::copy(results) @@ -117,6 +121,7 @@ plot_bar_dendro_facets <- function(results = load_example_results(), if(nrow(dat)==0) stopper("0 associations remaining.") if(!is.null(keep_ont_levels) || "ontLvl" %in% c(facets,cols)){ dat <- HPOExplorer::add_ont_lvl(dat, + hpo=hpo, keep_ont_levels = keep_ont_levels) } if(!is.null(target_branches_keep)){ @@ -172,8 +177,8 @@ plot_bar_dendro_facets <- function(results = load_example_results(), data_summary <- dat[,list( target_celltypes=paste(target_branches[[ancestor_name]],collapse = "/"), phenotypes_per_ancestor=unique(phenotypes_per_ancestor), - n_celltypes=data.table::uniqueN(cl_name), - n_celltypes_sig=data.table::uniqueN(cl_name[p.value.adj<0.05]) + n_celltypes=data.table::uniqueN(cl_name[term=="is_targetTRUE"]), + n_celltypes_sig=data.table::uniqueN(cl_name[term=="is_targetTRUE" & p.value.adj<0.05]) ), by=c("ancestor_name")] } diff --git a/man/plot_bar_dendro.Rd b/man/plot_bar_dendro.Rd index c5117f7..abdc8dd 100644 --- a/man/plot_bar_dendro.Rd +++ b/man/plot_bar_dendro.Rd @@ -41,6 +41,9 @@ correspond to on-target cell types across the two ontologies.} \item{hpo}{Human Phenotype Ontology object, loaded from \link[KGExplorer]{get_ontology}.} +\item{cl}{Cell Ontology (CL) object from +\code{KGExplorer::get_ontology("cl")}.} + \item{facets}{A set of variables or expressions quoted by \code{\link[ggplot2:vars]{vars()}} and defining faceting groups on the rows or columns dimension. The variables can be named (the names are passed to \code{labeller}). diff --git a/man/plot_bar_dendro_facets.Rd b/man/plot_bar_dendro_facets.Rd index a18ca93..0054a5a 100644 --- a/man/plot_bar_dendro_facets.Rd +++ b/man/plot_bar_dendro_facets.Rd @@ -7,6 +7,7 @@ plot_bar_dendro_facets( results = load_example_results(), results_full = NULL, + hpo = HPOExplorer::get_hpo(), target_branches = get_target_branches(), keep_ancestors = names(target_branches), target_celltypes = get_target_celltypes(target_branches = target_branches), @@ -45,6 +46,9 @@ and merged together with \link[MSTExplorer]{merge_results}} plotting in \code{results}) to be used as a background during proportional enrichment testing.} +\item{hpo}{Human Phenotype Ontology object, +loaded from \link[KGExplorer]{get_ontology}.} + \item{target_branches}{A named list of HPO branches each matched with CL cell type branches that correspond to on-target cell types across the two ontologies.}