Skip to content

Commit

Permalink
Add tests for ncbi_get_meta() with dbs
Browse files Browse the repository at this point in the history
  • Loading branch information
stitam committed Dec 11, 2023
1 parent 19d5e70 commit 3f54071
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion R/ncbi_get_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ ncbi_get_meta <- function(
meta = res_parsed,
web_history = if (use_history) uids$web_history else NULL
)
class(out) <- c(paste("ncbi", db, "meta", sep = "_"), class(out))
class(out) <- c("ncbi_meta", class(out))
return(out)
}
4 changes: 1 addition & 3 deletions R/ncbi_supported_dbs.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
ncbi_supported_dbs <- function() {
dbs <- c(
"assembly", "bioproject", "biosample", "gene", "nuccore", "protein", "sra"
)
dbs <- c("assembly", "bioproject", "biosample", "gene", "protein", "sra")
return(dbs)
}
Binary file modified data/examples.rda
Binary file not shown.
6 changes: 5 additions & 1 deletion scripts/prep_examples.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ examples <- list(
"GCF_000002435.2",
"GCF_000299415.1"
),
bioproject = "PRJEB54063",
biosample = c(
"SAMN02714232", # contact email
"SAMD00057211", # different ids, duplicated attributes
Expand All @@ -17,7 +18,10 @@ examples <- list(
"SAMN00778252",
"SAMEA3317914",
"SAMEA14036741"
)
),
gene = "948356",
protein = "AAA27507.1",
sra = "DRX061127"
)

save(examples, file = "data/examples.rda")
20 changes: 17 additions & 3 deletions tests/testthat/test-ncbi_get_meta.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
test_that("ncbi_get_meta() works with Microthrix parvicella", {
meta <- ncbi_get_meta("Microthrix parvicella", db = "biosample")
meta <- suppressWarnings(
ncbi_get_meta("Microthrix parvicella", db = "biosample")
)
expect_s3_class(meta$meta, c("tbl_df", "tbl", "data.frame"))
})



test_that("ncbi_get_meta() works with all supported dbs", {
data(examples)

expect_true(all(names(examples) %in% ncbi_supported_dbs()))

for (i in names(examples)) {
res <- suppressWarnings(ncbi_get_meta(examples[[i]], db = i, parse = FALSE))

expect_true(all(class(res) == c("ncbi_meta", "list")))
expect_true("meta" %in% names(res))
expect_true(class(res$meta) == "list")
expect_true(class(res$meta[[1]]) == "character")
}
})

0 comments on commit 3f54071

Please sign in to comment.