Skip to content

Commit

Permalink
Fix plot_bar_dendro_facets
Browse files Browse the repository at this point in the history
  • Loading branch information
bschilder committed May 6, 2024
1 parent 0b25e4d commit 82b46b6
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions R/add_logfc.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
5 changes: 4 additions & 1 deletion R/plot_bar_dendro.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <-
Expand Down
11 changes: 8 additions & 3 deletions R/plot_bar_dendro_facets.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -98,25 +99,29 @@ 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)
}
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)){
Expand Down Expand Up @@ -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")]
}
Expand Down
3 changes: 3 additions & 0 deletions man/plot_bar_dendro.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/plot_bar_dendro_facets.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 82b46b6

Please sign in to comment.