scanpy.tl.filter_rank_genes_groups#
- scanpy.tl.filter_rank_genes_groups(adata, *, key=None, groupby=None, use=None, use_raw=None, min_in_group_fraction=0.25, min_fold_change=1, max_out_group_fraction=0.5, compare_abs=False, out=False, key_added=None)[source]#
Filter out genes based on two criteria.
log fold change and
fraction of genes expressing the gene within and outside the
groupbycategories.
See
rank_genes_groups().Results are stored in
adata.uns['rank_genes_groups_filtered'](seeout).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'ifpts=Truewas passed),groupbyanduse_raware the same as for that call, and it compared each group toreference='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.unswhere the results ofrank_genes_groups()are stored (itskey_added). Defaults to'rank_genes_groups'.- groupby
AdRef|str|None(default:None) The key of the observations grouping to consider. Defaults to the one used for
rank_genes_groups().- use
LayerAcc|str|None(default:None) Which matrix to compute fractions and fold changes from. Defaults to
A.X(oradata.raw, seeuse_raw). Given by an accessor, e.g.A.XorA.layers['counts'].strs areanndata.acc.AdAcc.resolve()d, e.g.'layers.counts'. Unlikeuse_raw, it is not taken from the results.- use_raw
bool|None(default:None) Deprecated since version 1.13.0:
rawis deprecated. Keep the data in a layer instead.Use
rawattribute ofadatawhen fractions or fold changes are computed. Defaults to the value used forrank_genes_groups(), or toFalseifuseis specified.- 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 withmin_fold_change.- out
bool(default:False) Where to write the filtered results. If
True, the filtered results is returned instead of written. IfFalse, it is written to.uns['rank_genes_groups_filtered'].- key_added
str|None(default:None) Name of the
unsentry to write to instead (until there are.unsaccessors).
- adata
- Return type:
- Returns:
Same output as
scanpy.tl.rank_genes_groups()but with filtered genes names set tonan. Returned as adictifout=True, elseNone.
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")