spateo.digitization.borderline

Written by @Jinerhal, adapted by @Xiaojieqiu.

Functions

get_borderline(→ spateo.digitization.utils.np.ndarray)

Identify the borderline at the interface of the source and target cell clusters.

grid_borderline(→ None)

Extend the borderline to either interior or exterior side to each create layer_num layers, and segment such

Module Contents

spateo.digitization.borderline.get_borderline(adata: spateo.digitization.utils.AnnData, cluster_key: str, source_clusters: int, target_clusters: int, bin_size: int = 1, spatial_key: str = 'spatial', borderline_key: str = 'borderline', k_size: int = 8, min_area: int = 30, dilate_k_size: int = 3) spateo.digitization.utils.np.ndarray[source]

Identify the borderline at the interface of the source and target cell clusters.

The borderline will be identified by first retrieving the outline/contour formed by the source clusters, which will then be cleaned up to retrieve the borderline by masking with the expanded contours formed by the target clusters.

Parameters:
adata

The adata object to be used for identifying the borderline.

cluster_key

The key name of the spatial cluster in adata.obs

source_clusters

The source cluster(s) that will interface with the target clusters.

target_clusters

The target cluster(s) that will interface with the source clusters.

bin_size

The size of the binning.

spatial_key

The key name of the spatial coordinates in adata.obs

borderline_key

The key name in adata.obs that will be used to store the borderline.

k_size

Kernel size of the elliptic structuring element.

min_area

Minimal area threshold corresponding to the resulting contour(s).

dilate_k_size

Kernel size of the cv2.dilate function.

Returns:

The matrix that stores the image information of the borderline between the source and target

cluster(s). Note that the adata object will also be updated with the boundary_line key that stores the information about whether the bucket is on the borderline.

Return type:

borderline_img

spateo.digitization.borderline.grid_borderline(adata: spateo.digitization.utils.AnnData, borderline_img: spateo.digitization.utils.np.ndarray, borderline_list: spateo.digitization.utils.List, layer_num: int = 3, column_num: int = 25, layer_width: int = 10, spatial_key: str = 'spatial', init: bool = False) None[source]
Extend the borderline to either interior or exterior side to each create layer_num layers, and segment such

layers to column_num columns.

Parameters:
adata

The adata object to be used for identifying the interior/exterior layers and columns.

borderline_img

The matrix that stores the image information of the borderline between the source and target cluster(s).

borderline_list

An order list of np.arrays of coordinates of the borderlines.

layer_num

Number of layers to extend on either interior or exterior side.

column_num

Number of columns to segment for each layer.

layer_width

Layer/column boundary width. This only affects grid_label.

spatial_key

The key name in adata.obsm of the spatial coordinates. Default to “spatial”. Passed to fill_grid_label function.

init

Whether to generate (and potentially overwrite) the layer_label_key and column_label_key in fill_grid_label function.

Returns:

  1. layer_label_key: this key points to layer labels.

  2. column_label_key: this key points to column labels.

Return type:

Nothing but update the adata object with following keys in .obs