Calculates the average percentage of cells of a target cell type within a radius from the cells with a reference cell type. The calculation is done per reference cell, so runtime will depend on the number of reference cells present. Output is a single value (the mean for the image).

average_percentage_of_cells_within_radius(
  spe_object,
  reference_celltype,
  target_celltype,
  radius = 100,
  feature_colname
)

Arguments

spe_object

SpatialExperiment object in the form of the output of format_image_to_spe.

reference_celltype

String specifying the cell type of reference cells.

target_celltype

String specifying the cell type for target cells

radius

Integer specifying the radius of search for cells around the reference cells. Radii of ~100 are recommended. If too small, too few cells might be present.

feature_colname

String specifying the column with the desired cell type annotations.

Value

A numeric vector and a plot are returned

Examples

average_percentage_of_cells_within_radius(SPIAT::defined_image, "Tumour", 
"Immune3", radius = 100, "Cell.Type")
#> [1] 17.45713