Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
functionalizing BaseSE
Browse files Browse the repository at this point in the history
jkanche committed Dec 1, 2023
1 parent 652b317 commit 9e34f8f
Showing 12 changed files with 436 additions and 856 deletions.
6 changes: 4 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -49,8 +49,9 @@ package_dir =
# For more information, check out https://semver.org/.
install_requires =
importlib-metadata; python_version<"3.8"
genomicranges>=0.3.6
scipy
genomicranges>=0.4.0,<0.5.0
biocframe>=0.5.0,<0.6.0
biocutils>=0.1.0,<0.2.0

[options.packages.find]
where = src
@@ -62,6 +63,7 @@ exclude =
# `pip install SummarizedExperiment[PDF]` like:
optional =
anndata
scipy

# Add here test requirements (semicolon/line-separated)
testing =
684 changes: 403 additions & 281 deletions src/summarizedexperiment/BaseSE.py

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions src/summarizedexperiment/_frameutils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from biocframe import BiocFrame, from_pandas

from .type_checks import is_pandas

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


def _sanitize_frame(frame, num_rows: int):
frame = frame if frame is not None else BiocFrame({}, number_of_rows=num_rows)

if is_pandas(frame):
frame = from_pandas(frame)

return frame
2 changes: 0 additions & 2 deletions src/summarizedexperiment/dispatchers/__init__.py

This file was deleted.

84 changes: 0 additions & 84 deletions src/summarizedexperiment/dispatchers/colnames.py

This file was deleted.

82 changes: 0 additions & 82 deletions src/summarizedexperiment/dispatchers/rownames.py

This file was deleted.

49 changes: 13 additions & 36 deletions src/summarizedexperiment/type_checks.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
from typing import Any, Callable

from biocframe import BiocFrame

# from .RangedSummarizedExperiment import RangedSummarizedExperiment

__author__ = "jkanche, keviny2"
__copyright__ = "jkanche"
__license__ = "MIT"


def is_bioc_or_pandas_frame(x: Any) -> bool:
"""Checks if ``x`` is either a :py:class:`~pandas.DataFrame` or :py:class:`~biocframe.BiocFrame.BiocFrame`.
Args:
x (Any): Any object.
Returns:
bool: True if ``x`` is `DataFrame`-like.
"""
return is_pandas(x) or isinstance(x, BiocFrame)


# def is_gr_or_rse(x: Union[GenomicRanges, RangedSummarizedExperiment]):
# """Check if the object is either a `RangedSummarizedExperiment` or `GenomicRanges`.

@@ -60,10 +46,11 @@ def is_matrix_like(x: Any) -> bool:
and allows slicing by implementing the `__getitem__` dunder method.
Args:
x (Any): Any object.
x:
Any object.
Returns:
bool: True if ``x``is matrix-like.
True if ``x``is matrix-like.
"""
# TODO: this only work for python 3.8 and below.
# return isinstance(x, MatrixProtocol)
@@ -74,40 +61,30 @@ def is_list_of_type(x: Any, target_type: Callable) -> bool:
"""Checks if ``x`` is a list or tuple and and whether all elements are of the same type.
Args:
x (Any): Any object.
target_type (callable): Type to check for, e.g. ``str``, ``int``.
Returns:
bool: True if ``x`` is :py:class:`~list` and all elements are of the same type.
"""
return (isinstance(x, list) or isinstance(x, tuple)) and all(
isinstance(item, target_type) for item in x
)
x:
Any object.

def is_list_of_subclass(x: Any, target_type: Callable) -> bool:
"""Checks if all provided objects subclass of ``target_type``.
Args:
x (Any): Any object.
target_type (callable): Type to check objects against.
target_type:
Type to check for, e.g. ``str``, ``int``.
Returns:
bool: True if ``x`` is :py:class:`~list` and all objects are derivatives of the same class.
True if ``x`` is :py:class:`~list` and all
elements are of the same type.
"""
return (isinstance(x, list) or isinstance(x, tuple)) and all(
issubclass(type(item), target_type) for item in x
isinstance(item, target_type) for item in x
)


def is_pandas(x: Any) -> bool:
"""Check if ``x`` is a :py:class:`~pandas.DataFrame`.
Args:
x (Any): Any object.
x:
Any object.
Returns:
bool: True if ``x`` is a :py:class:`~pandas.DataFrame`.
True if ``x`` is a :py:class:`~pandas.DataFrame`.
"""
if hasattr(x, "dtypes"):
return True
1 change: 0 additions & 1 deletion src/summarizedexperiment/types.py
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@

MatrixTypes = Union[np.ndarray, sp.spmatrix]
ArrayTypes = Union[np.ndarray, sp.lil_matrix]
BiocOrPandasFrame = Union[pd.DataFrame, BiocFrame]
MatrixSlicerTypes = Union[List[int], List[bool], slice]
SlicerTypes = Union[List[int], List[bool], List[str], slice]
SlicerArgTypes = Union[Tuple[SlicerTypes], List[SlicerTypes], slice]
3 changes: 0 additions & 3 deletions src/summarizedexperiment/utils/__init__.py

This file was deleted.

219 changes: 0 additions & 219 deletions src/summarizedexperiment/utils/combiners.py

This file was deleted.

78 changes: 0 additions & 78 deletions src/summarizedexperiment/utils/slicer.py

This file was deleted.

68 changes: 0 additions & 68 deletions src/summarizedexperiment/utils/validators.py

This file was deleted.

0 comments on commit 9e34f8f

Please sign in to comment.