Skip to content

Commit

Permalink
Fix copy operation when modifying an assay (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche authored Jan 2, 2025
1 parent 2bc81c0 commit a1339b8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## Version 0.5.1
## Version 0.5.1 - 0.5.2

- Add wrapper methods to combine Summarized and RangedSummarized by rows or columns.
- Implement getters and setters to access and modify an assay.
Expand Down
20 changes: 11 additions & 9 deletions src/summarizedexperiment/BaseSE.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ def __deepcopy__(self, memo=None, _nil=[]):
_rows_copy = deepcopy(self._rows)
_cols_copy = deepcopy(self._cols)
_metadata_copy = deepcopy(self.metadata)
_row_names_copy = None if self._row_names is None else deepcopy(self._row_names)
_col_names_copy = None if self._column_names is None else deepcopy(self._column_names)
_row_names_copy = deepcopy(self._row_names)
_col_names_copy = deepcopy(self._column_names)

current_class_const = type(self)
return current_class_const(
Expand All @@ -270,12 +270,12 @@ def __copy__(self):
"""
current_class_const = type(self)
return current_class_const(
assays=self._assays.copy(),
row_data=self._rows.__copy__(),
column_data=self._cols.__copy__(),
row_names=None if self._row_names is None else self._row_names.copy(),
column_names=None if self._column_names is None else self._column_names.copy(),
metadata=self._metadata.copy(),
assays=self._assays,
row_data=self._rows,
column_data=self._cols,
row_names=self._row_names,
column_names=self._column_names,
metadata=self._metadata,
)

def copy(self):
Expand Down Expand Up @@ -961,7 +961,7 @@ def assay(self, assay: Union[int, str]) -> Any:
return self.get_assay(assay)

def set_assay(self, name: str, assay: Any, in_place: bool = False) -> "BaseSE":
"""Add or Replace :py:attr:`~summarizedexperiment.BaseSE.BaseSE.assays`'s.
"""Add or replace :py:attr:`~summarizedexperiment.BaseSE.BaseSE.assays`'s.
Args:
name:
Expand Down Expand Up @@ -989,6 +989,8 @@ def set_assay(self, name: str, assay: Any, in_place: bool = False) -> "BaseSE":
raise ValueError("Porvided assay does not match the dimensions of the experiment.")

output = self._define_output(in_place)
if in_place is False:
output._assays = output._assays.copy()
output._assays[name] = assay
return output

Expand Down
22 changes: 11 additions & 11 deletions src/summarizedexperiment/RangedSummarizedExperiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def __deepcopy__(self, memo=None, _nil=[]):
_rows_copy = deepcopy(self._rows)
_rowranges_copy = deepcopy(self._row_ranges)
_cols_copy = deepcopy(self._cols)
_row_names_copy = None if self._row_names is None else deepcopy(self._row_names)
_col_names_copy = None if self._column_names is None else deepcopy(self._column_names)
_row_names_copy = deepcopy(self._row_names)
_col_names_copy = deepcopy(self._column_names)
_metadata_copy = deepcopy(self.metadata)

current_class_const = type(self)
Expand All @@ -206,13 +206,13 @@ def __copy__(self):
"""
current_class_const = type(self)
return current_class_const(
assays=self._assays.copy(),
row_ranges=self._row_ranges.__copy__(),
row_data=self._rows.__copy__(),
column_data=self._cols.__copy__(),
row_names=None if self._row_names is None else self._row_names.copy(),
column_names=None if self._column_names is None else self._column_names.copy(),
metadata=self._metadata.copy(),
assays=self._assays,
row_ranges=self._row_ranges,
row_data=self._rows,
column_data=self._cols,
row_names=self._row_names,
column_names=self._column_names,
metadata=self._metadata,
)

def copy(self):
Expand Down Expand Up @@ -933,11 +933,11 @@ def relaxed_combine_columns(self, *other) -> "RangedSummarizedExperiment":
return relaxed_combine_columns(self, *other)

def combine_rows(self, *other) -> "RangedSummarizedExperiment":
"""Wrapper around :py:func:`~biocutils.combine_rows`."""
"""Wrapper around :py:func:`~combine_rows`."""
return combine_rows(self, *other)

def combine_columns(self, *other) -> "RangedSummarizedExperiment":
"""Wrapper around :py:func:`~biocutils.combine_columns`."""
"""Wrapper around :py:func:`~combine_columns`."""
return combine_columns(self, *other)


Expand Down
4 changes: 2 additions & 2 deletions src/summarizedexperiment/SummarizedExperiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ def relaxed_combine_columns(self, *other) -> "SummarizedExperiment":
return relaxed_combine_columns(self, *other)

def combine_rows(self, *other) -> "SummarizedExperiment":
"""Wrapper around :py:func:`~biocutils.combine_rows`."""
"""Wrapper around :py:func:`~combine_rows`."""
return combine_rows(self, *other)

def combine_columns(self, *other) -> "SummarizedExperiment":
"""Wrapper around :py:func:`~biocutils.combine_columns`."""
"""Wrapper around :py:func:`~combine_columns`."""
return combine_columns(self, *other)


Expand Down

0 comments on commit a1339b8

Please sign in to comment.