Skip to content

Commit

Permalink
support for high resolution image
Browse files Browse the repository at this point in the history
  • Loading branch information
noriakis committed Feb 2, 2024
1 parent 7253f34 commit e6404a9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: ggkegg
Type: Package
Title: KEGG pathway visualization by ggplot2
Version: 1.1.10
Version: 1.1.11
Authors@R: person("Noriaki", "Sato", email = "nori@hgc.jp", role = c("cre", "aut"))
Description: This package aims to import, parse, and analyze KEGG data such as KEGG PATHWAY and KEGG MODULE. The package supports visualizing KEGG information using ggplot2 and ggraph through using the grammar of graphics. The package enables the direct visualization of the results from various omics analysis packages.
License: MIT + file LICENSE
Expand Down
25 changes: 19 additions & 6 deletions R/overlay_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#' Override `adjust`
#' @param use_cache whether to use BiocFileCache()
#' @param interpolate parameter in annotation_raster()
#' @param high_res Use high resolution (2x) image for the overlay
#' @import magick
#' @return ggplot2 object
#' @export
Expand All @@ -34,7 +35,8 @@ overlay_raw_map <- function(pid=NULL, directory=NULL,
adjust_manual_y=NULL,
clip=FALSE,
use_cache=TRUE,
interpolate=TRUE) {
interpolate=TRUE,
high_res=FALSE) {
structure(list(pid=pid,
transparent_colors=transparent_colors,
adjust=adjust,
Expand All @@ -43,7 +45,8 @@ overlay_raw_map <- function(pid=NULL, directory=NULL,
adjust_manual_y=adjust_manual_y,
directory=directory,
use_cache=use_cache,
interpolate=interpolate),
interpolate=interpolate,
high_res=high_res),
class="overlay_raw_map")
}

Expand All @@ -65,16 +68,26 @@ ggplot_add.overlay_raw_map <- function(object, plot, object_name) {
if (is.null(object$pid)) {
infer <- plot$data$pathway_id |> unique()
object$pid <- infer[!is.na(infer)]
if (object$high_res) {
## Convert to reference ID
cur_id <- object$pid
object$pid <- paste0("map",
regmatches(cur_id, gregexpr("[[:digit:]]+", cur_id)) %>% unlist())
}
}
if (!grepl("[[:digit:]]", object$pid)) {
warning("Looks like not KEGG ID for pathway")
return(1)
}
## Return the image URL, download and cache
url <- paste0(as.character(pathway(object$pid,
use_cache=object$use_cache,
directory=object$directory,
return_image=TRUE)))
## From 1.1.10
url <- paste0("https://rest.kegg.jp/get/",object$pid,"/image")
if (object$high_res) {
if (!startsWith(object$pid, "map")) {
stop("High resolution image can be obtained for the reference pathway.")
}
url <- paste0(url, "2x")
}
if (object$use_cache) {
bfc <- BiocFileCache()
path <- bfcrpath(bfc, url)
Expand Down
5 changes: 4 additions & 1 deletion man/overlay_raw_map.Rd

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

0 comments on commit e6404a9

Please sign in to comment.