Skip to content

Commit

Permalink
Merge pull request #75 from stemangiola/update-db-0.2
Browse files Browse the repository at this point in the history
Update db to 0.2
  • Loading branch information
stemangiola authored Feb 16, 2023
2 parents 0238471 + 7fde5a6 commit dffa328
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
20 changes: 11 additions & 9 deletions R/query.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ assay_map <- c(
)

REMOTE_URL <- "https://swift.rc.nectar.org.au/v1/AUTH_06d6e008e3e642da99d806ba3ea629c5/harmonised-human-atlas"
COUNTS_VERSION <- "0.2"

#' Given a data frame of HCA metadata, returns a SingleCellExperiment object
#' corresponding to the samples in that data frame
Expand Down Expand Up @@ -79,9 +80,10 @@ get_SingleCellExperiment <- function(
cli_alert_info("Realising metadata.")
raw_data <- collect(data)
inherits(raw_data, "tbl") |> assert_that()
has_name(raw_data, c(".cell", "file_id_db")) |> assert_that()
has_name(raw_data, c("_cell", "file_id_db")) |> assert_that()

cache_directory |> dir.create(showWarnings = FALSE)
versioned_cache_directory = file.path(cache_directory, COUNTS_VERSION)
versioned_cache_directory |> dir.create(showWarnings = FALSE, recursive = TRUE)

subdirs <- assay_map[assays]

Expand All @@ -100,7 +102,7 @@ get_SingleCellExperiment <- function(
as.character() |>
sync_assay_files(
url = parsed_repo,
cache_dir = cache_directory,
cache_dir = versioned_cache_directory,
files = _,
subdirs = subdirs
)
Expand All @@ -111,7 +113,7 @@ get_SingleCellExperiment <- function(
imap(function(current_subdir, current_assay) {
# Build up an SCE for each assay
dir_prefix <- file.path(
cache_directory,
versioned_cache_directory,
current_subdir
)

Expand Down Expand Up @@ -172,14 +174,14 @@ group_to_sce <- function(i, df, dir_prefix, features) {
sce <- loadHDF5SummarizedExperiment(sce_path)
# The cells we select here are those that are both available in the SCE
# object, and requested for this particular file
cells <- colnames(sce) |> intersect(df$.cell)
cells <- colnames(sce) |> intersect(df$`_cell`)
# We need to make the cell names globally unique, which we can guarantee
# by adding a suffix that is derived from file_id_db, which is the grouping
# variable
new_cellnames <- paste0(cells, "_", i)
new_coldata <- df |>
mutate(original_cell_id = .data$.cell, .cell = new_cellnames) |>
column_to_rownames(".cell") |>
mutate(original_cell_id = .data$`_cell`, `_cell` = new_cellnames) |>
column_to_rownames("_cell") |>
as("DataFrame")

features |>
Expand Down Expand Up @@ -364,10 +366,10 @@ get_seurat <- function(...) {
#' @importFrom httr progress
#' @importFrom cli cli_alert_info
get_metadata <- function(
remote_url = "https://object-store.rc.nectar.org.au/v1/AUTH_06d6e008e3e642da99d806ba3ea629c5/metadata-sqlite/metadata.parquet",
remote_url = "https://object-store.rc.nectar.org.au/v1/AUTH_06d6e008e3e642da99d806ba3ea629c5/metadata/metadata.0.2.2.parquet",
cache_directory = get_default_cache_dir()
) {
db_path <- file.path(cache_directory, "metadata.parquet")
db_path <- file.path(cache_directory, "metadata.0.2.2.parquet")
sync_remote_file(
remote_url,
db_path,
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-query.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ library(CuratedAtlasQueryR)

test_that("get_SingleCellExperiment() correctly handles duplicate cell IDs", {
meta <- get_metadata() |>
dplyr::filter(.cell == "868417_1") |>
dplyr::filter(`_cell` == "868417_1") |>
dplyr::collect()
sce <- get_SingleCellExperiment(meta)
# This query should return multiple cells, despite querying only 1 cell ID
Expand Down
2 changes: 1 addition & 1 deletion vignettes/Introduction.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ knitr::include_graphics(c(
"../man/figures/svcf_logo.jpeg",
"../man/figures/czi_logo.png",
"../man/figures/bioconductor_logo.jpg",
"../man/figures/vca_logo.png"
"../man/figures/vca_logo.png"
))
```

Expand Down

0 comments on commit dffa328

Please sign in to comment.