Skip to content

Commit

Permalink
Merge pull request #34 from natverse/fix/banc-no-meta
Browse files Browse the repository at this point in the history
empty query fixes for all keys and banc metadata
  • Loading branch information
jefferis authored Nov 18, 2024
2 parents 3000bd8 + ac246e8 commit d54f825
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
6 changes: 5 additions & 1 deletion R/ids.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ keys <- function(x, idcol='id') {
)
x$dataset=abbreviate_datasets(x$dataset)
}
paste0(x[['dataset']],":", x[[idcol]])
if(nrow(x)>0)
paste0(x[['dataset']],":", x[[idcol]])
else
character()
}

is_key <- function(x, compound=FALSE) {
Expand Down Expand Up @@ -269,6 +272,7 @@ expand_ids <- function(ids, dataset) {
ids=mapply(expand_ids, ids=ids, dataset=names(ids), SIMPLIFY = FALSE)
return(ids)
}
if(length(ids)==0) return(character())
dataset=match_datasets(dataset)
FUN <- switch(dataset,
manc=function(ids) malevnc::manc_ids(ids, mustWork = F),
Expand Down
3 changes: 2 additions & 1 deletion R/meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ fancorbanc_meta <- function(table, ids=NULL, ...) {
mutate(subclass=NA_character_) %>%
mutate(id=as.character(id))
}
if(length(ids))
if(!is.null(ids))
left_join(data.frame(id=ids), metadf, by='id')
else
metadf
Expand All @@ -269,6 +269,7 @@ fanc_ids <- function(ids) {

#' @importFrom dplyr pull
fancorbanc_ids <- function(ids, dataset=c("banc", "fanc")) {
if(is.null(ids)) return(NULL)
dataset=match.arg(dataset)
# extract numeric ids if possible
ids <- extract_ids(ids)
Expand Down
9 changes: 8 additions & 1 deletion tests/testthat/test-ids.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ test_that("key handling works", {
flywire=as.character(1:5)))

expect_output(print(res), regexp = 'flywire.*hemibrain')

expect_equal(keys(cf_ids(hemibrain = '/MBON01')), cf_ids(hemibrain = '/MBON01', keys = T))

expect_warning(
expect_equal(cf_ids(hemibrain = "/rhubarb", keys = T), character()),
"No matching ids")
})

test_that("fanc/banc ids/metadata", {
Expand All @@ -52,4 +56,7 @@ test_that("fanc/banc ids/metadata", {
expect_length(dna02keys <- cf_ids(banc='/DNa02', keys = T), 2L)
expect_warning(
expect_in(cf_ids(banc='DNa02', keys = T), dna02keys))
expect_warning(
expect_equal(lengths(cf_ids(banc='/rhubarb.+', expand = TRUE)), 0L, ignore_attr=TRUE),
"No matching ids")
})
6 changes: 6 additions & 0 deletions tests/testthat/test-meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ test_that("metadata", {
'data.frame')
expect_contains(colnames(dna02meta2), c("serial", "birthtime"))
})

test_that("fanc/banc ids/metadata", {
skip_if_not_installed('fancr')
skip_if_not_installed('reticulate')
expect_null(cf_meta(cf_ids(banc='/rhubarb.+')))
})

0 comments on commit d54f825

Please sign in to comment.