@@ -8,20 +8,23 @@ def celltype_signatures(
8
8
adata : ad .AnnData ,
9
9
* ,
10
10
celltype_col : str = "leiden" ,
11
+ layer : str | None = None ,
11
12
agg_method : str | Callable = "mean" ,
12
13
) -> pd .DataFrame :
13
14
"""
14
15
Calculate gene expression signatures per 'celltype'.
15
16
16
- Note, that this will make a dense copy of `adata.X` therefore potentially leading
17
- to large memory usage.
17
+ Note, that this will make a dense copy of `adata.X` or the selected `layer`,
18
+ therefore potentially leading to large memory usage.
18
19
19
20
Parameters
20
21
----------
21
22
adata : anndata.AnnData
22
23
celltype_col : str, optional
23
24
Name of column in :py:attr:`anndata.AnnData.obs` containing cell-type
24
25
information.
26
+ layer : str, optional
27
+ Which layer to use for aggregation. If `None`, `adata.X` is used.
25
28
agg_method : str or collections.abc.Callable, optional
26
29
Function to aggregate gene expression per cluster used by
27
30
:py:meth:`pandas.DataFrame.agg`.
@@ -32,7 +35,7 @@ def celltype_signatures(
32
35
:py:class:`pandas.DataFrame` of gene expression aggregated per 'celltype'.
33
36
"""
34
37
signatures = (
35
- adata .to_df ()
38
+ adata .to_df (layer = layer )
36
39
.merge (adata .obs [celltype_col ], left_index = True , right_index = True )
37
40
.groupby (celltype_col , observed = True , sort = False )
38
41
.agg (agg_method )
0 commit comments