From b51ade10be3278e65970cf877c67c24124f87536 Mon Sep 17 00:00:00 2001 From: kusurin Date: Sat, 14 Dec 2024 20:23:09 +0800 Subject: [PATCH 1/3] feat: add species specification feature to double_enrich() function --- R/7_quick_double_enrich.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/7_quick_double_enrich.R b/R/7_quick_double_enrich.R index 4558871..8d79359 100644 --- a/R/7_quick_double_enrich.R +++ b/R/7_quick_double_enrich.R @@ -146,14 +146,14 @@ quick_enrich <- function(genes, ##' @seealso ##' \code{\link{quick_enrich}} -double_enrich <- function(deg,n = 10,color = c("#2874C5", "#f87669")){ +double_enrich <- function(deg,n = 10,color = c("#2874C5", "#f87669"), species = "human"){ if(!requireNamespace("labeling",quietly = TRUE)) { stop("Package \"labeling\" needed for this function to work. Please install it byby install.packages('labeling')",call. = FALSE) } deg$change = str_to_lower(deg$change) - up = quick_enrich(deg$ENTREZID[deg$change=="up"],"up.rdata",destdir = tempdir()) - down = quick_enrich(deg$ENTREZID[deg$change=="down"],"down.rdata",destdir = tempdir()) + up = quick_enrich(deg$ENTREZID[deg$change=="up"],"up.rdata",destdir = tempdir(),species = species) + down = quick_enrich(deg$ENTREZID[deg$change=="down"],"down.rdata",destdir = tempdir(),species = species) if(!is.null(up$kk) & !is.null(down$kk) &!is.null(up$go) &!is.null(up$go)){ up$kk@result = mutate(up$kk@result,change = "up") down$kk@result = mutate(down$kk@result,change = "down") From 47108e27cf3f07f87779f3b363d1160fae3dd67d Mon Sep 17 00:00:00 2001 From: kusurin Date: Sat, 14 Dec 2024 20:27:18 +0800 Subject: [PATCH 2/3] docs: complete documentation for quick_enrich() and double_enrich() function --- R/7_quick_double_enrich.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/7_quick_double_enrich.R b/R/7_quick_double_enrich.R index 8d79359..03d4405 100644 --- a/R/7_quick_double_enrich.R +++ b/R/7_quick_double_enrich.R @@ -5,6 +5,7 @@ ##' @param genes a gene symbol or entrizid vector ##' @param kkgo_file Rdata filename for kegg and go result ##' @param destdir destdir to save kkgofile +##' @param species species for enrichment analysis, e.g. "human","mouse","rat" ##' @inheritParams trans_exp_new ##' @return enrichment results and dotplots ##' @author Xiaojie Sun @@ -112,6 +113,7 @@ quick_enrich <- function(genes, ##' @param deg a data.frame contains at least two columns:"ENTREZID" and "change" ##' @param n how many terms will you perform for up and down genes respectively ##' @param color color for bar plot +##' @param species species for enrichment analysis, e.g. "human","mouse","rat" ##' @return a list with kegg and go bar plot according to up and down genes enrichment result. ##' @author Xiaojie Sun ##' @importFrom stringr str_to_lower From 976ff4cd95696d40a0ff4ebc7ccc54fd5c730720 Mon Sep 17 00:00:00 2001 From: kusurin Date: Sat, 14 Dec 2024 20:49:57 +0800 Subject: [PATCH 3/3] fix: avoid `double_enrich()` reading first result Bug: The function `double_enrich()` was using the same temporary directory for each run, causing it to read the same result from first run. Solution: Added a timestamp to the temporary directory path. This ensures that each run of the function creates a unique directory. --- R/7_quick_double_enrich.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/R/7_quick_double_enrich.R b/R/7_quick_double_enrich.R index 03d4405..5ec1918 100644 --- a/R/7_quick_double_enrich.R +++ b/R/7_quick_double_enrich.R @@ -154,8 +154,11 @@ double_enrich <- function(deg,n = 10,color = c("#2874C5", "#f87669"), species = stop("Package \"labeling\" needed for this function to work. Please install it byby install.packages('labeling')",call. = FALSE) } deg$change = str_to_lower(deg$change) - up = quick_enrich(deg$ENTREZID[deg$change=="up"],"up.rdata",destdir = tempdir(),species = species) - down = quick_enrich(deg$ENTREZID[deg$change=="down"],"down.rdata",destdir = tempdir(),species = species) +timestamp <- format(Sys.time(), "%Y%m%d%H%M%S") +temp_dir <- file.path(tempdir(), timestamp) +dir.create(temp_dir, recursive = TRUE) +up = quick_enrich(deg$ENTREZID[deg$change=="up"], "up.rdata", destdir = temp_dir, species = species) +down = quick_enrich(deg$ENTREZID[deg$change=="down"], "down.rdata", destdir = temp_dir, species = species) if(!is.null(up$kk) & !is.null(down$kk) &!is.null(up$go) &!is.null(up$go)){ up$kk@result = mutate(up$kk@result,change = "up") down$kk@result = mutate(down$kk@result,change = "down")