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
49 changes: 49 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: build
on:
push:
branches:
- devel
jobs:
rworkflows:
permissions: write-all
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
container: ${{ matrix.config.cont }}
strategy:
fail-fast: ${{ false }}
matrix:
config:
- os: ubuntu-latest
bioc: devel
r: auto
cont: ghcr.io/bioconductor/bioconductor_docker:devel
rspm: ~
- os: macOS-latest
bioc: devel
r: auto
cont: ~
rspm: ~
- os: windows-latest
bioc: devel
r: auto
cont: ~
rspm: ~
steps:
- uses: neurogenomics/rworkflows@master
with:
run_bioccheck: ${{ false }}
run_rcmdcheck: ${{ false }}
as_cran: ${{ true }}
run_vignettes: ${{ true }}
has_testthat: ${{ true }}
run_covr: ${{ true }}
run_pkgdown: ${{ true }}
has_runit: ${{ false }}
has_latex: ${{ false }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run_docker: ${{ false }}
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
runner_os: ${{ runner.os }}
cache_version: cache-v1
docker_registry: ghcr.io
52 changes: 52 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: test
on:
pull-request:
branches:
- devel
jobs:
rworkflows:
permissions: write-all
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
container: ${{ matrix.config.cont }}
strategy:
fail-fast: ${{ false }}
matrix:
config:
- os: ubuntu-latest
bioc: devel
r: auto
cont: ghcr.io/bioconductor/bioconductor_docker:devel
rspm: ~
- os: macOS-latest
bioc: devel
r: auto
cont: ~
rspm: ~
- os: windows-latest
bioc: devel
r: auto
cont: ~
rspm: ~
env:
EP_USERNAME: ${{ secrets.EP_USERNAME }}
EP_PASSWORD: ${{ secrets.EP_PASSWORD }}
steps:
- uses: neurogenomics/rworkflows@master
with:
run_bioccheck: ${{ true }}
run_rcmdcheck: ${{ true }}
as_cran: ${{ true }}
run_vignettes: ${{ false }}
has_testthat: ${{ true }}
run_covr: ${{ false }}
run_pkgdown: ${{ false }}
has_runit: ${{ false }}
has_latex: ${{ false }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run_docker: ${{ false }}
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
runner_os: ${{ runner.os }}
cache_version: cache-v1
docker_registry: ghcr.io
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
.Rproj.user
.Rhistory
.Renviron
inst/doc
vignettes/*.html
vignettes/*.R
docs/
22 changes: 18 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
Package: enviPathR
Title: R client for enviPath API
Version: 0.0.0.9000
Authors@R:
person("Giulio", "Benedetti", , "giulio.benedetti@utu.fi", role = c("aut", "cre"))
Version: 0.99.0
Authors@R:
c(person(given = "Giulio", family = "Benedetti", role = c("aut", "cre"),
email = "giulio.benedetti@utu.fi",
comment = c(ORCID = "0000-0002-8732-7692")))
Description:
The environmental pathway database (enviPath) is a key resource for the
functional annotation and pathway prediction of microbial communities,
providing knowledge on biotransformation pathways along with the chemical
reactions and produced compounds. This package enables the programmatic
access to enviPath by porting the database API from R.
biocViews:
Software, DataImport, Cheminformatics, Microbiome, Annotation, Pathways,
Visualization, Network, GraphAndNetwork
Imports:
BiocParallel,
httr2,
jsonlite,
stats,
stringr,
tools
License: Artistic-2.0
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 8.0.0
Suggests:
BiocStyle,
httptest2,
igraph,
knitr,
rmarkdown,
testthat (>= 3.0.0)
Config/testthat/edition: 3
VignetteBuilder: knitr
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export(epGet)
export(epLink)
export(epList)
export(epLogin)
export(epModel)
importFrom(BiocParallel,bplapply)
importFrom(BiocParallel,bpmapply)
importFrom(httr2,req_body_form)
Expand Down
2 changes: 1 addition & 1 deletion R/constants.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
cache <- R_user_dir("enviPathR", "cache")
if( !dir.exists(cache) ) dir.create(cache)
# Preserve cookies between requests
eP_env$cookies <- tempfile("cookies", tmpdir = cache, fileext = ".txt")
eP_env$cookies <- file.path(cache, "cookies.txt")
# Add links
eP_env$links <- .make_ep_links()
return(eP_env)
Expand Down
12 changes: 12 additions & 0 deletions R/get.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,21 @@
#' A list of objects
#'
#' @examples
#' \dontshow{
#' username <- Sys.getenv("EP_USERNAME")
#' password <- Sys.getenv("EP_PASSWORD")
#'
#' epLogin(username, password)
#'
#' library(httptest2)
#' start_vignette("httptest/get")
#' }
#' rxn_id <- "2b6bbcc5-77f4-4bed-92a9-731cdc978f6a"
#'
#' epGet("reaction", rxn_id)
#' \dontshow{
#' end_vignette()
#' }
NULL

#' @export
Expand Down
14 changes: 13 additions & 1 deletion R/link.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,21 @@
#' A data frame with links between from and to.
#'
#' @examples
#' \dontshow{
#' username <- Sys.getenv("EP_USERNAME")
#' password <- Sys.getenv("EP_PASSWORD")
#'
#' epLogin(username, password)
#'
#' library(httptest2)
#' start_vignette("httptest/link")
#' }
#' rxn_id <- "2b6bbcc5-77f4-4bed-92a9-731cdc978f6a"
#'
#' epGet("reaction", rxn_id)
#' epLink("reaction", "compound", rxn_id)
#' \dontshow{
#' end_vignette()
#' }
NULL

#' @export
Expand Down
16 changes: 15 additions & 1 deletion R/list.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,21 @@
#' A data frame.
#'
#' @examples
#' \dontshow{
#' username <- Sys.getenv("EP_USERNAME")
#' password <- Sys.getenv("EP_PASSWORD")
#'
#' epLogin(username, password)
#'
#' library(httptest2)
#' start_vignette("httptest/list")
#' }
#' epList("package")
#'
#' epList("pathway", pkg = "32de3cf4-e3e6-4168-956e-32fa5ddb0ce1")
#' \dontshow{
#' end_vignette()
#' }
NULL

#' @export
Expand Down Expand Up @@ -45,7 +57,9 @@ epList <- function(type, pkg = NULL){
# Remove id prefix
df$id <- str_remove(df$id, ".*/")

to_keep <- c("name", "id", "reviewStatus")
to_keep <- c("name", "id")
# Include review status except for type setting
if( type != "setting" ) to_keep <- c(to_keep, "reviewStatus")

if( type == "package" ){

Expand Down
7 changes: 5 additions & 2 deletions R/login.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
#' A message upon successful login.
#'
#' @examples
#' # epLogin("FirstLast", "abc123")
#' #> Welcome to enviPath!
#' \dontshow{
#' username <- Sys.getenv("EP_USERNAME")
#' password <- Sys.getenv("EP_PASSWORD")
#' }
#' epLogin(username, password)
NULL

#' @importFrom httr2 request req_method req_body_form req_cookie_preserve req_perform
Expand Down
81 changes: 81 additions & 0 deletions R/model.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#' Predict biotransformation pathways for compounds
#'
#' @name epModel
#'
#' @description
#' epGet returns a raw object from enviPath.
#'
#' @param smiles \code{Character vector}.
#'
#' @param setting \code{Character scalar}.
#'
#' @returns
#' A list with two data frames with information on nodes and edges,
#' respectively.
#'
#' @examples
#' \dontshow{
#' username <- Sys.getenv("EP_USERNAME")
#' password <- Sys.getenv("EP_PASSWORD")
#'
#' epLogin(username, password)
#' }
#' library(igraph)
#'
#' # Define smiles of interest
#' smiles <- "ClC(Cl)=C(Cl)Cl"
#'
#' # Perform pathway prediction with enviFormer
#' former_out <- epModel(smiles)
#'
#' # Set id for PEPPER model setting
#' set_id <- "3cda8e56-f4ff-47a8-b68c-4cfcfc4e8c2a"
#'
#' # Perform pathway prediction with PEPPER
#' pepper_out <- epModel(smiles, set_id)
#'
#' # Convert model output to igraph object
#' path_graph <- graph_from_data_frame(
#' pepper_out$edges,
#' vertices = pepper_out$nodes
#' )
#'
#' # Visualise predicted pathway
#' plot(path_graph)
NULL

#' @export
#' @rdname epModel
#' @importFrom httr2 request req_method req_url_path_append req_body_form req_cookie_preserve req_perform resp_body_json
epModel <- function(smiles, setting = NULL){

if( smiles == "" ){
stop("'smiles' must be a valid SMILES string.", call. = FALSE)
}

if( is.null(setting) ) setting <- "1d915a48-286a-4394-9693-bfaa187326a5"

setting <- paste0("https://envipath.org/setting/", setting)

req <- request(eP_env$url) |>
req_method("POST") |>
req_url_path_append("util") |>
req_body_form(smiles = smiles, settingUri = setting) |>
req_cookie_preserve(path = eP_env$cookies)

resp <- req_perform(req)

out <- resp_body_json(resp, simplifyVector = TRUE)

if( is.data.frame(out$edges$rule) ){
out$edges$ruleId <- out$edges$rule$uuid
out$edges$ruleName <- out$edges$rule$name
out$edges$rule <- NULL
}

out$nodes$name <- out$nodes$smiles
out$nodes$smiles <- NULL

out$nodes <- out$nodes[c("id", "name", "depth")]
return(out)
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ Bioconductor release version:
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")

BiocManager::install("mia")
BiocManager::install("enviPathR")
```

Beta version:

```
remotes::install_github("Minotau-R/ariadne")
remotes::install_github("Minotau-R/enviPathR")
```

## References
Expand Down
12 changes: 12 additions & 0 deletions man/epGet.Rd

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

14 changes: 13 additions & 1 deletion man/epLink.Rd

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

Loading