Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow file pointers in tileset loaders #161

Merged
merged 6 commits into from
Jan 23, 2025
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [v1.0.2](https://github.com/higlass/higlass-python/compare/v1.0.2...v1.0.1)

- Calculate file pointer hash for track uids for tileset tracks

## [v1.0.1](https://github.com/higlass/higlass-python/compare/v1.0.1...v1.0.0)

- Pass kwargs in to Viewconf.widget() so that they can be passed on to the higlass widget and potentially make their way to the higlass component
Expand Down
32 changes: 19 additions & 13 deletions src/higlass/tilesets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pathlib
import typing
from dataclasses import dataclass
from typing import IO

from ._utils import TrackType
from .api import track
Expand Down Expand Up @@ -71,19 +72,21 @@ def remote(uid: str, server: str = "https://higlass.io/api/v1", **kwargs):
return RemoteTileset(uid, server, **kwargs)


def hash_absolute_filepath_as_default_uid(
fn: typing.Callable[[str, str], LocalTileset]
):
def wrapper(filepath: str, uid: None | str = None):
def hash_file_as_default_uid(fn: typing.Callable[[str | IO[bytes], str], LocalTileset]):
def wrapper(file: str | IO[bytes], uid: None | str = None):
if uid is None:
abspath = pathlib.Path(filepath).absolute()
uid = hashlib.md5(str(abspath).encode()).hexdigest()
return fn(filepath, uid)
if isinstance(file, str):
abspath = pathlib.Path(file).absolute()
uid = hashlib.md5(str(abspath).encode()).hexdigest()
else:
# File-like object likely provided
uid = hashlib.md5(str(hash(file)).encode()).hexdigest()
return fn(file, uid)

return wrapper


@hash_absolute_filepath_as_default_uid
@hash_file_as_default_uid
def bigwig(filepath: str, uid: str):
try:
from clodius.tiles.bigwig import tiles, tileset_info
Expand All @@ -100,7 +103,7 @@ def bigwig(filepath: str, uid: str):
)


@hash_absolute_filepath_as_default_uid
@hash_file_as_default_uid
def beddb(filepath: str, uid: str):
try:
from clodius.tiles.beddb import tiles, tileset_info
Expand All @@ -117,7 +120,7 @@ def beddb(filepath: str, uid: str):
)


@hash_absolute_filepath_as_default_uid
@hash_file_as_default_uid
def multivec(filepath: str, uid: str):
try:
from clodius.tiles.multivec import tiles, tileset_info
Expand All @@ -134,7 +137,7 @@ def multivec(filepath: str, uid: str):
)


@hash_absolute_filepath_as_default_uid
@hash_file_as_default_uid
def cooler(filepath: str, uid: str):
try:
from clodius.tiles.cooler import tiles, tileset_info
Expand All @@ -151,7 +154,7 @@ def cooler(filepath: str, uid: str):
)


@hash_absolute_filepath_as_default_uid
@hash_file_as_default_uid
def hitile(filepath: str, uid: str):
try:
from clodius.tiles.hitile import tiles, tileset_info
Expand All @@ -168,7 +171,7 @@ def hitile(filepath: str, uid: str):
)


@hash_absolute_filepath_as_default_uid
@hash_file_as_default_uid
def bed2ddb(filepath: str, uid: str):
try:
from clodius.tiles.bed2ddb import tiles, tileset_info
Expand All @@ -183,3 +186,6 @@ def bed2ddb(filepath: str, uid: str):
info=functools.partial(tileset_info, filepath),
uid=uid,
)


by_filetype = {"cooler": cooler, "bigwig": bigwig}
Loading
Loading