Skip to content

Commit e9e0eb6

Browse files
authored
Remove the confusing expansion of feature intervals (#18)
1 parent d3cc814 commit e9e0eb6

File tree

4 files changed

+33
-27
lines changed

4 files changed

+33
-27
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Changelog
22

3-
## Version 0.2.1
3+
## Version 0.2.1 - 0.2.2
44

55
- The aggregate function is expected to return either a scalar value or a 1-dimensional NumPy ndarray. If the later, users need to specify the expected dimension of the summarization. All values will be flattenned eventually.
6+
- Remove expanding the intervals to conform to output length; this is now incompatible with coercions to anndata and summarized experiments and has been removed.
67

78
## Version 0.2.0
89

src/genomicarrays/GenomicArrayDataset.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,22 +287,23 @@ def get_slice(
287287

288288
if not isinstance(feature_subset, (int, slice)):
289289
raise TypeError("feature indices must be continous; either a 'slice' or 'int' index.")
290+
290291
_fsubset = self.get_feature_subset(feature_subset)
291292
start_findex = _fsubset["genarr_feature_start_index"].astype(int).min()
292293
end_findex = _fsubset["genarr_feature_end_index"].astype(int).max()
293294

294295
# expand intervals
295-
final_rows = []
296-
for row in _fsubset.itertuples():
297-
for i, _ in enumerate(range(int(row.genarr_feature_start_index), int(row.genarr_feature_end_index))):
298-
final_rows.append(row._replace(starts=i + row.starts, ends=i + row.starts + 1))
299-
_feature_df = pd.DataFrame(final_rows)
296+
# final_rows = []
297+
# for row in _fsubset.itertuples():
298+
# for i, _ in enumerate(range(int(row.genarr_feature_start_index), int(row.genarr_feature_end_index))):
299+
# final_rows.append(row._replace(starts=i + row.starts, ends=i + row.starts + 1))
300+
# _feature_df = pd.DataFrame(final_rows)
300301

301302
_msubset = self.get_matrix_subset((list(range(start_findex, end_findex)), _sample_indices))
302303

303304
return GenomicArrayDatasetSlice(
304305
_ssubset,
305-
_feature_df,
306+
_fsubset,
306307
_msubset,
307308
)
308309

src/genomicarrays/GenomicArrayDatasetSlice.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,22 @@ class GenomicArrayDatasetSlice:
5151
## Interop
5252
####
5353

54-
def to_anndata(self):
55-
"""Convert the realized slice to :py:class:`~anndata.AnnData`."""
56-
return anndata.AnnData(
57-
layers={"matrix": self.matrix.transpose()},
58-
obs=self.sample_metadata,
59-
var=self.feature_annotation,
60-
)
61-
62-
def to_rangedsummarizedexperiment(self):
63-
"""Convert the realized slice to
64-
:py:class:`~summarizedexperiment.RangedSummarizedExperiment.RangedSummarizedExperiment`."""
65-
return se.RangedSummarizedExperiment(
66-
assays={"matrix": self.matrix},
67-
row_ranges=gr.GenomicRanges.from_pandas(self.feature_annotation),
68-
column_data=self.sample_metadata,
69-
)
54+
# def to_anndata(self):
55+
# """Convert the realized slice to :py:class:`~anndata.AnnData`."""
56+
# return anndata.AnnData(
57+
# layers={"matrix": self.matrix.transpose()},
58+
# obs=self.sample_metadata,
59+
# var=self.feature_annotation,
60+
# )
61+
62+
# def to_rangedsummarizedexperiment(self):
63+
# """Convert the realized slice to
64+
# :py:class:`~summarizedexperiment.RangedSummarizedExperiment.RangedSummarizedExperiment`."""
65+
# return se.RangedSummarizedExperiment(
66+
# assays={"matrix": self.matrix},
67+
# row_ranges=gr.GenomicRanges.from_pandas(self.feature_annotation),
68+
# column_data=self.sample_metadata,
69+
# )
7070

7171
####
7272
## Misc methods.

tests/test_query.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ def test_query_agg():
9393

9494
result1 = cd.get_slice(slice(0, 5), slice(None))
9595
assert result1 is not None
96+
assert len(result1.feature_annotation) == 6
97+
assert len(result1.sample_metadata) == 2
9698
assert result1.matrix.shape == (6, 2)
9799

98-
assert result1.to_anndata() is not None
99-
assert result1.to_rangedsummarizedexperiment() is not None
100+
# assert result1.to_anndata() is not None
101+
# assert result1.to_rangedsummarizedexperiment() is not None
100102

101103

102104
def test_query_noagg():
@@ -165,7 +167,9 @@ def test_query_noagg():
165167

166168
result1 = cd.get_slice(slice(0, 5), slice(None))
167169
assert result1 is not None
170+
assert len(result1.feature_annotation) == 6
171+
assert len(result1.sample_metadata) == 2
168172
assert result1.matrix.shape == (90, 2)
169173

170-
assert result1.to_anndata() is not None
171-
assert result1.to_rangedsummarizedexperiment() is not None
174+
# assert result1.to_anndata() is not None
175+
# assert result1.to_rangedsummarizedexperiment() is not None

0 commit comments

Comments
 (0)