Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.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.
Expand Down
41 changes: 37 additions & 4 deletions src/summarizedexperiment/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down Expand Up @@ -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
16 changes: 16 additions & 0 deletions tests/test_SE_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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