Skip to content

Commit

Permalink
Try using BiocFileCache instead of RDS files for persistence of sampl…
Browse files Browse the repository at this point in the history
…e info across examples (not tests yet)
  • Loading branch information
Nick-Eagles committed Oct 15, 2024
1 parent 3f73f8e commit 1389bd0
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 31 deletions.
25 changes: 19 additions & 6 deletions R/add_array_coords.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@
#' ########################################################################
#' # Prepare sample_info
#' ########################################################################
#'
#' if (file.exists("sample_info.rds")) {
#' sample_info <- readRDS("sample_info.rds")
#' } else {
#'
#' # Cache sample_info across examples
#' bfc <- BiocFileCache::BiocFileCache()
#' cached_file <- BiocFileCache::bfcquery(bfc, 'visiumStitched_sample_info')
#'
#' if (nrow(cached_file) == 0) {
#' # Then we need to construct the table of sample information
#' sample_info <- dplyr::tibble(
#' group = "Br2719",
#' capture_area = c("V13B23-283_A1", "V13B23-283_C1", "V13B23-283_D1")
Expand All @@ -92,8 +95,18 @@
#'
#' ## Re-size images and add more information to the sample_info
#' sample_info <- rescale_fiji_inputs(sample_info, out_dir = tempdir())
#'
#' saveRDS(sample_info, "sample_info.rds")
#'
#' # Cache sample info for later
#' sample_info_path <- BiocFileCache::bfcnew(
#' bfc, "visiumStitched_sample_info", ext = "csv"
#' )
#' readr::write_csv(sample_info, sample_info_path)
#' } else {
#' # Pull sample info from the cache
#' sample_info_path <- BiocFileCache::bfcquery(
#' bfc, 'visiumStitched_sample_info'
#' )$rpath
#' sample_info = readr::read_csv(sample_info_path)
#' }
#'
#' ## Preparing Fiji coordinates and images for build_SpatialExperiment()
Expand Down
23 changes: 18 additions & 5 deletions R/build_SpatialExperiment.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@
#' # Prepare sample_info
#' ########################################################################
#'
#' if (file.exists("sample_info.rds")) {
#' sample_info <- readRDS("sample_info.rds")
#' } else {
#' # Cache sample_info across examples
#' bfc <- BiocFileCache::BiocFileCache()
#' cached_file <- BiocFileCache::bfcquery(bfc, 'visiumStitched_sample_info')
#'
#' if (nrow(cached_file) == 0) {
#' # Then we need to construct the table of sample information
#' sample_info <- dplyr::tibble(
#' group = "Br2719",
#' capture_area = c("V13B23-283_A1", "V13B23-283_C1", "V13B23-283_D1")
Expand All @@ -67,8 +70,18 @@
#'
#' ## Re-size images and add more information to the sample_info
#' sample_info <- rescale_fiji_inputs(sample_info, out_dir = tempdir())
#'
#' saveRDS(sample_info, "sample_info.rds")
#'
#' # Cache sample info for later
#' sample_info_path <- BiocFileCache::bfcnew(
#' bfc, "visiumStitched_sample_info", ext = "csv"
#' )
#' readr::write_csv(sample_info, sample_info_path)
#' } else {
#' # Pull sample info from the cache
#' sample_info_path <- BiocFileCache::bfcquery(
#' bfc, 'visiumStitched_sample_info'
#' )$rpath
#' sample_info = readr::read_csv(sample_info_path)
#' }
#'
#' ## Preparing Fiji coordinates and images for build_SpatialExperiment()
Expand Down
23 changes: 18 additions & 5 deletions R/prep_fiji.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@
#' @author Nicholas J. Eagles
#'
#' @examples
#' if (file.exists("sample_info.rds")) {
#' sample_info <- readRDS("sample_info.rds")
#' } else {
#' # Cache sample_info across examples
#' bfc <- BiocFileCache::BiocFileCache()
#' cached_file <- BiocFileCache::bfcquery(bfc, 'visiumStitched_sample_info')
#'
#' if (nrow(cached_file) == 0) {
#' # Then we need to construct the table of sample information
#' sample_info <- dplyr::tibble(
#' group = "Br2719",
#' capture_area = c("V13B23-283_A1", "V13B23-283_C1", "V13B23-283_D1")
Expand All @@ -67,8 +70,18 @@
#'
#' ## Re-size images and add more information to the sample_info
#' sample_info <- rescale_fiji_inputs(sample_info, out_dir = tempdir())
#'
#' saveRDS(sample_info, "sample_info.rds")
#'
#' # Cache sample info for later
#' sample_info_path <- BiocFileCache::bfcnew(
#' bfc, "visiumStitched_sample_info", ext = "csv"
#' )
#' readr::write_csv(sample_info, sample_info_path)
#' } else {
#' # Pull sample info from the cache
#' sample_info_path <- BiocFileCache::bfcquery(
#' bfc, 'visiumStitched_sample_info'
#' )$rpath
#' sample_info = readr::read_csv(sample_info_path)
#' }
#'
#' spe_input_dir <- tempdir()
Expand Down
23 changes: 18 additions & 5 deletions man/add_array_coords.Rd

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

23 changes: 18 additions & 5 deletions man/build_SpatialExperiment.Rd

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

23 changes: 18 additions & 5 deletions man/prep_fiji.Rd

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

0 comments on commit 1389bd0

Please sign in to comment.