Skip to content

Commit

Permalink
Improves recovery of labels for pregenerated post-comps
Browse files Browse the repository at this point in the history
Due to an issue in the KB API (phenoscape/phenoscape-kb-services#199)
the /term/labels endpoint fails for most (all?) post-compositions.
This works around this bug for now by trying /term/classification for
those IDs for which /term/labels fails.

Includes tests.
  • Loading branch information
hlapp authored and johnbradley committed Jan 28, 2021
1 parent bfea6e3 commit 9d8e24d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
19 changes: 16 additions & 3 deletions R/pk_terms.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,22 @@ get_term_label <- function(term_iris, preserveOrder = FALSE, verbose = FALSE) {
if (length(res) > 0) {
names(res) <- sub("@", "", names(res))
}
if (preserveOrder && nrow(res) > 0) {
reordering <- match(term_iris, res$id)
res <- res[reordering,]
if (nrow(res) > 0) {
noLabel <- is.na(res$label)
if (any(noLabel)) {
res[noLabel, "label"] <- sapply(res$id[noLabel], function(iri) {
clInfo <- pk_class(iri, as = NA, verbose = verbose)
if (length(clInfo) <= 1 || clInfo$label == iri)
NA
else
clInfo$label
},
USE.NAMES = FALSE)
}
if (preserveOrder) {
reordering <- match(term_iris, res$id)
res <- res[reordering,]
}
}

res
Expand Down
14 changes: 12 additions & 2 deletions tests/testthat/test-pk.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,21 @@ test_that("Test getting labels", {
testthat::expect_equal(nrow(lbls), 1)
testthat::expect_false(is.na(lbls$label))

lbls <- get_term_label("urn:foobar")
lbls <- get_term_label("http://foobar")
testthat::expect_equal(nrow(lbls), 1)
testthat::expect_equal(lbls$id, "urn:foobar")
testthat::expect_equal(lbls$id, "http://foobar")
testthat::expect_true(is.na(lbls$label))
})

test_that("labels for pre-generated post-comps", {
phen <- sample(get_phenotypes("basihyal bone")$id, size = 1)
subs <- sample(rownames(subsumer_matrix(phen)), size = 30)
subs.l <- get_term_label(subs, preserveOrder = TRUE)
testthat::expect_lte(sum(is.na(subs.l$label)), 1)

subs <- sample(rownames(subsumer_matrix(c("femur"))), 30)
subs.l <- get_term_label(subs, preserveOrder = TRUE)
testthat::expect_lte(sum(is.na(subs.l$label)), 1)
})

test_that("Test getting study information", {
Expand Down

0 comments on commit 9d8e24d

Please sign in to comment.