Skip to content

Commit

Permalink
add hypergeo tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bschilder committed Mar 31, 2024
1 parent 4ec3031 commit 16c4eff
Show file tree
Hide file tree
Showing 10 changed files with 430 additions and 380 deletions.
720 changes: 360 additions & 360 deletions .Rhistory

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions R/0docs.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#' @param width Width of the saved plot.
#' @param heights Passed to \link[patchwork]{wrap_plots}.
#' @param subtitle_size Size of the plot subtitle.
#' @param phenotype_to_genes Phenotype to gene mapping from
#' \link[HPOExplorer]{load_phenotype_to_genes}.
#' @family plot_
#' @returns R object.
#' @name plot_
Expand Down
5 changes: 4 additions & 1 deletion R/plot_ontology_levels.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#' @param log_vars Logical vector indicating which variables to log-transform.
#' @param sig_vars Logical vector indicating which variables to only plot
#' for significant results.
#' @param return_data Return the full long data used in the plots.
#' @inheritParams plot_
#' @inheritParams ggpubr::stat_cor
#' @inheritParams prioritise_targets
Expand Down Expand Up @@ -57,7 +58,8 @@ plot_ontology_levels <- function(results = load_example_results(),
height=7,
width=length(x_vars)*5.75,
smooth.line.args=list(method = "loess",
se = FALSE)
se = FALSE),
return_data=TRUE
){

requireNamespace("ggplot2")
Expand Down Expand Up @@ -252,6 +254,7 @@ plot_ontology_levels <- function(results = load_example_results(),
height = height,
width = width)
}
if(isFALSE(return_data)) r2 <- NULL
return(list(data=r2,
data_stats=data_stats,
plot=plts2))
Expand Down
2 changes: 0 additions & 2 deletions R/plot_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#' @param rep_dt Report table.
#' @param annot HPO annotations.
#' @param remove_cols Columns to remove from \code{rep_dt}.
#' @param phenotype_to_genes Phenotype to gene mapping from
#' \link[HPOExplorer]{load_phenotype_to_genes}.
#' @inheritParams plot_
#' @inheritParams ggnetwork_plot_full
#' @inheritDotParams ggplot2::ggsave
Expand Down
4 changes: 4 additions & 0 deletions R/prioritise_targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ prioritise_targets <- function(#### Input data ####
Severity_score <- cl_name <- cl_id <- Severity_score_max <-
info_content <- NULL;

force(results)
force(ctd_list)
force(hpo)
force(phenotype_to_genes)
t1 <- Sys.time()
messager("Prioritising gene targets.",v=verbose)
#### Add logFC ####
Expand Down
26 changes: 13 additions & 13 deletions R/ttd_check.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,9 @@ ttd_check <- function(top_targets,
show_plot = TRUE,
save_path = NULL,
height=NULL,
width=NULL){
# top_targets <- prioritise_targets(
# keep_deaths = NULL,
# keep_tiers = NULL,
# severity_threshold_max = NULL,
# severity_threshold = NULL,
# pheno_frequency_threshold = NULL,
# keep_onsets = NULL,
# keep_ont_levels = seq(4),
# keep_celltypes = NULL,
# top_n = 2,
# group_vars = c("hpo_id","disease_id"))$top_targets
width=NULL,
phenotype_to_genes=HPOExplorer::load_phenotype_to_genes()){
# top_targets <- prioritise_targets()$top_targets
# drug_types <- c("Gene therapy"
# "Antisense drug",
# "Antisense oligonucleotide",
Expand Down Expand Up @@ -109,6 +100,14 @@ ttd_check <- function(top_targets,
# length(unique(paste0(dat_sub2$DRUGID,dat_sub2$INDICATI,
# dat_sub2$GENENAME2)))
dat_sub[,prioritised:=(DRUGID %in% dat_sub2$DRUGID)]
#### Hypergeometric test ####
dat_sub[,failed:=HIGHEST_STATUS %in% failed_status]
fail <- dat_sub[failed==TRUE,drop=FALSE]
notfail <- dat_sub[failed==FALSE,drop=FALSE]
ttd_hypergeo_out <- ttd_hypergeo(fail=fail,
notfail=notfail,
top_targets=top_targets,
p2g=phenotype_to_genes)
#### Plot ####
plt <- plot_ttd(dat_sub = dat_sub,
failed_status = failed_status)
Expand All @@ -124,6 +123,7 @@ ttd_check <- function(top_targets,
list(data=dat_sub,
data_overlap=dat_sub2,
pct_captured,
plot=plt)
plot=plt,
ttd_hypergeo_out=ttd_hypergeo_out)
)
}
37 changes: 37 additions & 0 deletions R/ttd_hypergeo.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
ttd_hypergeo <- function(fail,
notfail,
top_targets,
p2g=HPOExplorer::load_phenotype_to_genes()){
# https://seqqc.wordpress.com/2019/07/25/how-to-use-phyper-in-r/

## Test for over-representation (enrichment)
# phyper(Overlap-1, group2, Total-group2, group1,lower.tail= FALSE)
overlap <- data.table::uniqueN(notfail[prioritised==TRUE]$GENENAME3)
group2 <- data.table::uniqueN(notfail$GENENAME3)
total <- data.table::uniqueN(c(p2g$gene_symbol,notfail$GENENAME3))
group1 <- data.table::uniqueN(top_targets$gene_symbol)
nonfailed_enrichment <- stats::phyper(overlap-1,
group2,
total-group2,
group1,
lower.tail= FALSE)
messager("Non-failed gene targets enrichment p-value:",nonfailed_enrichment)
## Test for under-representation (depletion)
# phyper(Overlap, group2, Total-group2, group1, lower.tail= TRUE)
overlap <- data.table::uniqueN(fail[prioritised==TRUE]$GENENAME3)
group2 <- data.table::uniqueN(fail$GENENAME3)
total <- data.table::uniqueN(c(p2g$gene_symbol,fail$GENENAME3))
group1 <- data.table::uniqueN(top_targets$gene_symbol)
failed_depletion <- stats::phyper(overlap,
group2,
total-group2,
group1,
lower.tail= TRUE)
messager("Failed gene targets depletion p-value:",failed_depletion)
return(
list(
nonfailed_enrichment=nonfailed_enrichment,
failed_depletion=failed_depletion
)
)
}
3 changes: 3 additions & 0 deletions man/plot_.Rd

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

5 changes: 2 additions & 3 deletions man/predict_celltypes.Rd

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

6 changes: 5 additions & 1 deletion man/ttd_check.Rd

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

0 comments on commit 16c4eff

Please sign in to comment.