Learn how to install the TileDB-SOMA API to start working with SOMA experiments containing single-cell data.
How to run this tutorial
We recommend running this tutorial, as well as the other various tutorials in the Tutorials section, inside TileDB Cloud. This will allow you to quickly experiment avoiding all the installation and deployment hassles. Sign up for the free tier, spin up a TileDB Cloud notebook with a Python or R kernel, and follow the tutorial instructions.
This tutorial will cover basic access of a public single-cell dataset (available on the TileDB Cloud Marketplace) with TileDB-SOMA in Python and R, as well as the integrations with AnnData and Seurat.
You will use an example dataset generated by the Tabula Sapiens consortium, which contains nearly 265,000 immune cells. The original H5AD data file was downloaded from Figshare and converted to a SOMA experiment, which is available on TileDB Cloud.
Data from a single-cell study stored in TileDB-SOMA is called a SOMA experiment. Each SOMA experiment contains various data elements, including the assay measurements, annotations, and derived results, all organized into a well-defined on-disk format.
To access a SOMA experiment, you need to know its URI, which points to its physical location locally, a remote object store (e.g., Amazon S3), or TileDB Cloud. This example uses a SOMA experiment located on S3 that has been registered on TileDB Cloud.
tiledbsoma.__version__ 1.11.3
TileDB-Py version 0.29.0
TileDB core version (tiledb) 2.23.0
TileDB core version (libtiledbsoma) 2.23.0
python version 3.11.9.final.0
OS version Linux 6.8.0-1009-aws
Each data component within a SOMA experiment is stored hierarchically, with the top-level collection containing obs, a TileDB array containing observation-level metadata, and ms, a sub-collection containing one or more SOMA measurements.
Tip
Learn more about the SOMA data model in the Foundation section.
Any of these elements can be accessed directly, such as obs as shown below.
Visit the Data Access tutorial to learn about performing iterated reads, applying filters, sub-selecting columns, and in-memory formats for further analysis.
You can select and extract data from a SOMA experiment by performing an axis query to filter the data based on observation or variable metadata. For example, you can filter the experiment to retrieve only data for macrophage cells and genes with highly variable expression levels:
Similar to the experiment object, the query object allows access to any data component within a SOMA experiment. However, unlike the experiment, a query loads into memory only the data matching the filtering criteria specified in the axis_query(). This makes it possible to access and analyze specific slices of data from a larger dataset.
Additionally, the query object provides methods to read multiple components of the experiment into memory as objects compatible with popular single-cell analysis toolkits.
This will create an AnnData object containing the filtered expression data, cell metadata, and feature metadata. Any derived results (e.g., embeddings) can also be loaded into the AnnData object.
Remember to always close the query object when you are done with it.
query.close()
This will create a Seurat object containing the filtered expression data, cell metadata, and feature metadata. Any derived results (e.g., embeddings) can also be included in the Seurat object. Here, the obsm_layers arg is used to include the UMAP embeddings.
An object of class Seurat
2435 features across 12514 samples within 1 assay
Active assay: RNA (2435 features, 0 variable features)
1 layer present: data
1 dimensional reduction calculated: umap
Finally, the SOMA experiment class acts as a context manager, which needs to be closed to release the underlying resources.
Congratulations! You have successfully installed the TileDB-SOMA API and used it to access and query a single-cell dataset stored as a SOMA experiment.
Next steps
Learn more about the TileDB-SOMA data model and APIs in the Foundation section.
Explore the Tutorials to dive deeper into the TileDB-SOMA APIs.