Skip to content

Commit 5d0bb56

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 046de95 commit 5d0bb56

10 files changed

Lines changed: 134 additions & 135 deletions

File tree

‎README.md‎

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,36 +51,38 @@ ncols = 500 # Number of spots/cells
5151
counts = np.random.rand(nrows, ncols)
5252

5353
# Create feature annotations
54-
row_data = BiocFrame({
55-
"gene_ids": [f"gene_{i}" for i in range(nrows)],
56-
"gene_names": [f"Gene_{i}" for i in range(nrows)]
57-
})
54+
row_data = BiocFrame(
55+
{"gene_ids": [f"gene_{i}" for i in range(nrows)], "gene_names": [f"Gene_{i}" for i in range(nrows)]}
56+
)
5857

5958
# Create spot/cell annotations
60-
col_data = BiocFrame({
61-
"n_genes": [50, 200] * int(ncols / 2),
62-
"condition": ["healthy", "tumor"] * int(ncols / 2),
63-
"cell_id": [f"spot_{i}" for i in range(ncols)],
64-
"sample_id": ["sample_1"] * int(ncols / 2) + ["sample_2"] * int(ncols / 2),
65-
})
59+
col_data = BiocFrame(
60+
{
61+
"n_genes": [50, 200] * int(ncols / 2),
62+
"condition": ["healthy", "tumor"] * int(ncols / 2),
63+
"cell_id": [f"spot_{i}" for i in range(ncols)],
64+
"sample_id": ["sample_1"] * int(ncols / 2) + ["sample_2"] * int(ncols / 2),
65+
}
66+
)
6667

6768
# Generate spatial coordinates
68-
spatial_coords = BiocFrame({
69-
"x": np.random.uniform(low=0.0, high=100.0, size=ncols),
70-
"y": np.random.uniform(low=0.0, high=100.0, size=ncols)
71-
})
69+
spatial_coords = BiocFrame(
70+
{"x": np.random.uniform(low=0.0, high=100.0, size=ncols), "y": np.random.uniform(low=0.0, high=100.0, size=ncols)}
71+
)
7272

7373
# Create image data
74-
img_data = BiocFrame({
75-
"sample_id": ["sample_1", "sample_1", "sample_2"],
76-
"image_id": ["aurora", "dice", "desert"],
77-
"data": [
78-
construct_spatial_image_class("tests/images/sample_image1.jpg"),
79-
construct_spatial_image_class("tests/images/sample_image2.png"),
80-
construct_spatial_image_class("tests/images/sample_image3.jpg"),
81-
],
82-
"scale_factor": [1, 1, 1],
83-
})
74+
img_data = BiocFrame(
75+
{
76+
"sample_id": ["sample_1", "sample_1", "sample_2"],
77+
"image_id": ["aurora", "dice", "desert"],
78+
"data": [
79+
construct_spatial_image_class("tests/images/sample_image1.jpg"),
80+
construct_spatial_image_class("tests/images/sample_image2.png"),
81+
construct_spatial_image_class("tests/images/sample_image3.jpg"),
82+
],
83+
"scale_factor": [1, 1, 1],
84+
}
85+
)
8486

8587
# Create SpatialExperiment object
8688
spe = SpatialExperiment(

‎setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
if __name__ == "__main__":
1313
try:
1414
setup(use_scm_version={"version_scheme": "no-guess-dev"})
15-
except: # noqa
15+
except:
1616
print(
1717
"\n\nAn error occurred while building the project, "
1818
"please ensure you have the most updated version of setuptools, "

‎src/spatialexperiment/__init__.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
)
2727

2828
__all__ = [
29-
"read_tenx_visium",
30-
"SpatialExperiment",
3129
"LoadedSpatialImage",
3230
"RemoteSpatialImage",
31+
"SpatialExperiment",
3332
"StoredSpatialImage",
3433
"VirtualSpatialImage",
3534
"construct_spatial_image_class",
35+
"read_tenx_visium",
3636
]

‎src/spatialexperiment/_combineutils.py‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
from __future__ import annotations
2-
from typing import List, Tuple
32

4-
from warnings import warn
5-
from copy import deepcopy
63
import itertools
4+
from copy import deepcopy
5+
from warnings import warn
76

8-
from biocframe import BiocFrame
97
import biocutils as ut
8+
from biocframe import BiocFrame
109

1110

12-
def _append_indices_to_samples(bframes: List[BiocFrame]) -> List[BiocFrame]:
11+
def _append_indices_to_samples(bframes: list[BiocFrame]) -> list[BiocFrame]:
1312
"""Append indices to sample IDs for a list of `BiocFrames`.
1413
1514
For each `BiocFrame`, appends an index to all sample IDs to ensure uniqueness
@@ -29,7 +28,7 @@ def _append_indices_to_samples(bframes: List[BiocFrame]) -> List[BiocFrame]:
2928
return modified_bframes
3029

3130

32-
def merge_spatial_frames(x: List["SpatialExperiment"], relaxed: bool = False) -> Tuple[BiocFrame, BiocFrame]:
31+
def merge_spatial_frames(x: list[SpatialExperiment], relaxed: bool = False) -> tuple[BiocFrame, BiocFrame]:
3332
"""Merge column data and image data from multiple ``SpatialExperiment`` objects.
3433
3534
If duplicate sample IDs exist across objects, appends indices to make them unique.
@@ -70,7 +69,7 @@ def merge_spatial_frames(x: List["SpatialExperiment"], relaxed: bool = False) ->
7069
return _new_cols, _new_img_data
7170

7271

73-
def merge_spatial_coordinates(spatial_coords: List[BiocFrame], relaxed: bool = False) -> BiocFrame:
72+
def merge_spatial_coordinates(spatial_coords: list[BiocFrame], relaxed: bool = False) -> BiocFrame:
7473
"""Merge spatial coordinates from multiple frames.
7574
7675
Args:

‎src/spatialexperiment/_imgutils.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from typing import Union, List
2-
31
import os
42
from io import BytesIO
53
from pathlib import Path
64
from urllib.parse import urlparse
5+
76
import numpy as np
8-
from PIL import Image
97
from biocframe import BiocFrame
8+
from PIL import Image
9+
1010
from .spatialimage import construct_spatial_image_class
1111

1212
__author__ = "keviny2"
@@ -43,7 +43,7 @@ def read_image(input_image):
4343

4444

4545
def construct_img_data(
46-
img: Union[str, os.PathLike], scale_factor: str, sample_id: str, image_id: str, load: bool = True
46+
img: str | os.PathLike, scale_factor: str, sample_id: str, image_id: str, load: bool = True
4747
) -> BiocFrame:
4848
"""
4949
Construct an image data dataframe.
@@ -77,9 +77,9 @@ def construct_img_data(
7777

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

‎src/spatialexperiment/_initutils.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
from copy import deepcopy
2-
from typing import List, Tuple
32

43
from biocframe import BiocFrame
54
from PIL import Image
6-
from .spatialimage import construct_spatial_image_class
75
from summarizedexperiment._frameutils import _sanitize_frame
86

7+
from .spatialimage import construct_spatial_image_class
8+
99
__author__ = "keviny2"
1010
__copyright__ = "keviny2"
1111
__license__ = "MIT"
1212

1313

1414
def construct_spatial_coords_from_names(
15-
spatial_coords_names: List[str], column_data: BiocFrame
16-
) -> Tuple[BiocFrame, BiocFrame]:
15+
spatial_coords_names: list[str], column_data: BiocFrame
16+
) -> tuple[BiocFrame, BiocFrame]:
1717
"""Construct the `spatial_coords` dataframe from names.
1818
1919
Args:
@@ -54,8 +54,8 @@ def construct_spatial_coords_from_names(
5454
def construct_img_data(
5555
sample_id: str,
5656
image_id: str,
57-
image_sources: List[str],
58-
scale_factors: List[float],
57+
image_sources: list[str],
58+
scale_factors: list[float],
5959
load_image: bool = False,
6060
) -> BiocFrame:
6161
"""Construct the image data for a `SpatialExperiment`.

‎src/spatialexperiment/_validators.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import warnings
22

3-
from biocframe import BiocFrame
43
import biocutils as ut
4+
from biocframe import BiocFrame
55

66
__author__ = "keviny2"
77
__copyright__ = "keviny2"

‎src/spatialexperiment/io/tenx_visium.py‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
"""Creates a ``SpatialExperiment`` from the Space Ranger output directories for 10x Genomics Visium spatial gene expression data"""
22

3-
from typing import List, Union, Optional
4-
from warnings import warn
3+
import json
54
import os
65
import re
7-
import json
6+
from warnings import warn
87

9-
from biocframe import BiocFrame
108
import biocutils as ut
9+
from biocframe import BiocFrame
1110
from singlecellexperiment import read_tenx_mtx
12-
from ..spatialexperiment import SpatialExperiment
11+
1312
from .._imgutils import construct_img_data
1413
from .._initutils import construct_spatial_coords_from_names
14+
from ..spatialexperiment import SpatialExperiment
1515

1616

1717
def read_tissue_positions(tissue_positions_path) -> "pd.DataFrame":
@@ -46,8 +46,8 @@ def read_tissue_positions(tissue_positions_path) -> "pd.DataFrame":
4646

4747
def read_img_data(
4848
path: str = ".",
49-
sample_ids: Optional[List[str]] = None,
50-
image_sources: Optional[List[str]] = None,
49+
sample_ids: list[str] | None = None,
50+
image_sources: list[str] | None = None,
5151
scale_factors: str = None,
5252
load: bool = True,
5353
) -> BiocFrame:
@@ -118,11 +118,11 @@ def read_img_data(
118118

119119

120120
def read_tenx_visium(
121-
samples: List[Union[str, os.PathLike]],
122-
sample_ids: Optional[List[str]] = None,
121+
samples: list[str | os.PathLike],
122+
sample_ids: list[str] | None = None,
123123
type: str = "HDF5",
124124
data: str = "filtered",
125-
images: List[str] = "lowres",
125+
images: list[str] = "lowres",
126126
load: bool = True,
127127
):
128128
"""Create a ``SpatialExperiment`` from the Space Ranger output directories for 10x Genomics Visium spatial gene expression data.

0 commit comments

Comments
 (0)