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 .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.15.6
rev: v0.16.4
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
if __name__ == "__main__":
try:
setup(use_scm_version={"version_scheme": "no-guess-dev"})
except: # noqa
except:
print(
"\n\nAn error occurred while building the project, "
"please ensure you have the most updated version of setuptools, "
Expand Down
4 changes: 2 additions & 2 deletions src/spatialexperiment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
)

__all__ = [
"read_tenx_visium",
"SpatialExperiment",
"LoadedSpatialImage",
"RemoteSpatialImage",
"SpatialExperiment",
"StoredSpatialImage",
"VirtualSpatialImage",
"construct_spatial_image_class",
"read_tenx_visium",
]
13 changes: 6 additions & 7 deletions src/spatialexperiment/_combineutils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from __future__ import annotations
from typing import List, Tuple

from warnings import warn
from copy import deepcopy
import itertools
from copy import deepcopy
from warnings import warn

from biocframe import BiocFrame
import biocutils as ut
from biocframe import BiocFrame


def _append_indices_to_samples(bframes: List[BiocFrame]) -> List[BiocFrame]:
def _append_indices_to_samples(bframes: list[BiocFrame]) -> list[BiocFrame]:
"""Append indices to sample IDs for a list of `BiocFrames`.

For each `BiocFrame`, appends an index to all sample IDs to ensure uniqueness
Expand All @@ -29,7 +28,7 @@ def _append_indices_to_samples(bframes: List[BiocFrame]) -> List[BiocFrame]:
return modified_bframes


def merge_spatial_frames(x: List["SpatialExperiment"], relaxed: bool = False) -> Tuple[BiocFrame, BiocFrame]:
def merge_spatial_frames(x: list[SpatialExperiment], relaxed: bool = False) -> tuple[BiocFrame, BiocFrame]:
"""Merge column data and image data from multiple ``SpatialExperiment`` objects.

If duplicate sample IDs exist across objects, appends indices to make them unique.
Expand Down Expand Up @@ -70,7 +69,7 @@ def merge_spatial_frames(x: List["SpatialExperiment"], relaxed: bool = False) ->
return _new_cols, _new_img_data


def merge_spatial_coordinates(spatial_coords: List[BiocFrame], relaxed: bool = False) -> BiocFrame:
def merge_spatial_coordinates(spatial_coords: list[BiocFrame], relaxed: bool = False) -> BiocFrame:
"""Merge spatial coordinates from multiple frames.

Args:
Expand Down
14 changes: 7 additions & 7 deletions src/spatialexperiment/_imgutils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Union, List

import os
from io import BytesIO
from pathlib import Path
from urllib.parse import urlparse

import numpy as np
from PIL import Image
from biocframe import BiocFrame
from PIL import Image

from .spatialimage import construct_spatial_image_class

__author__ = "keviny2"
Expand Down Expand Up @@ -43,7 +43,7 @@ def read_image(input_image):


def construct_img_data(
img: Union[str, os.PathLike], scale_factor: str, sample_id: str, image_id: str, load: bool = True
img: str | os.PathLike, scale_factor: str, sample_id: str, image_id: str, load: bool = True
) -> BiocFrame:
"""
Construct an image data dataframe.
Expand Down Expand Up @@ -77,9 +77,9 @@ def construct_img_data(

def get_img_idx(
img_data: BiocFrame,
sample_id: Union[str, bool, None] = None,
image_id: Union[str, bool, None] = None,
) -> List[int]:
sample_id: str | bool | None = None,
image_id: str | bool | None = None,
) -> list[int]:
"""
Retrieve the row index/indices of image(s) with matching 'sample_id' and 'image_id' from the 'img_data'.

Expand Down
12 changes: 6 additions & 6 deletions src/spatialexperiment/_initutils.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from copy import deepcopy
from typing import List, Tuple

from biocframe import BiocFrame
from PIL import Image
from .spatialimage import construct_spatial_image_class
from summarizedexperiment._frameutils import _sanitize_frame

from .spatialimage import construct_spatial_image_class

__author__ = "keviny2"
__copyright__ = "keviny2"
__license__ = "MIT"


def construct_spatial_coords_from_names(
spatial_coords_names: List[str], column_data: BiocFrame
) -> Tuple[BiocFrame, BiocFrame]:
spatial_coords_names: list[str], column_data: BiocFrame
) -> tuple[BiocFrame, BiocFrame]:
"""Construct the `spatial_coords` dataframe from names.

Args:
Expand Down Expand Up @@ -54,8 +54,8 @@ def construct_spatial_coords_from_names(
def construct_img_data(
sample_id: str,
image_id: str,
image_sources: List[str],
scale_factors: List[float],
image_sources: list[str],
scale_factors: list[float],
load_image: bool = False,
) -> BiocFrame:
"""Construct the image data for a `SpatialExperiment`.
Expand Down
2 changes: 1 addition & 1 deletion src/spatialexperiment/_validators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import warnings

from biocframe import BiocFrame
import biocutils as ut
from biocframe import BiocFrame

__author__ = "keviny2"
__copyright__ = "keviny2"
Expand Down
20 changes: 10 additions & 10 deletions src/spatialexperiment/io/tenx_visium.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
"""Creates a ``SpatialExperiment`` from the Space Ranger output directories for 10x Genomics Visium spatial gene expression data"""

from typing import List, Union, Optional
from warnings import warn
import json
import os
import re
import json
from warnings import warn

from biocframe import BiocFrame
import biocutils as ut
from biocframe import BiocFrame
from singlecellexperiment import read_tenx_mtx
from ..spatialexperiment import SpatialExperiment

from .._imgutils import construct_img_data
from .._initutils import construct_spatial_coords_from_names
from ..spatialexperiment import SpatialExperiment


def read_tissue_positions(tissue_positions_path) -> "pd.DataFrame":
Expand Down Expand Up @@ -46,8 +46,8 @@ def read_tissue_positions(tissue_positions_path) -> "pd.DataFrame":

def read_img_data(
path: str = ".",
sample_ids: Optional[List[str]] = None,
image_sources: Optional[List[str]] = None,
sample_ids: list[str] | None = None,
image_sources: list[str] | None = None,
scale_factors: str = None,
load: bool = True,
) -> BiocFrame:
Expand Down Expand Up @@ -118,11 +118,11 @@ def read_img_data(


def read_tenx_visium(
samples: List[Union[str, os.PathLike]],
sample_ids: Optional[List[str]] = None,
samples: list[str | os.PathLike],
sample_ids: list[str] | None = None,
type: str = "HDF5",
data: str = "filtered",
images: List[str] = "lowres",
images: list[str] = "lowres",
load: bool = True,
):
"""Create a ``SpatialExperiment`` from the Space Ranger output directories for 10x Genomics Visium spatial gene expression data.
Expand Down
Loading
Loading