Container class for storing data from spatial-omics experiments
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spatialexperiment-0.0.7.tar.gz.
File metadata
- Download URL: spatialexperiment-0.0.7.tar.gz
- Upload date:
- Size: 3.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4bdfad9f379ae0d37c042f913b204ad8250c2b6d0a9f5dcf7055b99342e0fe9d
|
|
| MD5 |
003c23eea5763fab5a6889793a1c4081
|
|
| BLAKE2b-256 |
8de1265767e71e99b5d0db564630940e4836dda167dbdf6e9130df010da3a7d9
|
Provenance
The following attestation bundles were made for spatialexperiment-0.0.7.tar.gz:
Publisher:
publish-pypi.yml on BiocPy/SpatialExperiment
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spatialexperiment-0.0.7.tar.gz -
Subject digest:
4bdfad9f379ae0d37c042f913b204ad8250c2b6d0a9f5dcf7055b99342e0fe9d - Sigstore transparency entry: 192496883
- Sigstore integration time:
-
Permalink:
BiocPy/SpatialExperiment@d9fb07960da55a48ade13560d4fdfc2ea3f3c574 -
Branch / Tag:
refs/tags/0.0.7 - Owner: https://github.com/BiocPy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@d9fb07960da55a48ade13560d4fdfc2ea3f3c574 -
Trigger Event:
push
-
Statement type:
File details
Details for the file spatialexperiment-0.0.7-py3-none-any.whl.
File metadata
- Download URL: spatialexperiment-0.0.7-py3-none-any.whl
- Upload date:
- Size: 24.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8033c93e5cc8e6b3807b6619f270c83bcdfe08bff561fcb3a811306549d391b0
|
|
| MD5 |
2c533fddd50924f7552beac452e5d8ab
|
|
| BLAKE2b-256 |
682872dbf02f050a1a77bcbbfb641f78a48de32f99ca28fc458e707ef5fed293
|
Provenance
The following attestation bundles were made for spatialexperiment-0.0.7-py3-none-any.whl:
Publisher:
publish-pypi.yml on BiocPy/SpatialExperiment
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spatialexperiment-0.0.7-py3-none-any.whl -
Subject digest:
8033c93e5cc8e6b3807b6619f270c83bcdfe08bff561fcb3a811306549d391b0 - Sigstore transparency entry: 192496887
- Sigstore integration time:
-
Permalink:
BiocPy/SpatialExperiment@d9fb07960da55a48ade13560d4fdfc2ea3f3c574 -
Branch / Tag:
refs/tags/0.0.7 - Owner: https://github.com/BiocPy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@d9fb07960da55a48ade13560d4fdfc2ea3f3c574 -
Trigger Event:
push
-
Statement type: