Skip to content

Commit

Permalink
use all collections, datasets, files to determine available columns
Browse files Browse the repository at this point in the history
- e.g., 'first' data set did not contain 'batch_conditions', so
  column was not included
- use rjsoncons instead of jsonlite throughout
  • Loading branch information
mtmorgan committed Apr 1, 2024
1 parent 78fc406 commit b1f29d2
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 19 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: cellxgenedp
Title: Discover and Access Single Cell Data Sets in the CELLxGENE Data Portal
Version: 1.7.2
Version: 1.7.3
Authors@R:
c(person(
given = "Martin",
Expand All @@ -21,7 +21,7 @@ Encoding: UTF-8
Collate: db.R collections.R datasets.R files.R facets.R keys.R
cellxgene.R utilities.R publisher_metadata.R cxg.R
Depends: dplyr
Imports: httr, curl, jsonlite, utils, tools, shiny, DT, rjsoncons
Imports: httr, curl, utils, tools, shiny, DT, rjsoncons
Suggests:
zellkonverter,
SingleCellExperiment,
Expand All @@ -36,6 +36,6 @@ biocViews: SingleCell, DataImport, ThirdPartyClient
URL: https://mtmorgan.github.io/cellxgenedp/, https://github.com/mtmorgan/cellxgenedp
BugReports: https://github.com/mtmorgan/cellxgenedp/issues
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
VignetteBuilder: knitr
Config/testthat/edition: 3
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ importFrom(httr,progress)
importFrom(httr,status_code)
importFrom(httr,stop_for_status)
importFrom(httr,write_disk)
importFrom(jsonlite,parse_json)
importFrom(rjsoncons,jmespath)
importFrom(rjsoncons,j_pivot)
importFrom(rjsoncons,j_query)
importFrom(shiny,actionButton)
importFrom(shiny,hr)
importFrom(shiny,icon)
Expand Down
22 changes: 21 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
# cellxgenedp 1.8


SIGNIFICANT USER-VISIBLE CHANGES

* (v 1.7.2) Add vignette 'Case studies', include identifying dataset
authors and using ontolgies to identify datasets

* (v 1.7.1) Update vignette section on dataset visualization to

BUG FIXES

* (v 1.7.3) Use all collections, datasets, files to determine
available columns


# cellxgenedp 1.6

SIGNIFICANT USER-VISIBLE CHANGES

* (v 1.6.1) Update vignette section on dataset visualization to
accomodate changes in the 'Discover' API.
https://github.com/mtmorgan/cellxgenedp/issues/15

Expand All @@ -12,6 +27,11 @@
some return values. See 'API changes' of the 'Discover and download
datasets...' vignette.

BUG FIXES

* (v 1.6.2) Use all collections, datasets, and files when
identifying available columns.

# cellxgenedp 1.4

SIGNIFICANT USER-VISIBLE CHANGES
Expand Down
4 changes: 3 additions & 1 deletion R/db.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#' @importFrom dplyr bind_rows mutate arrange desc
#'
#' @importFrom rjsoncons j_pivot
.db <-
function(overwrite)
{
path <- .cellxgene_cache_get(
.COLLECTIONS, "collections", overwrite = overwrite
)
readLines(path) |>
parse_json(simplifyVector = TRUE) |>
j_pivot(as = "tibble") |>
bind_rows()
}

Expand Down
2 changes: 1 addition & 1 deletion R/facets.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ FACETS <- c(
}

#' @importFrom dplyr group_by ungroup count bind_cols tibble .data
#' @importFrom jsonlite parse_json
#'
#' @rdname facets
#'
#' @description `facets()` is used to query the cellxgene database for
Expand Down
11 changes: 6 additions & 5 deletions R/keys.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
query <- paste0(query_base, ".keys(@)")
key_names <-
.jmes_to_r(db, query) |>
unlist() |>
sort() |>
setdiff(.KEYS_BLOCKLIST)
path_base <- gsub("[0]", "[]", query_base, fixed = TRUE)
key_paths <- paste0(path_base, ".", key_names)
key_paths <- paste0(query_base, ".", key_names)
names(key_paths) <- key_names
key_paths
}
Expand All @@ -18,9 +19,9 @@ keys <-
function(cellxgene_db = db())
{
queries <- c(
collections = "[0]",
datasets = "[0].datasets[0]",
files = "[0].datasets[0].assets[0]"
collections = "[]",
datasets = "[].datasets[]",
files = "[].datasets[].assets[]"
)
lapply(queries, .keys, db = cellxgene_db)
}
Expand Down
4 changes: 2 additions & 2 deletions R/publisher_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ authors <-
function(cellxgene_db = db())
{
## publisher_metadata can be NULL; filter for non-null values
cellxgene_db <- jmespath(cellxgene_db, "[?not_null(publisher_metadata)]")
cellxgene_db <- j_query(cellxgene_db, "[?not_null(publisher_metadata)]")

author_length <-
.jmes_to_r(cellxgene_db, "[*].publisher_metadata[].length(authors)")
Expand Down Expand Up @@ -87,7 +87,7 @@ publisher_metadata <-
function(cellxgene_db = db())
{
## publisher_metadata can be NULL; filter for non-null values
cellxgene_db <- jmespath(cellxgene_db, "[?not_null(publisher_metadata)]")
cellxgene_db <- j_query(cellxgene_db, "[?not_null(publisher_metadata)]")

keys <- c(
"is_preprint", "journal",
Expand Down
5 changes: 2 additions & 3 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
.is_scalar(x) && is.logical(x)
}

#' @importFrom rjsoncons jmespath
#' @importFrom rjsoncons j_query
.jmes_to_r <-
function(db, path, ..., simplifyVector = TRUE)
{
jmespath(db, path) |>
parse_json(..., simplifyVector = simplifyVector)
j_query(db, path, as = "R")
}

.onLoad <-
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-db.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test_that("db() works", {
db <- db()
expect_s3_class(db, c("cellxgene_db", "character"))
expect_true(nzchar(db))
json <- jsonlite::parse_json(db)
json <- j_query(db, as = "R")
expect_type(json, "list")
expect_true(length(json) >= 48L)
})

0 comments on commit b1f29d2

Please # to comment.