This function constructs polygons around patch cells and computes their area.
patchSize(
object,
patch_name = "patch_id",
coords = c("Pos_X", "Pos_Y"),
convex = FALSE
)
a SingleCellExperiment
or SpatialExperiment
object
single character indicating the colData(object)
entry
containing the patch cell identifiers.
character vector of length 2 specifying the names of the
colData
(for a SingleCellExperiment
object) or the
spatialCoords
entries of the cells' x and y locations.
should the convex hull be computed to construct the polygon? Default: the concave hull is computed.
A DataFrame object containing the patch identifier, the constructed polygon and the polygon size.
library(cytomapper)
data(pancreasSCE)
# Build interaction graph
pancreasSCE <- buildSpatialGraph(pancreasSCE, img_id = "ImageNb",
type = "expansion", threshold = 20)
#> The returned object is ordered by the 'ImageNb' entry.
# Detect patches of "celltype_B" cells
pancreasSCE <- patchDetection(pancreasSCE,
patch_cells = pancreasSCE$CellType == "celltype_B",
expand_by = 5, img_id = "ImageNb",
colPairName = "expansion_interaction_graph")
#> The returned object is ordered by the 'ImageNb' entry.
# Compute the patch area
patchSize(pancreasSCE)
#> DataFrame with 8 rows and 3 columns
#> patch_id polygon size
#> <character> <list> <numeric>
#> 1 1 NA NA
#> 2 2 NA NA
#> 3 3 c(189.2317, 175.9615.. 39.143
#> 4 4 NA NA
#> 5 5 NA NA
#> 6 6 c(182.5446, 171.6403.. 2006.268
#> 7 7 c(156.5283, 142.6774.. 254.845
#> 8 8 c(255.9697, 263.4943.. 3605.491