Skip to contents

Compute minimum boundary distances for each cell within its corresponding image structures

Usage

minBoundaryDistances(spe, imageCol, structColumn, allStructs, nCores = 1)

Arguments

spe

SpatialExperiment object

imageCol

character; name of the colData column specifying the image name

structColumn

character; name of the colData column specifying structure assignments

allStructs

sf object; contains spatial structures with corresponding image names

nCores

integer; The number of cores to use for parallel processing (default is 1).

Value

A numeric vector containing the minimum distances between cells and structure boundaries, values within structures have negative values.

Examples

library("SpatialExperiment")
data("sostaSPE")
allStructs <- reconstructShapeDensitySPE(sostaSPE,
    marks = "cellType", imageCol = "imageName",
    markSelect = "A", bndw = 3.5, thres = 0.045
)
colData(sostaSPE)$structAssign <- assingCellsToStructures(
    spe = sostaSPE, allStructs = allStructs, imageCol = "imageName"
)
colData(sostaSPE)$minDist <- minBoundaryDistances(
    spe = sostaSPE, imageCol = "imageName", structColumn = "structAssign",
    allStructs = allStructs
)
if (require("ggplot2")) {
    cbind(colData(sostaSPE), spatialCoords(sostaSPE)) |>
        as.data.frame() |>
        ggplot(aes(x = x, y = y, color = minDist)) +
        geom_point(size = 0.25) +
        scale_colour_gradient2() +
        geom_sf(data = allStructs, fill = NA, inherit.aes = FALSE) +
        facet_wrap(~imageName)
}