Skip to content

Commit

Permalink
Fix subset operation on SingleCellExperiment slots (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche authored Jan 14, 2024
1 parent 73491d2 commit d759ba6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
13 changes: 2 additions & 11 deletions src/singlecellexperiment/SingleCellExperiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,18 +921,15 @@ def get_slice(

new_reduced_dims = {}
for rdim, rmat in self._reduced_dims.items():
if slicer.row_indices != slice(None):
rmat = rmat[slicer.row_indices, :]

if slicer.col_indices != slice(None):
rmat = rmat[:, slicer.col_indices]
rmat = rmat[slicer.col_indices, :]

new_reduced_dims[rdim] = rmat

new_alt_expts = {}
for altname, altexpt in self._alternative_experiments.items():
if slicer.row_indices != slice(None):
altexpt = altexpt[rows, :]
altexpt = altexpt[slicer.row_indices, :]

if slicer.col_indices != slice(None):
altexpt = altexpt[:, slicer.col_indices]
Expand All @@ -944,16 +941,10 @@ def get_slice(
if slicer.row_indices != slice(None):
rpair = rpair[slicer.row_indices, :]

if slicer.col_indices != slice(None):
rpair = rpair[:, slicer.col_indices]

new_row_pairs[rname] = rpair

new_col_pairs = {}
for cname, cpair in self._column_pairs.items():
if slicer.row_indices != slice(None):
cpair = cpair[slicer.row_indices, :]

if slicer.col_indices != slice(None):
cpair = cpair[:, slicer.col_indices]

Expand Down
5 changes: 4 additions & 1 deletion tests/test_sce_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@

def test_SCE_slice():
tse = SingleCellExperiment(
assays={"counts": counts}, row_data=row_data, column_data=col_data
assays={"counts": counts},
row_data=row_data,
column_data=col_data,
reduced_dims={"random_embeds": np.random.rand(ncols, 5)},
)

tse_slice = tse[0:10, 0:3]
Expand Down

0 comments on commit d759ba6

Please sign in to comment.