Metadata-Version: 2.5
Name: spatialexperiment
Version: 0.2.0
Summary: Container class for storing data from spatial-omics experiments
Project-URL: Homepage, https://github.com/BiocPy/spatialexperiment
Project-URL: Documentation, https://biocpy.github.io/spatialexperiment/
Project-URL: Source, https://github.com/BiocPy/spatialexperiment
Project-URL: Bug Tracker, https://github.com/BiocPy/spatialexperiment/issues
Author-email: Jayaram Kancherla <jayaram.kancherla@gmail.com>
License: The MIT License (MIT)
        
        Copyright (c) 2025 keviny2
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: AUTHORS.md
License-File: LICENSE.txt
Keywords: bioconductor,bioinformatics,single-cell,singlecellexperiment,spatial-omics,spatial-transcriptomics
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Classifier: Typing :: Typed
Requires-Python: >=3.9
Requires-Dist: biocframe>=0.7.2
Requires-Dist: biocutils>=0.3.3
Requires-Dist: pillow>=11.0
Requires-Dist: rasterio
Requires-Dist: requests
Requires-Dist: scipy~=1.13
Requires-Dist: singlecellexperiment>=0.6.0
Provides-Extra: optional
Requires-Dist: anndata; extra == 'optional'
Requires-Dist: delayedarray; extra == 'optional'
Requires-Dist: pandas; extra == 'optional'
Provides-Extra: testing
Requires-Dist: anndata; extra == 'testing'
Requires-Dist: delayedarray; extra == 'testing'
Requires-Dist: pandas; extra == 'testing'
Requires-Dist: pytest; extra == 'testing'
Requires-Dist: pytest-cov; extra == 'testing'
Description-Content-Type: text/markdown

[![PyPI-Server](https://img.shields.io/pypi/v/SpatialExperiment.svg)](https://pypi.org/project/SpatialExperiment/)
![Unit tests](https://github.com/BiocPy/SpatialExperiment/actions/workflows/run-tests.yml/badge.svg)

# SpatialExperiment

A Python package for storing and analyzing spatial-omics experimental data. `SpatialExperiment` extends [SingleCellExperiment](https://github.com/biocpy/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](https://pypi.org/project/SpatialExperiment/)

```bash
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:

```python
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](https://biocpy.github.io/SingleCellExperiment/).


<!-- biocsetup-notes -->

## Note

This project has been set up using [BiocSetup](https://github.com/biocpy/biocsetup)
and [PyScaffold](https://pyscaffold.org/).
