diff --git a/.github/workflows/rworkflows.yml b/.github/workflows/rworkflows.yml index e48f867..75a40a5 100644 --- a/.github/workflows/rworkflows.yml +++ b/.github/workflows/rworkflows.yml @@ -38,7 +38,7 @@ jobs: cont: ~ rspm: ~ steps: - - uses: neurogenomics/rworkflows@dev + - uses: neurogenomics/rworkflows@master with: run_bioccheck: ${{ false }} run_rcmdcheck: ${{ true }} diff --git a/DESCRIPTION b/DESCRIPTION index c6b653a..41c71aa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: MSTExplorer Title: Multi-Scale Target Explorer -Version: 1.0.4 +Version: 1.0.6 Authors@R: c( person(given = "Brian", @@ -54,7 +54,8 @@ Imports: future, furrr, tidygraph, - rstatix + rstatix, + simona Suggests: rmarkdown, knitr, diff --git a/NEWS.md b/NEWS.md index a7c2538..89f1cc3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,52 @@ +# MSTExplorer 1.0.6 + +## Bug fixes +* `get_color_map` + - Fix `color_vector` assignment. + +# MSTExplorer 1.0.5 + +## Bug fixes + +* Tests + - Use `force_new=TRUE` where some tests occasionally fail with cached + files. + - `test-load_example_results`: Update test files. + - `test-prioritise_targets`: Remove unused arguments and change input size. + - `test-prioritise_targets_network`: Process `top_targets` to include effect + - `test-plot_differential_outcomes`: Use non-specific plot name in + `patchwork::wrap_plots`. + - `test-plot_differential_outcomes`: Wrap p3 in `expect_error` to prevent + test failure even if error was handled. + - `test-report_plot`: Fix detection for ggplot object. + variable. +* Vignettes + - `MSTExplorer`: Update effect variable to `fold_change`. +* `add_logfc` + - Return `results` with new column rather than directly modifying the original + input. + - Update references (`add_logfc(results)` -> `results <- add_logfc(results)`). +* `ttd_check`, `plot_differential_outcomes`, `prioritise_targets_grid` + - Add check for `disease_name` column before executing + `HPOExplorer::add_disease` on input. +* `plot_ttd` + - Remove `fill` aesthetic for `geom_text` (doesn't exist anymore). +* `extract_help` + - [DEVELOPEMENT ONLY] Look for help docs only in legitimate pkg installation + paths. +* `subset_results` + - Add new `effect_var` argument. + - Adjust default `effect_threshold` to 0.1. +* `add_symptom_results` + - Only merge `results` and `phenotypes_to_genes` if required (prevents + column duplicates with altered names). +* `map_tissue` + - Rewrite merge logic to fix error: attempt to replicate non-vector. +* `test_target_celltypes` + - Uncomment `add_ancestors(results)` to ensure required ancestor columns are + present. +* Add missing import: simona + # MSTExplorer 1.0.4 ## New features diff --git a/R/add_logfc.R b/R/add_logfc.R index 1d5027a..63688b8 100644 --- a/R/add_logfc.R +++ b/R/add_logfc.R @@ -14,13 +14,12 @@ add_logfc <- function(results, logFC <- NULL; if(!"logFC" %in% names(results) || isTRUE(force_new)){ 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)))] - # hist(results$logFC) + results$logFC <- results[[effect_var]]+abs(min(results[[effect_var]])) + results$logFC <- log2(results$logFC/mean(results$logFC)) + return(results) } else { messager("logFC already exists in results.", "Use `force_new=TRUE` to overwrite.") + return(results) } } diff --git a/R/add_symptom_results.R b/R/add_symptom_results.R index 880136a..5c43c20 100644 --- a/R/add_symptom_results.R +++ b/R/add_symptom_results.R @@ -16,8 +16,8 @@ #' #' @export #' @examples -#' results = load_example_results()[seq(5000)] -#' results <- add_symptom_results() +#' results <- load_example_results()[seq(5000)] +#' results <- add_symptom_results(results) add_symptom_results <- function(results = load_example_results(), q_threshold = 0.05, effect_threshold = NULL, @@ -57,13 +57,19 @@ add_symptom_results <- function(results = load_example_results(), results <- HPOExplorer::add_genes(results, phenotype_to_genes = phenotype_to_genes, allow.cartesian = TRUE) - results_annot <- data.table::merge.data.table( - results, - unique(phenotype_to_genes[,c("hpo_id","disease_id", - "n_genes_hpo_id", - "n_genes_disease_id", - "n_genes_symptom")]), - by=c("hpo_id","disease_id")) + merge_cols <- c("hpo_id", + "disease_id", + "n_genes_hpo_id", + "n_genes_disease_id", + "n_genes_symptom") + if(all(merge_cols %in% colnames(results))){ + results_annot <- results + }else{ + results_annot <- data.table::merge.data.table( + results, + unique(phenotype_to_genes[,..merge_cols]), + by=c("hpo_id","disease_id")) + } #### Add genes that intersect between the phenos <- add_driver_genes(results = results_annot, ctd_list = ctd_list, diff --git a/R/extract_help.R b/R/extract_help.R index 422822b..dc06f9d 100644 --- a/R/extract_help.R +++ b/R/extract_help.R @@ -14,7 +14,7 @@ extract_help <- function(pkg, requireNamespace("tools") to <- match.arg(to) - rdbfile <- file.path(find.package(pkg), "help", pkg) + rdbfile <- file.path(find.package(pkg, lib.loc = .libPaths()), "help", pkg) fetchRdDB <- utils::getFromNamespace("fetchRdDB","tools") rdb <- fetchRdDB(rdbfile, key = fn) convertor <- switch(to, diff --git a/R/get_color_map.R b/R/get_color_map.R index cc2c393..82999c5 100644 --- a/R/get_color_map.R +++ b/R/get_color_map.R @@ -14,7 +14,7 @@ get_color_map <- function(dat, if(!is.null(celltype_col_order)){ dat2 <- dat2[order(match(dat2[[celltype_col]],celltype_col_order)),] } - dat2[,ancestor_color:=color_map[top_ancestor_name]] + dat2$ancestor_color<-color_map[dat2[[columns]]] color_vector <- dat2$ancestor_color return(list( color_map=color_map, diff --git a/R/map_tissue.R b/R/map_tissue.R index 6d4295b..6709c66 100644 --- a/R/map_tissue.R +++ b/R/map_tissue.R @@ -47,12 +47,15 @@ map_tissue <- function(results = NULL, by=by] #### Get the ancestor for each tissue ##### if(!isFALSE(lvl)){ + ancestor_dat <- data.frame(uberon@elementMetadata@listData) |> + dplyr::select(id,ancestor,ancestor_name) |> + dplyr::rename( + uberon_id = id, + uberon_ancestor = ancestor, + uberon_ancestor_name = ancestor_name + ) map_agg2 <- merge(map_agg, - data.table::data.table( - uberon@elementMetadata - )[,list(uberon_id=id, - uberon_ancestor=ancestor, - uberon_ancestor_name=ancestor_name)], + ancestor_dat, all.x=TRUE, by.x="top_uberon_id", by.y="uberon_id") diff --git a/R/plot_bar_dendro.R b/R/plot_bar_dendro.R index 1a7816a..2ab27b9 100644 --- a/R/plot_bar_dendro.R +++ b/R/plot_bar_dendro.R @@ -87,7 +87,7 @@ plot_bar_dendro <- function(results = load_example_results(), } #### Filter the results #### by <- unique(c(celltype_col,"cl_id","ancestor","ancestor_name")) - add_logfc(results) + results <- add_logfc(results) dat <- results[q - data.table::melt.data.table( - id.vars=c("hpo_id","hpo_name","severity_class","p"), - measure.vars=unique(c(label_cols,"gene_symbol"))) + dt2, by="hpo_name", sort=FALSE) + # Check for disease_name + if("disease_name" %in% label_cols && !"disease_name" %in% names(dat)){ + dat <- HPOExplorer::add_disease(dat, add_descriptions = TRUE) + } + dat <- data.table::melt.data.table(dat, + id.vars=c("hpo_id","hpo_name","severity_class","p"), + measure.vars=unique(c(label_cols,"gene_symbol"))) dat[,hpo_name:=factor(hpo_name, levels=rev(levels(dt1$hpo_name)), ordered=TRUE)] dat[startsWith(value,"GRANULOMATOUS"), value:=stringr::str_to_title(value)] diff --git a/R/prioritise_targets_network.R b/R/prioritise_targets_network.R index 6c56b21..23ea341 100644 --- a/R/prioritise_targets_network.R +++ b/R/prioritise_targets_network.R @@ -88,7 +88,7 @@ prioritise_targets_network <- function(top_targets, requireNamespace("ggplot2") requireNamespace("pals") - add_logfc(top_targets) + top_targets <- add_logfc(top_targets) if(any(c("cl_name","cl_id") %in% vertex_vars)){ map_celltype(top_targets) } diff --git a/R/subset_results.R b/R/subset_results.R index 23f48bb..c340f6d 100644 --- a/R/subset_results.R +++ b/R/subset_results.R @@ -4,6 +4,7 @@ #' @inheritParams ggnetwork_plot_full #' @inheritParams KGExplorer::filter_dt #' @inheritParams HPOExplorer::make_phenos_dataframe +#' @inheritParams add_logfc #' @returns A data frame of the selected subset of RD EWCE results #' with HPO ID column added. #' @@ -13,7 +14,8 @@ subset_results <- function(filters = list(cl_name=NULL), results = load_example_results(), q_threshold = 0.0005, - effect_threshold = 1, + effect_threshold = 0.1, + effect_var = "fold_change", verbose = TRUE){ effect <- hpo_id <- hpo_id <- NULL; @@ -24,7 +26,7 @@ subset_results <- function(filters = list(cl_name=NULL), results_sig <- results_sig[qeffect_threshold] + results_sig <- results_sig[results_sig[[effect_var]]>effect_threshold,] } #### Check that celltype is available #### if(nrow(results_sig)==0){ diff --git a/R/test_target_celltypes.R b/R/test_target_celltypes.R index 6d4646b..d082aad 100644 --- a/R/test_target_celltypes.R +++ b/R/test_target_celltypes.R @@ -40,7 +40,7 @@ test_target_celltypes <- function(results=load_example_results(), ancestor_name <- is_sig <- is_target <- valid <- cl_id <- NULL; method <- match.arg(method) - # results <- HPOExplorer::add_ancestor(results) + results <- HPOExplorer::add_ancestor(results) results <- map_celltype(results) results[,is_sig:=q
[![License: GPL-3](https://img.shields.io/badge/license-GPL--3-blue.svg)](https://cran.r-project.org/web/licenses/GPL-3) -[![](https://img.shields.io/badge/devel%20version-1.0.4-black.svg)](https://github.com/neurogenomics/MSTExplorer) +[![](https://img.shields.io/badge/devel%20version-1.0.6-black.svg)](https://github.com/neurogenomics/MSTExplorer) [![](https://img.shields.io/github/languages/code-size/neurogenomics/MSTExplorer.svg)](https://github.com/neurogenomics/MSTExplorer) [![](https://img.shields.io/github/last-commit/neurogenomics/MSTExplorer.svg)](https://github.com/neurogenomics/MSTExplorer/commits/master)
[![R build diff --git a/man/add_symptom_results.Rd b/man/add_symptom_results.Rd index 3dcb99d..269483f 100644 --- a/man/add_symptom_results.Rd +++ b/man/add_symptom_results.Rd @@ -58,6 +58,6 @@ via a specific disease) and the driver genes Add symptom results to the results data.table. } \examples{ -results = load_example_results()[seq(5000)] -results <- add_symptom_results() +results <- load_example_results()[seq(5000)] +results <- add_symptom_results(results) } diff --git a/man/ewce_para.Rd b/man/ewce_para.Rd index e39ae22..f67d6fb 100644 --- a/man/ewce_para.Rd +++ b/man/ewce_para.Rd @@ -106,10 +106,42 @@ cell type.} (passed to \link[stats]{p.adjust}).} \item{\code{sort_results}}{Sort enrichment results from smallest to largest p-values.} + \item{\code{standardise_sct_data}}{Should \code{sct_data} be standardised? +if \code{TRUE}: +\itemize{ +\item{When \code{sctSpecies!=output_species} + the \code{sct_data} will be checked for object formatting and + the genes will be converted to the orthologs of the \code{output_species} + with \link[EWCE]{standardise_ctd} + (which calls \link[orthogene]{map_genes} internally). +} +\item{When \code{sctSpecies==output_species}, + the \code{sct_data} will be checked for object formatting + with \link[EWCE]{standardise_ctd}, but the gene names + will remain untouched. + } +}} + \item{\code{standardise_hits}}{Should \code{hits} be standardised? +If \code{TRUE}: +\itemize{ +\item{When \code{genelistSpecies!=output_species}, + the genes will be converted to the orthologs of the \code{output_species} + with \link[orthogene]{convert_orthologs}. + } +\item{When \code{genelistSpecies==output_species}, + the genes will be standardised with \link[orthogene]{map_genes}. + } +} +If \code{FALSE}, \code{hits} will be passed on to subsequent steps as-is.} \item{\code{localHub}}{If working offline, add argument localHub=TRUE to work with a local, non-updated hub; It will only have resources available that have previously been downloaded. If offline, Please also see BiocManager vignette section on offline use to ensure proper functionality.} + \item{\code{store_gene_data}}{Store sampled gene data for every bootstrap iteration. +When the number of bootstrap \code{reps} is very high (>=100k) and/or + the number of genes in \code{hits} is very high, you may want + to set \code{store_gene_data=FALSE} to avoid using excessive amounts of + CPU memory.} }} } \value{ diff --git a/man/gen_results.Rd b/man/gen_results.Rd index a06f368..688ca5c 100644 --- a/man/gen_results.Rd +++ b/man/gen_results.Rd @@ -109,10 +109,42 @@ cell type.} (passed to \link[stats]{p.adjust}).} \item{\code{sort_results}}{Sort enrichment results from smallest to largest p-values.} + \item{\code{standardise_sct_data}}{Should \code{sct_data} be standardised? +if \code{TRUE}: +\itemize{ +\item{When \code{sctSpecies!=output_species} + the \code{sct_data} will be checked for object formatting and + the genes will be converted to the orthologs of the \code{output_species} + with \link[EWCE]{standardise_ctd} + (which calls \link[orthogene]{map_genes} internally). +} +\item{When \code{sctSpecies==output_species}, + the \code{sct_data} will be checked for object formatting + with \link[EWCE]{standardise_ctd}, but the gene names + will remain untouched. + } +}} + \item{\code{standardise_hits}}{Should \code{hits} be standardised? +If \code{TRUE}: +\itemize{ +\item{When \code{genelistSpecies!=output_species}, + the genes will be converted to the orthologs of the \code{output_species} + with \link[orthogene]{convert_orthologs}. + } +\item{When \code{genelistSpecies==output_species}, + the genes will be standardised with \link[orthogene]{map_genes}. + } +} +If \code{FALSE}, \code{hits} will be passed on to subsequent steps as-is.} \item{\code{localHub}}{If working offline, add argument localHub=TRUE to work with a local, non-updated hub; It will only have resources available that have previously been downloaded. If offline, Please also see BiocManager vignette section on offline use to ensure proper functionality.} + \item{\code{store_gene_data}}{Store sampled gene data for every bootstrap iteration. +When the number of bootstrap \code{reps} is very high (>=100k) and/or + the number of genes in \code{hits} is very high, you may want + to set \code{store_gene_data=FALSE} to avoid using excessive amounts of + CPU memory.} }} } \value{ diff --git a/man/load_example_CTD.Rd b/man/load_example_CTD.Rd index 0543b21..34063ac 100644 --- a/man/load_example_CTD.Rd +++ b/man/load_example_CTD.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/load_example_ctd.R +% Please edit documentation in R/load_example_CTD.R \name{load_example_ctd} \alias{load_example_ctd} \title{Load example CTD (Descartes)} diff --git a/man/plot_congenital_annotations.Rd b/man/plot_congenital_annotations.Rd index 3fddac2..e524258 100644 --- a/man/plot_congenital_annotations.Rd +++ b/man/plot_congenital_annotations.Rd @@ -56,7 +56,7 @@ be extracted. The available palettes and packages can be checked by running \item{proportion.test}{Decides whether proportion test for \code{x} variable is to be carried out for each level of \code{y}. Defaults to \code{results.subtitle}. In -\code{ggbarstats}, only \emph{p}-values from this test will be displayed.} +\code{\link[ggstatsplot:ggbarstats]{ggbarstats()}}, only \emph{p}-values from this test will be displayed.} \item{add_baseline}{Add a horizontal line showing the proportions expected by random.} @@ -78,7 +78,7 @@ Please note that if there are empty factor levels in your variable, they will be dropped. Default is \code{NULL}. If \code{NULL}, one-sample proportion test (a goodness of fit test) will be run for the \code{x} variable. Otherwise an appropriate association test will be run. This argument can not be \code{NULL} -for \code{ggbarstats} function.} +for \code{\link[ggstatsplot:ggbarstats]{ggbarstats()}}.} \item{\code{counts}}{The variable in data containing counts, or \code{NULL} if each row represents a single observation.} \item{\code{type}}{A character specifying the type of statistical approach: @@ -99,17 +99,17 @@ the plot will be returned.} on the label in each pie slice. Possible options are \code{"percentage"} (default), \code{"counts"}, \code{"both"}.} \item{\code{label.args}}{Additional aesthetic arguments that will be passed to -\code{ggplot2::geom_label()}.} - \item{\code{sample.size.label.args}}{Additional aesthetic arguments that will be passed to -\code{ggplot2::geom_text()}.} +\code{\link[ggplot2:geom_text]{ggplot2::geom_label()}}.} + \item{\code{sample.size.label.args}}{Additional aesthetic arguments that will be +passed to \code{\link[ggplot2:geom_text]{ggplot2::geom_text()}}.} \item{\code{digits}}{Number of digits for rounding or significant figures. May also be \code{"signif"} to return significant figures or \code{"scientific"} to return scientific notation. Control the number of digits by adding the value as suffix, e.g. \code{digits = "scientific4"} to have scientific notation with 4 decimal places, or \code{digits = "signif5"} for 5 significant figures (see also \code{\link[=signif]{signif()}}).} - \item{\code{digits.perc}}{Numeric that decides number of decimal places for percentage -labels (Default: \code{0L}).} + \item{\code{digits.perc}}{Numeric that decides number of decimal places for +percentage labels (Default: \code{0L}).} \item{\code{bf.message}}{Logical that decides whether to display Bayes Factor in favor of the \emph{null} hypothesis. This argument is relevant only \strong{for parametric test} (Default: \code{TRUE}).} @@ -121,10 +121,14 @@ E.g., \code{ratio = c(0.5, 0.5)} for two levels, \item{\code{conf.level}}{Scalar between \code{0} and \code{1} (default: \verb{95\%} confidence/credible intervals, \code{0.95}). If \code{NULL}, no confidence intervals will be computed.} - \item{\code{sampling.plan}}{Character describing the sampling plan. Possible options -are \code{"indepMulti"} (independent multinomial; default), \code{"poisson"}, -\code{"jointMulti"} (joint multinomial), \code{"hypergeom"} (hypergeometric). For -more, see \code{?BayesFactor::contingencyTableBF()}.} + \item{\code{sampling.plan}}{Character describing the sampling plan. Possible options: +\itemize{ +\item \code{"indepMulti"} (independent multinomial; default) +\item \code{"poisson"} +\item \code{"jointMulti"} (joint multinomial) +\item \code{"hypergeom"} (hypergeometric). +For more, see \code{\link[BayesFactor:contingencyTableBF]{BayesFactor::contingencyTableBF()}}. +}} \item{\code{fixed.margin}}{For the independent multinomial sampling plan, which margin is fixed (\code{"rows"} or \code{"cols"}). Defaults to \code{"rows"}.} \item{\code{prior.concentration}}{Specifies the prior concentration parameter, set @@ -142,13 +146,13 @@ variable name for \code{x} will be used.} \item{\code{ylab}}{Labels for \code{y} axis variable. If \code{NULL} (default), variable name for \code{y} will be used.} \item{\code{ggtheme}}{A \code{{ggplot2}} theme. Default value is -\code{ggstatsplot::theme_ggstatsplot()}. Any of the \code{{ggplot2}} themes (e.g., -\code{theme_bw()}), or themes from extension packages are allowed (e.g., -\code{ggthemes::theme_fivethirtyeight()}, \code{hrbrthemes::theme_ipsum_ps()}, etc.). -But note that sometimes these themes will remove some of the details that -\code{{ggstatsplot}} plots typically contains. For example, if relevant, -\code{ggbetweenstats()} shows details about multiple comparison test as a label -on the secondary Y-axis. Some themes (e.g. +\code{\link[ggstatsplot:theme_ggstatsplot]{theme_ggstatsplot()}}. Any of the \code{{ggplot2}} themes (e.g., +\code{\link[ggplot2:ggtheme]{ggplot2::theme_bw()}}), or themes from extension packages are allowed +(e.g., \code{ggthemes::theme_fivethirtyeight()}, \code{hrbrthemes::theme_ipsum_ps()}, +etc.). But note that sometimes these themes will remove some of the details +that \code{{ggstatsplot}} plots typically contains. For example, if relevant, +\code{\link[ggstatsplot:ggbetweenstats]{ggbetweenstats()}} shows details about multiple comparison test as a +label on the secondary Y-axis. Some themes (e.g. \code{ggthemes::theme_fivethirtyeight()}) will remove the secondary Y-axis and thus the details as well.} \item{\code{package,palette}}{Name of the package from which the given palette is to diff --git a/man/plot_differential_outcomes.Rd b/man/plot_differential_outcomes.Rd index 51f3d23..848dd60 100644 --- a/man/plot_differential_outcomes.Rd +++ b/man/plot_differential_outcomes.Rd @@ -55,7 +55,7 @@ data has already been sorted by such an id by the user and creates an internal identifier. So if your data is \strong{not} sorted, the results \emph{can} be inaccurate when there are more than two levels in \code{x} and there are \code{NA}s present. The data is expected to be sorted by user in -subject-1,subject-2, ..., pattern.} +subject-1, subject-2, ..., pattern.} \item{\code{y}}{The response (or outcome or dependent) variable from \code{data}.} \item{\code{type}}{A character specifying the type of statistical approach: \itemize{ @@ -88,8 +88,8 @@ omega-squared).} width to use in calculating Bayes factors and posterior estimates. In addition to numeric arguments, several named values are also recognized: \code{"medium"}, \code{"wide"}, and \code{"ultrawide"}, corresponding to \emph{r} scale values -of 1/2, sqrt(2)/2, and 1, respectively. In case of an ANOVA, this value -corresponds to scale for fixed effects.} +of \code{1/2}, \code{sqrt(2)/2}, and \code{1}, respectively. In case of an ANOVA, this +value corresponds to scale for fixed effects.} \item{\code{bf.message}}{Logical that decides whether to display Bayes Factor in favor of the \emph{null} hypothesis. This argument is relevant only \strong{for parametric test} (Default: \code{TRUE}).} @@ -148,24 +148,24 @@ to be: Just as \code{type} argument, abbreviations are also accepted.} \item{\code{centrality.point.args,centrality.label.args}}{A list of additional aesthetic -arguments to be passed to \code{ggplot2::geom_point()} and -\code{ggrepel::geom_label_repel} geoms, which are involved in mean plotting.} +arguments to be passed to \code{\link[ggplot2:geom_point]{ggplot2::geom_point()}} and +\code{\link[ggrepel:geom_text_repel]{ggrepel::geom_label_repel()}} geoms, which are involved in mean plotting.} \item{\code{point.args}}{A list of additional aesthetic arguments to be passed to -the \code{ggplot2::geom_point()} displaying the raw data.} +the \code{\link[ggplot2:geom_point]{ggplot2::geom_point()}}.} \item{\code{boxplot.args}}{A list of additional aesthetic arguments passed on to -\code{ggplot2::geom_boxplot()}.} +\code{\link[ggplot2:geom_boxplot]{ggplot2::geom_boxplot()}}.} \item{\code{violin.args}}{A list of additional aesthetic arguments to be passed to -the \code{ggplot2::geom_violin()}.} +the \code{\link[ggplot2:geom_violin]{ggplot2::geom_violin()}}.} \item{\code{ggsignif.args}}{A list of additional aesthetic -arguments to be passed to \code{ggsignif::geom_signif}.} +arguments to be passed to \code{\link[ggsignif:stat_signif]{ggsignif::geom_signif()}}.} \item{\code{ggtheme}}{A \code{{ggplot2}} theme. Default value is -\code{ggstatsplot::theme_ggstatsplot()}. Any of the \code{{ggplot2}} themes (e.g., -\code{theme_bw()}), or themes from extension packages are allowed (e.g., -\code{ggthemes::theme_fivethirtyeight()}, \code{hrbrthemes::theme_ipsum_ps()}, etc.). -But note that sometimes these themes will remove some of the details that -\code{{ggstatsplot}} plots typically contains. For example, if relevant, -\code{ggbetweenstats()} shows details about multiple comparison test as a label -on the secondary Y-axis. Some themes (e.g. +\code{\link[ggstatsplot:theme_ggstatsplot]{theme_ggstatsplot()}}. Any of the \code{{ggplot2}} themes (e.g., +\code{\link[ggplot2:ggtheme]{ggplot2::theme_bw()}}), or themes from extension packages are allowed +(e.g., \code{ggthemes::theme_fivethirtyeight()}, \code{hrbrthemes::theme_ipsum_ps()}, +etc.). But note that sometimes these themes will remove some of the details +that \code{{ggstatsplot}} plots typically contains. For example, if relevant, +\code{\link[ggstatsplot:ggbetweenstats]{ggbetweenstats()}} shows details about multiple comparison test as a +label on the secondary Y-axis. Some themes (e.g. \code{ggthemes::theme_fivethirtyeight()}) will remove the secondary Y-axis and thus the details as well.} \item{\code{package,palette}}{Name of the package from which the given palette is to diff --git a/man/subset_results.Rd b/man/subset_results.Rd index 193ebd0..abc30f2 100644 --- a/man/subset_results.Rd +++ b/man/subset_results.Rd @@ -8,7 +8,8 @@ subset_results( filters = list(cl_name = NULL), results = load_example_results(), q_threshold = 5e-04, - effect_threshold = 1, + effect_threshold = 0.1, + effect_var = "fold_change", verbose = TRUE ) } @@ -26,6 +27,8 @@ and merged together with \link[MSTExplorer]{merge_results}} \item{effect_threshold}{The minimum fold change in specific expression to subset the \code{results} by.} +\item{effect_var}{Name of the effect size column in the \code{results}.} + \item{verbose}{Print messages.} } \value{ diff --git a/tests/testthat/test-gen_results.R b/tests/testthat/test-gen_results.R index 17e401f..41da81d 100644 --- a/tests/testthat/test-gen_results.R +++ b/tests/testthat/test-gen_results.R @@ -7,7 +7,8 @@ test_that("gen_results works", { all_results <- gen_results(ctd = ctd, gene_data = gene_data, list_names = list_names, - reps = 10) + reps = 10, + force_new = TRUE) testthat::expect_true(methods::is(all_results$results,"data.table")) testthat::expect_true(methods::is(all_results$gene_data,"data.table")) testthat::expect_gte(sum(list_names %in% unique(all_results$results$hpo_id)), diff --git a/tests/testthat/test-load_example_results.R b/tests/testthat/test-load_example_results.R index c517105..8e9c4c1 100644 --- a/tests/testthat/test-load_example_results.R +++ b/tests/testthat/test-load_example_results.R @@ -1,8 +1,4 @@ test_that("load_example_results works", { - - res1 <- load_example_results("Descartes_All_Results_extras.rds") - testthat::expect_equal(nrow(res1), 475321) - - res2 <- load_example_results("tabulamuris_merged.rds") - testthat::expect_equal(nrow(res2), 213028) + res1 <- load_example_results("phenomix_results.tsv.gz") + testthat::expect_equal(nrow(res1), 2206994) }) diff --git a/tests/testthat/test-plot_bar_dendro.R b/tests/testthat/test-plot_bar_dendro.R index bf95e79..5636b17 100644 --- a/tests/testthat/test-plot_bar_dendro.R +++ b/tests/testthat/test-plot_bar_dendro.R @@ -1,6 +1,6 @@ test_that("plot_bar_dendro works", { - results <- load_example_results(multi_dataset=TRUE) + results <- load_example_results() out <- plot_bar_dendro(results = results) testthat::expect_true(methods::is(out$plot,"gg")) testthat::expect_true(methods::is(out$data,"data.table")) diff --git a/tests/testthat/test-plot_differential_outcomes.R b/tests/testthat/test-plot_differential_outcomes.R index ce7e32e..f326068 100644 --- a/tests/testthat/test-plot_differential_outcomes.R +++ b/tests/testthat/test-plot_differential_outcomes.R @@ -48,16 +48,17 @@ test_that("plot_differential_outcomes works", { facet_var = "disease_name", y_var = "cancer", run_stats = TRUE) - patchwork::wrap_plots(p1c$plot$`Granulomatosis with polyangiitis`) + patchwork::wrap_plots(p1c$plot[1]) run_tests(p1c) # #### Multiple diseases per phenotype: Severity_score ##### results <- HPOExplorer::add_severity(results) - p2 <- plot_differential_outcomes(results, + # Testthat interprets messages with errors as failures even with tryCatch() + testthat::expect_error(p2 <- plot_differential_outcomes(results, max_facets=10, facet_var = "hpo_name", y_var = "Severity_score", - run_stats = TRUE) + run_stats = TRUE)) # #### Multiple diseases per phenotype: AgeOfDeath ##### results <- HPOExplorer::add_death(results, diff --git a/tests/testthat/test-prioritise_targets.R b/tests/testthat/test-prioritise_targets.R index d3337d2..a47a5c3 100644 --- a/tests/testthat/test-prioritise_targets.R +++ b/tests/testthat/test-prioritise_targets.R @@ -1,6 +1,6 @@ test_that("prioritise_targets works", { - results <- load_example_results()[seq(50000),] + results <- load_example_results()[q<0.01] ctd_list <- load_example_ctd(c("ctd_DescartesHuman.rds", "ctd_HumanCellLandscape.rds"), multi_dataset = TRUE) @@ -17,7 +17,7 @@ test_that("prioritise_targets works", { testthat::expect_gte(nrow(res2$top_targets), 6) #### Plot evidence score vs. specificity #### - res3 <- prioritise_targets(results = results[seq(2500)], + res3 <- prioritise_targets(results = results, ctd_list = ctd_list, keep_deaths = NULL, #### Phenotype level #### @@ -32,8 +32,6 @@ test_that("prioritise_targets works", { #### Celltype level #### q_threshold = 0.05, effect_threshold = 1, - symptom_p_threshold = NULL, - symptom_intersection_size_threshold = 1, keep_celltypes = NULL, #### Gene level #### evidence_score_threshold = NULL, @@ -43,7 +41,6 @@ test_that("prioritise_targets works", { gene_frequency_threshold = NULL, keep_biotypes = NULL, keep_specificity_quantiles = NULL, - keep_mean_exp_quantiles = seq(1,40), - symptom_gene_overlap = TRUE) - testthat::expect_gte(nrow(res3$top_targets), 40000) + keep_mean_exp_quantiles = seq(1,40)) + testthat::expect_gte(nrow(res3$top_targets), 1000) }) diff --git a/tests/testthat/test-prioritise_targets_network.R b/tests/testthat/test-prioritise_targets_network.R index d521c48..4988551 100644 --- a/tests/testthat/test-prioritise_targets_network.R +++ b/tests/testthat/test-prioritise_targets_network.R @@ -1,6 +1,9 @@ test_that("prioritise_targets_network works", { - vn <- prioritise_targets_network(top_targets = example_targets$top_targets) + top_targets <- example_targets$top_targets + top_targets[,estimate:=fold_change] + top_targets <- map_celltype(top_targets) + vn <- prioritise_targets_network(top_targets) testthat::expect_true(methods::is(vn$plot,"visNetwork")) testthat::expect_true(methods::is(vn$data,"tbl_graph")) diff --git a/tests/testthat/test-report_plot.R b/tests/testthat/test-report_plot.R index 07a1086..7a5d849 100644 --- a/tests/testthat/test-report_plot.R +++ b/tests/testthat/test-report_plot.R @@ -3,5 +3,5 @@ test_that("plot_report works", { results <- load_example_results() rep_dt <- example_targets$report gp <- plot_report(rep_dt=rep_dt, results=results) - testthat::expect_true(methods::is(gp,"ggplot")) + testthat::expect_true(methods::is(gp$plot,"ggplot")) }) diff --git a/vignettes/MSTExplorer.Rmd b/vignettes/MSTExplorer.Rmd index 778b984..b0f4b67 100644 --- a/vignettes/MSTExplorer.Rmd +++ b/vignettes/MSTExplorer.Rmd @@ -113,7 +113,7 @@ library(data.table) #### Aggregate results #### n_signif <- results[q<=0.05 & !is.na(q), list(sig_enrichments = .N, - mean_effect=mean(effect)), + mean_effect=mean(fold_change)), by="hpo_id"] #### Plot #### plot1 <- ggplot(n_signif, aes(x = stringr::str_wrap(hpo_id,width = 10),