Skip to content

Commit

Permalink
we are getting somewhere now...
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche committed Dec 21, 2023
1 parent 2ec1a75 commit e1edbf9
Show file tree
Hide file tree
Showing 8 changed files with 290 additions and 209 deletions.
337 changes: 208 additions & 129 deletions src/summarizedexperiment/BaseSE.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/summarizedexperiment/RangedSummarizedExperiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def __init__(
metadata (Dict, optional): Additional experimental metadata describing the
methods. Defaults to None.
"""
super().__init__(assays, row_data, col_data, metadata)
super().__init__(assays, rows=row_data, cols=col_data, metadata=metadata)

if row_ranges is None:
row_ranges = GenomicRangesList.empty(n=self._shape[0])
Expand Down
17 changes: 9 additions & 8 deletions src/summarizedexperiment/SummarizedExperiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from warnings import warn

from genomicranges import GenomicRanges
from biocframe import BiocFrame

from .BaseSE import BaseSE
from .types import BiocOrPandasFrame, MatrixTypes, SlicerArgTypes
from .types import MatrixTypes, SlicerArgTypes

__author__ = "jkanche"
__copyright__ = "jkanche"
Expand All @@ -29,11 +30,11 @@ class SummarizedExperiment(BaseSE):
All matrices in assays must be 2-dimensional and have the same shape
(number of rows, number of columns).
row_data (BiocOrPandasFrame, optional): Features, which must be of the same length as the rows of
row_data (BiocFrame, optional): Features, which must be of the same length as the rows of
the matrices in assays. Features can be either a :py:class:`~pandas.DataFrame` or
:py:class:`~biocframe.BiocFrame.BiocFrame`. Defaults to None.
col_data (BiocOrPandasFrame, optional): Sample data, which must be of the same length as the
col_data (BiocFrame, optional): Sample data, which must be of the same length as the
columns of the matrices in assays. Sample Information can be either a :py:class:`~pandas.DataFrame`
or :py:class:`~biocframe.BiocFrame.BiocFrame`. Defaults to None.
Expand All @@ -43,8 +44,8 @@ class SummarizedExperiment(BaseSE):
def __init__(
self,
assays: Dict[str, MatrixTypes],
row_data: Optional[BiocOrPandasFrame] = None,
col_data: Optional[BiocOrPandasFrame] = None,
row_data: Optional[BiocFrame] = None,
col_data: Optional[BiocFrame] = None,
metadata: Optional[Dict] = None,
) -> None:
"""Initialize a Summarized Experiment (SE).
Expand All @@ -60,11 +61,11 @@ def __init__(
All matrices in assays must be 2-dimensional and have the same shape
(number of rows, number of columns).
row_data (BiocOrPandasFrame, optional): Features, which must be of the same length as the rows of
row_data (BiocFrame, optional): Features, which must be of the same length as the rows of
the matrices in assays. Features can be either a :py:class:`~pandas.DataFrame` or
:py:class:`~biocframe.BiocFrame.BiocFrame`. Defaults to None.
col_data (BiocOrPandasFrame, optional): Sample data, which must be of the same length as the
col_data (BiocFrame, optional): Sample data, which must be of the same length as the
columns of the matrices in assays. Sample Information can be either a :py:class:`~pandas.DataFrame`
or :py:class:`~biocframe.BiocFrame.BiocFrame`. Defaults to None.
Expand All @@ -76,7 +77,7 @@ def __init__(
"`row_data` is `GenomicRanges`, consider using `RangeSummarizedExperiment`."
)

super().__init__(assays, row_data, col_data, metadata)
super().__init__(assays, rows=row_data, cols=col_data, metadata=metadata)

def __getitem__(
self,
Expand Down
2 changes: 1 addition & 1 deletion src/summarizedexperiment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
del version, PackageNotFoundError

from .SummarizedExperiment import SummarizedExperiment
from .RangedSummarizedExperiment import RangedSummarizedExperiment
# from .RangedSummarizedExperiment import RangedSummarizedExperiment
20 changes: 18 additions & 2 deletions src/summarizedexperiment/_frameutils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from biocframe import BiocFrame, from_pandas
from typing import Any

from .type_checks import is_pandas
from biocframe import BiocFrame, from_pandas

__author__ = "jkanche"
__copyright__ = "jkanche"
Expand All @@ -14,3 +14,19 @@ def _sanitize_frame(frame, num_rows: int):
frame = from_pandas(frame)

return frame


def is_pandas(x: Any) -> bool:
"""Check if ``x`` is a :py:class:`~pandas.DataFrame`.
Args:
x:
Any object.
Returns:
True if ``x`` is a :py:class:`~pandas.DataFrame`.
"""
if hasattr(x, "dtypes"):
return True

return False
16 changes: 0 additions & 16 deletions src/summarizedexperiment/type_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,3 @@ def is_list_of_type(x: Any, target_type: Callable) -> bool:
return (isinstance(x, list) or isinstance(x, tuple)) and all(
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 object.
Returns:
True if ``x`` is a :py:class:`~pandas.DataFrame`.
"""
if hasattr(x, "dtypes"):
return True

return False
7 changes: 4 additions & 3 deletions src/summarizedexperiment/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
MatrixSlicerTypes = Union[List[int], List[bool], slice]
SlicerTypes = Union[List[int], List[bool], List[str], slice]
SlicerArgTypes = Union[Tuple[SlicerTypes], List[SlicerTypes], slice]
SlicerResult = namedtuple(
"SlicerResult", ["row_data", "col_data", "assays", "row_indices", "col_indices"]
)

SliceResult = namedtuple(
"SlicerResult", ["rows", "columns", "assays", "row_indices", "col_indices"]
)
Loading

0 comments on commit e1edbf9

Please sign in to comment.