## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  out.width = "100%"
)
library(pizzarr)

has_blosc <- requireNamespace("blosc", quietly = TRUE)

root <- paste0("https://data-1.vitessce.io/0.0.33/main/",
               "human-lymph-node-10x-visium/human_lymph_node_10x_visium.h5ad.zarr")

online <- tryCatch({
  con <- url(paste0(root, "/.zgroup"))
  on.exit(try(close(con), silent = TRUE))
  length(readLines(con, warn = FALSE)) > 0
}, error = function(e) FALSE, warning = function(w) FALSE)

## ----eval = has_blosc && online, message = FALSE------------------------------
# g <- zarr_open_group(HttpStore$new(root))

## ----eval = has_blosc && online-----------------------------------------------
# obs_attrs <- g$get_item("obs")$get_attrs()$to_list()
# index_colname <- obs_attrs[["_index"]]
# index_colname

## ----eval = has_blosc && online-----------------------------------------------
# index_arr <- g$get_item(paste0("obs/", index_colname))$get_item("...")$data
# 
# length(index_arr)
# head(index_arr, 3)

## ----eval = has_blosc && online-----------------------------------------------
# cluster_arr <- g$get_item("obs/clusters")$get_item("...")$data
# 
# table(cluster_arr)

## ----eval = has_blosc && online-----------------------------------------------
# umap_arr <- g$get_item("obsm/X_umap")$get_item("...")$data
# 
# dim(umap_arr)

## ----eval = has_blosc && online, fig.alt = "UMAP embedding of 3861 Visium spots, coloured by cluster assignment."----
# plot(umap_arr[, 1], umap_arr[, 2],
#      col = as.integer(as.factor(cluster_arr)),
#      pch = 19, cex = 0.4,
#      xlab = "UMAP 1", ylab = "UMAP 2")

