Skip to content

Commit

Permalink
Merge pull request #55 from ZhimingYe/ver0.8/StartUpFix
Browse files Browse the repository at this point in the history
Version 0.7.5 minimal fix for actual usage
  • Loading branch information
ZhimingYe authored Jan 8, 2025
2 parents 4af78b8 + aa8e44f commit 5543bb5
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 17 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: EnrichGT
Title: EnrichGT - all in one enrichment analysis soluction
Version: 0.7.0
Version: 0.7.4
Author: Zhiming Ye
Maintainer: Zhiming Ye <[email protected]>
Description: Do biological enrichment analysis and parsing and clustering
Expand Down
36 changes: 28 additions & 8 deletions R/figures.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#' @description
#' This plot is the most widely like `enrichplot::dotplot()`used method to visualize enriched terms. It shows the enrichment scores (e.g. p values) and gene ratio or NES as dot size and color / or bar height. Users can specify the number of terms using `ntop` or selected terms to color via the `low.col` and `hi.col`.
#' @param x a data frame form enriched result like `egt_enrichment_analysis()` or `egt_gsea_analysis()`, or an re-clustered `EnrichGT` object
#' @param ntop Show top N in each cluster
#' @param ntop Show top N in each cluster. In default, for origin enriched result, showing top 15; for re-clustered object, showing top 5 in each cluster.
#' @param showIDs bool, show pathway IDs or not. Default is FALSE
#' @param low.col the color for the lowest
#' @param hi.col the color for the highest
#' @param max_len_descript the label format length, default as 40.
Expand Down Expand Up @@ -35,12 +36,21 @@
#' @importFrom methods is
#' @importFrom forcats fct_reorder
#' @author Zhiming Ye
egt_plot_results <- function(x,ntop=30,...,P.adj=NULL){
egt_plot_results <- function(x,ntop=NULL,showIDs=F,max_len_descript=40,...,P.adj=NULL){
if(is.null(ntop)){
ntop <- 15
}
if(class(x)[1]=="EnrichGT_obj"){
if(is.null(ntop)){
ntop <- 5
}
if(x@fused){
cli::cli_alert_info("Found a fused EnrichGT_obj, you can set showIDs=T to show the source database the pathways from. ")
}
if(sum(colnames(x@enriched_result)=="absNES")==0){
figure0<-ORA2dp(x,...)
figure0<-ORA2dp(x,ntop=ntop,showIDs=showIDs,max_len_descript=max_len_descript,...)
}else{
figure0<-GSEA2dp(x,...)
figure0<-GSEA2dp(x,ntop=ntop,showIDs=showIDs,max_len_descript=max_len_descript,...)
}
}else if(is.data.frame(x)){
plotingTemp <- new.env()
Expand Down Expand Up @@ -70,7 +80,7 @@ egt_plot_results <- function(x,ntop=30,...,P.adj=NULL){
dplyr::arrange(desc(absNES), .by_group = TRUE) |>
dplyr::slice_head(n = round(round(ntop / 2) + 1 + round(ntop/20))) |> # For balance
dplyr::ungroup() # Balance up and down
figure0<-GSEA2dp(obj,ntop=ntop,...)
figure0<-GSEA2dp(obj,ntop=ntop,showIDs=showIDs,max_len_descript=max_len_descript,...)
}else{
InnerDF<-x |> dplyr::filter(p.adjust<(plotingTemp$PadjVal)) |> dplyr::select(ID,Description,GeneRatio,`p.adjust`,geneID,Count) # Need Fix
obj<-InnerDF |>
Expand All @@ -84,7 +94,7 @@ egt_plot_results <- function(x,ntop=30,...,P.adj=NULL){
dplyr::arrange(desc(Count), .by_group = TRUE) |>
dplyr::slice_head(n = 2) |>
dplyr::ungroup()
figure0<-ORA2dp(obj,ntop=ntop,...)
figure0<-ORA2dp(obj,ntop=ntop,showIDs=showIDs,max_len_descript=max_len_descript,...)
}
}
return(figure0)
Expand Down Expand Up @@ -119,7 +129,7 @@ egt_plot_umap <- function(x,...){
return(px)
}

ORA2dp<-function(x,ntop = 7,low.col="#ff6f81",hi.col="#78cfe5",max_len_descript=40,...){
ORA2dp<-function(x,ntop = 7,showIDs=F,low.col="#ff6f81",hi.col="#78cfe5",max_len_descript=40,...){
if(is.list(x) & !is.data.frame(x)){
cli::cli_abort("For a list object, please run plotting for every object inside list, instead of the whole list.")
}
Expand All @@ -134,6 +144,11 @@ ORA2dp<-function(x,ntop = 7,low.col="#ff6f81",hi.col="#78cfe5",max_len_descript=
assign("df0",x,envir = TempPlotingEnv)
cli::cli_alert_warning("You are drawing origin results, for better result you can re-cluster it by egt_recluster_analysis()")
})
if(showIDs & (sum(TempPlotingEnv$df0$ID == TempPlotingEnv$df0$Description)>=5)){
TempPlotingEnv$df0$ID <- substr(TempPlotingEnv$df0$ID,1,15)
TempPlotingEnv$df0$Description <- paste0(TempPlotingEnv$df0$ID,":",TempPlotingEnv$df0$Description)
max_len_descript <- max_len_descript + 16
}
tryCatch({
df <- TempPlotingEnv$df0 |>
group_by(Cluster) |>
Expand All @@ -148,7 +163,7 @@ ORA2dp<-function(x,ntop = 7,low.col="#ff6f81",hi.col="#78cfe5",max_len_descript=
return(px)
}

GSEA2dp<-function(x,ntop = 7,low.col="#ff6f81",hi.col="#78cfe5",max_len_descript=40,...){
GSEA2dp<-function(x,ntop = 7,showIDs=F,low.col="#ff6f81",hi.col="#78cfe5",max_len_descript=40,...){
if(is.list(x) & !is.data.frame(x)){
cli::cli_abort("For a list object, please run plotting for every object inside list, instead of the whole list.")
}
Expand All @@ -163,6 +178,11 @@ GSEA2dp<-function(x,ntop = 7,low.col="#ff6f81",hi.col="#78cfe5",max_len_descript
assign("df0",x,envir = TempPlotingEnv)
cli::cli_alert_warning("You are drawing origin results, for better result you can re-cluster it by egt_recluster_analysis()")
})
if(showIDs & (sum(TempPlotingEnv$df0$ID == TempPlotingEnv$df0$Description)>=5)){
TempPlotingEnv$df0$ID <- substr(TempPlotingEnv$df0$ID,1,15)
TempPlotingEnv$df0$Description <- paste0(TempPlotingEnv$df0$ID,":",TempPlotingEnv$df0$Description)
max_len_descript <- max_len_descript + 16
}
tryCatch({
df <- TempPlotingEnv$df0 |>
group_by(Cluster) |>
Expand Down
1 change: 1 addition & 0 deletions R/fuser.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,6 @@ universalGT<-function(x,...){
else{
x1<-.genGT(x,...)
}
x1@fused <- T
return(x1)
}
6 changes: 6 additions & 0 deletions R/gt_generator.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ gt_gsea<-function(x,ClusterNum,objname,objname2=NULL,...){
}
orderlist<-fix_order(x$Cluster)
orderlist<-orderlist[orderlist%in%x$Cluster]
if(sum(x$ID == x$Description)>=5){
x$ID <- paste0(objname," / ",1:nrow(x))
}
y<-x |> gt::gt(groupname_col = "Cluster") |>
gt_hulk_col_numeric2(Padj,pal = RColorBrewer::brewer.pal(8,"Spectral")) |>
gt_hulk_col_numeric2(absNES,pal = RColorBrewer::brewer.pal(8,"PuBuGn") |> rev()) |>
Expand Down Expand Up @@ -33,6 +36,9 @@ gt_ora<-function(x,ClusterNum,objname,objname2=NULL,...){
}
orderlist<-fix_order(x$Cluster)
orderlist<-orderlist[orderlist%in%x$Cluster]
if(sum(x$ID == x$Description)>=5){
x$ID <- paste0(objname," / ",1:nrow(x))
}
y<-x |> gt::gt(groupname_col = "Cluster") |>
gt_hulk_col_numeric2(PCT,pal = RColorBrewer::brewer.pal(8,"PiYG") |> rev()) |>
gt_hulk_col_numeric2(Padj,pal = RColorBrewer::brewer.pal(8,"Spectral")) |>
Expand Down
6 changes: 3 additions & 3 deletions R/interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ egt_recluster_analysis<-function(x,ClusterNum=17,P.adj=0.05,force=F,nTop=10,meth
required_packages <- c(
"dplyr", "fontawesome", "glue", "gt", "proxy",
"RColorBrewer", "rlang", "scales", "text2vec",
"tibble","forcats","ggplot2","Matrix"
"tibble","forcats","ggplot2", "Matrix", "xfun"
)
missing_packages <- required_packages[!(required_packages %in% installed.packages()[,"Package"])]

Expand All @@ -73,7 +73,7 @@ egt_recluster_analysis<-function(x,ClusterNum=17,P.adj=0.05,force=F,nTop=10,meth
require("Matrix")
require("cli")
cli::cli_h1("EnrichGT")
cli::cli_alert_info("View your enrichment result by entring `EnrichGT(result)`")
cli::cli_alert("by Zhiming Ye, https://github.com/ZhimingYe/EnrichGT")
cli::cli_alert_info("See help on https://zhimingye.github.io/EnrichGT/")
cli::cli_alert("by Zhiming Ye")
}
}
4 changes: 3 additions & 1 deletion R/objFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ setClass("EnrichGT_obj",slots=list(enriched_result="data.frame",
pathway_clusters="list",
document_term_matrix="dgCMatrix",
clustering_tree="hclust",
raw_enriched_result="data.frame"))
raw_enriched_result="data.frame",
fused="logical"))


setMethod("show", "EnrichGT_obj", function(object) {
Expand All @@ -23,6 +24,7 @@ new.egt <- function(x1,x2,x3,x4,x5,x6,x7){
objegt@document_term_matrix <- x5
objegt@clustering_tree <- x6
objegt@raw_enriched_result <- x7
objegt@fused <- F
flag0<-T
},error=function(e){
message_egt("Failed to create EnrichGT object! Please re-check your input.")
Expand Down
17 changes: 13 additions & 4 deletions man/egt_plot_results.Rd

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

0 comments on commit 5543bb5

Please sign in to comment.