Skip to content

Commit e72a10a

Browse files
committed
Update after KGExplorer updates
1 parent 24522b3 commit e72a10a

66 files changed

Lines changed: 1003 additions & 312 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎DESCRIPTION‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: MSTExplorer
22
Title: Multi-Scale Target Explorer
3-
Version: 1.0.9
3+
Version: 1.0.10
44
Authors@R:
55
c(
66
person(given = "Brian",
@@ -30,7 +30,7 @@ Encoding: UTF-8
3030
URL: https://github.com/neurogenomics/MSTExplorer
3131
BugReports: https://github.com/neurogenomics/MSTExplorer/issues
3232
Roxygen: list(markdown = TRUE)
33-
RoxygenNote: 7.3.2
33+
RoxygenNote: 7.3.3
3434
Depends:
3535
R (>= 4.1)
3636
Imports:
@@ -77,7 +77,8 @@ Suggests:
7777
tibble,
7878
tidytext,
7979
ggrepel,
80-
gtools
80+
gtools,
81+
ggrastr
8182
Remotes:
8283
github::neurogenomics/HPOExplorer,
8384
github::neurogenomics/KGExplorer,

‎NAMESPACE‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
# Generated by roxygen2: do not edit by hand
22

33
export(add_ctd)
4+
export(add_driver_genes)
45
export(add_logfc)
56
export(add_symptom_results)
67
export(agg_results)
78
export(correlation_heatmap)
89
export(create_dt)
910
export(ewce_para)
11+
export(filter_ggstatsplot_subtitle)
1012
export(gen_overlap)
1113
export(gen_results)
1214
export(get_bg)
1315
export(get_cl)
16+
export(get_replication_rate)
1417
export(get_unfinished_list_names)
1518
export(ggnetwork_plot_full)
1619
export(load_example_ctd)
@@ -37,6 +40,7 @@ export(prioritise_targets_grid)
3740
export(prioritise_targets_multiheatmap)
3841
export(prioritise_targets_network)
3942
export(run_congenital_enrichment)
43+
export(run_permutation_test_cor)
4044
export(run_phenomix)
4145
export(subset_phenos)
4246
export(subset_results)
@@ -51,12 +55,15 @@ import(HPOExplorer)
5155
import(KGExplorer)
5256
import(data.table)
5357
import(ggplot2)
58+
importFrom(BiocParallel,MulticoreParam)
59+
importFrom(BiocParallel,bplapply)
5460
importFrom(EWCE,bootstrap_enrichment_test)
5561
importFrom(HPOExplorer,add_ancestor)
5662
importFrom(HPOExplorer,add_gene_frequency)
5763
importFrom(HPOExplorer,get_gene_lists)
5864
importFrom(HPOExplorer,load_phenotype_to_genes)
5965
importFrom(data.table,":=")
66+
importFrom(data.table,data.table)
6067
importFrom(data.table,fread)
6168
importFrom(data.table,melt)
6269
importFrom(data.table,rbindlist)
@@ -71,7 +78,9 @@ importFrom(plotly,ggplotly)
7178
importFrom(scales,pretty_breaks)
7279
importFrom(stats,as.formula)
7380
importFrom(stats,complete.cases)
81+
importFrom(stats,cor)
7482
importFrom(stats,dist)
83+
importFrom(stats,quantile)
7584
importFrom(stats,setNames)
7685
importFrom(stringr,str_replace_all)
7786
importFrom(stringr,str_wrap)

‎NEWS.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# MSTExplorer 1.0.10
2+
3+
## New features
4+
* `run_permutation_test_cor`: New function to run permutation tests.
5+
* `plot_ontology_levels`: Add more args. Make "info_content_binned"
6+
a separate col from raw "info_content".
7+
8+
## Bug fixes
9+
* Update all calls to `facet_grid` to not use deprecated `facets` arg.
10+
111
# MSTExplorer 1.0.9
212

313
## New features

‎R/0docs.R‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#' @param subtitle_size Size of the plot subtitle.
2222
#' @param phenotype_to_genes Phenotype to gene mapping from
2323
#' \link[HPOExplorer]{load_phenotype_to_genes}.
24+
#' @param dpi Resolution of image after rasterization.
2425
#' @family plot_
2526
#' @returns R object.
2627
#' @name plot_

‎R/add_ctd.R‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#'
33
#' Annotate genes in \code{results} with data from a CellTypeDataset (CTD).
44
#' The following columns will be added:
5-
#' \itemize{
6-
#' \item{"specificity"} Cell-type specificity score.
7-
#' \item{"specificity_quantiles"} Cell-type specificity quantile.
8-
#' \item{"mean_exp"} Mean expression per cell-type.
9-
#' \item{"mean_exp_quantiles"} Mean expression quantile per cell-type.
5+
#' \describe{
6+
#' \item{"specificity"}{Cell-type specificity score.}
7+
#' \item{"specificity_quantiles"}{Cell-type specificity quantile.}
8+
#' \item{"mean_exp"}{Mean expression per cell-type.}
9+
#' \item{"mean_exp_quantiles"}{Mean expression quantile per cell-type.}
1010
#' }
1111
#' @param keep_celltypes A character vector of cell types to keep.
1212
#' @inheritParams ewce_para

‎R/add_driver_genes.R‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
1+
#' Add driver genes
2+
#'
3+
#' This function identifies "driver genes" from phenotype-cell type association analyses.
4+
#' For a given phenotype-cell type pair, driver genes are defined as the intersect of genes that had a
5+
#' phenotype evidence score >0 and were within the top 75th expression specificity percentile
6+
#' (quantiles 30-40 out of 40) for the associated cell type.
7+
#'
8+
#' @param min_value Miniumum specificity quantile to keep.
9+
#' @param metric Which metric to use in the CellTypeDatasets.
10+
#' @param group_var Grouping variable to use when selecting top N genes.
11+
#' Only used when \code{top_n!=NULL}.
12+
#' @param celltype_var The name of the cell type column to merge on.
13+
#' @inheritParams prioritise_targets
14+
#' @inheritParams add_symptom_results
15+
#' @inheritDotParams HPOExplorer::add_genes
16+
#' @export
17+
#' @examples
18+
#' res <- load_example_results()[seq(100)]
19+
#' res <- add_driver_genes(results=res)
120
add_driver_genes <- function(results = load_example_results(),
221
ctd_list = load_example_ctd(
322
file = paste0("ctd_",unique(results$ctd),".rds"),
423
multi_dataset = TRUE
524
),
625
annotLevels = map_ctd_levels(results),
7-
keep_quantiles = NULL,
26+
keep_quantiles = seq(30,40),
827
min_value = NULL,
928
metric = "specificity_quantiles",
1029
top_n = NULL,

‎R/add_symptom_results.R‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ add_symptom_results <- function(results = load_example_results(),
3535
){
3636
n_genes_hpo_id <- n_genes_disease_id <- n_genes_symptom <- gene_symbol <-
3737
celltype_symptom <- n_driver_genes_symptom <-
38-
proportion_driver_genes_symptom <- NULL;
38+
proportion_driver_genes_symptom <- ..merge_cols <- NULL;
3939

4040
if("proportion_driver_genes_symptom" %in% names(results)){
4141
messager("Symptom results already present in input.")

‎R/agg_results.R‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,37 @@
1616
#' phenos <- subset_results(filters = list(CellType="Microglia"))
1717
#' agg_res <- agg_results(phenos = phenos)
1818
agg_results <- function(phenos,
19-
count_var = "hpo_name",
19+
count_var = "hpo_id",
2020
group_var = "CellType",
2121
sep="; ",
2222
verbose = TRUE){
23-
effect <- sd_from_mean <- . <- gene_symbol <- NULL;
23+
estimate <- std.error <- sd_from_mean <- . <- gene_symbol <- NULL;
24+
25+
26+
group_var <- group_var[group_var %in% names(phenos)]
27+
if("sd_from_mean" %in% names(phenos)){
28+
phenos$std.error <- phenos$sd_from_mean
29+
}
30+
2431
messager("Aggregating results by",
2532
paste0("group_var=",paste(shQuote(group_var),collapse = "/")),
2633
v=verbose)
34+
2735
phenos <- HPOExplorer::add_hpo_name(phenos)
36+
2837
#### Aggregate ####
29-
counts_df <- unique(phenos[,.(
38+
counts_df <- unique(
39+
phenos[,.(
3040
count=data.table::uniqueN(eval(parse(text = count_var))),
3141
n_genes=if("gene_symbol" %in% names(phenos)) {
3242
data.table::uniqueN(gene_symbol,na.rm = TRUE)
3343
} else NA,
3444
genes=if("gene_symbol" %in% names(phenos)){
3545
paste(unique(gene_symbol),collapse = sep)
3646
} else NA,
37-
mean_effect=round(mean(effect),3),
47+
mean_estimate=round(mean(estimate),3),
3848
mean_q=round(mean(q),3),
39-
mean_sd_from_mean=round(mean(sd_from_mean),3),
49+
mean_std.error=round(mean(std.error),3),
4050
values=paste(
4151
stringr::str_wrap(paste(unique(eval(parse(text = count_var))),
4252
collapse = sep)),
@@ -46,10 +56,11 @@ agg_results <- function(phenos,
4656
"count",
4757
"n_genes",
4858
"genes",
49-
"mean_effect",
59+
"mean_estimate",
5060
"mean_q",
51-
"mean_sd_from_mean",
52-
"values"), with=FALSE])
61+
"mean_std.error",
62+
"values"), with=FALSE]
63+
)
5364
data.table::setnames(counts_df,
5465
c("count","values"),
5566
c(paste("n",paste0(tolower(count_var),"s"),sep="_"),

‎R/construct_labeller.R‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ construct_labeller <- function(dat,
33
facets_n,
44
suffix="phenotypes"){
55
facet_label <- NULL;
6+
dat <- data.table::copy(dat)
67
if(is.null(facets_n) ||
78
!facets_n %in% names(dat)) {
89
"label_value"

‎R/extract_filters.R‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@ extract_filters <- function(pkg = "MSTExplorer",
77
out <- extract_help(pkg = pkg,
88
fn = fn,
99
to = "html")
10-
filters <- (
11-
rvest::read_html(paste(out,collapse = "")) |>
12-
rvest::html_elements("ol")
13-
)[[1]] |>
14-
rvest::html_children() |>
15-
rvest::html_text() |>
16-
stringr::str_split(":",n = 3, simplify = TRUE) |>
17-
data.table::as.data.table() |>
10+
11+
txt <- (rvest::read_html(paste(out,collapse = ""))|>
12+
rvest::html_elements("dl"))[[1]] |>
13+
rvest::html_children()|>
14+
rvest::html_text()
15+
16+
filters <- data.table::data.table(
17+
stringr::str_split(txt[seq(from = 1, to = length(txt)-1, by = 2)] ,"; ",
18+
n = 2,
19+
simplify = TRUE)[,c(1,2)],
20+
txt[seq(from = 2, to = length(txt), by = 2)]
21+
)|>
1822
`colnames<-`(c("level","step","description"))
23+
1924
cols <- names(filters)
2025
filters[ , (cols) := lapply(.SD, trimws), .SDcols = cols]
26+
filters[ , (cols) := lapply(.SD, trimws, whitespace=";"), .SDcols = cols]
2127
filters[,level:=gsub("[-]|level|levels","",level)]
2228
#### Print for plot legend ####
2329
# cat(paste(filters[,legend:=paste0(step,": ",description)]$legend, collapse = "\n"))

0 commit comments

Comments
 (0)