Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
test:
strategy:
matrix:
python: ["3.9", "3.10", "3.11", "3.12"] # , "3.13"
python: ["3.10", "3.11", "3.12", "3.13"]
platform:
- ubuntu-latest
# - macos-latest
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Version 0.1.0

- Migrating changes related to SPE and SCE.

## Version 0.0.4-0.0.5

- Implement `to_anndata()` to convert from spatial feature experiment to AnnData
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ python_requires = >=3.9
# For more information, check out https://semver.org/.
install_requires =
importlib-metadata; python_version<"3.8"
spatialexperiment>=0.0.12
spatialexperiment>=0.1.0
pillow
geopandas
shapely
Expand Down
34 changes: 19 additions & 15 deletions src/spatialfeatureexperiment/sfe.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from typing import Any, Dict, List, Optional, Union, Tuple
from __future__ import annotations

from typing import Any, Dict, List, Optional, Tuple, Union
from warnings import warn

import biocutils as ut
import geopandas as gpd
import numpy as np
from biocframe import BiocFrame
from libpysal.graph import Graph
from spatialexperiment import SpatialExperiment
from spatialexperiment._validators import _validate_column_data, _validate_sample_ids
from libpysal.graph import Graph
from summarizedexperiment._frameutils import _sanitize_frame
from summarizedexperiment.RangedSummarizedExperiment import GRangesOrGRangesList

Expand Down Expand Up @@ -105,7 +107,7 @@ def __init__(
column_data: Optional[BiocFrame] = None,
row_names: Optional[List[str]] = None,
column_names: Optional[List[str]] = None,
metadata: Optional[dict] = None,
metadata: Optional[Union[Dict[str, Any], ut.NamedList]] = None,
reduced_dims: Optional[Dict[str, Any]] = None,
main_experiment_name: Optional[str] = None,
alternative_experiments: Optional[Dict[str, Any]] = None,
Expand All @@ -120,7 +122,7 @@ def __init__(
annot_geometries: Optional[Dict[str, gpd.GeoDataFrame]] = None,
spatial_graphs: Optional[Dict[str, Union[Graph, Any]]] = None,
unit: str = "full_res_image_pixel",
validate: bool = True,
_validate: bool = True,
**kwargs,
) -> None:
"""Initialize a spatial feature class.
Expand Down Expand Up @@ -253,7 +255,7 @@ def __init__(
unit:
Unit for spatial coordinates ('full_res_image_pixel' or 'micron').

validate:
_validate:
Internal use only.
"""
# Initialize parent class
Expand All @@ -273,7 +275,7 @@ def __init__(
alternative_experiment_check_dim_names=alternative_experiment_check_dim_names,
img_data=img_data,
spatial_coords=spatial_coords,
validate=validate,
_validate=_validate,
**kwargs,
)

Expand All @@ -286,7 +288,7 @@ def __init__(
)
self._unit = unit

if validate:
if _validate:
self._validate()

def _validate(self) -> None:
Expand Down Expand Up @@ -356,6 +358,7 @@ def __deepcopy__(self, memo=None, _nil=[]):
annot_geometries=_annot_geometries_copy,
spatial_graphs=_spatial_graphs_copy,
unit=_unit_copy,
_validate=False,
)

def __copy__(self):
Expand Down Expand Up @@ -384,6 +387,7 @@ def __copy__(self):
annot_geometries=self._annot_geometries,
spatial_graphs=self._spatial_graphs,
unit=self._unit,
_validate=False,
)

def copy(self):
Expand Down Expand Up @@ -447,7 +451,7 @@ def get_unit(self) -> str:
"""Get the coordinate unit."""
return self._unit

def set_unit(self, unit: str, in_place: bool = False) -> "SpatialFeatureExperiment":
def set_unit(self, unit: str, in_place: bool = False) -> SpatialFeatureExperiment:
"""Set the coordinate unit.

Args:
Expand Down Expand Up @@ -499,7 +503,7 @@ def get_annot_geometries(self) -> Dict[str, gpd.GeoDataFrame]:

def set_col_geometries(
self, geometries: Dict[str, gpd.GeoDataFrame], in_place: bool = False
) -> "SpatialFeatureExperiment":
) -> SpatialFeatureExperiment:
"""Set column geometries.

Args:
Expand All @@ -521,7 +525,7 @@ def set_col_geometries(

def set_row_geometries(
self, geometries: Dict[str, gpd.GeoDataFrame], in_place: bool = False
) -> "SpatialFeatureExperiment":
) -> SpatialFeatureExperiment:
"""Set row geometries.

Args:
Expand All @@ -543,7 +547,7 @@ def set_row_geometries(

def set_annot_geometries(
self, geometries: Dict[str, gpd.GeoDataFrame], in_place: bool = False
) -> "SpatialFeatureExperiment":
) -> SpatialFeatureExperiment:
"""Set annotation geometries.

Args:
Expand Down Expand Up @@ -615,7 +619,7 @@ def get_spatial_graphs(self) -> Optional[BiocFrame]:
"""Get spatial neighborhood graphs."""
return self._spatial_graphs

def set_spatial_graphs(self, graphs: Optional[BiocFrame], in_place: bool = False) -> "SpatialFeatureExperiment":
def set_spatial_graphs(self, graphs: Optional[BiocFrame], in_place: bool = False) -> SpatialFeatureExperiment:
"""Set spatial neighborhood graphs.

Args:
Expand Down Expand Up @@ -658,7 +662,7 @@ def get_slice(
self,
rows: Optional[Union[str, int, bool, List]] = None,
columns: Optional[Union[str, int, bool, List]] = None,
) -> "SpatialFeatureExperiment":
) -> SpatialFeatureExperiment:
"""Get a slice of the experiment.

Args:
Expand Down Expand Up @@ -746,7 +750,7 @@ def set_column_data(
cols: Optional[BiocFrame],
replace_column_names: bool = False,
in_place: bool = False,
) -> "SpatialFeatureExperiment":
) -> SpatialFeatureExperiment:
"""Override: Set sample data.

Args:
Expand Down Expand Up @@ -837,7 +841,7 @@ def from_spatial_experiment(
spatial_graphs: BiocFrame = None,
spot_diameter: float = None,
unit: str = None,
) -> "SpatialFeatureExperiment":
) -> SpatialFeatureExperiment:
"""Coerce a :py:class:~`spatialexperiment.SpatialExperiment` to a `SpatialFeatureExperiment`.

Args:
Expand Down
Loading