smurf.expanding_cells¶
- smurf.expanding_cells(so, adata_sc, weights, iter_cells, data_temp, min_percent=0.4, cortex=False)¶
Expands cell regions by iteratively adding neighboring spots based on a scoring criterion.
This function aims to grow the regions of cells in spatial data by evaluating neighboring spots and including them if they improve a cell-specific score. The score is calculated using the dot product of the cell’s expression vector and precomputed weights for the cell type, normalized by the vector norm. Optionally, the function can perform additional processing for cortical data using Delaunay triangulation to fill in cell regions more completely.
- Parameters:
so (spatial_object) – A spatial object containing spatial mappings, spot data, and other necessary attributes.
adata_sc (anndata.AnnData) – An AnnData object containing single-cell gene expression data with cell IDs and cell types.
weights (dict) – A dictionary mapping cell types to weight vectors used in the scoring function.
iter_cells (dict) – A dictionary mapping cell IDs to the number of iterations allowed for expanding each cell.
data_temp (scipy.sparse.csr_matrix or similar) – A sparse matrix containing gene expression data used for calculations during cell expansion.
min_percent (float, optional) – The minimum percentage threshold for including neighboring spots in the cell expansion. Spots with a proportion below this threshold will be excluded. Defaults to 0.4.
cortex (bool, optional) – If True, performs additional processing suitable for cortical data using Delaunay triangulation to fill in cell regions. Defaults to False.
- Returns:
A tuple containing:
cells_final (dict): A dictionary mapping cell IDs to their final set of spots after expansion.
final_data (scipy.sparse.lil_matrix): A matrix containing the aggregated gene expression data for each expanded cell.
cellscore (numpy.ndarray): An array containing the final score for each cell.
length_final (numpy.ndarray): An array containing the final number of spots for each cell.
- Return type: