Skip to main content

Container class for storing data from spatial-omics experiments

Project description

PyPI-Server Unit tests

SpatialExperiment

A Python package for storing and analyzing spatial-omics experimental data. SpatialExperiment extends SingleCellExperiment with dedicated slots for image data and spatial coordinates, making it ideal for spatial transcriptomics and other spatially-resolved omics data.

[!NOTE]

This package is in active development.

Install

To get started, install the package from PyPI

pip install spatialexperiment

Usage

The SpatialExperiment class extends SingleCellExperiment with the following key attributes:

  • spatial_coords: A BioFrame containing spot/cell spatial coordinates relative to the image, typically including:

    • x-coordinates
    • y-coordinates
    • Additional spatial metadata
  • img_data: A BiocFrame containing image-related information:

    • sample_ids: Unique identifiers for each sample
    • image_ids: Unique identifiers for each image
    • data: The actual image data
    • scale_factor: Scaling factors for proper image interpretation
  • column_data: Contains sample_id mappings that link spots to their corresponding images

Quick Start

Here's how to create a SpatialExperiment object from scratch:

from spatialexperiment import SpatialExperiment, construct_spatial_image_class
import numpy as np
from biocframe import BiocFrame

# Create example data
nrows = 200  # Number of features (e.g., genes)
ncols = 500  # Number of spots/cells

# Generate random count data
counts = np.random.rand(nrows, ncols)

# Create feature annotations
row_data = BiocFrame({
    "gene_ids": [f"gene_{i}" for i in range(nrows)],
    "gene_names": [f"Gene_{i}" for i in range(nrows)]
})

# Create spot/cell annotations
col_data = BiocFrame({
    "n_genes": [50, 200] * int(ncols / 2),
    "condition": ["healthy", "tumor"] * int(ncols / 2),
    "cell_id": [f"spot_{i}" for i in range(ncols)],
    "sample_id": ["sample_1"] * int(ncols / 2) + ["sample_2"] * int(ncols / 2),
})

# Generate spatial coordinates
spatial_coords = BiocFrame({
    "x": np.random.uniform(low=0.0, high=100.0, size=ncols),
    "y": np.random.uniform(low=0.0, high=100.0, size=ncols)
})

# Create image data
img_data = BiocFrame({
    "sample_id": ["sample_1", "sample_1", "sample_2"],
    "image_id": ["aurora", "dice", "desert"],
    "data": [
        construct_spatial_image_class("tests/images/sample_image1.jpg"),
        construct_spatial_image_class("tests/images/sample_image2.png"),
        construct_spatial_image_class("tests/images/sample_image3.jpg"),
    ],
    "scale_factor": [1, 1, 1],
})

# Create SpatialExperiment object
spe = SpatialExperiment(
    assays={"counts": counts},
    row_data=row_data,
    column_data=col_data,
    spatial_coords=spatial_coords,
    img_data=img_data,
)

For more detailed information about available methods and functionality, please refer to the SingleCellExperiment documentation.

Note

This project has been set up using BiocSetup and PyScaffold.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spatialexperiment-0.0.3.tar.gz (2.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

SpatialExperiment-0.0.3-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file spatialexperiment-0.0.3.tar.gz.

File metadata

  • Download URL: spatialexperiment-0.0.3.tar.gz
  • Upload date:
  • Size: 2.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for spatialexperiment-0.0.3.tar.gz
Algorithm Hash digest
SHA256 a03cce86a1e1f769dbff686aa130540d156d1049ab694ca74480e579e4d9c8c5
MD5 176a56051f8ae26626cdea9cf5b2bed6
BLAKE2b-256 ca7ce92a1cf2974253d4b2b817f63fb66389d0a4a3ed7a4c98761b16ced54fe3

See more details on using hashes here.

Provenance

The following attestation bundles were made for spatialexperiment-0.0.3.tar.gz:

Publisher: publish-pypi.yml on BiocPy/SpatialExperiment

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file SpatialExperiment-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for SpatialExperiment-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 40ef34d0c4162a1d8e0064abd50be2f1d5fea85bf8f08b1eef2d0d6d68aa1cd4
MD5 f164662d52d9b3abc89a3d67865b573e
BLAKE2b-256 1ea04bfdf6eb51bebed484a6269aaf9e1f4397144c81228900e265907b6022e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for SpatialExperiment-0.0.3-py3-none-any.whl:

Publisher: publish-pypi.yml on BiocPy/SpatialExperiment

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page