From c8dd4cb8c80705b6732318da6599c0bdbd84f3cf Mon Sep 17 00:00:00 2001 From: vjcitn Date: Wed, 26 Feb 2025 07:27:14 -0500 Subject: [PATCH 1/7] first cleanup steps --- DESCRIPTION | 2 +- NAMESPACE | 2 - R/get_demo_SD.R | 164 +++++++++--------- R/sdio.R | 9 +- ...{get_demo_SD.Rd => MouseIntestineVisHD.Rd} | 17 +- 5 files changed, 89 insertions(+), 105 deletions(-) rename man/{get_demo_SD.Rd => MouseIntestineVisHD.Rd} (93%) diff --git a/DESCRIPTION b/DESCRIPTION index acdbb68..e4f750e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: SpatialData.data Title: SpatialData datasets Depends: R (>= 4.4), SpatialData -Version: 0.99.2 +Version: 0.99.2.1 Description: Makes 'scverse' data examples available through the NSF OSN, and accessible from within R, using 'BiocFileCache'. Furthermore, provides an interface to Python's 'spatialdata-io' for reading and diff --git a/NAMESPACE b/NAMESPACE index 482e75c..78b1043 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -14,7 +14,6 @@ export(MulticancerSteinbock) export(available_10x_xen_zips) export(available_sdio) export(available_spd_zarr_zips) -export(get_demo_SD) export(merfish_demo_path) export(path_to_10x_xen_demo) export(spd_demo_cached_path) @@ -23,5 +22,4 @@ export(unzip_merfish_demo) export(unzip_spd_demo) export(use_sdio) import(BiocFileCache) -importFrom(basilisk,BasiliskEnvironment) importFrom(utils,unzip) diff --git a/R/get_demo_SD.R b/R/get_demo_SD.R index e828eb5..024fb7d 100644 --- a/R/get_demo_SD.R +++ b/R/get_demo_SD.R @@ -11,66 +11,13 @@ #' The individual functions in this package give similarly detailed references. "demo_spatialdata" -#' @title retrieve scverse-curated `SpatialData` .zarr archive -#' @aliases MouseIntestineVisHD -#' -#' @description -#' This function consolidates the retrieval and caching and transformation -#' of scverse-curated Zarr archives and 10x-curated Xenium archives. -#' -#' @param patt character(1) sufficient to identify an OSN resource -#' @param cache like `BiocFileCache` -#' @param target character(1), defaults to tempfile(); use a different -#' value if you wish to retain the unzipped .zarr store persistently. #' -#' @details -#' \describe{ -#' \item{ -#' \code{MouseIntestineVisHD()}}{ -#' Visium HD 3.0.0 (10x Genomics) dataset of mouse intestine; source: -#' \emph{https://www.10xgenomics.com/datasets/visium-hd-cytassist-gene-expression-libraries-of-mouse-intestine}} -#' \item{ -#' \code{LungAdenocarcinomaMCMICRO()}}{ -#' MCMICRO dataset of human small cell lung adenocarcinoma} -#' \item{ -#' \code{MouseBrainMERFISH()}}{ -#' MERFISH dataset of mouse brain tissue} -#' \item{ -#' \code{MulticancerSteinbock()}}{ -#' imaging mass cytometry dataset of four cancers; source: -#' \emph{https://www.nature.com/articles/s41596-023-00881-0}} -#' \item{ -#' \code{ColorectalCarcinomaMIBITOF()}}{ -#' MIBI-TOF dataset of colorectal carcinoma} -#' \item{ -#' \code{JanesickBreastVisiumEnh()}}{ -#' Visium (10x Genomics) dataset of breast cancer; source: -#' \emph{https://www.nature.com/articles/s41467-023-43458-x}} -#' \item{ -#' \code{JanesickBreastXeniumRep1/2()}}{ -#' two Xenium (10x Genomics) sections associated with -#' the above Visium section from Janesick \emph{et al.}} -#' \item{ -#' \code{Breast2fov_10x()}}{ -#' Xenium (10x Genomics) data on breast cancer, trimmed to 2 FOVs; source: -#' \emph{https://www.10xgenomics.com/support/software/xenium-onboard-analysis/latest/resources/xenium-example-data}} -#' \item{ -#' \code{Lung2fov_10x()}}{ -#' Xenium (10x Genomics) data on lung cancer, trimmed to 2 FOVs; source: -#' \emph{https://www.10xgenomics.com/support/software/xenium-onboard-analysis/latest/resources/xenium-example-data}} -#' \item{ -#' \code{HumanLungMulti_10x()}}{ -#' Xenium (10x Genomics) data on lung cancer; -#' source: \emph{https://www.10xgenomics.com/datasets/preview-data-ffpe-human-lung-cancer-with-xenium-multimodal-cell-segmentation-1-standard}} -#' } -#' -#' @examples -#' # the following are equivalent: -#' get_demo_SD("merfish") -#' MouseBrainMERFISH() -#' -#' @export -get_demo_SD <- function(patt, +# @examples +# # the following are equivalent: +# get_demo_SD("merfish") +# MouseBrainMERFISH() +# +.get_demo_SD <- function(patt, cache=BiocFileCache::BiocFileCache(), target=tempfile()) { @@ -150,68 +97,121 @@ get_demo_SD <- function(patt, SpatialData::readSpatialData(dir(td, full.names=TRUE)) } -#' @rdname get_demo_SD +#' @title retrieve scverse-curated `SpatialData` .zarr archive +#' @aliases MouseIntestineVisHD +#' +#' @description +#' This function consolidates the retrieval and caching and transformation +#' of scverse-curated Zarr archives and 10x-curated Xenium archives. +#' +#' @param patt character(1) sufficient to identify an OSN resource +#' @param cache like `BiocFileCache` +#' @param target character(1), defaults to tempfile(); use a different +#' value if you wish to retain the unzipped .zarr store persistently. +#' +#' @details +#' \describe{ +#' \item{ +#' \code{MouseIntestineVisHD()}}{ +#' Visium HD 3.0.0 (10x Genomics) dataset of mouse intestine; source: +#' \emph{https://www.10xgenomics.com/datasets/visium-hd-cytassist-gene-expression-libraries-of-mouse-intestine}} +#' \item{ +#' \code{LungAdenocarcinomaMCMICRO()}}{ +#' MCMICRO dataset of human small cell lung adenocarcinoma} +#' \item{ +#' \code{MouseBrainMERFISH()}}{ +#' MERFISH dataset of mouse brain tissue} +#' \item{ +#' \code{MulticancerSteinbock()}}{ +#' imaging mass cytometry dataset of four cancers; source: +#' \emph{https://www.nature.com/articles/s41596-023-00881-0}} +#' \item{ +#' \code{ColorectalCarcinomaMIBITOF()}}{ +#' MIBI-TOF dataset of colorectal carcinoma} +#' \item{ +#' \code{JanesickBreastVisiumEnh()}}{ +#' Visium (10x Genomics) dataset of breast cancer; source: +#' \emph{https://www.nature.com/articles/s41467-023-43458-x}} +#' \item{ +#' \code{JanesickBreastXeniumRep1/2()}}{ +#' two Xenium (10x Genomics) sections associated with +#' the above Visium section from Janesick \emph{et al.}} +#' \item{ +#' \code{Breast2fov_10x()}}{ +#' Xenium (10x Genomics) data on breast cancer, trimmed to 2 FOVs; source: +#' \emph{https://www.10xgenomics.com/support/software/xenium-onboard-analysis/latest/resources/xenium-example-data}} +#' \item{ +#' \code{Lung2fov_10x()}}{ +#' Xenium (10x Genomics) data on lung cancer, trimmed to 2 FOVs; source: +#' \emph{https://www.10xgenomics.com/support/software/xenium-onboard-analysis/latest/resources/xenium-example-data}} +#' \item{ +#' \code{HumanLungMulti_10x()}}{ +#' Xenium (10x Genomics) data on lung cancer; +#' source: \emph{https://www.10xgenomics.com/datasets/preview-data-ffpe-human-lung-cancer-with-xenium-multimodal-cell-segmentation-1-standard}} +#' } + +#' @rdname MouseIntestineVisHD #' @export MouseIntestineVisHD <- function(target=tempfile()) { - get_demo_SD("visium_hd_3.0.0", target=target) + .get_demo_SD("visium_hd_3.0.0", target=target) } -#' @rdname get_demo_SD +#' @rdname MouseIntestineVisHD #' @export LungAdenocarcinomaMCMICRO <- function(target=tempfile()) { - get_demo_SD("mcmicro_io", target=target) + .get_demo_SD("mcmicro_io", target=target) } -#' @rdname get_demo_SD +#' @rdname MouseIntestineVisHD #' @export MouseBrainMERFISH = function(target=tempfile()) { - get_demo_SD("merfish", target=target) + .get_demo_SD("merfish", target=target) } -#' @rdname get_demo_SD +#' @rdname MouseIntestineVisHD #' @export MulticancerSteinbock <- function(target=tempfile()) { - get_demo_SD("steinbock_io", target=target) + .get_demo_SD("steinbock_io", target=target) } -#' @rdname get_demo_SD +#' @rdname MouseIntestineVisHD #' @export ColorectalCarcinomaMIBITOF <- function(target=tempfile()) { - get_demo_SD("mibitof", target=target) + .get_demo_SD("mibitof", target=target) } -#' @rdname get_demo_SD +#' @rdname MouseIntestineVisHD #' @export JanesickBreastVisiumEnh <- function(target=tempfile()) { - get_demo_SD("visium_associated_xenium_io", target=target) + .get_demo_SD("visium_associated_xenium_io", target=target) } -#' @rdname get_demo_SD +#' @rdname MouseIntestineVisHD #' @export JanesickBreastXeniumRep1 <- function(target=tempfile()) { - get_demo_SD("xenium_rep1_io", target=target) + .get_demo_SD("xenium_rep1_io", target=target) } -#' @rdname get_demo_SD +#' @rdname MouseIntestineVisHD #' @export JanesickBreastXeniumRep2 <- function(target=tempfile()) { - get_demo_SD("xenium_rep2_io", target=target) + .get_demo_SD("xenium_rep2_io", target=target) } -#' @rdname get_demo_SD +#' @rdname MouseIntestineVisHD #' @export Breast2fov_10x <- function(target=tempfile()) { - get_demo_SD("human_Breast_2fov", target=target) + .get_demo_SD("human_Breast_2fov", target=target) } -#' @rdname get_demo_SD +#' @rdname MouseIntestineVisHD #' @export Lung2fov_10x <- function(target=tempfile()) { - get_demo_SD("human_Lung_2fov", target=target) + .get_demo_SD("human_Lung_2fov", target=target) } -#' @rdname get_demo_SD +#' @rdname MouseIntestineVisHD #' @export HumanLungMulti_10x <- function(target=tempfile()) { - get_demo_SD("HuLungXenmulti", target=target) -} \ No newline at end of file + .get_demo_SD("HuLungXenmulti", target=target) +} diff --git a/R/sdio.R b/R/sdio.R index 94f0a99..2794748 100644 --- a/R/sdio.R +++ b/R/sdio.R @@ -1,8 +1,3 @@ -#' @importFrom basilisk BasiliskEnvironment -.env <- BasiliskEnvironment( - pkgname="SpatialData", envname="anndata_env", - packages=c("anndata==0.9.1", "zarr==2.14.2"), - pip=c("spatialdata==0.2.5", "spatialdata-io==0.1.5")) #' enumerate modules #' @examples @@ -10,7 +5,7 @@ #' @export available_sdio <- function() { # avoid package-specific import - proc <- basilisk::basiliskStart(.env, testload="spatialdata") + proc <- basilisk::basiliskStart(SpatialData:::.env, testload="spatialdata") on.exit(basilisk::basiliskStop(proc)) basilisk::basiliskRun(proc, function() { sdio <- reticulate::import("spatialdata_io") @@ -44,7 +39,7 @@ use_sdio <- function(platform="xenium", srcdir, dest) { stop("Won't write to existing folder;", " please provide a non-existent path.") # avoid package-specific import - proc <- basilisk::basiliskStart(.env, testload="spatialdata") + proc <- basilisk::basiliskStart(SpatialData:::.env, testload="spatialdata") on.exit(basilisk::basiliskStop(proc)) basilisk::basiliskRun(proc, function(platform, srcdir, dest) { sdio <- reticulate::import("spatialdata_io") diff --git a/man/get_demo_SD.Rd b/man/MouseIntestineVisHD.Rd similarity index 93% rename from man/get_demo_SD.Rd rename to man/MouseIntestineVisHD.Rd index 8bca4e2..7b74ba7 100644 --- a/man/get_demo_SD.Rd +++ b/man/MouseIntestineVisHD.Rd @@ -1,7 +1,6 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_demo_SD.R -\name{get_demo_SD} -\alias{get_demo_SD} +\name{MouseIntestineVisHD} \alias{MouseIntestineVisHD} \alias{LungAdenocarcinomaMCMICRO} \alias{MouseBrainMERFISH} @@ -15,8 +14,6 @@ \alias{HumanLungMulti_10x} \title{retrieve scverse-curated `SpatialData` .zarr archive} \usage{ -get_demo_SD(patt, cache = BiocFileCache::BiocFileCache(), target = tempfile()) - MouseIntestineVisHD(target = tempfile()) LungAdenocarcinomaMCMICRO(target = tempfile()) @@ -40,12 +37,12 @@ Lung2fov_10x(target = tempfile()) HumanLungMulti_10x(target = tempfile()) } \arguments{ +\item{target}{character(1), defaults to tempfile(); use a different +value if you wish to retain the unzipped .zarr store persistently.} + \item{patt}{character(1) sufficient to identify an OSN resource} \item{cache}{like `BiocFileCache`} - -\item{target}{character(1), defaults to tempfile(); use a different -value if you wish to retain the unzipped .zarr store persistently.} } \description{ This function consolidates the retrieval and caching and transformation @@ -92,9 +89,3 @@ of scverse-curated Zarr archives and 10x-curated Xenium archives. source: \emph{https://www.10xgenomics.com/datasets/preview-data-ffpe-human-lung-cancer-with-xenium-multimodal-cell-segmentation-1-standard}} } } -\examples{ -# the following are equivalent: -get_demo_SD("merfish") -MouseBrainMERFISH() - -} From 97b72266e5561826c5972ad7510390f47f5cb99d Mon Sep 17 00:00:00 2001 From: vjcitn Date: Wed, 26 Feb 2025 07:52:10 -0500 Subject: [PATCH 2/7] failing check, function names in unit tests --- NAMESPACE | 8 ---- R/merfish_demo.R | 42 ++++++++----------- R/sdio.R | 2 +- ..._zips.Rd => dot-available_10x_xen_zips.Rd} | 8 ++-- ...zips.Rd => dot-available_spd_zarr_zips.Rd} | 8 ++-- ..._demo_path.Rd => dot-merfish_demo_path.Rd} | 6 +-- ...en_demo.Rd => dot-path_to_10x_xen_demo.Rd} | 8 ++-- ...ed_path.Rd => dot-spd_demo_cached_path.Rd} | 6 +-- man/{spdzPath.Rd => dot-spdzPath.Rd} | 8 ++-- ...fish_demo.Rd => dot-unzip_merfish_demo.Rd} | 8 ++-- ...nzip_spd_demo.Rd => dot-unzip_spd_demo.Rd} | 8 ++-- man/use_sdio.Rd | 2 +- vignettes/SpatialData.data.Rmd | 4 +- 13 files changed, 51 insertions(+), 67 deletions(-) rename man/{available_10x_xen_zips.Rd => dot-available_10x_xen_zips.Rd} (76%) rename man/{available_spd_zarr_zips.Rd => dot-available_spd_zarr_zips.Rd} (76%) rename man/{merfish_demo_path.Rd => dot-merfish_demo_path.Rd} (89%) rename man/{path_to_10x_xen_demo.Rd => dot-path_to_10x_xen_demo.Rd} (69%) rename man/{spd_demo_cached_path.Rd => dot-spd_demo_cached_path.Rd} (89%) rename man/{spdzPath.Rd => dot-spdzPath.Rd} (74%) rename man/{unzip_merfish_demo.Rd => dot-unzip_merfish_demo.Rd} (76%) rename man/{unzip_spd_demo.Rd => dot-unzip_spd_demo.Rd} (84%) diff --git a/NAMESPACE b/NAMESPACE index 78b1043..533a810 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,15 +11,7 @@ export(LungAdenocarcinomaMCMICRO) export(MouseBrainMERFISH) export(MouseIntestineVisHD) export(MulticancerSteinbock) -export(available_10x_xen_zips) export(available_sdio) -export(available_spd_zarr_zips) -export(merfish_demo_path) -export(path_to_10x_xen_demo) -export(spd_demo_cached_path) -export(spdzPath) -export(unzip_merfish_demo) -export(unzip_spd_demo) export(use_sdio) import(BiocFileCache) importFrom(utils,unzip) diff --git a/R/merfish_demo.R b/R/merfish_demo.R index e4c65e1..160ff13 100644 --- a/R/merfish_demo.R +++ b/R/merfish_demo.R @@ -24,8 +24,7 @@ build_sandbox_path <- function(zipname) { #' @return Returns character(1) path to cached zip file. #' #' @import BiocFileCache -#' @export -merfish_demo_path <- function(cache=BiocFileCache::BiocFileCache(), zipname="merfish.zarr.zip") { +.merfish_demo_path <- function(cache=BiocFileCache::BiocFileCache(), zipname="merfish.zarr.zip") { .get_spdzip_path_in_cache_add_if_needed(cache=cache, zipname=zipname, source="biocOSN") } @@ -36,14 +35,13 @@ merfish_demo_path <- function(cache=BiocFileCache::BiocFileCache(), zipname="mer #' @examples #' tf <- tempfile() #' dir.create(tf) -#' pa <- unzip_merfish_demo(tf) +#' pa <- .unzip_merfish_demo(tf) #' dir(pa, full.names=TRUE) #' #' @importFrom utils unzip -#' @export -unzip_merfish_demo <- function(destination, cache=BiocFileCache::BiocFileCache()) { +.unzip_merfish_demo <- function(destination, cache=BiocFileCache::BiocFileCache()) { stopifnot(dir.exists(destination)) - unzip(merfish_demo_path(cache=cache), exdir=destination) + unzip(.merfish_demo_path(cache=cache), exdir=destination) dir(destination, pattern="merfish.zarr", full.names=TRUE) } @@ -51,10 +49,9 @@ unzip_merfish_demo <- function(destination, cache=BiocFileCache::BiocFileCache() #' bucket for zipped zarr archives for various platforms #' @examples #' if (requireNamespace("paws")) { -#' available_spd_zarr_zips() +#' .available_spd_zarr_zips() #' } -#' @export -available_spd_zarr_zips <- function() { +.available_spd_zarr_zips <- function() { if (!requireNamespace("paws")) stop("install 'paws' to use this function; without it", " we can't check existence of data in OSN bucket") @@ -75,13 +72,12 @@ available_spd_zarr_zips <- function() { #' @param zipname character(1) name of zip archive to find #' @param source character(1) one of "biocOSN", "sandbox", "local" #' @examples -#' spdzPath(zipname="merfish.zarr.zip", source="biocOSN") -#' @export -spdzPath <- function(cache=BiocFileCache::BiocFileCache(), zipname, source) { +#' .spdzPath(zipname="merfish.zarr.zip", source="biocOSN") +.spdzPath <- function(cache=BiocFileCache::BiocFileCache(), zipname, source) { if (missing(zipname)) stop("zipname must be supplied") # protect user from bad request if paws is available if (requireNamespace("paws")) { - avail <- available_spd_zarr_zips() + avail <- .available_spd_zarr_zips() stopifnot(zipname %in% avail) } .get_spdzip_path_in_cache_add_if_needed(cache=cache, zipname=zipname, source) @@ -115,8 +111,7 @@ spdzPath <- function(cache=BiocFileCache::BiocFileCache(), zipname, source) { #' @return Returns character(1) path to cached zip file. #' #' @import BiocFileCache -#' @export -spd_demo_cached_path <- function(cache=BiocFileCache::BiocFileCache(), zipname="mibitof.zip", source) { +.spd_demo_cached_path <- function(cache=BiocFileCache::BiocFileCache(), zipname="mibitof.zip", source) { .get_spdzip_path_in_cache_add_if_needed(cache=cache, zipname=zipname, source=source) } @@ -129,13 +124,12 @@ spd_demo_cached_path <- function(cache=BiocFileCache::BiocFileCache(), zipname=" #' @examples #' tf <- tempfile() #' dir.create(tf) -#' pa <- unzip_spd_demo(zipname="mibitof.zip", destination=tf, source="biocOSN") +#' pa <- .unzip_spd_demo(zipname="mibitof.zip", destination=tf, source="biocOSN") #' dir(pa, full.names=TRUE) -#' @export -unzip_spd_demo <- function(zipname="mibitof.zip", destination, cache=BiocFileCache::BiocFileCache(), source) { +.unzip_spd_demo <- function(zipname="mibitof.zip", destination, cache=BiocFileCache::BiocFileCache(), source) { stopifnot(dir.exists(destination)) chk <- try({ - fnm <- spd_demo_cached_path(cache=cache, zipname=zipname, source=source) + fnm <- .spd_demo_cached_path(cache=cache, zipname=zipname, source=source) unzip(fnm, exdir=destination) }) if (inherits(chk, "try-error")) @@ -147,10 +141,9 @@ unzip_spd_demo <- function(zipname="mibitof.zip", destination, cache=BiocFileCac #' bucket for zipped 10x-produced Xenium outputs #' @examples #' if (requireNamespace("paws")) { -#' available_10x_xen_zips() +#' .available_10x_xen_zips() #' } -#' @export -available_10x_xen_zips <- function() { +.available_10x_xen_zips <- function() { if (!requireNamespace("paws")) stop("install 'paws' to use this function; without it", " we can't check existence of data in OSN bucket") @@ -169,10 +162,9 @@ available_10x_xen_zips <- function() { #' provide path to a zip file from 10x genomics for Xenium platform #' @param zipname character(1) name of zip archive to find #' @examples -#' path_to_10x_xen_demo() +#' .path_to_10x_xen_demo() #' # see ?use_sdio -#' @export -path_to_10x_xen_demo <- function(zipname="Xenium_V1_human_Breast_2fov_outs.zip") { +.path_to_10x_xen_demo <- function(zipname="Xenium_V1_human_Breast_2fov_outs.zip") { .cache_add_if_needed_xendemo( cache=BiocFileCache::BiocFileCache(), zipname=zipname, source="biocOSN") diff --git a/R/sdio.R b/R/sdio.R index 2794748..f52a786 100644 --- a/R/sdio.R +++ b/R/sdio.R @@ -22,7 +22,7 @@ available_sdio <- function() { #' #' @examples #' # unzip flat files -#' pa <- path_to_10x_xen_demo() +#' pa <- SpatialData.data:::.path_to_10x_xen_demo() #' dir.create(td <- tempfile()) #' unzip(pa, exdir=td) #' diff --git a/man/available_10x_xen_zips.Rd b/man/dot-available_10x_xen_zips.Rd similarity index 76% rename from man/available_10x_xen_zips.Rd rename to man/dot-available_10x_xen_zips.Rd index 9c445d8..3eee3ff 100644 --- a/man/available_10x_xen_zips.Rd +++ b/man/dot-available_10x_xen_zips.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/merfish_demo.R -\name{available_10x_xen_zips} -\alias{available_10x_xen_zips} +\name{.available_10x_xen_zips} +\alias{.available_10x_xen_zips} \title{use 'paws::s3' to interrogate an NSF Open Storage Network bucket for zipped 10x-produced Xenium outputs} \usage{ -available_10x_xen_zips() +.available_10x_xen_zips() } \description{ use 'paws::s3' to interrogate an NSF Open Storage Network @@ -13,6 +13,6 @@ bucket for zipped 10x-produced Xenium outputs } \examples{ if (requireNamespace("paws")) { - available_10x_xen_zips() + .available_10x_xen_zips() } } diff --git a/man/available_spd_zarr_zips.Rd b/man/dot-available_spd_zarr_zips.Rd similarity index 76% rename from man/available_spd_zarr_zips.Rd rename to man/dot-available_spd_zarr_zips.Rd index 830c5ce..35915f5 100644 --- a/man/available_spd_zarr_zips.Rd +++ b/man/dot-available_spd_zarr_zips.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/merfish_demo.R -\name{available_spd_zarr_zips} -\alias{available_spd_zarr_zips} +\name{.available_spd_zarr_zips} +\alias{.available_spd_zarr_zips} \title{use 'paws::s3' to interrogate an NSF Open Storage Network bucket for zipped zarr archives for various platforms} \usage{ -available_spd_zarr_zips() +.available_spd_zarr_zips() } \description{ use 'paws::s3' to interrogate an NSF Open Storage Network @@ -13,6 +13,6 @@ bucket for zipped zarr archives for various platforms } \examples{ if (requireNamespace("paws")) { - available_spd_zarr_zips() + .available_spd_zarr_zips() } } diff --git a/man/merfish_demo_path.Rd b/man/dot-merfish_demo_path.Rd similarity index 89% rename from man/merfish_demo_path.Rd rename to man/dot-merfish_demo_path.Rd index 0972cbc..83ad4b6 100644 --- a/man/merfish_demo_path.Rd +++ b/man/dot-merfish_demo_path.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/merfish_demo.R -\name{merfish_demo_path} -\alias{merfish_demo_path} +\name{.merfish_demo_path} +\alias{.merfish_demo_path} \title{check cache for merfish.zarr.zip and return path; retrieve/stash/return path if not found} \usage{ -merfish_demo_path( +.merfish_demo_path( cache = BiocFileCache::BiocFileCache(), zipname = "merfish.zarr.zip" ) diff --git a/man/path_to_10x_xen_demo.Rd b/man/dot-path_to_10x_xen_demo.Rd similarity index 69% rename from man/path_to_10x_xen_demo.Rd rename to man/dot-path_to_10x_xen_demo.Rd index 3caa0b1..afe43f2 100644 --- a/man/path_to_10x_xen_demo.Rd +++ b/man/dot-path_to_10x_xen_demo.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/merfish_demo.R -\name{path_to_10x_xen_demo} -\alias{path_to_10x_xen_demo} +\name{.path_to_10x_xen_demo} +\alias{.path_to_10x_xen_demo} \title{provide path to a zip file from 10x genomics for Xenium platform} \usage{ -path_to_10x_xen_demo(zipname = "Xenium_V1_human_Breast_2fov_outs.zip") +.path_to_10x_xen_demo(zipname = "Xenium_V1_human_Breast_2fov_outs.zip") } \arguments{ \item{zipname}{character(1) name of zip archive to find} @@ -13,6 +13,6 @@ path_to_10x_xen_demo(zipname = "Xenium_V1_human_Breast_2fov_outs.zip") provide path to a zip file from 10x genomics for Xenium platform } \examples{ -path_to_10x_xen_demo() +.path_to_10x_xen_demo() # see ?use_sdio } diff --git a/man/spd_demo_cached_path.Rd b/man/dot-spd_demo_cached_path.Rd similarity index 89% rename from man/spd_demo_cached_path.Rd rename to man/dot-spd_demo_cached_path.Rd index 5ea6909..0f49006 100644 --- a/man/spd_demo_cached_path.Rd +++ b/man/dot-spd_demo_cached_path.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/merfish_demo.R -\name{spd_demo_cached_path} -\alias{spd_demo_cached_path} +\name{.spd_demo_cached_path} +\alias{.spd_demo_cached_path} \title{check cache for demonstration .zarr.zip and return path; retrieve data, cache it, return path if not found} \usage{ -spd_demo_cached_path( +.spd_demo_cached_path( cache = BiocFileCache::BiocFileCache(), zipname = "mibitof.zip", source diff --git a/man/spdzPath.Rd b/man/dot-spdzPath.Rd similarity index 74% rename from man/spdzPath.Rd rename to man/dot-spdzPath.Rd index 6e591b1..b8997a9 100644 --- a/man/spdzPath.Rd +++ b/man/dot-spdzPath.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/merfish_demo.R -\name{spdzPath} -\alias{spdzPath} +\name{.spdzPath} +\alias{.spdzPath} \title{obtain path to cached zip archive of SpatialData zarr} \usage{ -spdzPath(cache = BiocFileCache::BiocFileCache(), zipname, source) +.spdzPath(cache = BiocFileCache::BiocFileCache(), zipname, source) } \arguments{ \item{cache}{inherits from \code{BiocFileCache::BiocFileCache()}} @@ -17,5 +17,5 @@ spdzPath(cache = BiocFileCache::BiocFileCache(), zipname, source) obtain path to cached zip archive of SpatialData zarr } \examples{ -spdzPath(zipname="merfish.zarr.zip", source="biocOSN") +.spdzPath(zipname="merfish.zarr.zip", source="biocOSN") } diff --git a/man/unzip_merfish_demo.Rd b/man/dot-unzip_merfish_demo.Rd similarity index 76% rename from man/unzip_merfish_demo.Rd rename to man/dot-unzip_merfish_demo.Rd index b359b18..a0eb0a8 100644 --- a/man/unzip_merfish_demo.Rd +++ b/man/dot-unzip_merfish_demo.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/merfish_demo.R -\name{unzip_merfish_demo} -\alias{unzip_merfish_demo} +\name{.unzip_merfish_demo} +\alias{.unzip_merfish_demo} \title{unzip cached merfish demo data to specified folder} \usage{ -unzip_merfish_demo(destination, cache = BiocFileCache::BiocFileCache()) +.unzip_merfish_demo(destination, cache = BiocFileCache::BiocFileCache()) } \arguments{ \item{destination}{character(1) a path to a folder that must exist} @@ -20,7 +20,7 @@ unzip cached merfish demo data to specified folder \examples{ tf <- tempfile() dir.create(tf) -pa <- unzip_merfish_demo(tf) +pa <- .unzip_merfish_demo(tf) dir(pa, full.names=TRUE) } diff --git a/man/unzip_spd_demo.Rd b/man/dot-unzip_spd_demo.Rd similarity index 84% rename from man/unzip_spd_demo.Rd rename to man/dot-unzip_spd_demo.Rd index c3392e6..413b749 100644 --- a/man/unzip_spd_demo.Rd +++ b/man/dot-unzip_spd_demo.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/merfish_demo.R -\name{unzip_spd_demo} -\alias{unzip_spd_demo} +\name{.unzip_spd_demo} +\alias{.unzip_spd_demo} \title{unzip selected demo data to specified folder} \usage{ -unzip_spd_demo( +.unzip_spd_demo( zipname = "mibitof.zip", destination, cache = BiocFileCache::BiocFileCache(), @@ -29,6 +29,6 @@ unzip selected demo data to specified folder \examples{ tf <- tempfile() dir.create(tf) -pa <- unzip_spd_demo(zipname="mibitof.zip", destination=tf, source="biocOSN") +pa <- .unzip_spd_demo(zipname="mibitof.zip", destination=tf, source="biocOSN") dir(pa, full.names=TRUE) } diff --git a/man/use_sdio.Rd b/man/use_sdio.Rd index 4df6161..978dc05 100644 --- a/man/use_sdio.Rd +++ b/man/use_sdio.Rd @@ -20,7 +20,7 @@ output to .zarr with specific folder structure. } \examples{ # unzip flat files -pa <- path_to_10x_xen_demo() +pa <- SpatialData.data:::.path_to_10x_xen_demo() dir.create(td <- tempfile()) unzip(pa, exdir=td) diff --git a/vignettes/SpatialData.data.Rmd b/vignettes/SpatialData.data.Rmd index 4f0f106..d298c7c 100644 --- a/vignettes/SpatialData.data.Rmd +++ b/vignettes/SpatialData.data.Rmd @@ -32,14 +32,14 @@ and can be retrieved with caching support using `r BiocStyle::Biocpkg("BiocFileC We can interrogate the bucket for available (zipped) .zarr archives: ```{r ons-list} -available_spd_zarr_zips() +SpatialData.data:::.available_spd_zarr_zips() ``` Any of the above can be retrieved (once) into some location, and read into R; for example: ```{r ons-read} dir.create(td <- tempfile()) -pa <- unzip_spd_demo( +pa <- SpatialData.data:::.unzip_spd_demo( zipname="merfish.zarr.zip", dest=td, source="biocOSN") (x <- readSpatialData(pa)) From 6e29946fd067c4915929c9c5ffc6f3678aeafac6 Mon Sep 17 00:00:00 2001 From: vjcitn Date: Wed, 26 Feb 2025 16:57:11 -0500 Subject: [PATCH 3/7] updating to .-prefixed functions --- tests/testthat/test-caching.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/testthat/test-caching.R b/tests/testthat/test-caching.R index 61e3362..8b97304 100644 --- a/tests/testthat/test-caching.R +++ b/tests/testthat/test-caching.R @@ -2,7 +2,7 @@ library(SpatialData) test_that("available_sdio()", { expect_error(available_sdio(1)) - x <- available_sdio() + x <- available_sdio() # lists methods known to spatialdata-io python module expect_is(x, "character") expect_true(length(x) > 0) expect_true(any(grepl("^(vis|xen)", x))) @@ -10,7 +10,7 @@ test_that("available_sdio()", { test_that("use_sdio()", { # get dataset - zip <- path_to_10x_xen_demo() + zip <- SpatialData.data:::.path_to_10x_xen_demo() dir.create(src <- tempfile()) unzip(zip, exdir=src) # directory already exists @@ -27,7 +27,7 @@ test_that("use_sdio()", { test_that("OSN payloads exist", { if (requireNamespace("paws", quietly=TRUE)) { - x <- available_spd_zarr_zips() + x <- SpatialData.data:::.available_spd_zarr_zips() expect_gt(length(x), 0) expect_is(x, "character") expect_true(all(grepl("\\.zip$", x))) @@ -38,7 +38,7 @@ test_that("merfish demo zip has expected content", { tf <- tempfile() dir.create(tf) bfc <- BiocFileCache::BiocFileCache() - dem <- unzip_merfish_demo(cache=bfc, destination=tf) + dem <- SpatialData.data:::.unzip_merfish_demo(cache=bfc, destination=tf) cont <- dir(tf, full.names=TRUE, recursive=TRUE) expect_true(length(cont) == 29L) parq <- grep("parquet", cont) @@ -55,7 +55,7 @@ test_that("sandbox data can be acquired and used", { .clean_cache("mibitof.zip") tf <- tempfile() dir.create(tf) - dem <- unzip_spd_demo( + dem <- SpatialData.data:::.unzip_spd_demo( zipname="mibitof.zip", cache=BiocFileCache::BiocFileCache(), destination=tf, From 8e8ee56895a85047d0a07e0d980fb1a79a78ab68 Mon Sep 17 00:00:00 2001 From: vjcitn Date: Wed, 26 Feb 2025 17:41:21 -0500 Subject: [PATCH 4/7] passing check --- DESCRIPTION | 5 +++-- NAMESPACE | 1 + R/get_demo_SD.R | 9 ++++++--- R/merfish_demo.R | 12 ++++++------ man/MouseIntestineVisHD.Rd | 4 ---- man/dot-available_10x_xen_zips.Rd | 2 +- man/dot-available_spd_zarr_zips.Rd | 2 +- man/dot-get_demo_SD.Rd | 19 +++++++++++++++++++ man/dot-path_to_10x_xen_demo.Rd | 2 +- man/dot-spdzPath.Rd | 2 +- man/dot-unzip_merfish_demo.Rd | 2 +- man/dot-unzip_spd_demo.Rd | 2 +- 12 files changed, 41 insertions(+), 21 deletions(-) create mode 100644 man/dot-get_demo_SD.Rd diff --git a/DESCRIPTION b/DESCRIPTION index e4f750e..4cfb7f6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: SpatialData.data Title: SpatialData datasets -Depends: R (>= 4.4), SpatialData +Depends: R (>= 4.4) Version: 0.99.2.1 Description: Makes 'scverse' data examples available through the NSF OSN, and accessible from within R, using 'BiocFileCache'. Furthermore, @@ -18,7 +18,8 @@ Authors@R: c( Imports: basilisk, BiocFileCache, - reticulate + reticulate, + SpatialData Suggests: BiocStyle, knitr, diff --git a/NAMESPACE b/NAMESPACE index 533a810..5f42beb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -14,4 +14,5 @@ export(MulticancerSteinbock) export(available_sdio) export(use_sdio) import(BiocFileCache) +importFrom(SpatialData,readSpatialData) importFrom(utils,unzip) diff --git a/R/get_demo_SD.R b/R/get_demo_SD.R index 024fb7d..b6cc16b 100644 --- a/R/get_demo_SD.R +++ b/R/get_demo_SD.R @@ -11,7 +11,12 @@ #' The individual functions in this package give similarly detailed references. "demo_spatialdata" -#' +#' all logic for finding, caching, loading an OSN-based dataset, hidden +#' @importFrom SpatialData readSpatialData +#' @param patt character(1) sufficient to identify an OSN resource +#' @param cache like `BiocFileCache` +#' @param target character(1), defaults to tempfile(); use a different +#' value if you wish to retain the unzipped .zarr store persistently. # @examples # # the following are equivalent: # get_demo_SD("merfish") @@ -104,8 +109,6 @@ #' This function consolidates the retrieval and caching and transformation #' of scverse-curated Zarr archives and 10x-curated Xenium archives. #' -#' @param patt character(1) sufficient to identify an OSN resource -#' @param cache like `BiocFileCache` #' @param target character(1), defaults to tempfile(); use a different #' value if you wish to retain the unzipped .zarr store persistently. #' diff --git a/R/merfish_demo.R b/R/merfish_demo.R index 160ff13..163d9ef 100644 --- a/R/merfish_demo.R +++ b/R/merfish_demo.R @@ -35,7 +35,7 @@ build_sandbox_path <- function(zipname) { #' @examples #' tf <- tempfile() #' dir.create(tf) -#' pa <- .unzip_merfish_demo(tf) +#' pa <- SpatialData.data:::.unzip_merfish_demo(tf) #' dir(pa, full.names=TRUE) #' #' @importFrom utils unzip @@ -49,7 +49,7 @@ build_sandbox_path <- function(zipname) { #' bucket for zipped zarr archives for various platforms #' @examples #' if (requireNamespace("paws")) { -#' .available_spd_zarr_zips() +#' SpatialData.data:::.available_spd_zarr_zips() #' } .available_spd_zarr_zips <- function() { if (!requireNamespace("paws")) @@ -72,7 +72,7 @@ build_sandbox_path <- function(zipname) { #' @param zipname character(1) name of zip archive to find #' @param source character(1) one of "biocOSN", "sandbox", "local" #' @examples -#' .spdzPath(zipname="merfish.zarr.zip", source="biocOSN") +#' SpatialData.data:::.spdzPath(zipname="merfish.zarr.zip", source="biocOSN") .spdzPath <- function(cache=BiocFileCache::BiocFileCache(), zipname, source) { if (missing(zipname)) stop("zipname must be supplied") # protect user from bad request if paws is available @@ -124,7 +124,7 @@ build_sandbox_path <- function(zipname) { #' @examples #' tf <- tempfile() #' dir.create(tf) -#' pa <- .unzip_spd_demo(zipname="mibitof.zip", destination=tf, source="biocOSN") +#' pa <- SpatialData.data:::.unzip_spd_demo(zipname="mibitof.zip", destination=tf, source="biocOSN") #' dir(pa, full.names=TRUE) .unzip_spd_demo <- function(zipname="mibitof.zip", destination, cache=BiocFileCache::BiocFileCache(), source) { stopifnot(dir.exists(destination)) @@ -141,7 +141,7 @@ build_sandbox_path <- function(zipname) { #' bucket for zipped 10x-produced Xenium outputs #' @examples #' if (requireNamespace("paws")) { -#' .available_10x_xen_zips() +#' SpatialData.data:::.available_10x_xen_zips() #' } .available_10x_xen_zips <- function() { if (!requireNamespace("paws")) @@ -162,7 +162,7 @@ build_sandbox_path <- function(zipname) { #' provide path to a zip file from 10x genomics for Xenium platform #' @param zipname character(1) name of zip archive to find #' @examples -#' .path_to_10x_xen_demo() +#' SpatialData.data:::.path_to_10x_xen_demo() #' # see ?use_sdio .path_to_10x_xen_demo <- function(zipname="Xenium_V1_human_Breast_2fov_outs.zip") { .cache_add_if_needed_xendemo( diff --git a/man/MouseIntestineVisHD.Rd b/man/MouseIntestineVisHD.Rd index 7b74ba7..e41897e 100644 --- a/man/MouseIntestineVisHD.Rd +++ b/man/MouseIntestineVisHD.Rd @@ -39,10 +39,6 @@ HumanLungMulti_10x(target = tempfile()) \arguments{ \item{target}{character(1), defaults to tempfile(); use a different value if you wish to retain the unzipped .zarr store persistently.} - -\item{patt}{character(1) sufficient to identify an OSN resource} - -\item{cache}{like `BiocFileCache`} } \description{ This function consolidates the retrieval and caching and transformation diff --git a/man/dot-available_10x_xen_zips.Rd b/man/dot-available_10x_xen_zips.Rd index 3eee3ff..79e1eae 100644 --- a/man/dot-available_10x_xen_zips.Rd +++ b/man/dot-available_10x_xen_zips.Rd @@ -13,6 +13,6 @@ bucket for zipped 10x-produced Xenium outputs } \examples{ if (requireNamespace("paws")) { - .available_10x_xen_zips() + SpatialData.data:::.available_10x_xen_zips() } } diff --git a/man/dot-available_spd_zarr_zips.Rd b/man/dot-available_spd_zarr_zips.Rd index 35915f5..777dc80 100644 --- a/man/dot-available_spd_zarr_zips.Rd +++ b/man/dot-available_spd_zarr_zips.Rd @@ -13,6 +13,6 @@ bucket for zipped zarr archives for various platforms } \examples{ if (requireNamespace("paws")) { - .available_spd_zarr_zips() + SpatialData.data:::.available_spd_zarr_zips() } } diff --git a/man/dot-get_demo_SD.Rd b/man/dot-get_demo_SD.Rd new file mode 100644 index 0000000..f2438fe --- /dev/null +++ b/man/dot-get_demo_SD.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_demo_SD.R +\name{.get_demo_SD} +\alias{.get_demo_SD} +\title{all logic for finding, caching, loading an OSN-based dataset, hidden} +\usage{ +.get_demo_SD(patt, cache = BiocFileCache::BiocFileCache(), target = tempfile()) +} +\arguments{ +\item{patt}{character(1) sufficient to identify an OSN resource} + +\item{cache}{like `BiocFileCache`} + +\item{target}{character(1), defaults to tempfile(); use a different +value if you wish to retain the unzipped .zarr store persistently.} +} +\description{ +all logic for finding, caching, loading an OSN-based dataset, hidden +} diff --git a/man/dot-path_to_10x_xen_demo.Rd b/man/dot-path_to_10x_xen_demo.Rd index afe43f2..10eec20 100644 --- a/man/dot-path_to_10x_xen_demo.Rd +++ b/man/dot-path_to_10x_xen_demo.Rd @@ -13,6 +13,6 @@ provide path to a zip file from 10x genomics for Xenium platform } \examples{ -.path_to_10x_xen_demo() +SpatialData.data:::.path_to_10x_xen_demo() # see ?use_sdio } diff --git a/man/dot-spdzPath.Rd b/man/dot-spdzPath.Rd index b8997a9..6171987 100644 --- a/man/dot-spdzPath.Rd +++ b/man/dot-spdzPath.Rd @@ -17,5 +17,5 @@ obtain path to cached zip archive of SpatialData zarr } \examples{ -.spdzPath(zipname="merfish.zarr.zip", source="biocOSN") +SpatialData.data:::.spdzPath(zipname="merfish.zarr.zip", source="biocOSN") } diff --git a/man/dot-unzip_merfish_demo.Rd b/man/dot-unzip_merfish_demo.Rd index a0eb0a8..88e5a08 100644 --- a/man/dot-unzip_merfish_demo.Rd +++ b/man/dot-unzip_merfish_demo.Rd @@ -20,7 +20,7 @@ unzip cached merfish demo data to specified folder \examples{ tf <- tempfile() dir.create(tf) -pa <- .unzip_merfish_demo(tf) +pa <- SpatialData.data:::.unzip_merfish_demo(tf) dir(pa, full.names=TRUE) } diff --git a/man/dot-unzip_spd_demo.Rd b/man/dot-unzip_spd_demo.Rd index 413b749..130afb0 100644 --- a/man/dot-unzip_spd_demo.Rd +++ b/man/dot-unzip_spd_demo.Rd @@ -29,6 +29,6 @@ unzip selected demo data to specified folder \examples{ tf <- tempfile() dir.create(tf) -pa <- .unzip_spd_demo(zipname="mibitof.zip", destination=tf, source="biocOSN") +pa <- SpatialData.data:::.unzip_spd_demo(zipname="mibitof.zip", destination=tf, source="biocOSN") dir(pa, full.names=TRUE) } From 7b63d0718c3adcdc1192ed9dbd9def085bd63c00 Mon Sep 17 00:00:00 2001 From: vjcitn Date: Thu, 27 Feb 2025 07:03:08 -0500 Subject: [PATCH 5/7] almost ready --- DESCRIPTION | 4 ++-- NAMESPACE | 3 +++ R/availableOSN.R | 23 +++++++++++++++++++++++ R/get_demo_SD.R | 1 + R/loadFromOSN.R | 26 ++++++++++++++++++++++++++ man/availableOSN.Rd | 18 ++++++++++++++++++ man/loadFromOSN.Rd | 24 ++++++++++++++++++++++++ vignettes/SpatialData.data.Rmd | 12 +++++------- 8 files changed, 102 insertions(+), 9 deletions(-) create mode 100644 R/availableOSN.R create mode 100644 R/loadFromOSN.R create mode 100644 man/availableOSN.Rd create mode 100644 man/loadFromOSN.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 4cfb7f6..7cab136 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,10 +24,10 @@ Suggests: BiocStyle, knitr, magick, - paws, Rgraphviz, testthat, - DT + DT, + paws Remotes: HelenaLC/SpatialData biocViews: diff --git a/NAMESPACE b/NAMESPACE index 5f42beb..0cdc4f5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,8 +11,11 @@ export(LungAdenocarcinomaMCMICRO) export(MouseBrainMERFISH) export(MouseIntestineVisHD) export(MulticancerSteinbock) +export(availableOSN) export(available_sdio) +export(loadFromOSN) export(use_sdio) import(BiocFileCache) +importClassesFrom(SpatialData,SpatialData) importFrom(SpatialData,readSpatialData) importFrom(utils,unzip) diff --git a/R/availableOSN.R b/R/availableOSN.R new file mode 100644 index 0000000..fc66c34 --- /dev/null +++ b/R/availableOSN.R @@ -0,0 +1,23 @@ +#' use 'paws::s3' to interrogate an NSF Open Storage Network +#' bucket for zipped zarr archives for various platforms +#' @examples +#' if (requireNamespace("paws")) { +#' availableOSN() +#' } +#' @export +availableOSN <- function() { + if (!requireNamespace("paws")) + stop("install 'paws' to use this function; without it", + " we can't check existence of data in OSN bucket") +# x = curl::curl("https://mghp.osn.xsede.org/bir190004-bucket01") +# y = xml2::read_xml(x) +# z = xml2::as_list(y) + message("checking Bioconductor OSN bucket...") + s3 <- paws::s3( + credentials=list(anonymous=TRUE), + endpoint="https://mghp.osn.xsede.org") + zz <- s3$list_objects("bir190004-bucket01") + allk <- lapply(zz$Contents, "[[", "Key") + basename(grep("BiocSpatialData\\/", allk, value=TRUE)) +} + diff --git a/R/get_demo_SD.R b/R/get_demo_SD.R index b6cc16b..0207321 100644 --- a/R/get_demo_SD.R +++ b/R/get_demo_SD.R @@ -13,6 +13,7 @@ #' all logic for finding, caching, loading an OSN-based dataset, hidden #' @importFrom SpatialData readSpatialData +#' @importClassesFrom SpatialData SpatialData #' @param patt character(1) sufficient to identify an OSN resource #' @param cache like `BiocFileCache` #' @param target character(1), defaults to tempfile(); use a different diff --git a/R/loadFromOSN.R b/R/loadFromOSN.R new file mode 100644 index 0000000..87c99d5 --- /dev/null +++ b/R/loadFromOSN.R @@ -0,0 +1,26 @@ +#' use a string to identify a resource in SpatialData format and +#' ingest via SpatialData::readSpatialData +#' @param stub character(1) a string that identifies a resource +#' @return an instance of SpatialData, or NULL if the stub does not +#' uniquely match (using grep()) the name of any resource +#' @examples +#' lu = loadFromOSN("Lung2") +#' lu +#' @export +loadFromOSN = function(stub) { + opts = ls("package:SpatialData.data") + hit = grep(stub, opts, value=TRUE) + if (!is.na(hit[1]) && length(hit)==1L) return(get(hit)()) + else if (is.na(hit[1])) { + message("stub provided has no match in OSN resources") + message("returning NULL") + } + else { + message("stub does not uniquely match an OSN resource") + message("matched: ") + print(hit) + message("returning NULL") + } + NULL +} + diff --git a/man/availableOSN.Rd b/man/availableOSN.Rd new file mode 100644 index 0000000..ace8615 --- /dev/null +++ b/man/availableOSN.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/availableOSN.R +\name{availableOSN} +\alias{availableOSN} +\title{use 'paws::s3' to interrogate an NSF Open Storage Network +bucket for zipped zarr archives for various platforms} +\usage{ +availableOSN() +} +\description{ +use 'paws::s3' to interrogate an NSF Open Storage Network +bucket for zipped zarr archives for various platforms +} +\examples{ +if (requireNamespace("paws")) { + availableOSN() +} +} diff --git a/man/loadFromOSN.Rd b/man/loadFromOSN.Rd new file mode 100644 index 0000000..072f116 --- /dev/null +++ b/man/loadFromOSN.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/loadFromOSN.R +\name{loadFromOSN} +\alias{loadFromOSN} +\title{use a string to identify a resource in SpatialData format and +ingest via SpatialData::readSpatialData} +\usage{ +loadFromOSN(stub) +} +\arguments{ +\item{stub}{character(1) a string that identifies a resource} +} +\value{ +an instance of SpatialData, or NULL if the stub does not +uniquely match (using grep()) the name of any resource +} +\description{ +use a string to identify a resource in SpatialData format and +ingest via SpatialData::readSpatialData +} +\examples{ +lu = loadFromOSN("Lung2") +lu +} diff --git a/vignettes/SpatialData.data.Rmd b/vignettes/SpatialData.data.Rmd index d298c7c..b48ea51 100644 --- a/vignettes/SpatialData.data.Rmd +++ b/vignettes/SpatialData.data.Rmd @@ -32,17 +32,15 @@ and can be retrieved with caching support using `r BiocStyle::Biocpkg("BiocFileC We can interrogate the bucket for available (zipped) .zarr archives: ```{r ons-list} -SpatialData.data:::.available_spd_zarr_zips() +if (requireNamespace("paws")) availableOSN() ``` -Any of the above can be retrieved (once) into some location, and read into R; for example: +Any of the above can be retrieved (once) into some location, and read into R. We +use dataset-specific functions, or `loadFromOSN`: ```{r ons-read} -dir.create(td <- tempfile()) -pa <- SpatialData.data:::.unzip_spd_demo( - zipname="merfish.zarr.zip", - dest=td, source="biocOSN") -(x <- readSpatialData(pa)) +ls("package:SpatialData.data") # run a dataset-specific function, or +(x <- loadFromOSN("Lung2fov")) # stub can be used ``` # Session info From 6b5dc608d4767047095fd5ef68b1200ec1e5ef03 Mon Sep 17 00:00:00 2001 From: vjcitn Date: Thu, 27 Feb 2025 15:18:31 -0500 Subject: [PATCH 6/7] deal with stale cache entry --- DESCRIPTION | 2 +- R/get_demo_SD.R | 8 ++++++++ man/dot-get_demo_SD.Rd | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7cab136..4e5a3e3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: SpatialData.data Title: SpatialData datasets Depends: R (>= 4.4) -Version: 0.99.2.1 +Version: 0.99.2.2 Description: Makes 'scverse' data examples available through the NSF OSN, and accessible from within R, using 'BiocFileCache'. Furthermore, provides an interface to Python's 'spatialdata-io' for reading and diff --git a/R/get_demo_SD.R b/R/get_demo_SD.R index 0207321..7348e35 100644 --- a/R/get_demo_SD.R +++ b/R/get_demo_SD.R @@ -18,6 +18,8 @@ #' @param cache like `BiocFileCache` #' @param target character(1), defaults to tempfile(); use a different #' value if you wish to retain the unzipped .zarr store persistently. +#' @note This function checks for stale element in cache and uses bfcupdate to rectify +#' before retrieving from cache. # @examples # # the following are equivalent: # get_demo_SD("merfish") @@ -89,6 +91,9 @@ } # so a single pattern has hit, and it is in cache if (chkdf[ind,]$rname %in% xdzips) { # it is a Xenium 10x output resource + # check if update needed + stale = BiocFileCache::bfcneedsupdate(cache, chkdf[ind,]$rid) + if (stale) BiocFileCache::bfcupdate(cache, chkdf[ind,]$rid, fpath=chkdf[ind,]$fpath, rtype="web") preloc <- chkdf[ind,]$rpath td <- tempfile() # can't use target dir.create(td) @@ -96,6 +101,9 @@ use_sdio("xenium", srcdir=td, dest=target) # zarr in target return(SpatialData::readSpatialData(target)) } +# check again, this one is not in xdzips + stale = BiocFileCache::bfcneedsupdate(cache, chkdf[ind,]$rid) + if (stale) BiocFileCache::bfcupdate(cache, chkdf[ind,]$rid, fpath=chkdf[ind,]$fpath, rtype="web") loc <- chkdf[ind,]$rpath td <- target dir.create(td) diff --git a/man/dot-get_demo_SD.Rd b/man/dot-get_demo_SD.Rd index f2438fe..53d1955 100644 --- a/man/dot-get_demo_SD.Rd +++ b/man/dot-get_demo_SD.Rd @@ -17,3 +17,7 @@ value if you wish to retain the unzipped .zarr store persistently.} \description{ all logic for finding, caching, loading an OSN-based dataset, hidden } +\note{ +This function checks for stale element in cache and uses bfcupdate to rectify +before retrieving from cache. +} From f996d1f5d02435f7f9287eaf48c316f25a93fa46 Mon Sep 17 00:00:00 2001 From: vjcitn Date: Fri, 28 Feb 2025 08:26:48 -0500 Subject: [PATCH 7/7] make a good version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4e5a3e3..9220189 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: SpatialData.data Title: SpatialData datasets Depends: R (>= 4.4) -Version: 0.99.2.2 +Version: 0.99.3 Description: Makes 'scverse' data examples available through the NSF OSN, and accessible from within R, using 'BiocFileCache'. Furthermore, provides an interface to Python's 'spatialdata-io' for reading and