Skip to content

Commit

Permalink
fix: Provide uid on tileset (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt authored Oct 23, 2024
1 parent 5a9a22a commit 6f3b1a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion gosling/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ def __rich_repr__(self):

data_server = GoslingDataServer()


def _create_loader(
type_: str,
create_ts: typing.Callable[[pathlib.Path], tilesets.Tileset] | None = None
create_ts: typing.Callable[[pathlib.Path], tilesets.Tileset] | None = None,
):
def load(url: pathlib.Path | str, **kwargs):
"""Adds resource to data_server if local file is detected."""
Expand Down
23 changes: 18 additions & 5 deletions gosling/data/_tilesets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@
import pathlib
import typing
from dataclasses import dataclass
import hashlib


@dataclass(frozen=True)
class Tileset:
filepath: pathlib.Path
tiles: typing.Callable[[typing.Sequence[str]], list[typing.Any]]
tiles_impl: typing.Callable[[typing.Sequence[str]], list[typing.Any]]
info: typing.Callable[[], typing.Any]
uid: str
type: None | str = None

def tiles(self, tile_ids: typing.Sequence[str]) -> list[typing.Any]:
return self.tiles_impl(tile_ids)


def create_uid(filepath: pathlib.Path) -> str:
return hashlib.md5(str(filepath).encode()).hexdigest()[0:8]


def beddb(filepath: pathlib.Path):
try:
Expand All @@ -25,8 +34,9 @@ def beddb(filepath: pathlib.Path):
return Tileset(
filepath=filepath,
type="beddb",
tiles=functools.partial(tiles, filepath),
tiles_impl=functools.partial(tiles, filepath),
info=functools.partial(tileset_info, filepath),
uid=create_uid(filepath),
)


Expand All @@ -41,8 +51,9 @@ def bigwig(filepath: pathlib.Path):
return Tileset(
filepath=filepath,
type="bigwig",
tiles=functools.partial(tiles, filepath),
tiles_impl=functools.partial(tiles, filepath),
info=functools.partial(tileset_info, filepath),
uid=create_uid(filepath),
)


Expand All @@ -57,8 +68,9 @@ def multivec(filepath: pathlib.Path):
return Tileset(
filepath=filepath,
type="multivec",
tiles=functools.partial(tiles, filepath),
tiles_impl=functools.partial(tiles, filepath),
info=functools.partial(tileset_info, filepath),
uid=create_uid(filepath),
)


Expand All @@ -73,6 +85,7 @@ def cooler(filepath: pathlib.Path):
return Tileset(
filepath=filepath,
type="cooler",
tiles=functools.partial(tiles, filepath),
tiles_impl=functools.partial(tiles, filepath),
info=functools.partial(tileset_info, filepath),
uid=create_uid(filepath),
)

0 comments on commit 6f3b1a3

Please sign in to comment.