scanpy.tl.score_genes#

scanpy.tl.score_genes(adata, gene_list, *, ctrl_as_ref=True (sc.settings.preset='scanpy-v1' – changes in 2.0), ctrl_size=50, gene_pool=None, n_bins=25, use=None, out=False, rng=None, score_name=None, copy=False, use_raw=None, layer=None)[source]#

Score a set of genes [Tirosh et al., 2016].

The score is the average expression of a set of genes after subtraction by the average expression of a reference set of genes. The reference set is randomly sampled from the gene_pool for each binned expression value.

This reproduces the approach in Seurat [Tirosh et al., 2016] (“MITF and AXL expression programs and cell scores” in materials and methods) and has been implemented for Scanpy by Davide Cittaro.

Array type support#

Array type

supported

… experimentally in dask Array

numpy.ndarray

✅

❌

scipy.sparse.{csr,csc}_{array,matrix}

✅

❌

Parameters:
adata AnnData

The annotated data matrix.

gene_list Sequence[str] | pd.Index[str]

The list of gene names used for score calculation.

ctrl_as_ref bool | Default (default: True (sc.settings.preset='scanpy-v1' – changes in 2.0))

Allow the algorithm to use the control genes as reference. Will be changed to False in scanpy 2.0.

ctrl_size int (default: 50)

Number of reference genes to be sampled from each bin. If len(gene_list) is not too low, you can set ctrl_size=len(gene_list).

gene_pool Sequence[str] | pd.Index[str] | None (default: None)

Genes for sampling the reference set. Default is all genes.

n_bins int (default: 25)

Number of expression level bins for sampling.

use LayerAcc | str | None (default: None)

Which matrix to score on. Given by an accessor, e.g. A.X or A.layers['counts']. strs are anndata.acc.AdAcc.resolve()d, e.g. 'layers.counts'.

layer str | None (default: None)

Deprecated since version 1.13.0: Use use instead.

A key of layers, i.e. layer='k' is use=A.layers['k'].

out AdRef[Idx2D | int, AnnData] | str | str | bool (default: False)

Where to write the result, e.g. A.obs['score']. strs are anndata.acc.AdAcc.resolve()d, e.g. 'obs.score'. If True, the result is returned instead of written. If False, it is written to .obs['score'].

rng int | integer | Sequence[int] | SeedSequence | Generator | BitGenerator | None (default: None)

Random number generation to control stochasticity.

If a type:SeedLike value, it’s used to seed a new random number generator; If a numpy.random.Generator, rng’s state will be directly advanced; If None, a non-reproducible random number generator is used. See numpy.random.default_rng() for more details.

The default value matches legacy scanpy behavior and will change to None in scanpy 2.0.

score_name str | None (default: None)

Deprecated since version 1.13.0: Use out instead.

A column of obs, i.e. score_name='k' is out=A.obs['k'].

copy bool (default: False)

Deprecated since version 1.13.0: Copy adata before calling this function instead.

Whether to return a modified copy instead of modifying adata in place.

use_raw bool | None (default: None)

Deprecated since version 1.13.0: raw is deprecated. Keep the data in a layer instead.

Whether to use raw attribute of adata. Defaults to True if .raw is present.

Changed in version 1.4.5: Default value changed from False to None.

Return type:

AnnData | Series | None

Returns:

Returns None if the result was written, else the scores as a Series. By default sets the following field (see out for others):

adata.obs['score']numpy.ndarray (dtype float)

Scores of each cell.

Examples

See this notebook.