[go: nahoru, domu]

Skip to content

Commit

Permalink
add lasso reader
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinblampey committed Feb 7, 2024
1 parent d17b438 commit 56a9cb6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 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

### Fixed

Expand Down
2 changes: 2 additions & 0 deletions src/spatialdata_io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from importlib.metadata import version

from spatialdata_io.readers._utils._utils import xenium_explorer_selection
from spatialdata_io.readers.codex import codex
from spatialdata_io.readers.cosmx import cosmx
from spatialdata_io.readers.curio import curio
Expand All @@ -18,6 +19,7 @@
"mcmicro",
"steinbock",
"merscope",
"xenium_explorer_selection",
]

__version__ = version("spatialdata-io")
23 changes: 23 additions & 0 deletions src/spatialdata_io/readers/_utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
from typing import Any, Optional, Union

import numpy as np
import pandas as pd
from anndata import AnnData, read_text
from h5py import File
from shapely.geometry import Polygon

from spatialdata_io.readers._utils._read_10x_h5 import _read_10x_h5

Expand Down Expand Up @@ -66,3 +68,24 @@ def _read_counts(

adata.uns["spatial"] = {library_id: {"metadata": {}}} # can overwrite
return adata, library_id


def xenium_explorer_selection(path: str | Path, pixelsize: float = 0.2125) -> Polygon:
"""
Read the coordinates of a selection file exported from the Xenium Explorer.
This `.csv` file can be generated by the "Freehand Selection" as well
as the "Rectangular Selection".
The output `Polygon` can be used for a polygon query on the pixel coordinate
system (called `"global"` for Xenium data).
Parameters
----------
path
Path to the `.csv` file containing the selection coordinates
pixelsize
Size of a pixel in microns. By default, the Xenium pixel size is used.
Returns
-------
:class:`shapely.geometry.Polygon`
"""
df = pd.read_csv(path, skiprows=2)
return Polygon(df.values / pixelsize)

0 comments on commit 56a9cb6

Please sign in to comment.