Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d42e8aa
EOD: progress on SpatialExperiment and SpatialImage
keviny2 Jan 16, 2025
abedc5b
EOD: Add suggestions by Jay - made some progress
keviny2 Jan 17, 2025
46db013
Write getters and setters for spatial_coords
keviny2 Jan 21, 2025
8d07afa
Write getters and setters for img_data
keviny2 Jan 21, 2025
aeaf63f
Implement get_img() and add_img()
keviny2 Jan 21, 2025
8b1e2c2
Coerce frames to BiocFrame
keviny2 Jan 21, 2025
7b2cc80
Add SpatialExperiment variables to copy
keviny2 Jan 21, 2025
34f1cc5
Add unifnished printing section
keviny2 Jan 21, 2025
1fa867e
Reduce complexity of constructor
keviny2 Jan 21, 2025
c5c308a
Remove type hints in docstrings
keviny2 Jan 21, 2025
721089e
Remove sample_id from constructor
keviny2 Jan 21, 2025
a35ae28
Implement getters and setters for spatial coordinates names
keviny2 Jan 22, 2025
6780ce2
Validate img_data and spatial_coords in constructor
keviny2 Jan 23, 2025
0891311
Add validation for one-to-one mapping between sample_ids in column_da…
keviny2 Jan 23, 2025
ecbd3ce
Override column_data setter
keviny2 Jan 23, 2025
ae55ff0
Make getters and setters consistent
keviny2 Jan 23, 2025
1fb5d79
Write first test
keviny2 Jan 23, 2025
c7df689
Implement get_slice()
keviny2 Jan 24, 2025
38e8159
Set default 'sample_id' to 'sample01'
keviny2 Jan 24, 2025
85e4b30
Set modified column_data in constructor
keviny2 Jan 24, 2025
ae6d4b3
Remove arguments that start with '_'
keviny2 Jan 24, 2025
18c17b7
Specify min version of packages
keviny2 Jan 24, 2025
2466305
Document the relationship between the 'sample_id' column in 'column_d…
keviny2 Jan 24, 2025
2768447
Make sure all calls to _sanitize_frame have num_rows specified
keviny2 Jan 24, 2025
e35c124
Ensure override method maintains the same definition as the parent
keviny2 Jan 24, 2025
6def483
Support in_place addition of images
keviny2 Jan 24, 2025
7c20760
Add spatial props to __repr__
keviny2 Jan 25, 2025
8e4d5cc
Refactor logic for filtering img_data by sample_id and image_id
keviny2 Jan 25, 2025
8cc1909
Implement get_scale_factors()
keviny2 Jan 25, 2025
82f2c38
Document behavior regarding 'img_data' and 'column_data'
keviny2 Jan 26, 2025
57b39a1
Implement printing
keviny2 Jan 26, 2025
b6af9a1
Document constraints on sample_id between column_data and img_data
keviny2 Jan 27, 2025
a9abc90
Write tests
keviny2 Jan 28, 2025
4f0d068
Run tests on github
keviny2 Jan 28, 2025
d92f8fb
Change True to bool in type hints
keviny2 Jan 28, 2025
91e0352
some minor improvements
jkanche Jan 28, 2025
cbb759d
add a callout
jkanche Jan 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Run tests

on:
push:
branches: [master]
branches: [main]
pull_request:
branches: [master]
branches: [main]

jobs:
build:
Expand Down
90 changes: 85 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,103 @@
[![PyPI-Server](https://img.shields.io/pypi/v/SpatialExperiment.svg)](https://pypi.org/project/SpatialExperiment/)
![Unit tests](https://github.com/BiocPy/SpatialExperiment/actions/workflows/pypi-test.yml/badge.svg)
![Unit tests](https://github.com/BiocPy/SpatialExperiment/actions/workflows/run-tests.yml/badge.svg)

# SpatialExperiment

> Container class for sotring data from spatial -omics experiments
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.

A longer description of your project goes here...
> [!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
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, SpatialImage
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": [
SpatialImage("tests/images/sample_image1.jpg"),
SpatialImage("tests/images/sample_image2.png"),
SpatialImage("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/).
and [PyScaffold](https://pyscaffold.org/).
5 changes: 5 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@
"scipy": ("https://docs.scipy.org/doc/scipy/reference", None),
"setuptools": ("https://setuptools.pypa.io/en/stable/", None),
"pyscaffold": ("https://pyscaffold.org/en/stable", None),
"biocframe": ("https://biocpy.github.io/BiocFrame", None),
"genomicranges": ("https://biocpy.github.io/GenomicRanges", None),
"summarizedexperiment": ("https://biocpy.github.io/SummarizedExperiment", None),
"biocutils": ("https://biocpy.github.io/BiocUtils", None),
"singlecellexperiment": ("https://biocpy.github.io/SingleCellExperiment", None),
}

print(f"loading configurations for {project} {version} ...", file=sys.stderr)
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ version_scheme = "no-guess-dev"
line-length = 120
src = ["src"]
exclude = ["tests"]
extend-ignore = ["F821"]
lint.extend-ignore = ["F821"]

[tool.ruff.pydocstyle]
[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.format]
docstring-code-format = true
docstring-code-line-length = 20

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["E402", "F401"]
6 changes: 6 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ package_dir =
# For more information, check out https://semver.org/.
install_requires =
importlib-metadata; python_version<"3.8"
pandas>=2.0
biocframe>=0.6
biocutils>=0.2
summarizedexperiment>=0.5
singlecellexperiment>=0.5.6
pillow>=11.0


[options.packages.find]
Expand Down
Loading
Loading