Calculates the number and proportion of each cell type.

calculate_cell_proportions(
  spe_object,
  reference_celltypes = NULL,
  celltypes_to_exclude = NULL,
  feature_colname = "Phenotype",
  plot.image = TRUE
)

Arguments

spe_object

SpatialExperiment object in the form of the output of format_image_to_spe.

reference_celltypes

String Vector specifying reference cell types. If NULL (default), then the proportion of each cell type against all cells is returned. Alternatively, a custom vector of cell types can be used as input, and these will be used as the denominator in the calculation of the proportions.

celltypes_to_exclude

String Vector specifying cell types to exclude. For example "OTHER" will exclude that celltype from the Total. If NULL, all cell types are included.

feature_colname

String. Column of cells to choose the cell type from (e.g. Phenotype, Cell.Type, etc).

plot.image

Boolean. Whether to plot the barplot of the cell percentages. By default is TRUE.

Value

A data.frame is returned

Examples

calculate_cell_proportions(SPIAT::defined_image, reference_celltypes = NULL, 
celltypes_to_exclude = "Others", feature_colname="Cell.Type", plot.image = FALSE)
#>   Cell_type Number_of_celltype Proportion Percentage Proportion_name
#> 5    Tumour                819 0.41679389  41.679389          /Total
#> 3   Immune3                630 0.32061069  32.061069          /Total
#> 1   Immune1                338 0.17201018  17.201018          /Total
#> 2   Immune2                178 0.09058524   9.058524          /Total