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.tl: subcellular spatial analyses

  • bt.pl: conveniently plot spatial data and embeddings

  • bt.io: reading and writing spatial data to AnnData as h5ad files

  • bt.geo: manipulating spatial data

  • bt.datasets: included spatial transcriptomics datasets

  • bt.ut: utility functions


Point features#

Compute spatial summary statistics describing groups of molecules e.g. distance to the cell membrane, relative symmetry, dispersion, etc.

A list of available cell features and their names is stored in the dict :func:bt.tl.point_features.

tl.analyze_points(data, shape_names, ...[, ...])

Calculate the set of specified features for each point group.

tl.register_point_feature(name, FeatureClass)

Register a new point feature function.

Shape features#

Compute spatial properties of shape features e.g. area, aspect ratio, etc. of the cell, nucleus, or other region of interest.

A list of available cell features and their names is stored in the dict :func:bt.tl.shape_features.

tl.analyze_shapes(data, shape_names, ...[, ...])

Analyze features of shapes.

tl.register_shape_feature(name, func)

Register a shape feature function.

tl.obs_stats(data[, feature_names, copy])

Compute features for each cell shape.

RNAflux: Subcellular RNA embeddings and domains#

Methods for computing RNAflux embeddings and semantic segmentation of subcellular domains.

tl.flux(data[, method, n_neighbors, radius, ...])

RNAflux: Embedding each pixel as normalized local composition normalized by cell composition.

tl.fluxmap(data[, n_clusters, ...])

Cluster flux embeddings using self-organizing maps (SOMs) and vectorize clusters as Polygon shapes.

tl.fe(data, net[, source, target, weight, ...])

Perform functional enrichment on point embeddings.

tl.fe_fazal2019(data[, copy])

Compute enrichment scores from subcellular compartment gene sets from Fazal et al. 2019 (APEX-seq).


Load a gene set from bento.

RNAforest: Predict RNA localization patterns#

Perform multilabel classification of RNA localization patterns using spatial summary statistics as features.

tl.lp(data[, groupby, copy])

Predict transcript subcellular localization patterns.

tl.lp_stats(data[, copy])

Computes frequencies of localization patterns across cells and genes.

tl.lp_diff(data[, phenotype, continuous, copy])

Gene-wise test for differential localization across phenotype of interest.

Colocalization analysis#

Methods for colocalization analyses of gene pairs.

tl.colocation(data, ranks[, iterations, ...])

Decompose a tensor of pairwise colocalization quotients into signatures.

tl.coloc_quotient(data[, shapes, radius, ...])

Calculate pairwise gene colocalization quotient in each cell.


Spatial plots#

These are convenient functions for quick 2D visualizations of cells, molecules, and embeddings. We generate matplotlib style figures for accessible publication quality plots.

pl.points(data[, batch, hue, size, style, ...])

pl.density(data[, batch, kind, hue, shapes, ...])

pl.shapes(data[, batch, shapes, color, ...])

pl.flux(data[, batch, res, shapes, ...])

pl.fluxmap(data[, batch, palette, ...])

Plot fluxmap shapes in different colors.

Shape features#

pl.obs_stats(data[, obs_cols, s, alpha, ...])

Plot shape statistic distributions for each cell.


pl.flux_summary(data[, groupby, ...])

Plot RNAflux summary with a radviz plot describing gene embedding across flux clusters.

pl.fe(data, gs[, batch, res, shapes, cmap, ...])


pl.lp_genes(data[, groupby, annotate, ...])

Plot the pattern distribution of each group in a RadViz plot.

pl.lp_gene_dist(data[, fname])

Plot the cell fraction distribution of each pattern as a density plot.

pl.lp_dist(data[, percentage, scale, fname])

Plot pattern combination frequencies as an UpSet plot.

pl.lp_diff(data, phenotype[, fname])

Visualize gene pattern frequencies between groups of cells by plotting log2 fold change and -log10p, similar to volcano plot.

Colocalization analysis#

pl.signatures(adata, rank[, fname])

Plot signatures for specified rank across each dimension.

pl.signatures_error(adata[, fname])

Plot error for each rank.

pl.factor(factors, labels, names[, n_top, ...])

Plot a heatmap representation of a loadings matrix, optionally z-scored and subsetted to the n_top rows of each factor.

pl.colocation(adata, rank[, n_top, z_score, ...])

Plot colocation of signatures for specified rank across each dimension.

Manipulating spatial data#

Convenient methods for setting, getting, and reformatting data.

geo.count_points(data, shape_names[, copy])

Count points in shapes and add as layers to data.

geo.crop(data, xlims, ylims[, copy])

Returns a view of data within specified coordinates.

geo.get_points(data[, key, asgeo])

Get points DataFrame synced to AnnData object.

geo.get_points_metadata(data, metadata_key)

Get points metadata synced to AnnData object.

geo.get_shape(adata, shape_name)

Get a GeoSeries of Polygon objects from an AnnData object.

geo.rename_shapes(data, mapping[, ...])

Rename shape columns in adata.obs and points columns in adata.uns.

geo.sindex_points(data, points_key, shape_names)

Index points to shapes and add as columns to data.uns[points_key].


io.read_h5ad(filename[, backed])

Load bento processed AnnData object from h5ad.

io.write_h5ad(data, filename)

Write AnnData to h5ad.


io.prepare(molecules, cell_seg[, x, y, ...])

Prepare AnnData with molecule-level spatial data.



ds.load_dataset(name[, cache, data_home])

Load a builtin dataset.


Return DataFrame with info about builtin datasets.

Utility functions#

ut.sync(data[, copy])

Sync existing point sets and associated metadata with data.obs_names and data.var_names

ut.geo_format(data[, copy])

Convert data.obs scanpy columns to GeoPandas compatible types.

ut.sc_format(data[, copy])

Convert data.obs GeoPandas columns to string for compatibility with scanpy.

ut.pheno_to_color(pheno, palette)

Maps list of categorical labels to a color palette.