API#

Import Bento with:

import bento

Bento takes inspiration from the success of other tools in the python single-cell omics ecosystem. The API is organized under a set of modules including:

  • bento.pp: preprocessing data

  • bento.tl: subcellular spatial analyses

  • bento.pl: visualizing molecule-resolved spatial data, localization pattern statistics, and more

  • bento.io: reading and writing data stored in the AnnData format, customized to hold molecular coordinates and segmentation masks

Preprocessing#

pp.get_points(data[, asgeo])

Get points DataFrame.

pp.set_points(data[, copy])

Set points for the given AnnData object, data.

pp.get_layers(data, layers[, min_count])

Get values of layers reformatted as a long-form dataframe.

Tools#

Sample Features#

Compute spatial properties of samples. A sample is the set of points for a given gene-pair. These include properties of shape(s) and points associated with each cell.

A list of available cell features and their names is stored in the dict bento.tl.sample_features.

tl.analyze_samples(data, features[, copy])

Calculate the set of specified features for every sample, defined as the set of molecules corresponding to every cell-gene pair.

tl.PointDispersion()

For a set of points, calculates the second moment of all points in a cell relative to the centroid of the total RNA signal.

tl.RipleyStats()

For a set of points, calculates properties of the L-function.

tl.ShapeAsymmetry(shape_name)

For a set of points, computes the asymmetry of points within shape_name as well as the asymmetry of points outside shape_name.

tl.ShapeDispersion(shape_name)

For a set of points, calculates the second moment of all points in a cell relative to the centroid of shape_name.

tl.ShapeEnrichment(shape_name)

For a set of points, calculates the fraction of points within shape_name out of all points in the cell.

tl.ShapeProximity(shape_name)

For a set of points, computes the proximity of points within shape_name as well as the proximity of points outside shape_name.

Cell Features#

Compute spatial properties of cells. These include properties of shape(s) and points associated with each cell.

A list of available cell features and their names is stored in the dict bento.tl.cell_features.

tl.analyze_cells(data, feature_names[, ...])

Compute multiple cell features at once.

tl.cell_area(data[, copy])

Compute the area of each cell.

tl.cell_aspect_ratio(data[, copy])

Compute the aspect ratio of the minimum rotated rectangle that contains each cell.

tl.cell_bounds(data[, copy])

Compute the minimum and maximum coordinate values that bound each cell.

tl.cell_density(data[, copy])

Compute the RNA density of each cell.

tl.cell_moments(data[, copy])

Compute the second moment of each cell.

tl.cell_morph_open(data, proportion[, ...])

Compute the opening (morphological) of distance d for each cell.

tl.cell_perimeter(data[, copy])

Compute the perimeter of each cell.

tl.cell_radius(data[, overwrite, copy])

Compute the radius of each cell.

tl.cell_span(data[, copy])

Compute the length of the longest diagonal of each cell.

Subcellular Shape Features#

Compute spatial properties of shapes linked to each cell, such as nuclei, other organelles, or regions of interest.

tl.is_nuclear(data, shape_name[, overwrite, ...])

Check if shape_name is contained within the nucleus.

tl.nucleus_area(data[, copy])

tl.nucleus_area_ratio(data[, copy])

tl.nucleus_aspect_ratio(data[, copy])

tl.nucleus_offset(data[, copy])

tl.raster_cell(data[, copy])

Generate a grid of points contained within each cell.

Localization Patterns#

tl.lp(data[, min_count, 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, ...])

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

tl.lp_signatures(data, rank[, device, ...])

Calculate localization signatures by performing tensor decomposition on the dataset tensor.

tl.decompose_tensor(data, layers, rank[, ...])

Perform tensor decomposition on the 3-dimensional tensor built from [cell, gene, layers].

tl.select_tensor_rank(data, layers[, ...])

Perform bento.tl.decompose_tensor() up to rank upper_rank repeating each decomposition runs times to compute a 95% confidence interval, plotting reconstruction error for each rank.

Colocalization#

tl.coloc_quotient(data[, n_neighbors, ...])

Calculate pairwise gene colocalization quotient in each cell.

Plotting#

pl.qc_metrics(adata[, fname])

Plot quality control metric distributions.

pl.cellplot(adata[, hue, kind, col, legend, ...])

pl.lp_genes(data[, kind, hue, sizes, ...])

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

pl.lp_gene_dist(data[, fname])

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

pl.lp_signatures(data[, scale, fname])

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.

Read/Write#

io.read_h5ad(filename[, backed])

Load bento processed AnnData object from h5ad.

io.write_h5ad(data, filename)

Write AnnData to h5ad.

io.concatenate(adatas)

Datasets#

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