diff --git a/CHANGELOG.md b/CHANGELOG.md index b97806a..3754935 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## Version 0.6.0 - 0.6.4 +## Version 0.6.0 - 0.6.5 - Classes now extend `BiocObject` from biocutils, which provides a metadata field. - `valdiate` is renamed to `_validate` for consistency with other classes and packages. diff --git a/src/summarizedexperiment/base.py b/src/summarizedexperiment/base.py index d2a14fd..3da43a5 100644 --- a/src/summarizedexperiment/base.py +++ b/src/summarizedexperiment/base.py @@ -1198,9 +1198,9 @@ def to_anndata(self): return obj - ###################################### - ######>> col_data accessors <<######## - ###################################### + ########################################## + ######>> col/row data accessors <<######## + ########################################## def get_column_data_column(self, column: str) -> Any: """Access a column from the ``column_data``. @@ -1232,5 +1232,38 @@ def set_column_data_column(self, column: str, value: Any, in_place: bool = False or as a reference to the (in-place-modified) original. """ output = self._define_output(in_place) - output._cols = output._cols.set_column(column, value, in_place=False) + output._cols = output._cols.set_column(column, value, in_place=in_place) + return output + + def get_row_data_column(self, column: str) -> Any: + """Access a column from the ``row_data``. + + Args: + column: + Name of the column to retrieve. + + Returns: + The content of the column. + """ + return self._rows.get_column(column) + + def set_row_data_column(self, column: str, value: Any, in_place: bool = False) -> BaseSE: + """Set or replace a column in ``row_data``. + + Args: + column: + Name of the column to set. + + value: + Values for the column. Must match the number of features (rows). + + in_place: + Whether to modify the ``BaseSE`` in place. + + Returns: + A modified ``BaseSE`` object, either as a copy of the original + or as a reference to the (in-place-modified) original. + """ + output = self._define_output(in_place) + output._rows = output._rows.set_column(column, value, in_place=in_place) return output diff --git a/tests/test_SE_methods.py b/tests/test_SE_methods.py index 0efdba1..009a3d9 100644 --- a/tests/test_SE_methods.py +++ b/tests/test_SE_methods.py @@ -187,3 +187,19 @@ def test_SE_coldata_accessors(): tse.set_column_data_column("stuff", [1, 2, 3, 4, 5, 6], in_place=True) assert "stuff" in tse.col_data.column_names + +def test_SE_rowdata_accessors(): + tse = SummarizedExperiment( + assays={"counts": counts}, row_data=row_data, column_data=col_data + ) + + assert tse.get_row_data_column("strand") is not None + assert len(tse.get_row_data_column("strand")) == 200 + + new_tse = tse.set_row_data_column("new_scores", np.arange(200) * 2) + assert new_tse.shape == tse.shape + assert "new_scores" in new_tse.row_data.column_names + assert "new_scores" not in tse.row_data.column_names + + tse.set_row_data_column("new_scores", np.arange(200) * 3, in_place=True) + assert "new_scores" in tse.row_data.column_names