Skip to content

Commit

Permalink
Added examples
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdamoses committed May 10, 2024
1 parent 10d326f commit 850f474
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 28 deletions.
19 changes: 19 additions & 0 deletions R/formatTxSpots.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@
#' the transcript spots of the selected genes added.
#' @name readSelectTx
#' @export
#' @examples
#' library(SFEData)
#' fp <- tempdir()
#' dir_use <- XeniumOutput("v2", file_path = file.path(fp, "xenium_test"))
#' fn_tx <- formatTxTech(dir_use, tech = "Xenium", flip = TRUE, return = FALSE,
#' file_out = file.path(dir_use, "tx_spots.parquet"))
#' gene_select <- c("ACE2", "BMX")
#' df <- readSelectTx(fn_tx, gene_select)
#'
#' sfe <- readXenium(dir_use)
#' sfe <- addSelectTx(sfe, fn_tx, head(rownames(sfe), 5), swap_rownames = "Symbol")
#' unlink(dir_use, recursive = TRUE)
readSelectTx <- function(file, gene_select, z = "all",
z_option = c("3d", "split")) {
if (!gdalParquetAvailable()) {
Expand Down Expand Up @@ -504,6 +516,13 @@ addTxSpots <- function(sfe, file, sample_id = 1L,
#' `return = FALSE`.
#' @name formatTxTech
#' @export
#' @examples
#' library(SFEData)
#' fp <- tempdir()
#' dir_use <- XeniumOutput("v2", file_path = file.path(fp, "xenium_test"))
#' fn_tx <- formatTxTech(dir_use, tech = "Xenium", flip = TRUE, return = FALSE,
#' file_out = file.path(dir_use, "tx_spots.parquet"))
#'
formatTxTech <- function(data_dir, tech = c("Vizgen", "Xenium", "CosMX"),
dest = c("rowGeometry", "colGeometry"),
z = "all", min_phred = 20,
Expand Down
23 changes: 9 additions & 14 deletions R/read.R
Original file line number Diff line number Diff line change
Expand Up @@ -832,20 +832,15 @@ readCosMX <- function(data_dir,
#' @importFrom DropletUtils read10xCounts
#' @importFrom zeallot %<-%
#' @examples
#' # TODO: Example code for Xenium toy data
#'
#' # custom example run:
#' if (FALSE)
#' sfe <-
#' readXenium(data_dir = data_dir,
#' sample_id = "test_xenium",
#' image = c("morphology_focus", "morphology_mip"),
#' segmentations = c("cell", "nucleus"),
#' flip = "geometry",
#' filter_counts = TRUE,
#' add_molecules = TRUE,
#' file_out = NULL)
#'
#' library(SFEData)
#' library(RBioFormats)
#' fp <- tempdir()
#' dir_use <- XeniumOutput("v2", file_path = file.path(fp, "xenium_test"))
#' # RBioFormats issue
#' try(sfe <- readXenium(dir_use, add_molecules = TRUE))
#' sfe <- readXenium(dir_use, add_molecules = TRUE)
#' unlink(dir_use, recursive = TRUE)

readXenium <- function(data_dir,
sample_id = "sample01",
image = c("morphology_focus", "morphology_mip"),
Expand Down
18 changes: 18 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ bbox_center <- function(bbox) {
#' @return Numeric vector of length 2 of pixel size in x and y. Usually they're
#' the same.
#' @export
#' @examples
#' library(SFEData)
#' fp <- tempdir()
#' dir_use <- XeniumOutput("v1", file_path = file.path(fp, "xenium_test"))
#' getPixelSize(file.path(dir_use, "morphology_focus.ome.tif"))
#' unlink(dir_use, recursive = TRUE)
getPixelSize <- function(file, resolution = 1L) {
check_installed(c("xml2", "RBioFormats"))
xml_meta <- RBioFormats::read.omexml(file) |>
Expand Down Expand Up @@ -206,6 +212,10 @@ getPixelSize <- function(file, resolution = 1L) {
#' or a list of bounding boxes which are named numeric vectors.
#' @return A named numeric vector for the total bounding box.
#' @export
#' @examples
#' bboxes <- list(c(xmin = 5, xmax = 10, ymin = 2, ymax = 20),
#' c(xmin = 8, xmax = 18, ymin = 0, ymax = 15))
#' bbox_all <- aggBboxes(bboxes)
aggBboxes <- function(bboxes) {
if (is.list(bboxes)) {
bboxes <- lapply(bboxes, function(x) x[c("xmin", "ymin", "xmax", "ymax")])
Expand All @@ -227,6 +237,11 @@ aggBboxes <- function(bboxes) {
#' @inheritParams sampleIDs
#' @return A character vector of \code{image_ids}.
#' @export
#' @examples
#' fp <- system.file(file.path("extdata", "sample01"),
#' package = "SpatialFeatureExperiment")
#' sfe <- read10xVisiumSFE(fp, type = "sparse")
#' imageIDs(sfe)
imageIDs <- function(sfe) imgData(sfe)$image_id

#' Check if Parquet GDAL driver is available
Expand All @@ -248,6 +263,9 @@ imageIDs <- function(sfe) imgData(sfe)$image_id
#'
#' @return Logical, indicating whether the Parquet driver is present.
#' @export
#' @examples
#' gdalParquetAvailable()
#'
gdalParquetAvailable <- function() {
"Parquet" %in% rownames(sf::st_drivers())
}
Expand Down
5 changes: 5 additions & 0 deletions man/aggBboxes.Rd

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

8 changes: 8 additions & 0 deletions man/formatTxTech.Rd

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

4 changes: 4 additions & 0 deletions man/gdalParquetAvailable.Rd

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

7 changes: 7 additions & 0 deletions man/getPixelSize.Rd

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

6 changes: 6 additions & 0 deletions man/imageIDs.Rd

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

13 changes: 13 additions & 0 deletions man/readSelectTx.Rd

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

22 changes: 8 additions & 14 deletions man/readXenium.Rd

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

0 comments on commit 850f474

Please sign in to comment.