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 withSpatialData
objectsbt.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 each point group. |
|
Return a DataFrame of available point features. |
|
Register a new point feature function. |
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 descriptive stats for cells. |
|
Analyze features of shapes. |
|
Return a dictionary of available shape features and their descriptions. |
|
Register a shape feature function. The function should take an SpatialData object and a shape name as input. |
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 the aspect ratio of the minimum rotated rectangle that contains each shape. |
|
Compute the minimum and maximum coordinate values that bound each shape. |
|
Compute the RNA density of each shape. |
|
Compute the opening (morphological) of distance d for each cell. |
|
Compute the perimeter of each shape. |
|
Compute the radius of each cell. |
|
Generate a grid of points contained within each shape. |
|
Compute the second moment of each shape. |
|
Compute the length of the longest diagonal 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. |
|
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; list available ones with bento.tl.gene_sets. |
RNAforest: Predict RNA localization patterns¶
Perform multilabel classification of RNA localization patterns using spatial summary statistics as features.
Predict transcript subcellular localization patterns. |
|
Computes frequencies of localization patterns across cells and genes. |
|
Gene-wise test for differential localization across phenotype of interest. |
|
Gene-wise test for differential localization across phenotype of interest. |
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 DataFrame synced to AnnData object. |
|
Get points metadata. |
|
Write metadata in SpatialData points element as column(s). |
|
Get a GeoSeries of Polygon objects from an SpatialData object. |
|
Get shape metadata. |
|
Write metadata in SpatialData shapes element as column(s). |
Geometric operations¶
Overlay two shape elements in a SpatialData object and store the result as a new shape element. |