R/st_grid_class.R
connected_components-STGrid-method.RdThis function identifies and labels connected components in a binary matrix representation of features of an STGrid object. The connected components are determined using the specified threshold and a minimum size for the components.
# S4 method for STGrid
connected_components(
object = NULL,
feat_list = NULL,
threshold = NULL,
min_size = 9
)An STGrid object containing the spatial expression data.
A character vector specifying the features of interest.
A numeric value specifying the threshold for binarizing the matrix. If NULL, the matrix should already be binary.
An integer specifying the minimum size of the connected components to retain. Default is 9.
The input STGrid object with additional fields for each feature's connected components.
example_dataset()
#> |-- INFO : Dataset 11284233/files/Xenium_Mouse_Brain_Coronal_7g was already loaded.
xen <- Xenium_Mouse_Brain_Coronal_7g
xen <- connected_components(xen, feat_list = feat_names(xen)[1:5], threshold = 1, min_size = 9)
head(meta(xen))
#> count_sum Ano1_cpt Chat_cpt Ebf3_cpt Kctd8_cpt
#> [1.01e+03,1.03e+03)~[22,47) 0 0 0 0 0
#> [1.01e+03,1.03e+03)~[47,72) 0 0 0 0 0
#> [1.01e+03,1.03e+03)~[72,97) 0 0 0 0 0
#> [1.01e+03,1.03e+03)~[97,122) 0 0 0 0 0
#> [1.01e+03,1.03e+03)~[122,147) 0 0 0 0 0
#> [1.01e+03,1.03e+03)~[147,172) 0 0 0 0 0
#> Necab2_cpt
#> [1.01e+03,1.03e+03)~[22,47) 0
#> [1.01e+03,1.03e+03)~[47,72) 0
#> [1.01e+03,1.03e+03)~[72,97) 0
#> [1.01e+03,1.03e+03)~[97,122) 0
#> [1.01e+03,1.03e+03)~[122,147) 0
#> [1.01e+03,1.03e+03)~[147,172) 0
spatial_image(xen, feat=meta_names(xen)[-1], ncol=2, as_factor=TRUE, colors = c("black", rainbow(60)))