Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ repos:
docs/references.bib|
)
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v22.1.4
rev: v22.1.5
hooks:
- id: clang-format
args: [--style=file, -i]
Expand Down
10 changes: 10 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,17 @@ Then run the following command to execute the container:
```bash
apptainer run --nv rsc.sif
```
### Running on HPC systems with SLURM

When running on HPC systems via SLURM, conda must be explicitly activated before running Python scripts. Use `apptainer exec` instead of `apptainer run`:

```bash
apptainer exec --nv \
--bind /path/to/your/data:/path/to/your/data \
rsc.sif \
bash -c "source /opt/conda/etc/profile.d/conda.sh && conda activate base && python"
```
Without sourcing conda first, `CONDA_PREFIX` will be unset and CuPy will fail to locate the CUDA libraries inside the container, resulting in a `TypeError: expected str, bytes or os.PathLike object, not NoneType` error.

# System requirements

Expand Down
11 changes: 11 additions & 0 deletions docs/release-notes/0.15.1.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
### 0.15.1 {small}`the-future`

```{rubric} Features
```
* ``tl.leiden`` and ``tl.louvain`` now record the final modularity value in ``adata.uns[key_added]["modularity"]``
(scalar for a single resolution, list for multiple resolutions) {pr}`648` {smaller}`J Pintar`

```{rubric} Bug fixes
```
* Fixes `tl.rank_genes_groups` returning NaN/zero `logfoldchanges`/`pvals` with `groups=[subset]` and `reference='rest'` {pr}`651` {smaller}`S Dicks`

```{rubric} Misc
```
* ``adata.uns[key_added]["params"]["resolution"]`` is now stored as a scalar ``float`` when a single resolution
is passed to ``tl.leiden`` and ``tl.louvain`` to match behaviour in Scanpy, and as a ``list`` when multiple
resolutions are passed. Previously it was always stored as a list. {pr}`648`. {smaller}`J Pintar`
2 changes: 0 additions & 2 deletions docs/release-notes/blank.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
```{rubric} Performance
```


```{rubric} Bug fixes
```


```{rubric} Misc
```

Expand Down
18 changes: 14 additions & 4 deletions src/rapids_singlecell/tools/_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ def leiden(
resolutions = [resolution]
else:
resolutions = resolution
modularities = []
for resolution in resolutions:
leiden_parts, _ = culeiden(
leiden_parts, modularity = culeiden(
g,
resolution=resolution,
random_state=random_state,
Expand All @@ -241,6 +242,7 @@ def leiden(
leiden_parts = leiden_parts.to_backend("pandas").compute()
else:
leiden_parts = leiden_parts.to_pandas()
modularities.append(modularity)

# Format output
groups = leiden_parts.sort_values("vertex")[["partition"]].to_numpy().ravel()
Expand Down Expand Up @@ -270,10 +272,13 @@ def leiden(
# store information on the clustering parameters
adata.uns[key_added] = {}
adata.uns[key_added]["params"] = {
"resolution": resolutions,
"resolution": resolutions if len(resolutions) > 1 else resolutions[0],
"random_state": random_state,
"n_iterations": n_iterations,
}
adata.uns[key_added]["modularity"] = (
modularities if len(modularities) > 1 else modularities[0]
)
return adata if copy else None


Expand Down Expand Up @@ -383,8 +388,9 @@ def louvain(
resolutions = [resolution]
else:
resolutions = resolution
modularities = []
for resolution in resolutions:
louvain_parts, _ = culouvain(
louvain_parts, modularity = culouvain(
g,
resolution=resolution,
max_level=n_iterations,
Expand All @@ -394,6 +400,7 @@ def louvain(
louvain_parts = louvain_parts.to_backend("pandas").compute()
else:
louvain_parts = louvain_parts.to_pandas()
modularities.append(modularity)

# Format output
groups = louvain_parts.sort_values("vertex")[["partition"]].to_numpy().ravel()
Expand Down Expand Up @@ -422,10 +429,13 @@ def louvain(
Comms.destroy()
adata.uns[key_added] = {}
adata.uns[key_added]["params"] = {
"resolution": resolutions,
"resolution": resolutions if len(resolutions) > 1 else resolutions[0],
"n_iterations": n_iterations,
"threshold": threshold,
}
adata.uns[key_added]["modularity"] = (
modularities if len(modularities) > 1 else modularities[0]
)
return adata if copy else None


Expand Down
5 changes: 5 additions & 0 deletions tests/test_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,13 @@ def test_clustering_resolution(adata_neighbors, clustering_function, resolution)
if isinstance(resolution, list):
for r in resolution:
assert f"test_clustering_{r}" in adata.obs.columns
assert isinstance(adata.uns["test_clustering"]["modularity"], list)
assert len(adata.uns["test_clustering"]["modularity"]) == len(resolution)
assert adata.uns["test_clustering"]["params"]["resolution"] == resolution
else:
assert "test_clustering" in adata.obs.columns
assert isinstance(adata.uns["test_clustering"]["modularity"], float)
assert adata.uns["test_clustering"]["params"]["resolution"] == resolution


def test_kmeans_basic(adata_neighbors):
Expand Down