Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Visium ingestor and sample spatial notebook #3123

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1,517 changes: 1,517 additions & 0 deletions apis/python/notebooks/tutorial_spatial.ipynb

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion apis/python/src/tiledbsoma/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
)
from ._indexer import IntIndexer, tiledbsoma_build_index
from ._measurement import Measurement
from ._multiscale_image import MultiscaleImage
from ._multiscale_image import ImageProperties, MultiscaleImage
from ._point_cloud_dataframe import PointCloudDataFrame
from ._scene import Scene
from ._sparse_nd_array import SparseNDArray, SparseNDArrayRead
Expand Down Expand Up @@ -210,6 +210,7 @@
"get_SOMA_version",
"get_storage_engine",
"IntIndexer",
"ImageProperties",
"Measurement",
"MultiscaleImage",
"NotCreateableError",
Expand Down
2 changes: 1 addition & 1 deletion apis/python/src/tiledbsoma/_multiscale_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def level_count(self) -> int:
"""
return len(self._levels)

def level_properties(self, level: Union[int, str]) -> somacore.ImageProperties:
def level_properties(self, level: Union[int, str]) -> ImageProperties:
"""The properties of an image at the specified level.

Lifecycle:
Expand Down
9 changes: 9 additions & 0 deletions apis/python/src/tiledbsoma/experimental/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Experimental SOMA features

This module is for experimental features. Support for these features
may be dropped.
"""

from .ingest import VisiumPaths, from_visium

Check warning on line 7 in apis/python/src/tiledbsoma/experimental/__init__.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/experimental/__init__.py#L7

Added line #L7 was not covered by tests

__all__ = ["from_visium", "VisiumPaths"]

Check warning on line 9 in apis/python/src/tiledbsoma/experimental/__init__.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/experimental/__init__.py#L9

Added line #L9 was not covered by tests
56 changes: 56 additions & 0 deletions apis/python/src/tiledbsoma/experimental/_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright (c) 2024 The Chan Zuckerberg Initiative Foundation
# Copyright (c) 2024 TileDB, Inc
#
# Licensed under the MIT License.
from pathlib import Path
from typing import Tuple, Union

Check warning on line 6 in apis/python/src/tiledbsoma/experimental/_util.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/experimental/_util.py#L5-L6

Added lines #L5 - L6 were not covered by tests

import h5py

Check warning on line 8 in apis/python/src/tiledbsoma/experimental/_util.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/experimental/_util.py#L8

Added line #L8 was not covered by tests

from .._exception import SOMAError

Check warning on line 10 in apis/python/src/tiledbsoma/experimental/_util.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/experimental/_util.py#L10

Added line #L10 was not covered by tests


def _str_to_int(value: str) -> int:
if not value.isdigit():
raise ValueError("{value} is not an integer.")
return int(value)

Check warning on line 16 in apis/python/src/tiledbsoma/experimental/_util.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/experimental/_util.py#L13-L16

Added lines #L13 - L16 were not covered by tests


def _read_visium_software_version(

Check warning on line 19 in apis/python/src/tiledbsoma/experimental/_util.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/experimental/_util.py#L19

Added line #L19 was not covered by tests
gene_expression_path: Union[str, Path]
) -> Tuple[int, int, int]:
with h5py.File(gene_expression_path) as dataset:
try:
version = dataset.attrs["software_version"]
except KeyError as ke:
raise SOMAError(

Check warning on line 26 in apis/python/src/tiledbsoma/experimental/_util.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/experimental/_util.py#L22-L26

Added lines #L22 - L26 were not covered by tests
f"Unable to read software version from gene expression file "
f"{gene_expression_path}."
) from ke
if not isinstance(version, str):
raise SOMAError(

Check warning on line 31 in apis/python/src/tiledbsoma/experimental/_util.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/experimental/_util.py#L30-L31

Added lines #L30 - L31 were not covered by tests
f"Unexpected type {type(version)!r} for software version in gene "
f"expression file {gene_expression_path}. Expected a string."
)
version_prefix = "spaceranger-"
if not version.startswith(version_prefix):
raise SOMAError(

Check warning on line 37 in apis/python/src/tiledbsoma/experimental/_util.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/experimental/_util.py#L35-L37

Added lines #L35 - L37 were not covered by tests
f"Unexpected value {version} for software version in gene expresion "
f"file {gene_expression_path}."
)
version = version[len(version_prefix) :].split(".")
if len(version) not in {3, 4}:
raise SOMAError(

Check warning on line 43 in apis/python/src/tiledbsoma/experimental/_util.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/experimental/_util.py#L41-L43

Added lines #L41 - L43 were not covered by tests
f"Unexpected value {version} for software version in gene expresion "
f"file {gene_expression_path}."
)
try:
major = _str_to_int(version[0])
minor = _str_to_int(version[1])
patch = _str_to_int(version[2])
except ValueError:
raise SOMAError(

Check warning on line 52 in apis/python/src/tiledbsoma/experimental/_util.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/experimental/_util.py#L47-L52

Added lines #L47 - L52 were not covered by tests
f"Unexpected value {version} for software version in gene expresion "
f"file {gene_expression_path}."
)
return (major, minor, patch)

Check warning on line 56 in apis/python/src/tiledbsoma/experimental/_util.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/experimental/_util.py#L56

Added line #L56 was not covered by tests
Loading
Loading