File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ def __init__(
9696 # because of transpose we check if its csr
9797 if issparse (counts ) and not isinstance (counts , csr_matrix ):
9898 warnings .warn (
99- "Hotspot will work faster when counts are a csc sparse matrix."
99+ "Hotspot will work faster when counts are a csr sparse matrix."
100100 )
101101
102102 if tree is not None :
@@ -129,11 +129,24 @@ def __init__(
129129 if model not in valid_models :
130130 raise ValueError ("Input `model` should be one of {}" .format (valid_models ))
131131
132- valid_genes = counts .sum (axis = 1 ) > 0
132+ if issparse (counts ):
133+ # For a sparse matrix, check if all values in each row are identical
134+ # A row (gene) is considered valid if it has more than one unique value.
135+ row_min = counts .min (axis = 1 ).toarray ().flatten ()
136+ row_max = counts .max (axis = 1 ).toarray ().flatten ()
137+ valid_genes = (
138+ row_min != row_max
139+ ) # Valid if min and max are not equal, indicating variation
140+ else :
141+ # For a dense matrix, check if all values in each row are identical
142+ valid_genes = ~ (np .all (counts == counts [:, [0 ]], axis = 1 ))
143+
144+ # valid_genes is now a boolean array indicating which rows (genes) have non-identical values.
145+
133146 n_invalid = counts .shape [0 ] - valid_genes .sum ()
134147 if n_invalid > 0 :
135148 raise ValueError (
136- "\n Detected all zero genes . Please filter adata and reinitialize."
149+ "\n Detected genes with zero variance . Please filter adata and reinitialize."
137150 )
138151
139152 self .adata = adata
You can’t perform that action at this time.
0 commit comments