Skip to content
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## Version 0.0.4
## Version 0.0.4-0.0.5

- Implement `to_anndata()` to convert from spatial feature experiment to AnnData

Expand Down
17 changes: 14 additions & 3 deletions src/spatialfeatureexperiment/sfe.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Optional, Union, Tuple
from warnings import warn

import biocutils as ut
Expand Down Expand Up @@ -790,15 +790,26 @@ def set_column_data(
######>> AnnData interop <<#####
################################

def to_anndata(self, include_alternative_experiments: bool = False) -> "anndata.AnnData":
def to_anndata(
self, include_alternative_experiments: bool = False
) -> Tuple["anndata.AnnData", Dict[str, "anndata.AnnData"]]:
"""Transform :py:class:`~SpatialFeatureExperiment`-like into a :py:class:`~anndata.AnnData` representation.

This method extends the :py:meth:`~SpatialExperiment.to_anndata` method from the parent class
by adding SpatialFeatureExperiment-specific elements to the AnnData object's `uns["spatial"]`
dictionary. The additional elements include:
- `col_geometries`
- `row_geometries`
- `annot_geometries`
- `spatial_graphs`
- `unit`

Args:
include_alternative_experiments:
Whether to transform alternative experiments.

Returns:
An ``AnnData`` representation of the experiment.
A tuple containing an ``AnnData`` object with spatial information and a list of alternative experiments.
"""
obj, alt_exps = super().to_anndata(include_alternative_experiments=include_alternative_experiments)

Expand Down