Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
joyceyan committed Dec 9, 2024
1 parent 6de64f6 commit 8f03e2a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
10 changes: 0 additions & 10 deletions cellxgene_schema_cli/cellxgene_schema/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,6 @@ def read_h5ad(h5ad_path: Union[str, bytes, os.PathLike]) -> ad.AnnData:
"""
try:
adata = ad.read_h5ad(h5ad_path, backed="r")

# This code, and AnnData in general, is optimized for row access.
# Running backed, with CSC, is prohibitively slow. Read the entire
# AnnData into memory if it is CSC.
if (get_matrix_format(adata, adata.X) == "csc") or (
(adata.raw is not None) and (get_matrix_format(adata, adata.raw.X) == "csc")
):
logger.warning("Matrices are in CSC format; loading entire dataset into memory.")
adata = adata.to_memory()

except (OSError, TypeError):
logger.info(f"Unable to open '{h5ad_path}' with AnnData")
sys.exit(1)
Expand Down
16 changes: 16 additions & 0 deletions cellxgene_schema_cli/cellxgene_schema/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,20 @@ def _validate_uns_dict(self, uns_dict: dict) -> None:
self.errors.append(
f"Colors in uns[{key}] must be either all hex colors or all CSS4 named colors. Found: {value}"
)

def _validate_X(self):
to_validate = [(self.adata.X, "X")]

# check if there's raw data
if self.adata.raw:
to_validate.append((self.adata.raw.X, "raw.X"))

for x, x_name in to_validate:
matrix_format = get_matrix_format(self.adata, x)
if matrix_format != "csr":
self.errors.append(
f"Matrix '{x_name}' is not a 'scipy.sparse.csr_matrix'. Please convert to CSR format."
)

def _validate_sparsity(self):
"""
Expand Down Expand Up @@ -2055,6 +2069,8 @@ def _deep_check(self):
logger.debug("Validating sparsity...")
self._validate_sparsity()

self._validate_X()

# Checks spatial
self._check_spatial()

Expand Down

0 comments on commit 8f03e2a

Please sign in to comment.