Skip to content

Commit

Permalink
starting to rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche committed Jan 25, 2024
1 parent b889120 commit 90ede9d
Show file tree
Hide file tree
Showing 17 changed files with 35,665 additions and 158 deletions.
2 changes: 1 addition & 1 deletion src/rds2py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
as_summarized_experiment,
)

from .parser import read_rds, get_class
from .rds_interface import read_rds, get_class
57 changes: 57 additions & 0 deletions src/rds2py/generics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from functools import singledispatch
from importlib import import_module

from .rds_interface import get_class, load_rds

__author__ = "jkanche"
__copyright__ = "jkanche"
__license__ = "MIT"

registry = {}


@singledispatch
def save_object(x, path: str):
"""Save a Python object as RDS file
Args:
x:
Object to save.
path:
Path to save the object.
"""
raise NotImplementedError(
"No `save_object` method implemented for '" + type(x[0]).__name__ + "' objects."
)


def read_object(path: str, **kwargs):
"""Read an object from RDS file.
Args:
path:
Path to the RDS file.
kwargs:
Further arguments, passed to individual methods.
Returns:
Some kind of object.
"""
_robj = load_rds(path=path)
_class_name = get_class(_robj)

if _class_name not in registry:
raise NotImplementedError(
"no `read_object` method implemented for '{_class_name}' objects."
)

command = registry[_class_name]
if isinstance(command, str):
first_period = command.find(".")
mod = import_module(command[:first_period])
command = getattr(mod, command[first_period + 1 :])
registry[_class_name] = command

return command(path, **kwargs)
2 changes: 1 addition & 1 deletion src/rds2py/granges.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from iranges import IRanges
from biocframe import BiocFrame

from .parser import get_class
from .rds_interface import get_class
from .pdf import as_pandas_from_dframe

__author__ = "jkanche"
Expand Down
2 changes: 1 addition & 1 deletion src/rds2py/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from summarizedexperiment import SummarizedExperiment
from biocframe import BiocFrame

from .parser import get_class
from .rds_interface import get_class
from .pdf import as_pandas_from_data_frame, as_pandas_from_dframe

__author__ = "jkanche"
Expand Down
Loading

0 comments on commit 90ede9d

Please sign in to comment.