diff --git a/DESCRIPTION b/DESCRIPTION index 96bfa28..248c572 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -38,14 +38,14 @@ Imports: stats, tidyr, utils, - yulab.utils (>= 0.2.3) + yulab.utils (>= 0.2.3), + ggplot2 Suggests: AnnotationHub, BiocManager, DOSE, fanyi (>= 0.1.0), ggtangle, - jsonlite, readr, org.Hs.eg.db, quarto, diff --git a/NAMESPACE b/NAMESPACE index 5c189ad..9f81f09 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -149,11 +149,16 @@ importFrom(enrichplot,goplot) importFrom(enrichplot,gseaplot) importFrom(enrichplot,heatplot) importFrom(enrichplot,ridgeplot) +importFrom(ggplot2,aes) +importFrom(ggplot2,geom_label) +importFrom(ggplot2,geom_point) +importFrom(ggplot2,ggplot) +importFrom(ggplot2,ggtitle) +importFrom(ggplot2,scale_color_manual) +importFrom(ggplot2,theme_void) importFrom(gson,gson) importFrom(gson,read.gmt) importFrom(gson,read.gmt.wp) -importFrom(jsonlite,fromJSON) -importFrom(jsonlite,toJSON) importFrom(magrittr,"%<>%") importFrom(magrittr,"%>%") importFrom(methods,is) @@ -166,6 +171,7 @@ importFrom(rlang,"%||%") importFrom(rlang,.data) importFrom(rlang,check_installed) importFrom(rlang,quos) +importFrom(rlang,sym) importFrom(stats,formula) importFrom(stats,setNames) importFrom(tidyr,gather) diff --git a/R/gson.R b/R/gson.R index f4f848e..d44ea40 100644 --- a/R/gson.R +++ b/R/gson.R @@ -149,7 +149,7 @@ gson_WP <- function(organism) { #' #' @examples #' data = data.frame(gene_id = "gene1", -#' go_id = c("GO:0035492", "GO:0009764", "GO:0031063", "GO:0033714", "GO:0036349")) +#' go_id = c("GO:0035492", "GO:0009764", "GO:0031040", "GO:0033714", "GO:0036349")) #' gson_GO_local(data, species = "E. coli") gson_GO_local <- function(data, ont = c("ALL", "BP", "CC", "MF"), @@ -424,4 +424,4 @@ kegg_release = function(db){ y = readLines(url) release <- sub("\\w+\\s+", "", y[grep('Release', y)]) return(release) -} \ No newline at end of file +} diff --git a/R/interpret.R b/R/interpret.R index 6b58609..caa717b 100644 --- a/R/interpret.R +++ b/R/interpret.R @@ -269,6 +269,10 @@ run_agent_synthesizer <- function(pathways, detective_report, context, model, ap #' @param n_pathways Number of top significant pathways to include in the analysis. Default is 20. #' @param model The LLM model to use. Default is "deepseek-chat". Supported models include "deepseek-chat", "glm-4", "qwen-turbo" etc. #' @param api_key The API key for the LLM. If NULL, it tries to fetch from `getOption('yulab_translate')` based on the model. +#' @param task Task type, default is "interpretation". Other options include "cell_type"/"annotation" and "phenotype"/"phenotyping". +#' @param prior Optional prior knowledge (e.g., a biological hypothesis) to guide the task. +#' @param add_ppi Boolean, whether to use PPI network integration. +#' @param gene_fold_change Named vector of logFC for expression context. #' @return A character string containing the LLM-generated interpretation. #' @author Guangchuang Yu #' @export @@ -847,7 +851,6 @@ Ensure the response is a valid JSON object. Do not include any markdown formatti return(base_prompt) } -#' @importFrom jsonlite toJSON fromJSON call_llm_fanyi <- function(prompt, model, api_key) { if (!requireNamespace("fanyi", quietly = TRUE)) { stop("Package 'fanyi' is required for interpret(). Please install it.") diff --git a/R/plot_interpret.R b/R/plot_interpret.R index af91430..1484873 100644 --- a/R/plot_interpret.R +++ b/R/plot_interpret.R @@ -3,7 +3,10 @@ #' @title plot #' @param x An `interpretation` object. #' @param layout Graph layout, default is "nicely". -#' @param ... Additional arguments passed to `ggtangle::ggtangle`. +#' @param ... Additional arguments passed to `ggplot2::ggplot`. +#' @importFrom ggplot2 ggplot geom_label geom_point aes scale_color_manual +#' @importFrom ggplot2 theme_void ggtitle +#' @importFrom rlang sym #' @export plot.interpretation <- function(x, layout = "nicely", ...) { @@ -26,8 +29,8 @@ plot.interpretation <- function(x, layout = "nicely", ...) { # Add edges # We try to map interaction type to color if available if ("interaction" %in% igraph::edge_attr_names(g)) { - p <- p + ggtangle::geom_edge(ggplot2::aes(color = interaction)) + - ggplot2::scale_color_manual(values = c( + p <- p + ggtangle::geom_edge(aes(color = !!sym("interaction"))) + + scale_color_manual(values = c( activation = "green3", inhibition = "red3", repression = "red3", @@ -40,15 +43,15 @@ plot.interpretation <- function(x, layout = "nicely", ...) { # Add nodes and labels p <- p + geom_point(size = 5, color = "lightblue") + - geom_label(ggplot2::aes(label = name)) + - ggplot2::theme_void() + geom_label(aes(label = !!sym("name"))) + + theme_void() main_title <- "Refined Regulatory Network" if (!is.null(x$cluster)) { main_title <- paste0(main_title, " (", x$cluster, ")") } - p <- p + ggplot2::ggtitle(main_title) + p <- p + ggtitle(main_title) return(p) } diff --git a/man/gson_GO_local.Rd b/man/gson_GO_local.Rd index a3608b8..5319be0 100644 --- a/man/gson_GO_local.Rd +++ b/man/gson_GO_local.Rd @@ -23,6 +23,6 @@ Build a gson object that annotate Gene Ontology } \examples{ data = data.frame(gene_id = "gene1", - go_id = c("GO:0035492", "GO:0009764", "GO:0031063", "GO:0033714", "GO:0036349")) + go_id = c("GO:0035492", "GO:0009764", "GO:0031040", "GO:0033714", "GO:0036349")) gson_GO_local(data, species = "E. coli") } diff --git a/man/interpret.Rd b/man/interpret.Rd index eb2a810..ee1779c 100644 --- a/man/interpret.Rd +++ b/man/interpret.Rd @@ -26,6 +26,14 @@ interpret( \item{model}{The LLM model to use. Default is "deepseek-chat". Supported models include "deepseek-chat", "glm-4", "qwen-turbo" etc.} \item{api_key}{The API key for the LLM. If NULL, it tries to fetch from `getOption('yulab_translate')` based on the model.} + +\item{task}{Task type, default is "interpretation". Other options include "cell_type"/"annotation" and "phenotype"/"phenotyping".} + +\item{prior}{Optional prior knowledge (e.g., a biological hypothesis) to guide the task.} + +\item{add_ppi}{Boolean, whether to use PPI network integration.} + +\item{gene_fold_change}{Named vector of logFC for expression context.} } \value{ A character string containing the LLM-generated interpretation. diff --git a/man/plot.interpretation.Rd b/man/plot.interpretation.Rd index 373e5b1..757dbad 100644 --- a/man/plot.interpretation.Rd +++ b/man/plot.interpretation.Rd @@ -11,7 +11,7 @@ \item{layout}{Graph layout, default is "nicely".} -\item{...}{Additional arguments passed to `ggtangle::ggtangle`.} +\item{...}{Additional arguments passed to `ggplot2::ggplot`.} } \description{ plot