Skip to content

Commit

Permalink
Merge branch 'master' into docs-readme
Browse files Browse the repository at this point in the history
  • Loading branch information
HDash authored Jan 8, 2025
2 parents 107b2b6 + 97c8360 commit 6640165
Show file tree
Hide file tree
Showing 37 changed files with 242 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rworkflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
cont: ~
rspm: ~
steps:
- uses: neurogenomics/rworkflows@dev
- uses: neurogenomics/rworkflows@master
with:
run_bioccheck: ${{ false }}
run_rcmdcheck: ${{ true }}
Expand Down
5 changes: 3 additions & 2 deletions 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.4
Version: 1.0.6
Authors@R:
c(
person(given = "Brian",
Expand Down Expand Up @@ -54,7 +54,8 @@ Imports:
future,
furrr,
tidygraph,
rstatix
rstatix,
simona
Suggests:
rmarkdown,
knitr,
Expand Down
49 changes: 49 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 4 additions & 5 deletions R/add_logfc.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
24 changes: 15 additions & 9 deletions R/add_symptom_results.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion R/extract_help.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion R/get_color_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 8 additions & 5 deletions R/map_tissue.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions R/plot_bar_dendro.R
Original file line number Diff line number Diff line change
Expand Up @@ -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<q_threshold & cl_id %in% unique(ddata$labels$id),
lapply(.SD,mean),
by=by,
Expand All @@ -104,7 +104,7 @@ plot_bar_dendro <- function(results = load_example_results(),
normalise_group=TRUE)
#### Color each cell type x-axis label by the most commonly enriched HPO category ####
cmap <- get_color_map(dat=dat,
columns = "top_ancestor_name",
columns = "ancestor_name",
ddata=ddata,
celltype_col=celltype_col,
preferred_palettes=preferred_palettes)
Expand Down
2 changes: 1 addition & 1 deletion R/plot_bar_dendro_facets.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ plot_bar_dendro_facets <- function(results = load_example_results(),
data_summary <- NULL
} else {
cl_name <- p.value.adj <- term <- p.value.adj.signif <- NULL;
dat <- merge(dat[,-c("term")],
dat <- merge(dat,
target_tests[[1]][term=="is_targetTRUE"],
all.x = TRUE,
by=c("ancestor_name","cl_id"))
Expand Down
4 changes: 4 additions & 0 deletions R/plot_differential_outcomes.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ plot_differential_outcomes <- function(results,

{
results <- HPOExplorer::add_hpo_name(results)
if ("disease_name" %in% c(facet_var, x_var, y_var) &&
!"disease_name" %in% names(results)) {
results <- HPOExplorer::add_disease(results, add_descriptions = TRUE)
}
plot_dat <- results[!is.na(get(y_var)),]
plot_dat[,n_celltype:=length(unique(get(x_var))),by=c(facet_var)]
plot_dat[,n_ids:=.N, by=c(facet_var)]
Expand Down
2 changes: 1 addition & 1 deletion R/plot_ttd.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ plot_ttd <- function(dat_sub,
size=label_size,
angle=90,
hjust=1,
ggplot2::aes(x=HIGHEST_STATUS, fill=prioritised,
ggplot2::aes(x=HIGHEST_STATUS,
label=paste0("n=",n_drugs), y=.95),
# fill="white", alpha=.75,
inherit.aes = FALSE) +
Expand Down
2 changes: 1 addition & 1 deletion R/predict_celltypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ predict_celltypes <- function(phenotypes,
hpo_ids <- HPOExplorer::map_phenotypes(terms = phenotypes,
to = "id")
res <- data.table::copy(results)
add_logfc(res)
res <- add_logfc(res)
res[,effect:=scales::rescale(get(effect_var),c(0,1))]
# res <- res[q<0.05]
# res[,effect:=scales::rescale(abs(effect))]
Expand Down
2 changes: 1 addition & 1 deletion R/prioritise_targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ prioritise_targets <- function(#### Input data ####
t1 <- Sys.time()
messager("Prioritising gene targets.",v=verbose)
#### Add logFC ####
add_logfc(results = results)
results <- add_logfc(results)
#### add_hpo_id #####
results <- HPOExplorer::add_hpo_id(phenos = results,
hpo = hpo)
Expand Down
12 changes: 8 additions & 4 deletions R/prioritise_targets_grid.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,14 @@ prioritise_targets_grid <- function(top_targets,
size=3){
if(!is.null(labels)) labels <- stats::setNames(labels,as.character(x_pos))
dat <- merge(dt1[,-c("hpo_id")],
dt2, by="hpo_name", sort=FALSE)|>
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)]
Expand Down
2 changes: 1 addition & 1 deletion R/prioritise_targets_network.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 4 additions & 2 deletions R/subset_results.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#'
Expand All @@ -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;

Expand All @@ -24,7 +26,7 @@ subset_results <- function(filters = list(cl_name=NULL),
results_sig <- results_sig[q<q_threshold]
}
if(is.numeric(effect_threshold)){
results_sig <- results_sig[effect>effect_threshold]
results_sig <- results_sig[results_sig[[effect_var]]>effect_threshold,]
}
#### Check that celltype is available ####
if(nrow(results_sig)==0){
Expand Down
2 changes: 1 addition & 1 deletion R/test_target_celltypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -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<q_threshold][,is_target:=get(celltype_col) %in%
target_celltypes[[get(ancestor_var)]],
Expand Down
6 changes: 5 additions & 1 deletion R/ttd_check.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ ttd_check <- function(top_targets,
TARGETID <- DRUGNAME <- DRUGTYPE <- DRUGID <-
GENENAME2 <- prioritised <- HIGHEST_STATUS <- NULL;

top_targets <- HPOExplorer::add_disease(top_targets,
#### add_disease if not already done ###
if (!"disease_name" %in% names(top_targets) |
!"disease_id" %in% names(top_targets)) {
top_targets <- HPOExplorer::add_disease(top_targets,
add_descriptions = TRUE)
}
ttdi <- KGExplorer::get_ttd(force_new = force_new,
run_map_genes = run_map_genes)
#### Remove results that can't be linked to specific genes #####
Expand Down
2 changes: 1 addition & 1 deletion R/validate_associations_correlate_ctd.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ validate_associations_correlate_ctd <- function(results=load_example_results(),
...){
test_id <- NULL;
results <- map_celltype(results)
add_logfc(results)
results <- add_logfc(results)
results <- KGExplorer::filter_dt(results,
filters = filters)
group_values <- unique(results[[group_var]])
Expand Down
2 changes: 1 addition & 1 deletion R/validate_associations_mkg.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ validate_associations_mkg <- function(results=load_example_results(),
){
from <- hpo_id <- NULL;
# kg <- data.table::fread(here::here("data/monarch_kg_cells.csv"))
add_logfc(results)
results <- add_logfc(results)
kg_og <- data.table::copy(kg)
kg <- kg[grepl("HP:",from)][from %in% unique(results$hpo_id)]
message(paste(
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ MSTExplorer
<img src='https://github.com/neurogenomics/MSTExplorer/raw/master/inst/hex/hex.png' title='Hex sticker for MSTExplorer' height='300'><br>
[![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)
<br> [![R build
Expand Down
4 changes: 2 additions & 2 deletions man/add_symptom_results.Rd

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

32 changes: 32 additions & 0 deletions man/ewce_para.Rd

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

Loading

0 comments on commit 6640165

Please sign in to comment.