Compute Local Cell Type Composition in the Spatial Neighborhood
Source:R/Cell_type_neighborhood.R
Cell_type_neighborhood.RdComputes the local cell type composition for each spot or cell based on spatial proximity. Supports both single-cell resolution using nearest neighbors and spot-level resolution using distance thresholding with cell type proportions.
Usage
Cell_type_neighborhood(
sample_information_coordinate,
resolution = c("single_cell", "spot"),
sample_information_cellType = NULL,
sample_information_decon = NULL,
k = 50,
r = 4
)Arguments
- sample_information_coordinate
A data.frame or matrix of spatial coordinates (x, y). Row names must correspond to cell or spot IDs.
- resolution
One of
"single_cell"or"spot".- sample_information_cellType
Named vector of cell types for single-cell resolution. Names must match rownames of
sample_information_coordinate.- sample_information_decon
A matrix of cell type proportions per spot (for
"spot"mode). Row names must match those ofsample_information_coordinate.- k
Integer, number of nearest neighbors (used only in
"single_cell"mode). Default is 50.- r
Numeric, distance threshold for neighborhood (used only in
"spot"mode). Default is 4.
Value
A matrix of normalized cell type proportions for each spatial unit (rows) across cell types (columns).
Details
This function calculates the distribution of cell types around each spatial unit using one of the following modes:
"single_cell": Uses discrete cell-type labels and K-nearest neighbors."spot": Uses continuous deconvolution proportions and radius threshold.
The returned matrix represents normalized cell-type compositions in each local neighborhood.
Examples
if (FALSE) { # \dontrun{
data("osmFISH_metadata_cellType")
data("osmFISH_bulk_decon")
data("osmFISH_bulk_pheno")
data("osmFISH_bulk_coordinate")
Cell_type_neighborhood(
sample_information_coordinate = osmFISH_bulk_coordinate,
resolution = "single_cell",
sample_information_cellType = osmFISH_metadata_cellType
)
} # }