-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Artifact$open()
method
#117
base: main
Are you sure you want to change the base?
Changes from all commits
cfc279b
ad1e016
95a7f9a
b8ca5a8
7940721
8a284fa
7b8acc3
07ff95d
bbaf11a
73e1968
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,35 @@ ArtifactRecord <- R6::R6Class( # nolint object_name_linter | |
} | ||
}, | ||
#' @description | ||
#' Return a backed data object. Currently only supports TileDB-SOMA | ||
#' artifacts. | ||
#' | ||
#' @return A [tiledbsoma::SOMACollection] or [tiledbsoma::SOMAExperiment] | ||
#' object | ||
open = function() { | ||
is_tiledbsoma <- private$get_value("suffix") == ".tiledbsoma" || | ||
private$get_value("_accessor") == "tiledbsoma" | ||
|
||
if (!is_tiledbsoma) { | ||
cli::cli_abort( | ||
"The {.code open} method is only supported for TileDB-SOMA artifacts" | ||
) | ||
} | ||
|
||
check_requires( | ||
"Opening TileDB-SOMA artifacts", "tiledbsoma", | ||
extra_repos = "https://chanzuckerberg.r-universe.dev" | ||
) | ||
|
||
artifact_uri <- paste0( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem is that it won't work for s3 paths i think. At least the correct region should be provided, we have additional setup here https://github.com/laminlabs/lamindb/blob/39e0f529a41d9cbc475e52fe3aa0b8095af21494/lamindb/core/storage/_tiledbsoma.py#L33 but not sure what is available in R. |
||
private$get_value("storage")$root, | ||
"/", | ||
private$get_value("key") | ||
) | ||
|
||
tiledbsoma::SOMAOpen(artifact_uri) | ||
}, | ||
#' @description | ||
#' Print a more detailed description of an `ArtifactRecord` | ||
#' | ||
#' @param style Logical, whether the output is styled using ANSI codes | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,22 @@ | ||
test_that("check_requires works", { | ||
expect_true(check_requires("Imported packages", "cli")) | ||
|
||
expect_error( | ||
check_requires("Missing packages", "a_missing_package"), | ||
regexp = "Missing packages requires" | ||
) | ||
|
||
expect_warning( | ||
check_requires("Missing packages", "a_missing_package", alert = "warning"), | ||
regexp = "Missing packages requires" | ||
) | ||
|
||
expect_message( | ||
check_requires("Missing packages", "a_missing_package", alert = "message"), | ||
regexp = "Missing packages requires" | ||
) | ||
|
||
expect_false( | ||
check_requires("Missing packages", "a_missing_package", alert = "none") | ||
) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ knitr::opts_chunk$set( | |
# actually upload results to the LaminDB instance | ||
# -> testuser1 is a test account that cannot upload results | ||
submit_eval <- laminr:::.get_user_settings()$handle != "testuser1" | ||
submit_eval <- FALSE | ||
``` | ||
|
||
This vignette introduces the basic **{laminr}** workflow. | ||
|
@@ -149,29 +148,37 @@ DotPlot(seurat_obj, features = unique(markers$gene)) + | |
ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90, vjust = 0.5)) | ||
``` | ||
|
||
# Slice the tiledbsoma array store | ||
# Slice a TileDB-SOMA array store | ||
|
||
Alternatively to accessing individual CELLxGENE datasets from LaminDB, the **{cellxgene.census}** package can be used to slice the TileDB-SOMA array store for CELLxGENE Census, a concatenated version of most datasets in CELLxGENE. | ||
When artifacts contain TileDB-SOMA array stores they can be opened and sliced using the [**{tiledbsoma}** package](https://single-cell-data.github.io/TileDB-SOMA/index.html). | ||
|
||
```{r slice-tiledbsoma, eval=FALSE} | ||
library(cellxgene.census) | ||
```{r slice-tiledbsoma, eval = requireNamespace("tiledbsoma", quietly = TRUE)} | ||
# Set some environment variables to avoid an issue with {tiledbsoma} | ||
# https://github.com/chanzuckerberg/cellxgene-census/issues/1261 | ||
Sys.setenv(TILEDB_VFS_S3_REGION = "us-west-2") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aha, ok, the region is provided here, i see. But it is probably much better to provide via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was just a hacky workaround because there is a bug in the {tiledbsoma} package. I'll look into the context stuff but I'm not sure if we get all the necessary information from the API. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that work-around is OK for now given you clearly marked it in the comments! Sergei can help find a cleaner solution over the next weeks & months; it's not so urgent yet that this is 100% polished. I think this is good to merge! |
||
Sys.setenv(AWS_DEFAULT_REGION = "us-west-2") | ||
Sys.setenv(TILEDB_VFS_S3_NO_SIGN_REQUEST = "true") | ||
|
||
census <- open_soma() | ||
|
||
organism <- "Homo sapiens" | ||
gene_filter <- "feature_id %in% c('ENSG00000107317', 'ENSG00000106034')" | ||
cell_filter <- "cell_type == 'sympathetic neuron'" | ||
cell_columns <- c( | ||
"assay", "cell_type", "tissue", "tissue_general", "suspension_type", "disease" | ||
# Define a filter to select specific cells | ||
value_filter <- paste( | ||
"tissue == 'brain' &&", | ||
"cell_type %in% c('microglial cell', 'neuron') &&", | ||
"suspension_type == 'cell' &&", | ||
"assay == '10x 3\\' v3'" | ||
) | ||
|
||
seurat_obj2 <- get_seurat( | ||
census = census, | ||
organism = organism, | ||
var_value_filter = gene_filter, | ||
obs_value_filter = cell_filter, | ||
obs_column_names = cell_columns | ||
) | ||
# Get the artifact containing the CELLxGENE Census TileDB-SOMA store | ||
census_artifact <- cellxgene$Artifact$get("FYMewVq5twKMDXVy0001") | ||
# Open the SOMACollection | ||
soma_collection <- census_artifact$open() | ||
# Slice the store to get a SOMADataFrame containing metadata for the cells of interest | ||
cell_metadata <- soma_collection$get("census_data")$get("homo_sapiens")$obs$read(value_filter = value_filter) | ||
# Concatenate the results to an arrow::Table | ||
cell_metadata <- cell_metadata$concat() | ||
# Convert to a data.frame | ||
cell_metadata <- cell_metadata$to_data_frame() | ||
|
||
cell_metadata | ||
``` | ||
|
||
# Save the results | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also allow
name=="soma"
https://github.com/laminlabs/lamindb/blob/39e0f529a41d9cbc475e52fe3aa0b8095af21494/lamindb/core/storage/_backed_access.py#L84There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I'll have to see if we have access to that.