https://mybinder.org/badge_logo.svg

Compute Subcellular Spatial Features#

Author: Clarence Mah | Last Updated: 6/15/2022

Here we will demonstrate how to compute various subcellular spatial features with bento. We will use the included seqFISH+ dataset.

Load Libraries#

[6]:
import bento
import seaborn as sns

Load Data#

Let’s start with the preprocessed seqFISH+ data.

[2]:
adata = bento.datasets.load_dataset('seqfish')

Cell Features#

There are a number of tools to compute cell-level features. List available features like so.

[3]:
bento.tl.cell_features.keys()
[3]:
dict_keys(['cell_span', 'cell_bounds', 'cell_moments', 'raster_cell', 'cell_aspect_ratio', 'cell_density', 'cell_area', 'cell_perimeter', 'cell_radius'])

We can compute a single feature…

[4]:
bento.tl.cell_area(adata)
AnnData object modified:
    obs:
        + cell_area

Or conveniently, a whole set of features simultaneously.

[9]:
some_features = ["cell_area", "cell_density", "cell_aspect_ratio"]
bento.tl.analyze_cells(adata, some_features)
AnnData object modified:
    obs:
        + cell_density, cell_aspect_ratio

For starters, we can study pairwise relationships of these cell features.

[10]:
sns.pairplot(
    data=adata.obs[["cell_area", "cell_density", "cell_aspect_ratio"]],
    kind="reg",
)
[10]:
<seaborn.axisgrid.PairGrid at 0x1554e0dc0fd0>
../_images/tutorial_gallery_Subcellular_Features_13_1.png
[21]:
sns.clustermap(
    adata.obs[["cell_area", "cell_density", "cell_aspect_ratio"]].T,
    standard_scale=0,
    figsize=(8, 3),
    cmap="Reds",
)
[21]:
<seaborn.matrix.ClusterGrid at 0x1554c7f9a2e0>
../_images/tutorial_gallery_Subcellular_Features_14_1.png
[27]:
dense_cells = adata.obs["cell_density"].sort_values(ascending=False).index[:10]
bento.pl.cellplot(adata[dense_cells], col="cell", col_wrap=5, height=3)
../_images/tutorial_gallery_Subcellular_Features_15_2.png

Sample Features#

Similarly, we can compute subcellular spatial features for samples (sample corresponds to molecules for a given cell-gene pair), to produce high-dimensional feature spaces.

[22]:
bento.tl.sample_features.keys()
[22]:
dict_keys(['cell_proximity', 'nucleus_proximity', 'cell_asymmetry', 'nucleus_asymmetry', 'point_dispersion', 'nucleus_dispersion', 'ripley_stats', 'nucleus_enrichment'])
[ ]:
bento.tl.analyze_samples(
    adata, ['cell_proximity', 'nucleus_proximity', 'point_dispersion'], chunksize=100
)

Note

Bento is able to utilize these feature spaces for predicting RNA localization patterns. For unsupervised analysis, Bento implements tensor decomposition to generate interpretable low dimensional signatures.