[go: nahoru, domu]

Skip to content

Commit

Permalink
Merge branch 'main' into dbit
Browse files Browse the repository at this point in the history
  • Loading branch information
lillux committed Feb 8, 2024
2 parents 90ba226 + 51202b6 commit b9ddfb0
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning][].

- (MCMICRO) support for TMAs (such as the data of exemplar-002)
- (Xenium) support for post-xenium aligned images (IF, HE)
- (Xenium) reader for the selection coordinates file from the Xenium Explorer
- DBiT-seq reader

### Fixed
Expand Down
12 changes: 12 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

I/O for the `spatialdata` project.

### Readers

```{eval-rst}
.. autosummary::
:toctree: generated
Expand All @@ -22,3 +24,13 @@ I/O for the `spatialdata` project.
mcmicro
dbit
```

### Utility functions

```{eval-rst}
.. autosummary::
:toctree: generated
xenium_aligned_image
xenium_explorer_selection
```
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"geopandas": ("https://geopandas.org/en/stable/", None),
"xarray": ("https://docs.xarray.dev/en/stable/", None),
"datatree": ("https://datatree.readthedocs.io/en/latest/", None),
"shapely": ("https://shapely.readthedocs.io/en/stable/", None),
}

# List of patterns, relative to source directory, that match files and
Expand Down
20 changes: 18 additions & 2 deletions src/spatialdata_io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,24 @@
from spatialdata_io.readers.merscope import merscope
from spatialdata_io.readers.steinbock import steinbock
from spatialdata_io.readers.visium import visium
from spatialdata_io.readers.xenium import xenium
from spatialdata_io.readers.xenium import (
xenium,
xenium_aligned_image,
xenium_explorer_selection,
)

__all__ = ["curio", "visium", "xenium", "codex", "cosmx", "mcmicro", "steinbock", "merscope", "dbit"]
__all__ = [
"curio",
"visium",
"xenium",
"codex",
"cosmx",
"mcmicro",
"steinbock",
"merscope",
"xenium_aligned_image",
"xenium_explorer_selection",
"dbit"
]

__version__ = version("spatialdata-io")
26 changes: 25 additions & 1 deletion src/spatialdata_io/readers/xenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from spatialdata_io._utils import deprecation_alias
from spatialdata_io.readers._utils._read_10x_h5 import _read_10x_h5

__all__ = ["xenium"]
__all__ = ["xenium", "xenium_aligned_image", "xenium_explorer_selection"]


@deprecation_alias(cells_as_shapes="cells_as_circles")
Expand Down Expand Up @@ -325,3 +325,27 @@ def xenium_aligned_image(
transformations={"global": transformation},
**image_models_kwargs,
)


def xenium_explorer_selection(path: str | Path, pixel_size: float = 0.2125) -> Polygon:
"""Read the coordinates of a selection `.csv` file exported from the `Xenium Explorer <https://www.10xgenomics.com/support/software/xenium-explorer/latest>`_.
This file can be generated by the "Freehand Selection" or the "Rectangular Selection".
The output `Polygon` can be used for a polygon query on the pixel coordinate
system (by default, this is the `"global"` coordinate system for Xenium data).
If `spatialdata_xenium_explorer <https://github.com/quentinblampey/spatialdata_xenium_explorer>`_ was used,
the `pixel_size` argument must be set to the one used during conversion with `spatialdata_xenium_explorer`.
Parameters
----------
path
Path to the `.csv` file containing the selection coordinates
pixel_size
Size of a pixel in microns. By default, the Xenium pixel size is used.
Returns
-------
:class:`shapely.geometry.polygon.Polygon`
"""
df = pd.read_csv(path, skiprows=2)
return Polygon(df.values / pixel_size)

0 comments on commit b9ddfb0

Please sign in to comment.