scviva.tools.vision.apply_filters#

scviva.tools.vision.apply_filters(X, gene_names, filters=('threshold', 'fano'), threshold=10, num_mad=2.0)[source]#

Apply one or more gene filters sequentially and return a boolean gene mask.

Each filter in filters is applied in order; its result overwrites the previous one, mirroring R VISION’s applyFilters behaviour.

Available filters#

"novar"

Remove genes with zero variance across cells.

"threshold"

Remove genes expressed in fewer than threshold cells.

"fano"

Apply threshold filtering first, then retain only overdispersed genes using the Fano factor within mean-expression bins. Because the fano filter embeds a threshold step, passing both "threshold" and "fano" gives the same result as passing just "fano".

param X:

Expression matrix, cells × genes.

type X:

ndarray | spmatrix

param gene_names:

Gene identifiers corresponding to columns of X. Used for logging; the returned mask is aligned to this ordering.

type gene_names:

ndarray

param filters:

Ordered list of filter names to apply, by default ("threshold", "fano").

type filters:

Sequence[Literal['novar', 'threshold', 'fano']]

param threshold:

Minimum number of expressing cells for threshold / fano filters, by default 10.

type threshold:

int

param num_mad:

MAD multiplier for the fano filter, by default 2.0.

type num_mad:

float

rtype:

ndarray

returns:

np.ndarray Boolean mask of shape (n_genes,); True for genes retained after all filters.

raises ValueError:

If an unrecognised filter name is provided.

Examples

>>> mask = apply_filters(adata.X, adata.var_names)
>>> adata_filtered = adata[:, mask].copy()