Skip to content

Commit aeb6953

Browse files
authored
Updated tl.rankby_obsm function to optionally accept obs keys
2 parents 545c96a + a492d45 commit aeb6953

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning][].
88
[keep a changelog]: https://keepachangelog.com/en/1.0.0/
99
[semantic versioning]: https://semver.org/spec/v2.0.0.html
1010

11+
## 2.1.2
12+
13+
### Changes
14+
15+
- `tl.rankby_obsm` now accepts `AnnData.obs` column names specified in the `obs_keys` argument.
16+
1117
## 2.1.1
1218

1319
### Added

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ requires = [ "hatchling" ]
44

55
[project]
66
name = "decoupler"
7-
version = "2.1.1"
7+
version = "2.1.2"
88
description = "Python package to perform enrichment analysis from omics data."
99
readme = "README.md"
1010
license = { file = "LICENSE" }

src/decoupler/tl/_rankby_obsm.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ def _input_rank_obsm(
3131

3232
@docs.dedent
3333
def rankby_obsm(
34-
adata: AnnData,
35-
key: str,
36-
uns_key: str | None = "rank_obsm",
34+
adata: AnnData, key: str, uns_key: str | None = "rank_obsm", obs_keys: list | None = None
3735
) -> None | pd.DataFrame:
3836
"""
3937
Ranks features in ``adata.obsm`` by the significance of their association with metadata in ``adata.obs``.
@@ -48,6 +46,8 @@ def rankby_obsm(
4846
%(key)s
4947
uns_key
5048
``adata.uns`` key to store the results.
49+
obs_keys
50+
list of columns in adata.obs to use for testing.
5151
5252
Returns
5353
-------
@@ -64,10 +64,17 @@ def rankby_obsm(
6464
sc.pp.scale(adata)
6565
sc.tl.pca(adata)
6666
dc.tl.rankby_obsm(adata, "X_pca")
67+
68+
# or, to perform based on a subset of obs columns.
69+
dc.tl.rankby_obsm(adata, "X_pca", obs_keys=["condition"])
6770
"""
6871
assert isinstance(uns_key, str) or uns_key is None, "uns_key must be str or None"
6972
# Extract
7073
df, x_vars, y_vars = _input_rank_obsm(adata=adata, key=key)
74+
75+
if obs_keys is not None:
76+
x_vars = obs_keys
77+
7178
# Test
7279
res = []
7380
for x_var in x_vars:

0 commit comments

Comments
 (0)