Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: enviPathR
Title: Client for the 'enviPath' 'RESTful' API
Version: 1.0.2
Version: 1.0.3
Authors@R:
c(person(given = "Giulio", family = "Benedetti",
role = c("aut", "cre", "cph"),
Expand All @@ -23,7 +23,7 @@ Imports:
BiocParallel,
httr2,
stats,
stringr,
stringi,
tools
Suggests:
BiocStyle,
Expand All @@ -36,8 +36,8 @@ Suggests:
License: Artistic-2.0
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 8.0.0
URL: https://envipath.github.io/enviPathR/
URL: https://github.com/enviPath/enviPathR, https://envipath.github.io/enviPathR
BugReports: https://github.com/enviPath/enviPathR/issues
Config/testthat/edition: 3
VignetteBuilder: knitr
Config/roxygen2/version: 8.1.1
39 changes: 23 additions & 16 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,28 @@ export(epLogin)
export(epLogout)
export(epModel)
export(epTypes)
importFrom(BiocParallel,bplapply)
importFrom(BiocParallel,bpmapply)
importFrom(BiocParallel,bpparam)
importFrom(httr2,req_body_form)
importFrom(httr2,req_cookie_preserve)
importFrom(httr2,req_error)
importFrom(httr2,req_method)
importFrom(httr2,req_perform)
importFrom(httr2,req_retry)
importFrom(httr2,req_throttle)
importFrom(httr2,req_url_path_append)
importFrom(httr2,request)
importFrom(httr2,resp_body_json)
importFrom(BiocParallel,
bplapply,
bpmapply,
bpparam
)
importFrom(httr2,
req_body_form,
req_cookie_preserve,
req_error,
req_get_body,
req_method,
req_perform,
req_retry,
req_throttle,
req_url_path_append,
request,
resp_body_json,
resp_url
)
importFrom(stats,complete.cases)
importFrom(stringr,fixed)
importFrom(stringr,str_remove)
importFrom(stringr,str_split)
importFrom(stringi,
stri_replace_first_regex,
stri_split_fixed
)
importFrom(tools,R_user_dir)
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Changes in version 1.0.x
* Submitted to CRAN
* Included raw API calls in output metadata

Changes in version 0.99.x
* Introduced epTypes, epLogin, epLogout, epList, epLink, epGet and epModel
15 changes: 13 additions & 2 deletions R/get.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#' Get enviPath objects
#'

Check warning on line 2 in R/get.R

View workflow job for this annotation

GitHub Actions / ubuntu-latest (auto)

[lintr] Remove trailing whitespace.
#' @name epGet
#'

Check warning on line 4 in R/get.R

View workflow job for this annotation

GitHub Actions / ubuntu-latest (auto)

[lintr] Remove trailing whitespace.
#' @description
#' epGet returns raw objects from enviPath.
#'

Check warning on line 7 in R/get.R

View workflow job for this annotation

GitHub Actions / ubuntu-latest (auto)

[lintr] Remove trailing whitespace.
#' @param type \code{Character scalar}. String specifying the object type to be
#' fetched.
#'

Check warning on line 10 in R/get.R

View workflow job for this annotation

GitHub Actions / ubuntu-latest (auto)

[lintr] Remove trailing whitespace.
#' @param init \code{Character vector}. Vector of strings specifying the initial
#' values of \code{type} that should be fetched. When null, all objects
#' belonging to \code{type} in \code{pkg} are used. (Default: \code{NULL})
#'

Check warning on line 14 in R/get.R

View workflow job for this annotation

GitHub Actions / ubuntu-latest (auto)

[lintr] Remove trailing whitespace.
#' @param pkg \code{Character scalar}. String specifying the unique identifier
#' of the package from which objects should be fetched. When null, EAWAG-BBD
#' is used. (Default: \code{NULL})
Expand All @@ -30,7 +30,11 @@
#' not serial. (Default: \code{5})
#'
#' @returns
#' A list of objects.
#' A list of retrieved objects.
#'
#' @details
#' For transparency, the performed raw API calls can be accessed with
#' \code{attr(x, "call")}, where \code{x} is the output of \code{epGet}.
#'
#' @examples
#' \dontshow{
Expand Down Expand Up @@ -76,10 +80,15 @@
SIMPLIFY = FALSE,
BPPARAM = BPPARAM
)
# Store raw API calls in corresponding attribute
attr(out, "call")$url <- vapply(
out, attr, character(1L), "call", USE.NAMES = FALSE
)
return(out)
}

#' @importFrom httr2 request req_url_path_append req_cookie_preserve req_throttle resp_body_json
#' @importFrom httr2 request req_url_path_append req_cookie_preserve
#' req_throttle resp_url resp_body_json
.ep_get <- function(init, type, pkg, property, rate){
# Prepare get request
req <- request(eP_env$url) |>
Expand All @@ -92,5 +101,7 @@
resp <- .ep_perform(req)
# Process response
out <- resp_body_json(resp, simplifyVector = TRUE)
# Store raw API call in corresponding attribute
attr(out, "call") <- resp_url(resp)
return(out)
}
18 changes: 14 additions & 4 deletions R/link.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#' @returns
#' A data frame with links between from and to.
#'
#' @details
#' For transparency, the performed raw API calls can be accessed with
#' \code{attr(x, "call")}, where \code{x} is the output of \code{epLink}.
#'
#' @examples
#' \dontshow{
#' username <- Sys.getenv("EP_USERNAME")
Expand All @@ -54,7 +58,7 @@ NULL
#' @export
#' @rdname epLink
#' @importFrom BiocParallel bplapply bpparam
#' @importFrom stringr str_remove
#' @importFrom stringi stri_replace_first_regex
#' @importFrom stats complete.cases
epLink <- function(from, to, init = NULL, pkg = NULL, BPPARAM = bpparam(), rate = 5){
# Check from
Expand Down Expand Up @@ -97,6 +101,8 @@ epLink <- function(from, to, init = NULL, pkg = NULL, BPPARAM = bpparam(), rate
x = rep(init, lengths(out, use.names = FALSE)),
y = unlist(out, use.names = FALSE)
)
# Store raw API calls in corresponding attribute
attr(linkmap, "call")$url <- vapply(out, attr, character(1L), "call")
# Set linkmap column names
colnames(linkmap) <- c(from, to)
# Remove missing values
Expand All @@ -108,19 +114,21 @@ epLink <- function(from, to, init = NULL, pkg = NULL, BPPARAM = bpparam(), rate
}
# Remove structure identifier for compounds
if( by == "pathway2compound" ){
linkmap[to] <- str_remove(linkmap[[to]], "/structure/.*")
linkmap[to] <- linkmap[[to]] |>
stri_replace_first_regex("/structure/.*", "")
}
if( by == "pathway2reaction" ){
rxn_df <- epList("reaction", pkg = pkg)
linkmap[to] <- rxn_df$id[rxn_df$name %in% linkmap[[to]]]
}
# Remove id prefix
linkmap[to] <- str_remove(linkmap[[to]], ".*/")
linkmap[to] <- stri_replace_first_regex(linkmap[[to]], ".*/", "")
return(linkmap)
}


#' @importFrom httr2 request req_url_path_append req_cookie_preserve req_throttle resp_body_json
#' @importFrom httr2 request req_url_path_append req_cookie_preserve
#' req_throttle resp_url resp_body_json
.ep_link <- function(init, from, to, pkg, rate){
# Prepare link request
req <- request(eP_env$url) |>
Expand All @@ -137,6 +145,8 @@ epLink <- function(from, to, init = NULL, pkg = NULL, BPPARAM = bpparam(), rate
unlist(use.names = FALSE)
# Simplify list to single object
if( is.null(out) ) out <- NA
# Store raw API call in corresponding attribute
attr(out, "call") <- resp_url(resp)
return(out)
}

Expand Down
32 changes: 20 additions & 12 deletions R/list.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#' @returns
#' A data frame with all objects belonging to \code{type} in \code{pkg}.
#'
#' @details
#' For transparency, the performed raw API call can be accessed with
#' \code{attr(x, "call")}, where \code{x} is the output of \code{epList}.
#'
#' @examples
#' \dontshow{
#' username <- Sys.getenv("EP_USERNAME")
Expand Down Expand Up @@ -53,8 +57,8 @@ NULL

#' @export
#' @rdname epList
#' @importFrom httr2 req_url_path_append req_cookie_preserve resp_body_json
#' @importFrom stringr str_remove
#' @importFrom httr2 req_url_path_append req_cookie_preserve resp_url resp_body_json
#' @importFrom stringi stri_replace_first_regex
epList <- function(type, pkg = NULL){
# Check type
.check_type(type)
Expand All @@ -64,36 +68,40 @@ epList <- function(type, pkg = NULL){
if( type == "package" && is_pkg ){
stop("'pkg' cannot be defined when listing packages.", call. = FALSE)
}

# Initialise request and preserve cookies
req <- request(eP_env$url) |>
req_cookie_preserve(eP_env$cookies)

# Append package id to call url
if( is_pkg ) req <- req_url_path_append(req, "package", pkg)
# Append object type to call url
req <- req_url_path_append(req, type)

# Perform query
resp <- .ep_perform(req)

# Retrieve result from response
out <- resp_body_json(resp, simplifyVector = TRUE)
# Extract data.frame
df <- out[[1L]]
# Remove id prefix
df$id <- str_remove(df$id, ".*/")

df$id <- stri_replace_first_regex(df$id, ".*/", "")
# Select relevant variables to keep
to_keep <- c("name", "id")
# Include review status except for type setting
if( type != "setting" ) to_keep <- c(to_keep, "reviewStatus")

# Add package-specific stats
if( type == "package" ){

# Retrieve object types
obj.types <- names(df$links[[1L]])
# Count objects for each type
obj.counts <- vapply(obj.types, .extract_obj_counts, numeric(nrow(df)), df)

# Combine object counts into table
df <- cbind(df, obj.counts)
# Add description and object counts to relevant variables
to_keep <- c(to_keep, "description", obj.types)
}
# Select relevant columns
df <- df[ , to_keep]
# Store raw API call in corresponding attribute
attr(df, "call")$url <- resp_url(resp)
return(df)
}

Expand Down
10 changes: 9 additions & 1 deletion R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#' A list with two data frames with information on nodes and edges,
#' respectively.
#'
#' @details
#' For transparency, the performed raw API call can be accessed with
#' \code{attr(x, "call")}, where \code{x} is the output of \code{epModel}.
#'
#' @examples
#' \dontshow{
#' username <- Sys.getenv("EP_USERNAME")
Expand Down Expand Up @@ -77,7 +81,8 @@ NULL

#' @export
#' @rdname epModel
#' @importFrom httr2 request req_method req_url_path_append req_body_form req_cookie_preserve resp_body_json
#' @importFrom httr2 request req_method req_url_path_append req_body_form
#' req_cookie_preserve req_get_body resp_url resp_body_json
epModel <- function(smiles, setting = NULL){
# Check smiles
if( !is.character(smiles) || !nzchar(smiles) ){
Expand All @@ -99,6 +104,9 @@ epModel <- function(smiles, setting = NULL){
resp <- .ep_perform(req)
# Process response
out <- resp_body_json(resp, simplifyVector = TRUE)
# Store raw API call in corresponding attribute
attr(out, "call")$url <- resp_url(resp)
attr(out, "call")$body <- req_get_body(req)
# Process rule variables
if( is.data.frame(out$edges$rule) ){
out$edges$ruleId <- out$edges$rule$uuid
Expand Down
4 changes: 2 additions & 2 deletions R/types.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ NULL

#' @export
#' @rdname epTypes
#' @importFrom stringr str_split fixed
#' @importFrom stringi stri_split_fixed
epTypes <- function(){
# Retrieve links between object types
links <- eP_env$links |>
names() |>
str_split(fixed("2"), simplify = TRUE) |>
stri_split_fixed("2", simplify = TRUE) |>
as.data.frame()
# Give names to link columns
colnames(links) <- c("from", "to")
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
[![pulls](https://img.shields.io/github/issues-pr/enviPath/enviPathR)](https://github.com/enviPath/enviPathR/pulls)
[![CRAN status](https://www.r-pkg.org/badges/version/enviPathR)](https://CRAN.R-project.org/package=enviPathR)
[![R-CMD-check](https://github.com/enviPath/enviPathR/workflows/build/badge.svg)](https://github.com/enviPath/enviPathR/actions)
[![](https://cranlogs.r-pkg.org/badges/enviPathR)](https://cran.r-project.org/package=enviPathR)
[![CodeFactor](https://www.codefactor.io/repository/github/enviPath/envipathr/badge)](https://www.codefactor.io/repository/github/enviPath/envipathr)
[![downloads](https://cranlogs.r-pkg.org/badges/enviPathR)](https://cran.r-project.org/package=enviPathR)

This package provides a client to the enviPath biotransformation database and
pathway prediction system. It accesses enviPath resources through its [legacy
Expand Down
6 changes: 5 additions & 1 deletion man/epGet.Rd

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

4 changes: 4 additions & 0 deletions man/epLink.Rd

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

4 changes: 4 additions & 0 deletions man/epList.Rd

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

4 changes: 4 additions & 0 deletions man/epModel.Rd

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

8 changes: 8 additions & 0 deletions pkgdown/_pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
url: https://envipath.github.io/enviPathR
destination: docs

template:
bootstrap: 5
light-switch: true
bslib:
navbar-bg: "#142D4A"

reference:
- title: Work with enviPath API
- contents:
Expand Down
10 changes: 5 additions & 5 deletions tests/httptest/get/package_reaction/wrong.R

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions tests/httptest/link/package_compound/wrong.R

Large diffs are not rendered by default.

Loading
Loading