spateo.io.bbs#

IO functions for calculating the bounding box.

Module Contents#

Functions#

alpha_shape(...)

Compute the alpha shape (concave hull) of a set of points.

get_concave_hull(→ Tuple[shapely.geometry.Polygon, List])

Return the convex hull of all nanoballs that have non-zero UMI (or at least > min_agg_umi UMI).

spateo.io.bbs.alpha_shape(x: numpy.ndarray, y: numpy.ndarray, alpha: float = 1, buffer: float = 1, vectorize: bool = True) Tuple[shapely.geometry.MultiPolygon | shapely.geometry.Polygon, List][source]#

Compute the alpha shape (concave hull) of a set of points. Code adapted from: https://gist.github.com/dwyerk/10561690

Parameters:
x

x-coordinates of the DNA nanoballs or buckets, etc.

y

y-coordinates of the DNA nanoballs or buckets, etc.

alpha

alpha value to influence the gooeyness of the border. Smaller numbers don’t fall inward as much as larger numbers. Too large, and you lose everything!

buffer

the buffer used to smooth and clean up the shapley identified concave hull polygon.

vectorize

Whether to vectorize the alpha-shape calculation instead of looping through.

Returns:

The computed concave hull. edge_points: The coordinates of the edge of the resultant concave hull.

Return type:

alpha_hull

spateo.io.bbs.get_concave_hull(path: str, binsize: int = 20, min_agg_umi: int | None = None, alpha: float = 1.0, buffer: float | None = None) Tuple[shapely.geometry.Polygon, List][source]#

Return the convex hull of all nanoballs that have non-zero UMI (or at least > min_agg_umi UMI).

Parameters:
path

Path to read file.

binsize

The number of spatial bins to aggregate RNAs captured by DNBs in those bins. By default it is 20, which is close to the size of a single cell. If stereo-seq chip used is bigger than 1 x 1 mm, you may need to increase the binsize.

min_agg_umi

the minimal aggregated UMI number for the bucket.

alpha

alpha value to influence the gooeyness of the border. Smaller numbers don’t fall inward as much as larger numbers. Too large, and you lose everything!

buffer

the buffer used to smooth and clean up the shapley identified concave hull polygon.

Returns:

The computed concave hull. edge_points: The coordinates of the edge of the resultant concave hull.

Return type:

alpha_hull