Skip to content

Coerce SPE to SFE #8

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
42 changes: 20 additions & 22 deletions src/spatialfeatureexperiment/sfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,18 +451,18 @@ def get_unit(self) -> str:
"""Get the coordinate unit."""
return self._unit

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

Args:
unit:
New unit ('full_res_image_pixel' or 'micron').

in_place:
Whether to modify the ``ProxySpatialFeatureExperiment`` in place. Defaults to False.
Whether to modify the ``SpatialFeatureExperiment`` in place. Defaults to False.

Returns:
A modified ``ProxySpatialFeatureExperiment`` object, either as a copy of the original or as a reference to the (in-place-modified) original.
A modified ``SpatialFeatureExperiment`` object, either as a copy of the original or as a reference to the (in-place-modified) original.
"""
if unit not in ("full_res_image_pixel", "micron"):
raise ValueError("unit must be 'full_res_image_pixel' or 'micron'")
Expand Down Expand Up @@ -503,18 +503,18 @@ def get_annot_geometries(self) -> Dict[str, gpd.GeoDataFrame]:

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

Args:
geometries:
New column geometries.

in_place:
Whether to modify the ``ProxySpatialFeatureExperiment`` in place. Defaults to False.
Whether to modify the ``SpatialFeatureExperiment`` in place. Defaults to False.

Returns:
A modified ``ProxySpatialFeatureExperiment`` object, either as a copy of the original or as a reference to the (in-place-modified) original.
A modified ``SpatialFeatureExperiment`` object, either as a copy of the original or as a reference to the (in-place-modified) original.
"""
_geoms = _sanitize_geomertries(geometries=geometries)
_validate_geometries(_geoms, "col_geometries")
Expand All @@ -525,18 +525,18 @@ def set_col_geometries(

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

Args:
geometries:
New row geometries.

in_place:
Whether to modify the ``ProxySpatialFeatureExperiment`` in place. Defaults to False.
Whether to modify the ``SpatialFeatureExperiment`` in place. Defaults to False.

Returns:
A modified ``ProxySpatialFeatureExperiment`` object, either as a copy of the original or as a reference to the (in-place-modified) original.
A modified ``SpatialFeatureExperiment`` object, either as a copy of the original or as a reference to the (in-place-modified) original.
"""
_geoms = _sanitize_geomertries(geometries=geometries)
_validate_geometries(_geoms, "row_geometries")
Expand All @@ -547,18 +547,18 @@ def set_row_geometries(

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

Args:
geometries:
New annotation geometries.

in_place:
Whether to modify the ``ProxySpatialFeatureExperiment`` in place. Defaults to False.
Whether to modify the ``SpatialFeatureExperiment`` in place. Defaults to False.

Returns:
A modified ``ProxySpatialFeatureExperiment`` object, either as a copy of the original or as a reference to the (in-place-modified) original.
A modified ``SpatialFeatureExperiment`` object, either as a copy of the original or as a reference to the (in-place-modified) original.
"""
_geoms = _sanitize_geomertries(geometries=geometries)

Expand Down Expand Up @@ -619,20 +619,18 @@ 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
) -> "ProxySpatialFeatureExperiment":
def set_spatial_graphs(self, graphs: Optional[BiocFrame], in_place: bool = False) -> "SpatialFeatureExperiment":
"""Set spatial neighborhood graphs.

Args:
graphs:
New spatial graphs as `BiocFrame`.

in_place:
Whether to modify the ``ProxySpatialFeatureExperiment`` in place. Defaults to False.
Whether to modify the ``SpatialFeatureExperiment`` in place. Defaults to False.

Returns:
A modified ``ProxySpatialFeatureExperiment`` object, either as a copy of the original or as a reference to the (in-place-modified) original.
A modified ``SpatialFeatureExperiment`` object, either as a copy of the original or as a reference to the (in-place-modified) original.
"""
_graphs = _sanitize_spatial_graphs(graphs, list(set(self.get_column_data().get_column("sample_id"))))
_validate_graph_structure(_graphs)
Expand Down Expand Up @@ -664,7 +662,7 @@ def get_slice(
self,
rows: Optional[Union[str, int, bool, List]] = None,
columns: Optional[Union[str, int, bool, List]] = None,
) -> "ProxySpatialFeatureExperiment":
) -> "SpatialFeatureExperiment":
"""Get a slice of the experiment.

Args:
Expand All @@ -675,7 +673,7 @@ def get_slice(
Column indices/names to select.

Returns:
Sliced ProxySpatialFeatureExperiment.
Sliced SpatialFeatureExperiment.
"""
sfe = super().get_slice(rows=rows, columns=columns)

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

Args:
Expand All @@ -769,10 +767,10 @@ def set_column_data(
new object. Defaults to False.

in_place:
Whether to modify the ``ProxySpatialFeatureExperiment`` in place. Defaults to False.
Whether to modify the ``SpatialFeatureExperiment`` in place. Defaults to False.

Returns:
A modified ``ProxySpatialFeatureExperiment`` object, either as a copy of the original or as a reference to the (in-place-modified) original.
A modified ``SpatialFeatureExperiment`` object, either as a copy of the original or as a reference to the (in-place-modified) original.
"""
cols = _sanitize_frame(cols, num_rows=self.shape[1])
if "sample_id" not in cols.columns:
Expand Down