scanpy.tl.filter_rank_genes_groups#

scanpy.tl.filter_rank_genes_groups(adata, *, key=None, groupby=None, layer=None, use_raw=None, key_added='rank_genes_groups_filtered', min_in_group_fraction=0.25, min_fold_change=1, max_out_group_fraction=0.5, compare_abs=False)[source]#

Filter out genes based on two criteria.

  1. log fold change and

  2. fraction of genes expressing the gene within and outside the groupby categories.

See rank_genes_groups().

Results are stored in adata.uns[key_added] (default: ‘rank_genes_groups_filtered’).

To preserve the original structure of adata.uns[‘rank_genes_groups’], filtered genes are set to NaN.

The log2 fold changes and fractions of expressing cells are taken from the rank_genes_groups() results if they are stored there ('logfoldchanges', and 'pts' and 'pts_rest' if pts=True was passed), groupby and use_raw are the same as for that call, and it compared each group to reference='rest'. Otherwise, they are computed from the expression values, comparing each group to all other cells.

Parameters:
adata AnnData

Annotated data matrix containing the results of rank_genes_groups().

key str | None (default: None)

The key in adata.uns where the results of rank_genes_groups() are stored (its key_added). Defaults to 'rank_genes_groups'.

groupby str | None (default: None)

The key of the observations grouping to consider. Defaults to the one used for rank_genes_groups().

layer str | None (default: None)

Key from adata.layers whose values are used when fractions or fold changes are computed. Defaults to adata.X (or adata.raw, see use_raw). Unlike use_raw, it is not taken from the results.

use_raw bool | None (default: None)

Use raw attribute of adata when fractions or fold changes are computed. Defaults to the value used for rank_genes_groups(), or to False if layer is specified.

key_added str (default: 'rank_genes_groups_filtered')

The key in adata.uns the filtered results are saved to.

min_in_group_fraction float (default: 0.25)

Only keep genes expressed (i.e. with a non-zero value) in more than this fraction of the cells in the group.

min_fold_change float (default: 1)

Only keep genes whose log2 fold change between the group and all other cells is greater than this. See compare_abs.

max_out_group_fraction float (default: 0.5)

Only keep genes expressed in less than this fraction of the cells outside the group.

compare_abs bool (default: False)

If True, compare absolute values of log fold change with min_fold_change.

Return type:

None

Returns:

Same output as scanpy.tl.rank_genes_groups() but with filtered genes names set to nan.

Examples

>>> import scanpy as sc
>>> adata = sc.datasets.pbmc68k_reduced()
>>> sc.tl.rank_genes_groups(adata, "bulk_labels", method="wilcoxon")
>>> sc.tl.filter_rank_genes_groups(adata, min_fold_change=3)
>>> # visualize results
>>> sc.pl.rank_genes_groups(adata, key="rank_genes_groups_filtered")
>>> # visualize results using dotplot
>>> sc.pl.rank_genes_groups_dotplot(adata, key="rank_genes_groups_filtered")