Calculate the proportion of cells of interest in each defined tissue structure relative to all cells in each structure and relative to the same cell type in the whole image.

calculate_proportions_of_cells_in_structure(
  spe_object,
  cell_types_of_interest,
  feature_colname
)

Arguments

spe_object

SpatialExperiment object in the form of the output of format_image_to_spe.

cell_types_of_interest

String Vector of cell types to consider.

feature_colname

String. The name of the column where the cell types of interest are under.

Value

A data.frame

Examples

spe_border <- identify_bordering_cells(SPIAT::defined_image,
reference_cell = "Tumour", feature_colname = "Cell.Type", n_to_exclude = 10)
#> [1] "The alpha of Polygon is: 63.24375"

spe_dist <- calculate_distance_to_margin(spe_border)
#> [1] "Markers had been selected in minimum distance calculation: "
#> [1] "Non-border" "Border"    
spe_structure <- define_structure(spe_dist,
cell_types_of_interest = c("Immune1","Immune2","Immune3"),
feature_colname = "Cell.Type", n_margin_layers = 5)
calculate_proportions_of_cells_in_structure(spe_structure,
cell_types_of_interest = c("Immune1","Immune3"),feature_colname="Cell.Type")
#>               Cell.Type                            Relative_to
#> 1               Immune1             All_cells_in_the_structure
#> 2               Immune3             All_cells_in_the_structure
#> 3               Immune1 All_cells_of_interest_in_the_structure
#> 4               Immune3 All_cells_of_interest_in_the_structure
#> 5               Immune1  The_same_cell_type_in_the_whole_image
#> 6               Immune3  The_same_cell_type_in_the_whole_image
#> 7 All_cells_of_interest             All_cells_in_the_structure
#>   P.Infiltrated.CoI P.Internal.Margin.CoI P.External.Margin.CoI P.Stromal.CoI
#> 1        0.00000000            0.00000000           0.001733102    0.09658928
#> 2        0.12576687            0.08071749           0.681109185    0.04585841
#> 3        0.00000000            0.00000000           0.002538071    0.67806841
#> 4        1.00000000            1.00000000           0.997461929    0.32193159
#> 5        0.00000000            0.00000000           0.002958580    0.99704142
#> 6        0.06507937            0.05714286           0.623809524    0.25396825
#> 7        0.12576687            0.08071749           0.684575390    0.19317856