Select cell types to keep or exclude in the analysis. The output of this function also includes the original image size and cell count.

select_celltypes(
  spe_object,
  celltypes,
  feature_colname = "Phenotype",
  keep = TRUE
)

Arguments

spe_object

SpatialExperiment object in the form of the output of format_image_to_spe.

celltypes

String Vector of celltypes of keep or exclude.

feature_colname

String. The column that has the interested cell types. If the cells ids are used to select cells, use "Cell.ID" for this arg.

keep

Boolean. TRUE if vector of `celltypes` are the cells that are going to be kept, FALSE if they are to be removed.

Value

A SpatialExperiment object is returned. The original image size and cell count can be accessed by `attr(slim_spe, "original_cell_number")` and `attr(slim_spe, "range_of_coords")`, where `slim_spe` is the output of this function.

Examples

data_subset <- select_celltypes(SPIAT::simulated_image,
celltypes = c("Tumour_marker","Immune_marker1","Immune_marker2",
"Immune_marker3","Immune_marker4"),
feature_colname = "Phenotype", keep=TRUE)
attr(data_subset, "original_cell_number") #cell number in the original image
#> [1] 4951
attr(data_subset, "range_of_coords")
#>         xmin         xmax         ymin         ymax 
#>    0.1869877 1999.9512939    0.3243161 1998.9921875 
dim(data_subset)[2] # this is the new image cell number
#> [1] 819