API¶
Import Bento with:
import bento as bt
Bento’s API structure takes inspiration from other libraries in the Scverse ecosystem. It is organized under a set of modules including:
bt.io: provides out of the box compatibility withSpatialDataobjectsbt.tl: subcellular analysis toolsbt.pl: conveniently plot spatial data and embeddingsbt.geo: manipulating data structuresbt.datasets: included spatial transcriptomics datasetsWIP
Read and Write¶
Bento is designed to work with SpatialData objects out of the box! Check out SpatialData documentation to learn how to bring your own data, whether it is from commercial platforms or a custom data format.
Computes spatial indices for elements in SpatialData to enable usage of bento-tools. |
Tools¶
Bento provides a set of tools to analyze the spatial composition of cells and molecules. These tools are designed to work with SpatialData objects and can be used to compute spatial summary statistics, shape features, and RNA localization patterns.
Composition¶
Calculate the average gene composition for shapes across all cells. |
|
Calculate the average difference in gene composition for shapes across batches of cells. |
Point Features¶
Compute spatial summary statistics describing groups of molecules e.g. distance to the cell membrane, relative symmetry, dispersion, etc. The set of available point features is described in the Point Feature Catalog. Use the function bt.tl.analyze_points() to compute features and add your own custom calculation. See the tutorial for more information.
Calculate features for point groups within cells. |
|
List available point feature calculations. |
|
Register a new point feature calculation class. |
Point Feature Catalog¶
The set of implemented point features is described below. Each feature is computed using the bt.tl.analyze_points() function.
TODO
Shape Features¶
Compute spatial properties of shape features e.g. area, aspect ratio, etc. of the cell, nucleus, or other region of interest. The set of available shape features is described in the Shape Feature Catalog. Use the function bt.analyze_points() to compute features and add your own custom calculation. See the tutorial for more information.
Compute common shape statistics. |
|
Compute multiple shape features. |
|
List available shape feature calculations. |
|
Register a new shape feature calculation function. |
Shape Feature Catalog¶
The set of implemented shape features is described below. Each feature is computed using the bt.analyze_shapes() function.
Compute the area of each shape. |
|
Compute aspect ratio of minimum rotated rectangle containing each shape. |
|
Compute bounding box coordinates for each shape. |
|
Compute RNA density (molecules per area) for each shape. |
|
Compute morphological opening of each shape. |
|
Compute perimeter length of each shape. |
|
Compute average radius of each shape. |
|
Generate grid of points within each shape. |
|
Compute second moment of each shape relative to its centroid. |
|
Compute maximum diameter of each shape. |
RNAflux: Subcellular RNA embeddings and domains¶
Methods for computing RNAflux embeddings and semantic segmentation of subcellular domains.
Compute RNAflux embeddings of each pixel as local composition normalized by cell composition. |
|
Cluster flux embeddings using self-organizing maps (SOMs) and vectorize clusters as Polygon shapes. |
|
Perform functional enrichment of RNAflux embeddings using decoupler's wsum function. |
|
Compute enrichment scores from subcellular compartment gene sets from Fazal et al. 2019 (APEX-seq). |
|
Compute enrichment scores from subcellular compartment gene sets from Xia et al. 2019 (MERFISH 10k U2-OS). |
|
Load a gene set from the predefined collection. |
RNAforest: Predict RNA localization patterns¶
Perform multilabel classification of RNA localization patterns using spatial summary statistics as features.
Predict transcript subcellular localization patterns. |
|
Compute frequencies of localization patterns across cells and genes. |
|
Test for differential localization patterns between discrete phenotype groups. |
|
Test correlation between localization patterns and continuous phenotype values. |
RNAcoloc: Colocalization analysis¶
Methods for compartments-ecific gene-gene colocalization analyses.
Decompose a tensor of pairwise colocalization quotients into signatures. |
|
Calculate pairwise gene colocalization quotient in each cell. |
Plotting¶
These are convenient functions for static 2D plots of cells, molecules, and embeddings. We generate matplotlib style figures for accessible publication quality plots. There are a couple additional functions summarizing results from bt.tl analysis.
Spatial plots¶
Plot points scatter. |
|
Plot points as 2D density. |
|
Plot shape layers. |
Composition¶
Plot gene composition across set of shapes. |
Shape features¶
Plot shape statistic distributions for each cell. |
RNAflux¶
Plot colorized representation of RNAflux embedding. |
|
Plot fluxmap shapes in different colors. |
|
Plot spatial heatmap of flux enrichment scores. |
RNAforest¶
Plot pattern combination frequencies as an UpSet plot. |
|
Plot the pattern distribution of each group in a RadViz plot. |
|
Visualize gene pattern frequencies between groups of cells. |
Colocalization analysis¶
Plot a heatmap representation of a loadings matrix, optionally z-scored and subsetted to the n_top rows of each factor. |
|
Plot colocation of signatures for specified rank across each dimension. |
Utilities for data manipulation¶
Convenient methods for setting, getting, and reformatting data. These functions are used internally by other functions in Bento.
Get points data synchronized with cell boundaries. |
|
Get metadata columns from points data. |
|
Add metadata columns to points data. |
|
Get shape geometries synchronized with cell boundaries. |
|
Get metadata columns from shapes data. |
|
Add metadata columns to shapes data. |
Geometric operations¶
Overlay two shape elements in a SpatialData object and store the result as a new shape element. |