Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
Closes #260
Browse files Browse the repository at this point in the history
  • Loading branch information
dweemx committed Nov 30, 2020
1 parent 228276f commit 2b1bd4e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/utils/bin/sc_h5ad_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import scanpy as sc
import numpy as np
import anndata as ad
from scipy.sparse import csr_matrix
from collections import OrderedDict

parser = argparse.ArgumentParser(description='')
Expand Down Expand Up @@ -41,9 +42,16 @@

index_unique = None

if not all([np.array_equal(adatas[0].X, _adata.X) for _adata in adatas]):

def is_same_matrix(mat1, mat2):
if type(mat1) == np.ndarray and type(mat2) == np.ndarray:
return np.array_equal(mat1, mat2)
return (mat1 != mat2).nnz == 0


if not all([is_same_matrix(mat1=adatas[0].X, mat2=_adata.X) for _adata in adatas]):
raise Exception("VSN ERROR: adata.X slots are not the same between h5ad files.")
if not all([(adatas[0].raw.X != _adata.raw.X).nnz == 0 for _adata in adatas]):
if not all([is_same_matrix(mat1=adatas[0].raw.X, mat2=_adata.raw.X) for _adata in adatas]):
# Source: https://stackoverflow.com/questions/30685024/check-if-two-scipy-sparse-csr-matrix-are-equal
raise Exception("VSN ERROR: adata.raw.X slots are not the same between h5ad files.")
if not all([np.array_equal(adatas[0].obs.index, _adata.obs.index) for _adata in adatas]):
Expand Down

0 comments on commit 2b1bd4e

Please sign in to comment.