scviva.tools.vision.filter_genes_fano#
- scviva.tools.vision.filter_genes_fano(X, num_mad=2.0, n_bins=30, max_cells=50000, random_state=0)[source]#
Select overdispersed genes via within-bin Fano factor filtering.
Genes are ranked by mean expression and divided into n_bins equal-size bins. Within each bin the median and MAD of the Fano factor (variance / mean) are computed; genes whose Fano factor exceeds
median + num_mad * MADare retained.- Parameters:
- X
ndarray|spmatrix Expression matrix, cells × genes.
- num_mad
float Number of median absolute deviations above the within-bin median Fano required to pass, by default 2.0.
- n_bins
int Number of mean-expression bins, by default 30.
- max_cells
int If the dataset exceeds this many cells, subsample max_cells rows for computing gene statistics, by default 50,000.
- random_state
int|Generator|None Seed (or generator) for the subsampling above
max_cells, for reproducible gene selection. Defaults to0.
- X
- Return type:
- Returns:
np.ndarray Boolean mask of shape (n_genes,);
Truefor genes that pass.
Notes
Genes with zero mean expression have their Fano factor set to 0 so they fall below any reasonable within-bin threshold; they are effectively excluded without producing NaN values.
This is a deliberate deviation from R VISION’s actual behavior, not an oversight: R’s
filterGenesFanocomputesfano <- var/muwith no zero-mean guard, so a single unexpressed gene produces0/0 = NaN, which (via R’smedian()having nona.rm) silently zeroes out every gene in that gene’s expression-level bin, not just the zero-mean one – R’s own attempted fix for this (mu_quant[mu_quant == 0] <- 1) is itself dead code, sincemu_quantis never read again afterwards. This implementation intentionally does not reproduce that bug: only the zero-mean gene itself is excluded, so Python can retain genes that R would silently (and unintentionally) drop.