Skip to content

Commit

Permalink
Merge pull request #62 from stemangiola/duckdb
Browse files Browse the repository at this point in the history
Use duckdb instead of sqlite
  • Loading branch information
stemangiola authored Feb 10, 2023
2 parents f110413 + 2bc5d87 commit dbe2d63
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 30 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ Imports:
S4Vectors,
tibble,
utils,
dbplyr (>= 2.3.0)
dbplyr (>= 2.3.0),
duckdb
Suggests:
here,
stringr,
Expand Down
3 changes: 1 addition & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ importFrom(BiocGenerics,cbind)
importFrom(DBI,dbConnect)
importFrom(HDF5Array,HDF5RealizationSink)
importFrom(HDF5Array,loadHDF5SummarizedExperiment)
importFrom(RSQLite,SQLITE_RO)
importFrom(RSQLite,SQLite)
importFrom(S4Vectors,DataFrame)
importFrom(SeuratObject,as.Seurat)
importFrom(SeuratObject,as.sparse)
Expand All @@ -35,6 +33,7 @@ importFrom(dplyr,pull)
importFrom(dplyr,tbl)
importFrom(dplyr,tibble)
importFrom(dplyr,transmute)
importFrom(duckdb,duckdb)
importFrom(glue,glue)
importFrom(httr,GET)
importFrom(httr,modify_url)
Expand Down
36 changes: 14 additions & 22 deletions R/query.R
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,16 @@ get_seurat <- function(...) {
get_SingleCellExperiment(...) |> as.Seurat(data = NULL)
}

#' Downloads an SQLite database of the Human Cell Atlas metadata to a local
#' Downloads a parquet database of the Human Cell Atlas metadata to a local
#' cache, and then opens it as a data frame. It can then be filtered and
#' passed into [get_SingleCellExperiment()]
#' to obtain a [`SingleCellExperiment`](SingleCellExperiment::SingleCellExperiment-class)
#'
#' @param remote_url Optional character vector of length 1. An HTTP URL pointing
#' to the location of the sqlite database.
#' to the location of the parquet database.
#' @param cache_directory Optional character vector of length 1. A file path on
#' your local system to a directory (not a file) that will be used to store
#' metadata.sqlite
#' metadata.parquet
#' @return A lazy data.frame subclass containing the metadata. You can interact
#' with this object using most standard dplyr functions. For string matching,
#' it is recommended that you use `stringr::str_like` to filter character
Expand All @@ -368,30 +368,22 @@ get_seurat <- function(...) {
#' )
#'
#' @importFrom DBI dbConnect
#' @importFrom RSQLite SQLite SQLITE_RO
#' @importFrom duckdb duckdb
#' @importFrom dplyr tbl
#' @importFrom httr progress
#' @importFrom cli cli_alert_info
#' @importFrom utils untar
get_metadata <- function(
remote_url = "https://object-store.rc.nectar.org.au/v1/AUTH_06d6e008e3e642da99d806ba3ea629c5/metadata-sqlite/metadata.tar.xz",
remote_url = "https://object-store.rc.nectar.org.au/v1/AUTH_06d6e008e3e642da99d806ba3ea629c5/metadata-sqlite/metadata.parquet",
cache_directory = get_default_cache_dir()
) {
tar_path <- file.path(cache_directory, "metadata.tar.xz")
sqlite_path <- file.path(cache_directory, "metadata.sqlite")
if (!file.exists(sqlite_path)){
tar_dir <- tempdir()
tar_file <- file.path(tar_dir, "metadata.tar.xz")
cli_alert_info("Downloading tar archive. The following procedure is performed once and will take approximately 3 minutes.")
sync_remote_file(
remote_url,
tar_file,
progress(type = "down", con = stderr())
)
cli_alert_info("Decompressing tar archive")
untar(tar_file, exdir = cache_directory)
}
SQLite() |>
dbConnect(drv = _, dbname = sqlite_path, flags = SQLITE_RO) |>
tbl("metadata")
db_path <- file.path(cache_directory, "metadata.parquet")
sync_remote_file(
remote_url,
db_path,
progress(type = "down", con = stderr())
)
table <- duckdb() |>
dbConnect(drv = _, read_only = TRUE) |>
tbl(db_path)
}
10 changes: 5 additions & 5 deletions man/get_metadata.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dbe2d63

Please sign in to comment.