Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinblampey committed Oct 15, 2024
1 parent bf06c6c commit 76c3f3d
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 39 deletions.
2 changes: 1 addition & 1 deletion docs/tutorials/api_usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@
}
],
"source": [
"sopa.io.write_xenium_explorer(\"tuto.explorer\", sdata)"
"sopa.io.explorer.write(\"tuto.explorer\", sdata)"
]
},
{
Expand Down
18 changes: 2 additions & 16 deletions sopa/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
from .explorer import (
write,
write_xenium_explorer,
align,
add_xenium_explorer_selection,
write_image,
write_transcripts,
write_cell_categories,
write_gene_counts,
write_polygons,
write_xenium_explorer_metadata,
str_cell_id,
int_cell_id,
save_column_csv,
)
from .explorer import write
from .standardize import write_standardized
from .reader.cosmx import cosmx
from .reader.merscope import merscope
Expand All @@ -25,5 +11,5 @@
from .reader.aics import aicsimageio
from .reader.visium_hd import visium_hd
from .report import write_report

from ..utils.data import blobs, uniform, toy_dataset
from . import explorer
4 changes: 2 additions & 2 deletions sopa/io/explorer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
from .points import write_transcripts
from .table import write_cell_categories, write_gene_counts, save_column_csv
from .shapes import write_polygons
from .converter import write, write_xenium_explorer, write_xenium_explorer_metadata
from .utils import str_cell_id, int_cell_id, add_xenium_explorer_selection
from .converter import write, write_metadata
from .utils import str_cell_id, int_cell_id, add_explorer_selection
14 changes: 3 additions & 11 deletions sopa/io/explorer/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import json
import logging
import warnings
from pathlib import Path

import geopandas as gpd
Expand Down Expand Up @@ -47,14 +46,7 @@ def _should_save(mode: str | None, character: str):
return character in mode if mode[0] == "+" else character not in mode


def write(*args, **kwargs):
warnings.warn(
"sopa.io.write is deprecated, use sopa.io.write_xenium_explorer instead", DeprecationWarning, stacklevel=2
)
write_xenium_explorer(*args, **kwargs)


def write_xenium_explorer(
def write(
path: str,
sdata: SpatialData,
image_key: str | None = None,
Expand Down Expand Up @@ -166,7 +158,7 @@ def write_xenium_explorer(

### Saving experiment.xenium file
if _should_save(mode, "m"):
write_xenium_explorer_metadata(path, image_key, shapes_key, _get_n_obs(sdata, geo_df), pixel_size)
write_metadata(path, image_key, shapes_key, _get_n_obs(sdata, geo_df), pixel_size)

if save_h5ad and SopaKeys.TABLE in sdata.tables:
sdata.tables[SopaKeys.TABLE].write_h5ad(path / FileNames.H5AD)
Expand All @@ -181,7 +173,7 @@ def _get_n_obs(sdata: SpatialData, geo_df: gpd.GeoDataFrame) -> int:
return len(geo_df) if geo_df is not None else 0


def write_xenium_explorer_metadata(
def write_metadata(
path: str,
image_key: str = "NA",
shapes_key: str = "NA",
Expand Down
2 changes: 1 addition & 1 deletion sopa/io/explorer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def xenium_explorer_selection(path: str | Path, pixel_size: float = 0.2125, retu
return [_selection_to_polygon(sub_df, pixel_size) for _, sub_df in df.groupby("Selection")]


def add_xenium_explorer_selection(
def add_explorer_selection(
sdata: SpatialData,
path: str,
shapes_key: str,
Expand Down
11 changes: 3 additions & 8 deletions sopa/io/standardize.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
log = logging.getLogger(__name__)


def sanity_check(sdata: SpatialData, delete_table: bool = False, warn: bool = False):
def sanity_check(sdata: SpatialData, delete_table: bool = False):
assert len(sdata.images) > 0, "The spatialdata object has no image. Sopa is not designed for this."

image = get_spatial_image(sdata)
Expand All @@ -26,11 +26,6 @@ def sanity_check(sdata: SpatialData, delete_table: bool = False, warn: bool = Fa
), f"Image must have the following three dimensions: {VALID_DIMENSIONS}. Found {image.dims}"
check_integer_dtype(image.dtype)

if len(sdata.points) > 1:
log.warning(
f"The spatialdata object has {len(sdata.points)} points objects. It's easier to have only one (corresponding to transcripts), since sopa will use it directly without providing a key argument"
)

c_coords = get_channel_names(image)
assert valid_c_coords(c_coords), f"Channel names must be strings, not {c_coords.dtype}"

Expand All @@ -42,9 +37,9 @@ def sanity_check(sdata: SpatialData, delete_table: bool = False, warn: bool = Fa
del sdata.tables[SopaKeys.TABLE]


def read_zarr_standardized(path: str, warn: bool = False) -> SpatialData:
def read_zarr_standardized(path: str) -> SpatialData:
sdata = spatialdata.read_zarr(path)
sanity_check(sdata, warn=warn)
sanity_check(sdata)
return sdata


Expand Down

0 comments on commit 76c3f3d

Please sign in to comment.