Skip to content

Commit a5b2fc6

Browse files
Müller-Bötticherniklasmueboe
authored andcommitted
celltype signatures of anndata layers
1 parent abf98b7 commit a5b2fc6

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

sainsc/utils/_signatures.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@ def celltype_signatures(
88
adata: ad.AnnData,
99
*,
1010
celltype_col: str = "leiden",
11+
layer: str | None = None,
1112
agg_method: str | Callable = "mean",
1213
) -> pd.DataFrame:
1314
"""
1415
Calculate gene expression signatures per 'celltype'.
1516
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.
1819
1920
Parameters
2021
----------
2122
adata : anndata.AnnData
2223
celltype_col : str, optional
2324
Name of column in :py:attr:`anndata.AnnData.obs` containing cell-type
2425
information.
26+
layer : str, optional
27+
Which layer to use for aggregation. If `None`, `adata.X` is used.
2528
agg_method : str or collections.abc.Callable, optional
2629
Function to aggregate gene expression per cluster used by
2730
:py:meth:`pandas.DataFrame.agg`.
@@ -32,7 +35,7 @@ def celltype_signatures(
3235
:py:class:`pandas.DataFrame` of gene expression aggregated per 'celltype'.
3336
"""
3437
signatures = (
35-
adata.to_df()
38+
adata.to_df(layer=layer)
3639
.merge(adata.obs[celltype_col], left_index=True, right_index=True)
3740
.groupby(celltype_col, observed=True, sort=False)
3841
.agg(agg_method)

0 commit comments

Comments
 (0)