@@ -118,7 +118,32 @@ def _create_function(n_cls: int, parallel: bool = False) -> Callable[[NDArrayA,
118118 return globals ()[fn_key ] # type: ignore[no-any-return]
119119
120120
121- def filter_clusters_by_min_cell_count (adata , int_clust , connectivity_key , min_cell_count ):
121+ def filter_clusters_by_min_cell_count (
122+ adata : AnnData ,
123+ int_clust : NDArrayA ,
124+ connectivity_key : str ,
125+ min_cell_count : int ,
126+ ) -> tuple [NDArrayA , NDArrayA ]:
127+ """
128+ Filter clusters by minimum cell count.
129+
130+ Parameters
131+ ----------
132+ %(adata)s
133+ int_clust
134+ Array of cluster labels per cell
135+ connectivity_key
136+ Key in adata.obsp with adjacency matrix
137+ min_cell_count
138+ Minimum number of cells required to keep a cluster
139+
140+ Returns
141+ -------
142+ int_clust_filtered
143+ Filtered cluster labels
144+ adj
145+ Adjacency matrix corresponding to filtered cells
146+ """
122147 clust_sizes = pd .Series (int_clust ).value_counts ()
123148 valid_clusters = clust_sizes [clust_sizes >= min_cell_count ].index .to_numpy ()
124149
@@ -147,7 +172,7 @@ def nhood_enrichment(
147172 min_cell_count : int = 10 ,
148173 handle_nan : str = "keep" ,
149174 show_progress_bar : bool = True ,
150- ) -> tuple [NDArrayA , NDArrayA ] | None :
175+ ) -> tuple [NDArrayA , NDArrayA ] | tuple [ NDArrayA , NDArrayA , NDArrayA ] | None :
151176 """
152177 Compute neighborhood enrichment by permutation test.
153178
@@ -211,7 +236,7 @@ def nhood_enrichment(
211236
212237 _test = _create_function (n_cls , parallel = numba_parallel )
213238 count = _test (indices , indptr , int_clust )
214- conditional_ratio = None
239+ conditional_ratio = np . full (( n_cls , n_cls ), np . nan , dtype = np . float64 )
215240
216241 if normalization == "total" :
217242 row_sums = count .sum (axis = 1 , keepdims = True )
@@ -568,7 +593,6 @@ def _nhood_enrichment_helper(
568593 has_b_neighbor = per_cell_neighbor_matrix [a_cells , b ]
569594 cond_counts [a , b ] = has_b_neighbor .sum ()
570595
571- low_count_mask = cond_counts < min_cond_count
572596 cond_counts [cond_counts == 0 ] = 1.0
573597 count_perms = count_perms / cond_counts
574598
0 commit comments