Skip to content

Commit

Permalink
Fix different URI locations (see #42)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgatto committed Feb 16, 2024
1 parent 1f85f31 commit cd7a870
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rols
Type: Package
Title: An R interface to the Ontology Lookup Service
Version: 2.99.1
Version: 2.99.2
Authors@R: c(person(given = "Laurent", family = "Gatto",
email = "[email protected]",
role = c("aut","cre")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# rols 2.99

## CHANGES IN VERSION 2.99.2

- Fix different URI locations (see #42)

## CHANGES IN VERSION 2.99.1

- Fix logical syntax in url.
Expand Down
1 change: 0 additions & 1 deletion R/OlsSearch.R
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ OlsSearch <- function(q,
searchUrl <- "http://www.ebi.ac.uk/ols4/api/search?"
url <- paste0(searchUrl,
paste(params, collapse = "&"))
message(url)
x <- request(url) |>
req_perform() |>
resp_body_json()
Expand Down
25 changes: 17 additions & 8 deletions R/Terms.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,24 +184,33 @@ setMethod("Terms", "Ontology",
##'
##' @param id `character(1)` with the term's identifier.
setMethod("Term", "character",
function(object, id) Term(Ontology(object), id))

##' @export
##' @rdname Terms
setMethod("Term", "Ontology",
function(object, id) {
## See https://github.com/EBISPOT/ols4/issues/621
url <- paste0(
"https://www.ebi.ac.uk/ols4/api/ontologies/",
object,
"/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252F")
url <- paste0(url, sub(":", "_", id))
olsNamespace(object),
"/terms/")
loc <- object@config$fileLocation
if (grepl("ebi.ac.uk", loc)) {
uri <- sub("/[a-zA-z]+\\.owl$", "", loc)
}
else if (grepl("purl.obolibrary.org", loc)) {
uri <- "http://purl.obolibrary.org/obo"
} else stop("Unknown fileLocation")
uri <- paste0(uri, "/", sub(":", "_", id))
uri <- gsub("%", "%25", URLencode(uri, TRUE))
url <- paste0(url, uri)
request(url) |>
req_perform() |>
resp_body_json() |>
termFromJson()
})

##' @export
##' @rdname Terms
setMethod("Term", "Ontology",
function(object, id)
Term(olsNamespace(object), id))

##' @export
##' @rdname Terms
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test_Terms.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ test_that("constructors", {
descendants(trm)@x[nms])
})

test_that("constructors different URIs (issue 42)", {
## See https://github.com/lgatto/rols/issues/42
expect_is(Term("ado", "ADO:0000090"), "Term")
expect_is(Term("efo", "EFO:0001200"), "Term")
expect_is(Term("go", "GO:0005802"), "Term")
})

test_that("show methods", {
expect_null(show(trms))
## expect_null(show(trms[1]))
Expand Down

0 comments on commit cd7a870

Please sign in to comment.