1. Structure
  2. Life Sciences
  3. Single-cell
  4. Spatial
  5. Tutorials
  6. Spatial Data Ingestion
  • Home
  • What is TileDB?
  • Get Started
  • Explore Content
  • Accounts
    • Individual Accounts
      • Apply for the Free Tier
      • Profile
        • Overview
        • Cloud Credentials
        • Storage Paths
        • REST API Tokens
        • Credits
    • Organization Admins
      • Create an Organization
      • Profile
        • Overview
        • Members
        • Cloud Credentials
        • Storage Paths
        • Billing
      • API Tokens
    • Organization Members
      • Organization Invitations
      • Profile
        • Overview
        • Members
        • Cloud Credentials
        • Storage Paths
        • Billing
      • API Tokens
  • Catalog
    • Introduction
    • Data
      • Arrays
      • Tables
      • Single-Cell (SOMA)
      • Genomics (VCF)
      • Biomedical Imaging
      • Vector Search
      • Files
    • Code
      • Notebooks
      • Dashboards
      • User-Defined Functions
      • Task Graphs
      • ML Models
    • Groups
    • Marketplace
    • Search
  • Collaborate
    • Introduction
    • Organizations
    • Access Control
      • Introduction
      • Share Assets
      • Asset Permissions
      • Public Assets
    • Logging
    • Marketplace
  • Analyze
    • Introduction
    • Slice Data
    • Multi-Region Redirection
    • Notebooks
      • Launch a Notebook
      • Usage
      • Widgets
      • Notebook Image Dependencies
    • Dashboards
      • Dashboards
      • Streamlit
    • Preview
    • User-Defined Functions
    • Task Graphs
    • Serverless SQL
    • Monitor
      • Task Log
      • Task Graph Log
  • Scale
    • Introduction
    • Task Graphs
    • API Usage
  • Structure
    • Why Structure Is Important
    • Arrays
      • Introduction
      • Quickstart
      • Foundation
        • Array Data Model
        • Key Concepts
          • Storage
            • Arrays
            • Dimensions
            • Attributes
            • Cells
            • Domain
            • Tiles
            • Data Layout
            • Compression
            • Encryption
            • Tile Filters
            • Array Schema
            • Schema Evolution
            • Fragments
            • Fragment Metadata
            • Commits
            • Indexing
            • Array Metadata
            • Datetimes
            • Groups
            • Object Stores
          • Compute
            • Writes
            • Deletions
            • Consolidation
            • Vacuuming
            • Time Traveling
            • Reads
            • Query Conditions
            • Aggregates
            • User-Defined Functions
            • Distributed Compute
            • Concurrency
            • Parallelism
        • Storage Format Spec
      • Tutorials
        • Basics
          • Basic Dense Array
          • Basic Sparse Array
          • Array Metadata
          • Compression
          • Encryption
          • Data Layout
          • Tile Filters
          • Datetimes
          • Multiple Attributes
          • Variable-Length Attributes
          • String Dimensions
          • Nullable Attributes
          • Multi-Range Reads
          • Query Conditions
          • Aggregates
          • Deletions
          • Catching Errors
          • Configuration
          • Basic S3 Example
          • Basic TileDB Cloud
          • fromDataFrame
          • Palmer Penguins
        • Advanced
          • Schema Evolution
          • Advanced Writes
            • Write at a Timestamp
            • Get Fragment Info
            • Consolidation
              • Fragments
              • Fragment List
              • Consolidation Plan
              • Commits
              • Fragment Metadata
              • Array Metadata
            • Vacuuming
              • Fragments
              • Commits
              • Fragment Metadata
              • Array Metadata
          • Advanced Reads
            • Get Fragment Info
            • Time Traveling
              • Introduction
              • Fragments
              • Array Metadata
              • Schema Evolution
          • Array Upgrade
          • Backends
            • Amazon S3
            • Azure Blob Storage
            • Google Cloud Storage
            • MinIO
            • Lustre
          • Virtual Filesystem
          • User-Defined Functions
          • Distributed Compute
          • Result Estimation
          • Incomplete Queries
        • Management
          • Array Schema
          • Groups
          • Object Management
        • Performance
          • Summary of Factors
          • Dense vs. Sparse
          • Dimensions vs. Attributes
          • Compression
          • Tiling and Data Layout
          • Tuning Writes
          • Tuning Reads
      • API Reference
    • Tables
      • Introduction
      • Quickstart
      • Foundation
        • Data Model
        • Key Concepts
          • Indexes
          • Columnar Storage
          • Compression
          • Data Manipulation
          • Optimize Tables
          • ACID
          • Serverless SQL
          • SQL Connectors
          • Dataframes
          • CSV Ingestion
      • Tutorials
        • Basics
          • Ingestion with SQL
          • CSV Ingestion
          • Basic S3 Example
          • Running Locally
        • Advanced
          • Scalable Ingestion
          • Scalable Queries
      • API Reference
    • AI & ML
      • Vector Search
        • Introduction
        • Quickstart
        • Foundation
          • Data Model
          • Key Concepts
            • Vector Search
            • Vector Databases
            • Algorithms
            • Distance Metrics
            • Updates
            • Deployment Methods
            • Architecture
            • Distributed Compute
          • Storage Format Spec
        • Tutorials
          • Basics
            • Ingestion & Querying
            • Updates
            • Deletions
            • Basic S3 Example
            • Running Locally
          • Advanced
            • Versioning
            • Time Traveling
            • Consolidation
            • Distributed Compute
            • RAG LLM
            • LLM Memory
            • File Search
            • Image Search
            • Protein Search
          • Performance
        • API Reference
      • ML Models
        • Introduction
        • Quickstart
        • Foundation
          • Basics
          • Storage
          • Cloud Execution
          • Why TileDB for Machine Learning
        • Tutorials
          • Ingestion
            • Data Ingestion
              • Dense Datasets
              • Sparse Datasets
            • ML Model Ingestion
          • Management
            • Array Schema
            • Machine Learning: Groups
            • Time Traveling
    • Life Sciences
      • Single-cell
        • Introduction
        • Quickstart
        • Foundation
          • Data Model
          • Key Concepts
            • Data Structures
            • Use of Apache Arrow
            • Join IDs
            • State Management
            • TileDB Cloud URIs
          • SOMA API Specification
        • Tutorials
          • Data Ingestion
          • Bulk Ingestion Tutorial
          • Data Access
          • Distributed Compute
          • Basic S3 Example
          • Multi-Experiment Queries
          • Appending Data to a SOMA Experiment
          • Add New Measurements
          • SQL Queries
          • Running Locally
          • Shapes in TileDB-SOMA
          • Drug Discovery App
        • Spatial
          • Introduction
          • Foundation
            • Spatial Data Model
            • Data Structures
          • Tutorials
            • Spatial Data Ingestion
            • Access Spatial Data
            • Manage Coordinate Spaces
        • API Reference
      • Population Genomics
        • Introduction
        • Quickstart
        • Foundation
          • Data Model
          • Key Concepts
            • The N+1 Problem
            • Architecture
            • Arrays
            • Ingestion
            • Reads
            • Variant Statistics
            • Annotations
            • User-Defined Functions
            • Tables and SQL
            • Distributed Compute
          • Storage Format Spec
        • Tutorials
          • Basics
            • Basic Ingestion
            • Basic Queries
            • Export to VCF
            • Add New Samples
            • Deleting Samples
            • Basic S3 Example
            • Basic TileDB Cloud
          • Advanced
            • Scalable Ingestion
            • Scalable Queries
            • Query Transforms
            • Handling Large Queries
            • Annotations
              • Finding Annotations
              • Embedded Annotations
              • External Annotations
              • Annotation VCFs
              • Ingesting Annotations
            • Variant Statistics
            • Tables and SQL
            • User-Defined Functions
            • Sample Metadata
            • Split VCF
          • Performance
        • API Reference
          • Command Line Interface
          • Python API
          • Cloud API
      • Biomedical Imaging
        • Introduction
        • Foundation
          • Data Model
          • Key Concepts
            • Arrays
            • Ingestion
            • Reads
            • User Defined Functions
          • Storage Format Spec
        • Quickstart
        • Tutorials
          • Basics
            • Ingestion
            • Read
              • OpenSlide
              • TileDB-Py
          • Advanced
            • Batched Ingestion
            • Chunked Ingestion
            • Machine Learning
              • PyTorch
            • Napari
    • Files
  • API Reference
  • Self-Hosting
    • Installation
    • Upgrades
    • Administrative Tasks
    • Image Customization
      • Customize User-Defined Function Images
      • AWS ECR Container Registry
      • Customize Jupyter Notebook Images
    • Single Sign-On
      • Configure Single Sign-On
      • OpenID Connect
      • Okta SCIM
      • Microsoft Entra
  • Glossary

On this page

  • Setup
  • Prerequisites
  • Dataset
  • Ingest
  • Clean-up
  1. Structure
  2. Life Sciences
  3. Single-cell
  4. Spatial
  5. Tutorials
  6. Spatial Data Ingestion

Spatial Data Ingestion

life sciences
single cell (soma)
spatial
tutorials
ingestion
Learn how to ingest 10X Visium Space Ranger data with TileDB-SOMA.

TileDB-SOMA’s support for spatial omics data includes the ability to convert output files from 10X’s Space Ranger pipeline to a SOMA Experiment.

Tip

Learn more about the process of converting datasets into TileDB-SOMA’s storage format in the data ingestion tutorial.

Setup

This tutorial relies on tiledbsoma and a few other packages.

  • Python
import os
import tempfile
from pathlib import Path

import tiledb.cloud
import tiledbsoma
import tiledbsoma.io.spatial
from scanpy.datasets._datasets import (
    _download_visium_dataset as download_visium_dataset,
)

tiledbsoma.show_package_versions()

Define a few variables to use throughout the tutorial. The DATASET_NAME and SPACERANGER_VERSION variables identify the 10X dataset to downloaded.

  • Python
# 10X Example dataset
EXPERIMENT_NAME = "CytAssist_FFPE_Mouse_Brain_Rep2"
SPACERANGER_VERSION = "2.0.0"

# SOMA experiment parameters
MEASUREMENT_NAME = "RNA"  # Dataset modality name
SCENE_NAME = "scene0"  # Name of scene where spatial data is stored

Prerequisites

While you can run this tutorial locally, note that this tutorial relies on remote resources to run correctly.

You must create a REST API token and create an environment variable named $TILEDB_REST_TOKEN set to the value of your generated token.

However, this is not necessary when running from inside a TileDB workspace where the API token is automatically generated and configured for you.

To proceed with this tutorial, you will need to update the following variables to correspond to your TileDB namespace and destination S3 bucket:

  • Python
tiledb_namespace = os.environ["TILEDB_ACCOUNT"]
s3_bucket = os.environ["S3_BUCKET"]

Dataset

The dataset you will use comes from the coronal section of a formalin-fixed, paraffin-embedded (FFPE) mouse brain, generated by 10X Genomics while using their Visium CytAssist Spatial Gene Expression platform. Space Ranger, 10X’s software for Visium data, processed the raw data. To view the data, visit 10X Genomics.

To create a spatial SOMA experiment you need to have a directory with Space Ranger output files from a 10X Visium experiment.

Download Space Ranger output files for the specified dataset by using the handy download_visium_dataset() function from scanpy.

  • Python
dataset_dir = download_visium_dataset(
    sample_id=EXPERIMENT_NAME,
    spaceranger_version=SPACERANGER_VERSION,
    base_dir=Path(tempfile.gettempdir()),
)

Take a look at the structure of the downloaded dataset.

  • Python
!tree {dataset_dir}

TileDB-SOMA will ingest the following information from the Space Ranger output files:

  • The filtered gene expression matrix,filtered_feature_bc_matrix.h5, stores the expression matrix where rows are genes and columns are barcodes corresponding to spatial spots.
  • The tissue positions list, tissue_positions_list.csv, stores the xy-coordinates and spot status (tissue or not).
  • The scale factors JSON, scalefactors_json.json, stores scale factors for aligning the image at different resolutions.
  • The tissue images tissue_lowres_image.png and tissue_hires_image.png.

Ingest

Construct the URI of where to create the new SOMA experiment.

  • Python
experiment_uri = f"tiledb://{tiledb_namespace}/{s3_bucket}/{EXPERIMENT_NAME}"
experiment_uri

You can use a local filepath or an S3 URI. In this case, use a TileDB URI, which will direct SOMA to create the experiment in the specified S3 bucket and register it in TileDB’s data catalog under the specified user namespace.

The ingestion function, from_visium(), requires the following parameters:

  • experiment_uri: URI (or local file path) for the new experiment.
  • input_path: Local path to the directory with the Space Ranger output files.
  • measurement_name: Name of the SOMA Measurement (in this case, it’s “RNA”).
  • scene_name: Name of the SOMA Scene collection that will store all the spatial data components.

The image_channel_first parameter controls the ordering of the dimensions of the tissue images. In the default setting, the image channel is the first dimension (that is, "CYX"), but setting image_channel_first=False will change the order to "YXC". Note that different image and machine learning libraries use different conventions for image dimension order. For example, matplotlib expects channel to be the last dimension, whereas pytorch expects the opposite order.

Calling the from_visium() function will create a new SOMA experiment at the specified URI, populated with the data from the Space Ranger output files.

  • Python
tiledbsoma.io.spatial.from_visium(
    experiment_uri=experiment_uri,
    input_path=dataset_dir,
    measurement_name=MEASUREMENT_NAME,
    scene_name=SCENE_NAME,
    image_channel_first=False,
)

Once the ingestion completes successfully, you can open the new SOMA experiment to explore the data.

  • Python
with tiledbsoma.Experiment.open(experiment_uri) as exp:
    print(exp)

Clean-up

Now that you have successfully ingested the Visium dataset into a SOMA experiment, you can clean it up by deleting it from S3 and deregistering it from your TileDB workspace.

  • Python
tiledb.cloud.asset.delete(experiment_uri, recursive=True)
Tutorials
Access Spatial Data