Skip to content

Commit 8c6aa07

Browse files
authored
Fix validation when some cells or genes are unexpessed (#82)
1 parent f73bbd2 commit 8c6aa07

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog
22

3-
## Version 0.5.3 - 0.5.4
3+
## Version 0.5.3 - 0.5.5
44

55
- 'config' is renamed to 'context_or_config' to accept both TileDB's context or config objects. This supports in-memory TileDB contexts from [Phil](https://github.com/hanslovsky) [[#79](https://github.com/TileOme/cellarr/pull/79)].
66
- Fixes the condition for path to assay groups.

src/cellarr/CellArrDataset.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
from functools import lru_cache
3131
from typing import List, Optional, Sequence, Union
32+
from warnings import warn
3233

3334
import pandas as pd
3435
import tiledb
@@ -173,12 +174,26 @@ def __init__(
173174

174175
def _validate(self):
175176
num_cells = self._cell_metadata_tdb.nonempty_domain()[0][1]
176-
num_rows = self._gene_annotation_tdb.nonempty_domain()[0][1]
177+
num_feats = self._gene_annotation_tdb.nonempty_domain()[0][1]
177178

178179
for mname, muri in self._matrix_tdb.items():
179180
dom = muri.nonempty_domain()
180-
if dom[0][1] != num_cells or dom[1][1] != num_rows:
181-
raise RuntimeError(f"Matrix {mname} has incorrect dimensions")
181+
if dom[0][1] != num_cells:
182+
warn(
183+
f"Matrix {mname} has fewer cells than expected - some cells may not have any gene expression.",
184+
UserWarning,
185+
)
186+
if dom[0][1] > num_cells:
187+
raise RuntimeError(f"Matrix {mname} has more cells than expected.")
188+
189+
if dom[1][1] != num_feats:
190+
warn(
191+
f"Matrix {mname} has fewer genes than expected - some genes may not be expressed in any cells.",
192+
UserWarning,
193+
)
194+
195+
if dom[1][1] > num_feats:
196+
raise RuntimeError(f"Matrix {mname} has more genes than expected.")
182197

183198
def __del__(self):
184199
self._gene_annotation_tdb.close()

0 commit comments

Comments
 (0)