Given a SpatialExperiment, sample information, and coordinates produced from the refinement workflow, add array and pixel coordinates appropriate for the linearly transformed capture areas making up each group present in the SpatialExperiment.

add_array_coords(spe, sample_info, coords_dir, overwrite = TRUE)

Arguments

spe

A SpatialExperiment

sample_info

A tibble with columns capture_area and group

coords_dir

A character(1) vector giving the directory containing sample directories each with tissue_positions.csv, scalefactors_json.json, and tissue_lowres_image.png files produced from refinement with prep_imagej_*() functions

overwrite

A logical(1) vector indicating whether to overwrite spatialCoords(spe), and colData(spe) columns array_row, array_col, pixel_row_in_fullres, and pixel_col_in_fullres with the transformed values. Note that the original values are preserved even when TRUE, in versions of colData(spe) columns ending in _original.

Value

A SpatialExperiment object with additional colData columns pxl_row_in_fullres_[suffix] and pxl_col_in_fullres_[suffix] with [suffix] values original, transformed, and rounded; array_row_[suffix] and array_col_[suffix] columns with [suffix] values original and transformed; and, if overwrite, modified colData columns array_row and array_col and spatialCoords() with their transformed values

Details

Array coordinates are determined via an algorithm that fits each spot to the nearest spot on a new, imaginary, Visium-like capture area. The imaginary capture area differs from a real capture area only in its extent; array coordinates still start at 0 but may extend arbitrarily beyond the normal maximum indices of 77 and 127 to fit every capture area in each group defined in the SpatialExperiment. The goal is to return well-defined array coordinates in a consistent spatial orientation for each group, such that downstream applications, such as clustering with BayesSpace, can process each group as if it really were one capture area in the first place.

Author

Nicholas J. Eagles

Examples

#   For internal testing
if (FALSE) { # \dontrun{
library("HDF5Array")
spe <- loadHDF5SummarizedExperiment("dev/test_data/spe_filtered")
sample_info <- readr::read_csv("dev/test_data/sample_info.csv")
coords_dir <- "dev/test_data"
spe_new <- add_array_coords(spe, sample_info, coords_dir, overwrite = TRUE)
} # }

## TODO: add working examples
args(add_array_coords)
#> function (spe, sample_info, coords_dir, overwrite = TRUE) 
#> NULL